@@ -25,73 +25,93 @@ public class DistanceClassification {
2525 private int [][] sortedProbability ;
2626
2727
28+ // --- Creating an object for distance classification --------------------------------------------------------------
2829 protected DistanceClassification (float [][] trainingDataPredictors , String [] trainingDataResults , int rowCount , int columnCount , float density ) {
30+ //Setting specific attributes
2931 this .trainingDataPredictors = trainingDataPredictors ;
3032 this .trainingDataResults = trainingDataResults ;
3133 this .rowCount = rowCount ;
3234 this .columnCount = columnCount ;
3335 this .density = density ;
3436
37+ // Getting the different classification classes
3538 getClassificationClasses ();
3639
40+ // Sorting the classification data
3741 sortClassificationData ();
3842
43+ // Calculating the mean per feature (to calculate the distance)
3944 calcFeatureMean ();
4045 }
4146
47+ // --- Functions for returning classification data for internal use in other classes -------------------------------
48+ // --- Function for returning the number of different classes
4249 protected int getNumberOfClasses () {
4350 return this .numberOfClasses ;
4451 }
4552
53+ // --- Function for returning the sorted classification data (after classification)
4654 protected float [][][] getSortedClassificationData () {
4755 return this .sortedClassificationData ;
4856 }
4957
58+ // --- Function for returning the predicted test data (probability per class)
5059 protected String [][][] getPredictedTestData () {
5160 return this .predictedTestData ;
5261 }
5362
63+ // --- Function for returning the sorted probability (ranking of the highest probability)
5464 protected int [][] getSortedProbability () {
5565 return this .sortedProbability ;
5666 }
5767
68+ // --- Function for returning the mean value per feature
5869 protected float [][] getFeatureMean () {
5970 return this .featureMean ;
6071 }
6172
73+ // --- Required Functions for classifying the data -----------------------------------------------------------------
74+ // All Functions have to been called in the ClassificationOfFloatValues.java file
75+
76+ // --- Function for setting the test data (with an upper and lower boundary -> already set in the classification file)
6277 protected void setTestData (float [][] testDataPredictors , String [] testDataResults , int rowCount , int columnCount ) {
6378 this .testDataPredictors = testDataPredictors ;
6479 this .testDataResults = testDataResults ;
6580 this .testDataRowCount = rowCount ;
6681 this .testDataColumnCount = columnCount ;
6782 }
6883
84+ // --- Calling a Function for testing the model
6985 protected void testModel () {
7086 testClassificationModel ();
7187 }
7288
89+ // --- Private Functions for intern calculations of the actual classification --------------------------------------
90+ // --- Function for getting the different classification classes and their number
7391 private void getClassificationClasses () {
7492 int numberOfClasses = 0 ;
7593 List <String > classes = new ArrayList <String >();
7694 List <String > tempClasses = Arrays .asList (this .trainingDataResults );
7795
96+ // Going through every column of the dataset (test data) and reading the result data (class)
7897 for (int i = 0 ; i < this .columnCount ; i ++) {
98+ // If the class is not already in the saved in the class array list, it will be added
7999 if (!classes .contains (tempClasses .get (i ))) {
80100 classes .add (tempClasses .get (i ));
81101 numberOfClasses ++;
82- //System.out.println(i);
83102 }
84103 }
85104
86105 this .numberOfClasses = numberOfClasses ;
87106 this .classes = new String [this .numberOfClasses ];
88107
108+ // Converting the array list to an array
89109 for (int i = 0 ; i < this .numberOfClasses ; i ++) {
90110 this .classes [i ] = classes .get (i );
91- //System.out.println(this.classes[i]);
92111 }
93112 }
94113
114+ // --- Function for sorting the classified data
95115 private void sortClassificationData () {
96116 ArrayList <ArrayList <ArrayList <Float >>> tempSortedClassificationData = new ArrayList <>();
97117 int [] tempNumberDataPerClass = new int [this .rowCount -1 ];
@@ -140,6 +160,7 @@ private void sortClassificationData() {
140160 }
141161 }
142162
163+ // --- Function for calculating the mean for every feature (training the model)
143164 private void calcFeatureMean () {
144165 this .featureMean = new float [this .numberOfClasses ][this .rowCount -1 ];
145166 for (int i = 0 ; i < this .numberOfClasses ; i ++) {
@@ -154,6 +175,7 @@ private void calcFeatureMean() {
154175 }
155176 }
156177
178+ // --- Function for testing the classification model
157179 private void testClassificationModel () {
158180 this .predictedTestData = new String [this .testDataColumnCount ][this .numberOfClasses ][2 ];
159181 this .sortedProbability = new int [this .testDataColumnCount ][this .numberOfClasses ];
0 commit comments