Files
PerzeptronLabor/Online-IDE-json/PerzeptronLabor.json

1 line
5.3 KiB
JSON

{"name":"PerzeptronLabor","modules":[{"name":"Start","text":"// Zum Testen, zeigeTrainingsdaten kann nach Abschluss\n// eigentlich entfernt werden…\nLabor lab = new Labor();\nlab.ladeTrainingsdaten(\"daten.txt\");\nlab.zeigeTrainingsdaten();\nlab.zeigeGraph();\n//lab.leereGraph();\n","identical_to_repository_version":false,"repository_file_version":-1},{"name":"DataPoint.java","text":"public class DataPoint {\n private double x1;\n private double x2;\n private int label; // 0 für rot, 1 für grün\n private String name;\n\n public DataPoint(double x1, double x2, int label, String name) {\n this.x1 = x1;\n this.x2 = x2;\n this.label = label;\n this.name = name;\n }\n\n public String toString() {\n String retStr = \"\";\n retStr += this.name + \": \";\n retStr += this.label == 0 ? \"rot, \" : \"grün, \";\n retStr += \"x1: \" + String.valueOf(this.x1);\n retStr += \", x2: \" + String.valueOf(this.x2);\n return retStr;\n }\n\n double getX1()\n {\n return x1;\n }\n \n double getX2()\n {\n return x2;\n }\n\n String getName()\n {\n return name;\n }\n\n int getLabel()\n {\n return label;\n }\n\n}","identical_to_repository_version":false,"repository_file_version":-1},{"name":"Labor.java","text":"/**\n * Portierung des Perzeptron-Labors von Christoph Grässl für die Online-IDE.\n * \n * @author: Jan Bertram ( jbsoc@mailbox.org )\n */\npublic class Labor {\n ArrayList<DataPoint> trainingset;\n Graph g;\n\n public Labor() {\n trainingset = new ArrayList<>();\n g = new Graph(trainingset);\n }\n\n public void ladeTrainingsdaten(String workspaceFilename) {\n String fileAsString = Files.read(workspaceFilename);\n String[] lines = fileAsString.split(\"\\n\");\n for (String line : lines) {\n String[] items = line.split(\";\");\n // 0 Beschriftung, 1 Klasse, 2 x1, 3 x2\n if(items[0] != \"Beschriftung\") { // Zeile mit Beschriftung aussparen\n double x1 = Double.valueOf(items[2]);\n double x2 = Double.valueOf(items[3]);\n int klasse = Integer.valueOf(items[1]);\n String name = items[0]; \n DataPoint dp = new DataPoint(x1, x2, klasse, name);\n this.trainingset.add(dp);\n }\n }\n }\n\n public void zeigeGraph()\n {\n g.zeichnen();\n }\n\n public void leereGraph()\n {\n g.leeren();\n }\n\n public void zeigeTrainingsdaten() {\n for (DataPoint dp : this.trainingset) {\n println(dp);\n }\n }\n}\n","identical_to_repository_version":false,"repository_file_version":-1},{"name":"daten.txt","text":"Beschriftung;Klasse;Kalorien;Eiweiß\nErbsen;1;37;3\nGurken;1;4;0\nKarotten;1;29;1\nSpinat;1;12;2\nTomaten;1;16;1\nApfel;1;49;0\nAprikose;1;49;1\nBanane;1;70;1\nWassermelone;1;12;0\nAal;0;204;9\nForelle;0;50;10\nThunfisch;0;239;22\nLachs;0;137;13\nMakrele;0;124;12\nEnte;0;192;15\nPute;0;122;23\nSchwein;0;167;18\nCroissant;0;280;0\nDonut;0;295;3\nSemmel;0;276;7\nToastbrot;0;326;10\nWeizenbrot;0;235;8\nRührkuchen;0;430;6\nRoggenbrot;0;243;6","identical_to_repository_version":false,"repository_file_version":-1},{"name":"Graph.java","text":"class Graph\n{\n int breite = 500;\n int hoehe = 400;\n int rand = 15;\n\n ArrayList<DataPoint> trainingset;\n\n ArrayList<Shape> graphenobjekte;\n\n double streckenInX1Faktor = 0.8;\n double streckenInX2Faktor = 10;\n\n World w = new World(breite, hoehe);\n\n public Graph(ArrayList<DataPoint> t)\n {\n trainingset = t;\n graphenobjekte = new ArrayList<Shape>();\n w.setBackgroundColor(Color.whitesmoke); \n // x1-Achse\n Line x1_Achse = new Line(rand, hoehe - rand, breite - rand, hoehe - rand);\n x1_Achse.setBorderWidth(1);\n x1_Achse.setBorderColor(Color.black); \n Text x1_Label = new Text(breite - 2 * rand, hoehe - 2 * rand, 10, \"x1\"); \n x1_Label.setFillColor(Color.darkgrey);\n Triangle t1 = new Triangle(breite - rand, hoehe - rand + 5, breite - rand, hoehe - rand - 5, breite - rand + 10, hoehe - rand);\n t1.setFillColor(Color.black);\n // x2-Achse\n Line x2_Achse = new Line(rand, rand, rand, hoehe - rand);\n x2_Achse.setBorderWidth(1);\n x2_Achse.setBorderColor(Color.black);\n Text x2_Label = new Text(rand + 2, rand, 10, \"x2\"); \n x2_Label.setFillColor(Color.darkgrey);\n Triangle t2 = new Triangle(rand + 5, rand, rand - 5, rand, rand, rand - 10);\n t2.setFillColor(Color.black);\n }\n\n public void zeichnen()\n {\n for (DataPoint p : trainingset)\n {\n double x = p.getX1() * streckenInX1Faktor + rand;\n double y = -p.getX2() * streckenInX2Faktor - rand + hoehe;\n Circle c = new Circle(x, y, 5);\n Text t = new Text(x + 2, y + 2, 10, p.getName());\n t.setFillColor(Color.darkgrey);\n if(p.getLabel() == 1)\n {\n c.setFillColor(Color.greenyellow);\n }\n else {\n c.setFillColor(Color.red);\n }\n graphenobjekte.add(c);\n graphenobjekte.add(t);\n }\n }\n\n public void leeren()\n {\n for (Shape o : graphenobjekte)\n {\n o.destroy();\n }\n graphenobjekte.clear();\n }\n}\n ","identical_to_repository_version":false,"repository_file_version":-1}],"settings":{"libraries":[]}}