Skip to content

Commit 0d87417

Browse files
committed
further commenting of distanceClassification.java
1 parent 724a55b commit 0d87417

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/classification/DistanceClassification.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,32 +111,45 @@ private void getClassificationClasses() {
111111
}
112112
}
113113

114-
// --- Function for sorting the classified data
114+
// --- Function for sorting the test data which are going to be classified
115115
private void sortClassificationData() {
116116
ArrayList<ArrayList<ArrayList<Float>>> tempSortedClassificationData = new ArrayList<>();
117117
int [] tempNumberDataPerClass = new int[this.rowCount -1];
118+
// Resetting the array
118119
for (int i = 0; i < rowCount -1; i++) {
119120
tempNumberDataPerClass[i] = 0;
120121
}
121122

123+
// Creating an array list for saving the sorted classification data
124+
// This has to be done because array list sometimes cause unintended behaviour
125+
// Going through every class
122126
for (int i = 0; i < this.numberOfClasses; i++) {
127+
// Adding elements in the second dimension (with a maximum value of the overall count of columns from the data set)
123128
tempSortedClassificationData.add(new ArrayList<ArrayList<Float>>(this.columnCount));
129+
// Going through every column of the prior initialised second dimension
124130
for (int j = 0; j < this.columnCount; j++) {
131+
// Adding elements in the third dimension (with the number of the features)
125132
tempSortedClassificationData.get(i).add(new ArrayList<Float>(this.rowCount -1));
126133
}
127134
}
128135

136+
// Going through every column of the dataset
129137
for (int i = 0; i < this.columnCount; i++) {
138+
// Going through every class to try to match the dataset to a class of the sorted classification data
130139
for (int j = 0; j < this.numberOfClasses; j++) {
140+
// If the result of the dataset matches a prior defined class, it will be written to it
131141
if (this.trainingDataResults[i].equals(this.classes[j])) {
142+
// Transferring all values to the new array
132143
for (int k = 0; k < this.rowCount -1; k++) {
133144
tempSortedClassificationData.get(j).get(tempNumberDataPerClass[j]).add(k, this.trainingDataPredictors[i][k]);
134145
}
146+
// The number of the data per class is being incremented
135147
tempNumberDataPerClass[j]++;
136148
}
137149
}
138150
}
139151

152+
// Getting the maximum number of elements which belong to one class
140153
this.elementsPerClass = tempNumberDataPerClass;
141154
int maxNumOfElementsPerClass = 0;
142155
for (int i = 0; i < this.elementsPerClass.length; i++) {
@@ -145,9 +158,10 @@ private void sortClassificationData() {
145158
}
146159
}
147160

161+
// Initialising an array for saving the sorted classification data ([class][test data][feature]: float[file data from feature])
148162
this.sortedClassificationData = new float[this.numberOfClasses][maxNumOfElementsPerClass][this.rowCount -1];
149163

150-
// Reducing the size of the Array List
164+
// Reducing the size of the Array List and writing it to an array
151165
for (int i = 0; i < this.numberOfClasses; i++) {
152166
for (int j = 0; j < maxNumOfElementsPerClass; j++) {
153167
if (j >= this.elementsPerClass[i]) {
@@ -162,13 +176,18 @@ private void sortClassificationData() {
162176

163177
// --- Function for calculating the mean for every feature (training the model)
164178
private void calcFeatureMean() {
179+
// Array Structure: [class][mean per feature]
165180
this.featureMean = new float[this.numberOfClasses][this.rowCount -1];
181+
// Iterating through every class
166182
for (int i = 0; i < this.numberOfClasses; i++) {
183+
// Iterating through every feature
167184
for (int j = 0; j < this.rowCount -1; j++) {
168185
float tempCalcVar = 0;
186+
// Adding all elements per class and feature to a temp var
169187
for (int k = 0; k < this.elementsPerClass[i]; k++) {
170188
tempCalcVar += this.sortedClassificationData[i][k][j];
171189
}
190+
// Calculating the mean for every feature
172191
tempCalcVar /= this.elementsPerClass[i];
173192
this.featureMean[i][j] = tempCalcVar;
174193
}

0 commit comments

Comments
 (0)