Compare commits
6 Commits
8f385622a4
...
koordinate
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d276e10d1 | |||
| aadbced16f | |||
| 577d83c925 | |||
| 9fcf9d8144 | |||
| cc914ab905 | |||
| eb314453b4 |
@@ -19,4 +19,25 @@ public class DataPoint {
|
||||
retStr += ", x2: " + String.valueOf(this.x2);
|
||||
return retStr;
|
||||
}
|
||||
|
||||
double getX1()
|
||||
{
|
||||
return x1;
|
||||
}
|
||||
|
||||
double getX2()
|
||||
{
|
||||
return x2;
|
||||
}
|
||||
|
||||
String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
int getLabel()
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
78
Online-IDE-files/Graph.java
Normal file
78
Online-IDE-files/Graph.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Graph-Klasse, die ein Trainingsset von Datenpunkten (DataPoint-Objekte)
|
||||
* entgegennimmt und diese nach Aufruf der Methode zeichnen() in einem
|
||||
* Koordinatensystem darstellt.
|
||||
*
|
||||
* @author: Sabine Schlötzer
|
||||
*/
|
||||
public class Graph
|
||||
{
|
||||
int breite = 500;
|
||||
int hoehe = 400;
|
||||
int rand = 15;
|
||||
|
||||
ArrayList<DataPoint> trainingset;
|
||||
|
||||
ArrayList<Shape> graphenobjekte;
|
||||
|
||||
// für x1-Werte bis etwa 500 (vgl. daten.txt)
|
||||
double streckenInX1Faktor = 0.8;
|
||||
// für x2-Werte bis etwa 25 (vgl. daten.txt)
|
||||
double streckenInX2Faktor = 10;
|
||||
|
||||
World w = new World(breite, hoehe);
|
||||
|
||||
public Graph(ArrayList<DataPoint> t)
|
||||
{
|
||||
trainingset = t;
|
||||
graphenobjekte = new ArrayList<Shape>();
|
||||
w.setBackgroundColor(Color.whitesmoke);
|
||||
// x1-Achse
|
||||
Line x1_Achse = new Line(rand, hoehe - rand, breite - rand, hoehe - rand);
|
||||
x1_Achse.setBorderWidth(1);
|
||||
x1_Achse.setBorderColor(Color.black);
|
||||
Text x1_Label = new Text(breite - 2 * rand, hoehe - 2 * rand, 10, "x1");
|
||||
x1_Label.setFillColor(Color.darkgrey);
|
||||
Triangle t1 = new Triangle(breite - rand, hoehe - rand + 5, breite - rand, hoehe - rand - 5, breite - rand + 10, hoehe - rand);
|
||||
t1.setFillColor(Color.black);
|
||||
// x2-Achse
|
||||
Line x2_Achse = new Line(rand, rand, rand, hoehe - rand);
|
||||
x2_Achse.setBorderWidth(1);
|
||||
x2_Achse.setBorderColor(Color.black);
|
||||
Text x2_Label = new Text(rand + 2, rand, 10, "x2");
|
||||
x2_Label.setFillColor(Color.darkgrey);
|
||||
Triangle t2 = new Triangle(rand + 5, rand, rand - 5, rand, rand, rand - 10);
|
||||
t2.setFillColor(Color.black);
|
||||
}
|
||||
|
||||
public void zeichnen()
|
||||
{
|
||||
for (DataPoint p : trainingset)
|
||||
{
|
||||
double x = p.getX1() * streckenInX1Faktor + rand;
|
||||
double y = -p.getX2() * streckenInX2Faktor - rand + hoehe;
|
||||
Circle c = new Circle(x, y, 5);
|
||||
Text t = new Text(x + 2, y + 2, 10, p.getName());
|
||||
t.setFillColor(Color.darkgrey);
|
||||
if(p.getLabel() == 1)
|
||||
{
|
||||
c.setFillColor(Color.greenyellow);
|
||||
}
|
||||
else {
|
||||
c.setFillColor(Color.red);
|
||||
}
|
||||
graphenobjekte.add(c);
|
||||
graphenobjekte.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
public void leeren()
|
||||
{
|
||||
for (Shape o : graphenobjekte)
|
||||
{
|
||||
o.destroy();
|
||||
}
|
||||
graphenobjekte.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
* Portierung des Perzeptron-Labors von Christoph Grässl für die Online-IDE.
|
||||
*
|
||||
* @author: Jan Bertram ( jbsoc@mailbox.org )
|
||||
* @author: Sabine Schlötzer
|
||||
*/
|
||||
public class Labor {
|
||||
ArrayList<DataPoint> trainingset;
|
||||
Graph g;
|
||||
|
||||
public Labor() {
|
||||
trainingset = new ArrayList<>();
|
||||
g = new Graph(trainingset);
|
||||
}
|
||||
|
||||
public void ladeTrainingsdaten(String workspaceFilename) {
|
||||
@@ -27,9 +30,20 @@ public class Labor {
|
||||
}
|
||||
}
|
||||
|
||||
public void zeigeGraph()
|
||||
{
|
||||
g.zeichnen();
|
||||
}
|
||||
|
||||
public void leereGraph()
|
||||
{
|
||||
g.leeren();
|
||||
}
|
||||
|
||||
public void zeigeTrainingsdaten() {
|
||||
for (DataPoint dp : this.trainingset) {
|
||||
println(dp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,4 +2,7 @@
|
||||
// eigentlich entfernt werden…
|
||||
Labor lab = new Labor();
|
||||
lab.ladeTrainingsdaten("daten.txt");
|
||||
lab.zeigeTrainingsdaten();
|
||||
// lab.zeigeTrainingsdaten();
|
||||
lab.zeigeGraph();
|
||||
//lab.leereGraph();
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user