id
int32
0
165k
repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
29,000
Waikato/moa
moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java
DataSet.getVariances
public double[] getVariances() { double N = this.size(); double[] LS = new double[this.getNrOfDimensions()]; double[] SS = new double[this.getNrOfDimensions()]; double[] tmpFeatures; double[] variances = new double[this.getNrOfDimensions()]; for (DataObject dataObject : dataList) { tmpFeatures = dataObject.getFeatures(); for (int j = 0; j < tmpFeatures.length; j++) { LS[j] += tmpFeatures[j]; SS[j] += tmpFeatures[j] * tmpFeatures[j]; } } // sigmaSquared[i] = (SS[i] / N) - ((LS[i] * LS [i]) / (N * N)); for (int i = 0; i < LS.length; i++) { variances[i] = (SS[i] / N - ((LS[i] / N)*(LS[i] / N))); } return variances; }
java
public double[] getVariances() { double N = this.size(); double[] LS = new double[this.getNrOfDimensions()]; double[] SS = new double[this.getNrOfDimensions()]; double[] tmpFeatures; double[] variances = new double[this.getNrOfDimensions()]; for (DataObject dataObject : dataList) { tmpFeatures = dataObject.getFeatures(); for (int j = 0; j < tmpFeatures.length; j++) { LS[j] += tmpFeatures[j]; SS[j] += tmpFeatures[j] * tmpFeatures[j]; } } // sigmaSquared[i] = (SS[i] / N) - ((LS[i] * LS [i]) / (N * N)); for (int i = 0; i < LS.length; i++) { variances[i] = (SS[i] / N - ((LS[i] / N)*(LS[i] / N))); } return variances; }
[ "public", "double", "[", "]", "getVariances", "(", ")", "{", "double", "N", "=", "this", ".", "size", "(", ")", ";", "double", "[", "]", "LS", "=", "new", "double", "[", "this", ".", "getNrOfDimensions", "(", ")", "]", ";", "double", "[", "]", "SS", "=", "new", "double", "[", "this", ".", "getNrOfDimensions", "(", ")", "]", ";", "double", "[", "]", "tmpFeatures", ";", "double", "[", "]", "variances", "=", "new", "double", "[", "this", ".", "getNrOfDimensions", "(", ")", "]", ";", "for", "(", "DataObject", "dataObject", ":", "dataList", ")", "{", "tmpFeatures", "=", "dataObject", ".", "getFeatures", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "tmpFeatures", ".", "length", ";", "j", "++", ")", "{", "LS", "[", "j", "]", "+=", "tmpFeatures", "[", "j", "]", ";", "SS", "[", "j", "]", "+=", "tmpFeatures", "[", "j", "]", "*", "tmpFeatures", "[", "j", "]", ";", "}", "}", "// sigmaSquared[i] = (SS[i] / N) - ((LS[i] * LS [i]) / (N * N));", "for", "(", "int", "i", "=", "0", ";", "i", "<", "LS", ".", "length", ";", "i", "++", ")", "{", "variances", "[", "i", "]", "=", "(", "SS", "[", "i", "]", "/", "N", "-", "(", "(", "LS", "[", "i", "]", "/", "N", ")", "*", "(", "LS", "[", "i", "]", "/", "N", ")", ")", ")", ";", "}", "return", "variances", ";", "}" ]
Calculates the variance of this data set for each dimension @return double array containing the variance per dimension
[ "Calculates", "the", "variance", "of", "this", "data", "set", "for", "each", "dimension" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java#L202-L223
29,001
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/SparseInstanceData.java
SparseInstanceData.toDoubleArray
@Override public double[] toDoubleArray() { double[] array = new double[numAttributes()]; for (int i = 0; i < numValues(); i++) { array[index(i)] = valueSparse(i); } return array; }
java
@Override public double[] toDoubleArray() { double[] array = new double[numAttributes()]; for (int i = 0; i < numValues(); i++) { array[index(i)] = valueSparse(i); } return array; }
[ "@", "Override", "public", "double", "[", "]", "toDoubleArray", "(", ")", "{", "double", "[", "]", "array", "=", "new", "double", "[", "numAttributes", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numValues", "(", ")", ";", "i", "++", ")", "{", "array", "[", "index", "(", "i", ")", "]", "=", "valueSparse", "(", "i", ")", ";", "}", "return", "array", ";", "}" ]
To double array. @return the double[]
[ "To", "double", "array", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/SparseInstanceData.java#L203-L210
29,002
Waikato/moa
moa/src/main/java/moa/clusterers/outliers/AnyOut/AnyOutCore.java
AnyOutCore.calcC1
private double calcC1(int objectId) { int nrOfPreviousResults = previousOScoreResultList.get(objectId).size(); if (nrOfPreviousResults == 0) { return 0.0; } int count=1; double difSum_k = Math.abs(lastOScoreResult.get(objectId)-previousOScoreResultList.get(objectId).get(nrOfPreviousResults-1)); //if previousOscoreResultList contains more than two results, this loop sums up further diffs for (int i=Math.max(0, nrOfPreviousResults - (confK-1)) + 1; i < nrOfPreviousResults; i++){ difSum_k += Math.abs(previousOScoreResultList.get(objectId).get(i)-previousOScoreResultList.get(objectId).get(i-1)); count++; } // hier msste gelten count==confK-1, d.h. wenn ich die letzten 3 Werte betrachten will, bekomme ich 2 differenzen // XXX SW: Nicht ganz. Wenn ich die letzten 4 Werte betrachten will, aber erst 2 Ergebnisse zur Verf�gung stehen, bekomme ich an anstatt der 3 Differenzen nur 1 // dafr die Zhlvariable difSum_k /= count; return Math.pow(Math.E, (-1.0 * difSum_k)); }
java
private double calcC1(int objectId) { int nrOfPreviousResults = previousOScoreResultList.get(objectId).size(); if (nrOfPreviousResults == 0) { return 0.0; } int count=1; double difSum_k = Math.abs(lastOScoreResult.get(objectId)-previousOScoreResultList.get(objectId).get(nrOfPreviousResults-1)); //if previousOscoreResultList contains more than two results, this loop sums up further diffs for (int i=Math.max(0, nrOfPreviousResults - (confK-1)) + 1; i < nrOfPreviousResults; i++){ difSum_k += Math.abs(previousOScoreResultList.get(objectId).get(i)-previousOScoreResultList.get(objectId).get(i-1)); count++; } // hier msste gelten count==confK-1, d.h. wenn ich die letzten 3 Werte betrachten will, bekomme ich 2 differenzen // XXX SW: Nicht ganz. Wenn ich die letzten 4 Werte betrachten will, aber erst 2 Ergebnisse zur Verf�gung stehen, bekomme ich an anstatt der 3 Differenzen nur 1 // dafr die Zhlvariable difSum_k /= count; return Math.pow(Math.E, (-1.0 * difSum_k)); }
[ "private", "double", "calcC1", "(", "int", "objectId", ")", "{", "int", "nrOfPreviousResults", "=", "previousOScoreResultList", ".", "get", "(", "objectId", ")", ".", "size", "(", ")", ";", "if", "(", "nrOfPreviousResults", "==", "0", ")", "{", "return", "0.0", ";", "}", "int", "count", "=", "1", ";", "double", "difSum_k", "=", "Math", ".", "abs", "(", "lastOScoreResult", ".", "get", "(", "objectId", ")", "-", "previousOScoreResultList", ".", "get", "(", "objectId", ")", ".", "get", "(", "nrOfPreviousResults", "-", "1", ")", ")", ";", "//if previousOscoreResultList contains more than two results, this loop sums up further diffs\r", "for", "(", "int", "i", "=", "Math", ".", "max", "(", "0", ",", "nrOfPreviousResults", "-", "(", "confK", "-", "1", ")", ")", "+", "1", ";", "i", "<", "nrOfPreviousResults", ";", "i", "++", ")", "{", "difSum_k", "+=", "Math", ".", "abs", "(", "previousOScoreResultList", ".", "get", "(", "objectId", ")", ".", "get", "(", "i", ")", "-", "previousOScoreResultList", ".", "get", "(", "objectId", ")", ".", "get", "(", "i", "-", "1", ")", ")", ";", "count", "++", ";", "}", "// hier msste gelten count==confK-1, d.h. wenn ich die letzten 3 Werte betrachten will, bekomme ich 2 differenzen \r", "// XXX SW: Nicht ganz. Wenn ich die letzten 4 Werte betrachten will, aber erst 2 Ergebnisse zur Verf�gung stehen, bekomme ich an anstatt der 3 Differenzen nur 1\r", "// dafr die Zhlvariable\r", "difSum_k", "/=", "count", ";", "return", "Math", ".", "pow", "(", "Math", ".", "E", ",", "(", "-", "1.0", "*", "difSum_k", ")", ")", ";", "}" ]
Calculates the Confidence on the basis of the standard deviation of previous OScore results @return confidence
[ "Calculates", "the", "Confidence", "on", "the", "basis", "of", "the", "standard", "deviation", "of", "previous", "OScore", "results" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/AnyOut/AnyOutCore.java#L234-L252
29,003
Waikato/moa
moa/src/main/java/moa/gui/experimentertab/Summary.java
Summary.invertedSumariesPerMeasure
public void invertedSumariesPerMeasure( String path) { int cont = 0; int algorithmSize = this.streams.get(0).algorithm.size(); int streamSize = this.streams.size(); int measureSize = this.streams.get(0).algorithm.get(0).measures.size(); while (cont != measureSize) { String output = ""; output += "\\documentclass{article}\n"; output += "\\usepackage{multirow}\n\\usepackage{booktabs}\n\\begin{document}\n\\begin{table}[htbp]\n\\caption{Add caption}"; output += "\\begin{tabular}"; output += "{"; for (int i = 0; i < algorithmSize + 1; i++) { output += "r"; } output += "}\n\\toprule\nAlgorithm"; for (int i = 0; i < algorithmSize; i++) { output += "& " + this.streams.get(0).algorithm.get(i).name; } output += "\\\\"; output += "\n\\midrule\n"; for (int i = 0; i < streamSize; i++) { List<Algorithm> alg = this.streams.get(i).algorithm; output += this.streams.get(i).name; for (int j = 0; j < algorithmSize; j++) { if (alg.get(j).measures.get(cont).isType()) { output += "&" + Algorithm.format(alg.get(j).measures.get(cont).getValue()) + "$\\,\\pm$" + Algorithm.format(alg.get(j).measures.get(cont).getStd()); } else { output += "&" + Algorithm.format1(alg.get(j).measures.get(cont).getValue()); } } output += "\\\\\n"; } output += "\\bottomrule\n\\end{tabular}%\n\\label{tab:addlabel}%\n\\end{table}%\n\\end{document}"; //PrintStream out = null; String name = this.streams.get(0).algorithm.get(0).measures.get(cont).getName(); // try { // out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + ".tex"))); // } catch (FileNotFoundException ex) { // Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex); // } // System.setOut(out); // System.out.println(output); // out.close(); try { BufferedWriter out = new BufferedWriter(new FileWriter(path + name + ".tex")); out.write(output); //Replace with the string //you are trying to write out.close(); } catch (IOException e) { System.out.println("Error saving "+name + ".tex"); } cont++; } }
java
public void invertedSumariesPerMeasure( String path) { int cont = 0; int algorithmSize = this.streams.get(0).algorithm.size(); int streamSize = this.streams.size(); int measureSize = this.streams.get(0).algorithm.get(0).measures.size(); while (cont != measureSize) { String output = ""; output += "\\documentclass{article}\n"; output += "\\usepackage{multirow}\n\\usepackage{booktabs}\n\\begin{document}\n\\begin{table}[htbp]\n\\caption{Add caption}"; output += "\\begin{tabular}"; output += "{"; for (int i = 0; i < algorithmSize + 1; i++) { output += "r"; } output += "}\n\\toprule\nAlgorithm"; for (int i = 0; i < algorithmSize; i++) { output += "& " + this.streams.get(0).algorithm.get(i).name; } output += "\\\\"; output += "\n\\midrule\n"; for (int i = 0; i < streamSize; i++) { List<Algorithm> alg = this.streams.get(i).algorithm; output += this.streams.get(i).name; for (int j = 0; j < algorithmSize; j++) { if (alg.get(j).measures.get(cont).isType()) { output += "&" + Algorithm.format(alg.get(j).measures.get(cont).getValue()) + "$\\,\\pm$" + Algorithm.format(alg.get(j).measures.get(cont).getStd()); } else { output += "&" + Algorithm.format1(alg.get(j).measures.get(cont).getValue()); } } output += "\\\\\n"; } output += "\\bottomrule\n\\end{tabular}%\n\\label{tab:addlabel}%\n\\end{table}%\n\\end{document}"; //PrintStream out = null; String name = this.streams.get(0).algorithm.get(0).measures.get(cont).getName(); // try { // out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + ".tex"))); // } catch (FileNotFoundException ex) { // Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex); // } // System.setOut(out); // System.out.println(output); // out.close(); try { BufferedWriter out = new BufferedWriter(new FileWriter(path + name + ".tex")); out.write(output); //Replace with the string //you are trying to write out.close(); } catch (IOException e) { System.out.println("Error saving "+name + ".tex"); } cont++; } }
[ "public", "void", "invertedSumariesPerMeasure", "(", "String", "path", ")", "{", "int", "cont", "=", "0", ";", "int", "algorithmSize", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "size", "(", ")", ";", "int", "streamSize", "=", "this", ".", "streams", ".", "size", "(", ")", ";", "int", "measureSize", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "0", ")", ".", "measures", ".", "size", "(", ")", ";", "while", "(", "cont", "!=", "measureSize", ")", "{", "String", "output", "=", "\"\"", ";", "output", "+=", "\"\\\\documentclass{article}\\n\"", ";", "output", "+=", "\"\\\\usepackage{multirow}\\n\\\\usepackage{booktabs}\\n\\\\begin{document}\\n\\\\begin{table}[htbp]\\n\\\\caption{Add caption}\"", ";", "output", "+=", "\"\\\\begin{tabular}\"", ";", "output", "+=", "\"{\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "algorithmSize", "+", "1", ";", "i", "++", ")", "{", "output", "+=", "\"r\"", ";", "}", "output", "+=", "\"}\\n\\\\toprule\\nAlgorithm\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "algorithmSize", ";", "i", "++", ")", "{", "output", "+=", "\"& \"", "+", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "i", ")", ".", "name", ";", "}", "output", "+=", "\"\\\\\\\\\"", ";", "output", "+=", "\"\\n\\\\midrule\\n\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "streamSize", ";", "i", "++", ")", "{", "List", "<", "Algorithm", ">", "alg", "=", "this", ".", "streams", ".", "get", "(", "i", ")", ".", "algorithm", ";", "output", "+=", "this", ".", "streams", ".", "get", "(", "i", ")", ".", "name", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "algorithmSize", ";", "j", "++", ")", "{", "if", "(", "alg", ".", "get", "(", "j", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "isType", "(", ")", ")", "{", "output", "+=", "\"&\"", "+", "Algorithm", ".", "format", "(", "alg", ".", "get", "(", "j", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getValue", "(", ")", ")", "+", "\"$\\\\,\\\\pm$\"", "+", "Algorithm", ".", "format", "(", "alg", ".", "get", "(", "j", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getStd", "(", ")", ")", ";", "}", "else", "{", "output", "+=", "\"&\"", "+", "Algorithm", ".", "format1", "(", "alg", ".", "get", "(", "j", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getValue", "(", ")", ")", ";", "}", "}", "output", "+=", "\"\\\\\\\\\\n\"", ";", "}", "output", "+=", "\"\\\\bottomrule\\n\\\\end{tabular}%\\n\\\\label{tab:addlabel}%\\n\\\\end{table}%\\n\\\\end{document}\"", ";", "//PrintStream out = null;", "String", "name", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "0", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getName", "(", ")", ";", "// try {", "// out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + \".tex\")));", "// } catch (FileNotFoundException ex) {", "// Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex);", "// }", "// System.setOut(out);", "// System.out.println(output);", "// out.close();", "try", "{", "BufferedWriter", "out", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "path", "+", "name", "+", "\".tex\"", ")", ")", ";", "out", ".", "write", "(", "output", ")", ";", "//Replace with the string ", "//you are trying to write ", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"Error saving \"", "+", "name", "+", "\".tex\"", ")", ";", "}", "cont", "++", ";", "}", "}" ]
Generates a latex summary, in which the rows are the datasets and the columns the algorithms.
[ "Generates", "a", "latex", "summary", "in", "which", "the", "rows", "are", "the", "datasets", "and", "the", "columns", "the", "algorithms", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/Summary.java#L155-L214
29,004
Waikato/moa
moa/src/main/java/moa/gui/experimentertab/Summary.java
Summary.generateCSV
public void generateCSV() { int cont = 0; int algorithmSize = this.streams.get(0).algorithm.size(); int streamSize = this.streams.size(); int measureSize = this.streams.get(0).algorithm.get(0).measures.size(); while (cont != measureSize) { String output = ""; output += "Algorithm,"; output += this.streams.get(0).algorithm.get(0).name; //Inicialize summary table for (int i = 1; i < algorithmSize; i++) { output += "," + this.streams.get(0).algorithm.get(i).name; } output += "\n"; for (int i = 0; i < streamSize; i++) { List<Algorithm> alg = this.streams.get(i).algorithm; output += this.streams.get(i).name; for (int j = 0; j < algorithmSize; j++) { output += "," + alg.get(j).measures.get(cont).getValue(); } output += "\n"; } //PrintStream out = null; String name = this.streams.get(0).algorithm.get(0).measures.get(cont).getName(); // try { // out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + ".csv"))); // } catch (FileNotFoundException ex) { // Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex); // } // System.setOut(out); // System.out.println(output); // out.close(); try { BufferedWriter out = new BufferedWriter(new FileWriter(path + name + ".csv")); out.write(output); //Replace with the string //you are trying to write out.close(); } catch (IOException e) { System.out.println(name + ".csv"); } cont++; } }
java
public void generateCSV() { int cont = 0; int algorithmSize = this.streams.get(0).algorithm.size(); int streamSize = this.streams.size(); int measureSize = this.streams.get(0).algorithm.get(0).measures.size(); while (cont != measureSize) { String output = ""; output += "Algorithm,"; output += this.streams.get(0).algorithm.get(0).name; //Inicialize summary table for (int i = 1; i < algorithmSize; i++) { output += "," + this.streams.get(0).algorithm.get(i).name; } output += "\n"; for (int i = 0; i < streamSize; i++) { List<Algorithm> alg = this.streams.get(i).algorithm; output += this.streams.get(i).name; for (int j = 0; j < algorithmSize; j++) { output += "," + alg.get(j).measures.get(cont).getValue(); } output += "\n"; } //PrintStream out = null; String name = this.streams.get(0).algorithm.get(0).measures.get(cont).getName(); // try { // out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + ".csv"))); // } catch (FileNotFoundException ex) { // Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex); // } // System.setOut(out); // System.out.println(output); // out.close(); try { BufferedWriter out = new BufferedWriter(new FileWriter(path + name + ".csv")); out.write(output); //Replace with the string //you are trying to write out.close(); } catch (IOException e) { System.out.println(name + ".csv"); } cont++; } }
[ "public", "void", "generateCSV", "(", ")", "{", "int", "cont", "=", "0", ";", "int", "algorithmSize", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "size", "(", ")", ";", "int", "streamSize", "=", "this", ".", "streams", ".", "size", "(", ")", ";", "int", "measureSize", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "0", ")", ".", "measures", ".", "size", "(", ")", ";", "while", "(", "cont", "!=", "measureSize", ")", "{", "String", "output", "=", "\"\"", ";", "output", "+=", "\"Algorithm,\"", ";", "output", "+=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "0", ")", ".", "name", ";", "//Inicialize summary table", "for", "(", "int", "i", "=", "1", ";", "i", "<", "algorithmSize", ";", "i", "++", ")", "{", "output", "+=", "\",\"", "+", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "i", ")", ".", "name", ";", "}", "output", "+=", "\"\\n\"", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "streamSize", ";", "i", "++", ")", "{", "List", "<", "Algorithm", ">", "alg", "=", "this", ".", "streams", ".", "get", "(", "i", ")", ".", "algorithm", ";", "output", "+=", "this", ".", "streams", ".", "get", "(", "i", ")", ".", "name", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "algorithmSize", ";", "j", "++", ")", "{", "output", "+=", "\",\"", "+", "alg", ".", "get", "(", "j", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getValue", "(", ")", ";", "}", "output", "+=", "\"\\n\"", ";", "}", "//PrintStream out = null;", "String", "name", "=", "this", ".", "streams", ".", "get", "(", "0", ")", ".", "algorithm", ".", "get", "(", "0", ")", ".", "measures", ".", "get", "(", "cont", ")", ".", "getName", "(", ")", ";", "// try {", "// out = new PrintStream(new BufferedOutputStream(new FileOutputStream(path + name + \".csv\")));", "// } catch (FileNotFoundException ex) {", "// Logger.getLogger(Summary.class.getName()).log(Level.SEVERE, null, ex);", "// }", "// System.setOut(out);", "// System.out.println(output);", "// out.close();", "try", "{", "BufferedWriter", "out", "=", "new", "BufferedWriter", "(", "new", "FileWriter", "(", "path", "+", "name", "+", "\".csv\"", ")", ")", ";", "out", ".", "write", "(", "output", ")", ";", "//Replace with the string ", "//you are trying to write ", "out", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "name", "+", "\".csv\"", ")", ";", "}", "cont", "++", ";", "}", "}" ]
Generate a csv file for the statistical analysis.
[ "Generate", "a", "csv", "file", "for", "the", "statistical", "analysis", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/Summary.java#L508-L558
29,005
Waikato/moa
moa/src/main/java/moa/clusterers/dstream/DensityGrid.java
DensityGrid.getNeighbours
public ArrayList<DensityGrid> getNeighbours() { ArrayList<DensityGrid> neighbours = new ArrayList<DensityGrid>(); DensityGrid h; int[] hCoord = this.getCoordinates(); for (int i = 0 ; i < this.dimensions ; i++) { hCoord[i] = hCoord[i]-1; h = new DensityGrid(hCoord); neighbours.add(h); hCoord[i] = hCoord[i]+2; h = new DensityGrid(hCoord); neighbours.add(h); hCoord[i] = hCoord[i]-1; } return neighbours; }
java
public ArrayList<DensityGrid> getNeighbours() { ArrayList<DensityGrid> neighbours = new ArrayList<DensityGrid>(); DensityGrid h; int[] hCoord = this.getCoordinates(); for (int i = 0 ; i < this.dimensions ; i++) { hCoord[i] = hCoord[i]-1; h = new DensityGrid(hCoord); neighbours.add(h); hCoord[i] = hCoord[i]+2; h = new DensityGrid(hCoord); neighbours.add(h); hCoord[i] = hCoord[i]-1; } return neighbours; }
[ "public", "ArrayList", "<", "DensityGrid", ">", "getNeighbours", "(", ")", "{", "ArrayList", "<", "DensityGrid", ">", "neighbours", "=", "new", "ArrayList", "<", "DensityGrid", ">", "(", ")", ";", "DensityGrid", "h", ";", "int", "[", "]", "hCoord", "=", "this", ".", "getCoordinates", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "dimensions", ";", "i", "++", ")", "{", "hCoord", "[", "i", "]", "=", "hCoord", "[", "i", "]", "-", "1", ";", "h", "=", "new", "DensityGrid", "(", "hCoord", ")", ";", "neighbours", ".", "add", "(", "h", ")", ";", "hCoord", "[", "i", "]", "=", "hCoord", "[", "i", "]", "+", "2", ";", "h", "=", "new", "DensityGrid", "(", "hCoord", ")", ";", "neighbours", ".", "add", "(", "h", ")", ";", "hCoord", "[", "i", "]", "=", "hCoord", "[", "i", "]", "-", "1", ";", "}", "return", "neighbours", ";", "}" ]
Generates an Array List of neighbours for this density grid by varying each coordinate by one in either direction. Does not test whether the generated neighbours are valid as DensityGrid is not aware of the number of partitions in each dimension. @return an Array List of neighbours for this density grid
[ "Generates", "an", "Array", "List", "of", "neighbours", "for", "this", "density", "grid", "by", "varying", "each", "coordinate", "by", "one", "in", "either", "direction", ".", "Does", "not", "test", "whether", "the", "generated", "neighbours", "are", "valid", "as", "DensityGrid", "is", "not", "aware", "of", "the", "number", "of", "partitions", "in", "each", "dimension", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/DensityGrid.java#L170-L190
29,006
Waikato/moa
moa/src/main/java/moa/clusterers/dstream/DensityGrid.java
DensityGrid.getInclusionProbability
@Override public double getInclusionProbability(Instance instance) { for (int i = 0 ; i < this.dimensions ; i++) { if ((int) instance.value(i) != this.coordinates[i]) return 0.0; } return 1.0; }
java
@Override public double getInclusionProbability(Instance instance) { for (int i = 0 ; i < this.dimensions ; i++) { if ((int) instance.value(i) != this.coordinates[i]) return 0.0; } return 1.0; }
[ "@", "Override", "public", "double", "getInclusionProbability", "(", "Instance", "instance", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "dimensions", ";", "i", "++", ")", "{", "if", "(", "(", "int", ")", "instance", ".", "value", "(", "i", ")", "!=", "this", ".", "coordinates", "[", "i", "]", ")", "return", "0.0", ";", "}", "return", "1.0", ";", "}" ]
Provides the probability of the argument instance belonging to the density grid in question. @return 1.0 if the instance equals the density grid's coordinates; 0.0 otherwise.
[ "Provides", "the", "probability", "of", "the", "argument", "instance", "belonging", "to", "the", "density", "grid", "in", "question", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/DensityGrid.java#L239-L248
29,007
Waikato/moa
moa/src/main/java/moa/gui/experimentertab/Stream.java
Stream.readBuffer
public void readBuffer(List<String> algPath, List<String> algNames, List<Measure> measures) { BufferedReader buffer = null; for (int i = 0; i < algPath.size(); i++) { try { buffer = new BufferedReader(new FileReader(algPath.get(i))); } catch (FileNotFoundException ex) { Logger.getLogger(Stream.class.getName()).log(Level.SEVERE, null, ex); } Algorithm algorithm = new Algorithm(algNames.get(i), measures, buffer,algPath.get(i)); this.algorithm.add(algorithm); } }
java
public void readBuffer(List<String> algPath, List<String> algNames, List<Measure> measures) { BufferedReader buffer = null; for (int i = 0; i < algPath.size(); i++) { try { buffer = new BufferedReader(new FileReader(algPath.get(i))); } catch (FileNotFoundException ex) { Logger.getLogger(Stream.class.getName()).log(Level.SEVERE, null, ex); } Algorithm algorithm = new Algorithm(algNames.get(i), measures, buffer,algPath.get(i)); this.algorithm.add(algorithm); } }
[ "public", "void", "readBuffer", "(", "List", "<", "String", ">", "algPath", ",", "List", "<", "String", ">", "algNames", ",", "List", "<", "Measure", ">", "measures", ")", "{", "BufferedReader", "buffer", "=", "null", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "algPath", ".", "size", "(", ")", ";", "i", "++", ")", "{", "try", "{", "buffer", "=", "new", "BufferedReader", "(", "new", "FileReader", "(", "algPath", ".", "get", "(", "i", ")", ")", ")", ";", "}", "catch", "(", "FileNotFoundException", "ex", ")", "{", "Logger", ".", "getLogger", "(", "Stream", ".", "class", ".", "getName", "(", ")", ")", ".", "log", "(", "Level", ".", "SEVERE", ",", "null", ",", "ex", ")", ";", "}", "Algorithm", "algorithm", "=", "new", "Algorithm", "(", "algNames", ".", "get", "(", "i", ")", ",", "measures", ",", "buffer", ",", "algPath", ".", "get", "(", "i", ")", ")", ";", "this", ".", "algorithm", ".", "add", "(", "algorithm", ")", ";", "}", "}" ]
Read each algorithm file. @param algPath @param algNames @param measures
[ "Read", "each", "algorithm", "file", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/Stream.java#L65-L77
29,008
Waikato/moa
moa/src/main/java/moa/streams/clustering/RandomRBFGeneratorEvents.java
RandomRBFGeneratorEvents.fireClusterChange
protected void fireClusterChange(long timestamp, String type, String message) { // if we have no listeners, do nothing... if (listeners != null && !listeners.isEmpty()) { // create the event object to send ClusterEvent event = new ClusterEvent(this, timestamp, type , message); // make a copy of the listener list in case // anyone adds/removes listeners Vector targets; synchronized (this) { targets = (Vector) listeners.clone(); } // walk through the listener list and // call the sunMoved method in each Enumeration e = targets.elements(); while (e.hasMoreElements()) { ClusterEventListener l = (ClusterEventListener) e.nextElement(); l.changeCluster(event); } } }
java
protected void fireClusterChange(long timestamp, String type, String message) { // if we have no listeners, do nothing... if (listeners != null && !listeners.isEmpty()) { // create the event object to send ClusterEvent event = new ClusterEvent(this, timestamp, type , message); // make a copy of the listener list in case // anyone adds/removes listeners Vector targets; synchronized (this) { targets = (Vector) listeners.clone(); } // walk through the listener list and // call the sunMoved method in each Enumeration e = targets.elements(); while (e.hasMoreElements()) { ClusterEventListener l = (ClusterEventListener) e.nextElement(); l.changeCluster(event); } } }
[ "protected", "void", "fireClusterChange", "(", "long", "timestamp", ",", "String", "type", ",", "String", "message", ")", "{", "// if we have no listeners, do nothing...", "if", "(", "listeners", "!=", "null", "&&", "!", "listeners", ".", "isEmpty", "(", ")", ")", "{", "// create the event object to send", "ClusterEvent", "event", "=", "new", "ClusterEvent", "(", "this", ",", "timestamp", ",", "type", ",", "message", ")", ";", "// make a copy of the listener list in case", "// anyone adds/removes listeners", "Vector", "targets", ";", "synchronized", "(", "this", ")", "{", "targets", "=", "(", "Vector", ")", "listeners", ".", "clone", "(", ")", ";", "}", "// walk through the listener list and", "// call the sunMoved method in each", "Enumeration", "e", "=", "targets", ".", "elements", "(", ")", ";", "while", "(", "e", ".", "hasMoreElements", "(", ")", ")", "{", "ClusterEventListener", "l", "=", "(", "ClusterEventListener", ")", "e", ".", "nextElement", "(", ")", ";", "l", ".", "changeCluster", "(", "event", ")", ";", "}", "}", "}" ]
Fire a ClusterChangeEvent to all registered listeners
[ "Fire", "a", "ClusterChangeEvent", "to", "all", "registered", "listeners" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/streams/clustering/RandomRBFGeneratorEvents.java#L940-L963
29,009
Waikato/moa
moa/src/main/java/com/github/javacliparser/gui/ClassOptionEditComponent.java
ClassOptionEditComponent.notifyChangeListeners
protected void notifyChangeListeners() { ChangeEvent e = new ChangeEvent(this); for (ChangeListener l : changeListeners) { l.stateChanged(e); } }
java
protected void notifyChangeListeners() { ChangeEvent e = new ChangeEvent(this); for (ChangeListener l : changeListeners) { l.stateChanged(e); } }
[ "protected", "void", "notifyChangeListeners", "(", ")", "{", "ChangeEvent", "e", "=", "new", "ChangeEvent", "(", "this", ")", ";", "for", "(", "ChangeListener", "l", ":", "changeListeners", ")", "{", "l", ".", "stateChanged", "(", "e", ")", ";", "}", "}" ]
Notifies all registered change listeners that the options have changed.
[ "Notifies", "all", "registered", "change", "listeners", "that", "the", "options", "have", "changed", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/github/javacliparser/gui/ClassOptionEditComponent.java#L137-L142
29,010
Waikato/moa
moa/src/main/java/moa/gui/visualization/GraphScatter.java
GraphScatter.setGraph
public void setGraph(MeasureCollection[] measures, MeasureCollection[] stds, double[] variedParamValues, Color[] colors) { this.variedParamValues = variedParamValues; super.setGraph(measures, stds, colors); }
java
public void setGraph(MeasureCollection[] measures, MeasureCollection[] stds, double[] variedParamValues, Color[] colors) { this.variedParamValues = variedParamValues; super.setGraph(measures, stds, colors); }
[ "public", "void", "setGraph", "(", "MeasureCollection", "[", "]", "measures", ",", "MeasureCollection", "[", "]", "stds", ",", "double", "[", "]", "variedParamValues", ",", "Color", "[", "]", "colors", ")", "{", "this", ".", "variedParamValues", "=", "variedParamValues", ";", "super", ".", "setGraph", "(", "measures", ",", "stds", ",", "colors", ")", ";", "}" ]
Draws a scatter graph based on the varied parameter and the measures. @param measures list of measure collections, one for each task @param stds standard deviation values @param variedParamValues values of the varied parameter @param colors color encodings for the different tasks
[ "Draws", "a", "scatter", "graph", "based", "on", "the", "varied", "parameter", "and", "the", "measures", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/visualization/GraphScatter.java#L50-L54
29,011
Waikato/moa
moa/src/main/java/moa/gui/visualization/GraphScatter.java
GraphScatter.scatter
private void scatter(Graphics g, int i) { int height = getHeight(); int width = getWidth(); int x = (int)(((this.variedParamValues[i] - this.lower_x_value) / (this.upper_x_value - this.lower_x_value)) * width); double value = this.measures[i].getLastValue(this.measureSelected); if(Double.isNaN(value)){ // no result for this budget yet return; } int y = (int)(height - (value / this.upper_y_value) * height); g.setColor(this.colors[i]); if (this.isStandardDeviationPainted) { int len = (int) ((this.measureStds[i].getLastValue(this.measureSelected)/this.upper_y_value)*height); paintStandardDeviation(g, len, x, y); } g.fillOval(x - DOT_SIZE/2, y - DOT_SIZE/2, DOT_SIZE, DOT_SIZE); }
java
private void scatter(Graphics g, int i) { int height = getHeight(); int width = getWidth(); int x = (int)(((this.variedParamValues[i] - this.lower_x_value) / (this.upper_x_value - this.lower_x_value)) * width); double value = this.measures[i].getLastValue(this.measureSelected); if(Double.isNaN(value)){ // no result for this budget yet return; } int y = (int)(height - (value / this.upper_y_value) * height); g.setColor(this.colors[i]); if (this.isStandardDeviationPainted) { int len = (int) ((this.measureStds[i].getLastValue(this.measureSelected)/this.upper_y_value)*height); paintStandardDeviation(g, len, x, y); } g.fillOval(x - DOT_SIZE/2, y - DOT_SIZE/2, DOT_SIZE, DOT_SIZE); }
[ "private", "void", "scatter", "(", "Graphics", "g", ",", "int", "i", ")", "{", "int", "height", "=", "getHeight", "(", ")", ";", "int", "width", "=", "getWidth", "(", ")", ";", "int", "x", "=", "(", "int", ")", "(", "(", "(", "this", ".", "variedParamValues", "[", "i", "]", "-", "this", ".", "lower_x_value", ")", "/", "(", "this", ".", "upper_x_value", "-", "this", ".", "lower_x_value", ")", ")", "*", "width", ")", ";", "double", "value", "=", "this", ".", "measures", "[", "i", "]", ".", "getLastValue", "(", "this", ".", "measureSelected", ")", ";", "if", "(", "Double", ".", "isNaN", "(", "value", ")", ")", "{", "// no result for this budget yet", "return", ";", "}", "int", "y", "=", "(", "int", ")", "(", "height", "-", "(", "value", "/", "this", ".", "upper_y_value", ")", "*", "height", ")", ";", "g", ".", "setColor", "(", "this", ".", "colors", "[", "i", "]", ")", ";", "if", "(", "this", ".", "isStandardDeviationPainted", ")", "{", "int", "len", "=", "(", "int", ")", "(", "(", "this", ".", "measureStds", "[", "i", "]", ".", "getLastValue", "(", "this", ".", "measureSelected", ")", "/", "this", ".", "upper_y_value", ")", "*", "height", ")", ";", "paintStandardDeviation", "(", "g", ",", "len", ",", "x", ",", "y", ")", ";", "}", "g", ".", "fillOval", "(", "x", "-", "DOT_SIZE", "/", "2", ",", "y", "-", "DOT_SIZE", "/", "2", ",", "DOT_SIZE", ",", "DOT_SIZE", ")", ";", "}" ]
Paint a dot onto the panel. @param g graphics object @param i index of the varied parameter
[ "Paint", "a", "dot", "onto", "the", "panel", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/visualization/GraphScatter.java#L76-L100
29,012
Waikato/moa
moa/src/main/java/moa/AbstractMOAObject.java
AbstractMOAObject.copy
public static MOAObject copy(MOAObject obj) { try { return (MOAObject) SerializeUtils.copyObject(obj); } catch (Exception e) { throw new RuntimeException("Object copy failed.", e); } }
java
public static MOAObject copy(MOAObject obj) { try { return (MOAObject) SerializeUtils.copyObject(obj); } catch (Exception e) { throw new RuntimeException("Object copy failed.", e); } }
[ "public", "static", "MOAObject", "copy", "(", "MOAObject", "obj", ")", "{", "try", "{", "return", "(", "MOAObject", ")", "SerializeUtils", ".", "copyObject", "(", "obj", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Object copy failed.\"", ",", "e", ")", ";", "}", "}" ]
This method produces a copy of an object. @param obj object to copy @return a copy of the object
[ "This", "method", "produces", "a", "copy", "of", "an", "object", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/AbstractMOAObject.java#L62-L68
29,013
Waikato/moa
moa/src/main/java/moa/gui/GUIDefaults.java
GUIDefaults.get
public static String get(String property, String defaultValue) { return PROPERTIES.getProperty(property, defaultValue); }
java
public static String get(String property, String defaultValue) { return PROPERTIES.getProperty(property, defaultValue); }
[ "public", "static", "String", "get", "(", "String", "property", ",", "String", "defaultValue", ")", "{", "return", "PROPERTIES", ".", "getProperty", "(", "property", ",", "defaultValue", ")", ";", "}" ]
returns the value for the specified property, if non-existent then the default value. @param property the property to retrieve the value for @param defaultValue the default value for the property @return the value of the specified property
[ "returns", "the", "value", "for", "the", "specified", "property", "if", "non", "-", "existent", "then", "the", "default", "value", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/GUIDefaults.java#L69-L71
29,014
Waikato/moa
moa/src/main/java/moa/gui/GUIDefaults.java
GUIDefaults.getTabs
public static String[] getTabs() { String[] result; String tabs; // read and split on comma tabs = get("Tabs", "moa.gui.ClassificationTabPanel,moa.gui.RegressionTabPanel,moa.gui.MultiLabelTabPanel,moa.gui.MultiTargetTabPanel,moa.gui.clustertab.ClusteringTabPanel,moa.gui.outliertab.OutlierTabPanel,moa.gui.ConceptDriftTabPanel,moa.gui.ALTabPanel,moa.gui.AuxiliarTabPanel,moa.gui.experimentertab.ExperimenterTabPanel"); result = tabs.split(","); return result; }
java
public static String[] getTabs() { String[] result; String tabs; // read and split on comma tabs = get("Tabs", "moa.gui.ClassificationTabPanel,moa.gui.RegressionTabPanel,moa.gui.MultiLabelTabPanel,moa.gui.MultiTargetTabPanel,moa.gui.clustertab.ClusteringTabPanel,moa.gui.outliertab.OutlierTabPanel,moa.gui.ConceptDriftTabPanel,moa.gui.ALTabPanel,moa.gui.AuxiliarTabPanel,moa.gui.experimentertab.ExperimenterTabPanel"); result = tabs.split(","); return result; }
[ "public", "static", "String", "[", "]", "getTabs", "(", ")", "{", "String", "[", "]", "result", ";", "String", "tabs", ";", "// read and split on comma", "tabs", "=", "get", "(", "\"Tabs\"", ",", "\"moa.gui.ClassificationTabPanel,moa.gui.RegressionTabPanel,moa.gui.MultiLabelTabPanel,moa.gui.MultiTargetTabPanel,moa.gui.clustertab.ClusteringTabPanel,moa.gui.outliertab.OutlierTabPanel,moa.gui.ConceptDriftTabPanel,moa.gui.ALTabPanel,moa.gui.AuxiliarTabPanel,moa.gui.experimentertab.ExperimenterTabPanel\"", ")", ";", "result", "=", "tabs", ".", "split", "(", "\",\"", ")", ";", "return", "result", ";", "}" ]
returns an array with the classnames of all the additional panels to display as tabs in the GUI. @return the classnames
[ "returns", "an", "array", "with", "the", "classnames", "of", "all", "the", "additional", "panels", "to", "display", "as", "tabs", "in", "the", "GUI", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/GUIDefaults.java#L134-L143
29,015
Waikato/moa
moa/src/main/java/moa/gui/GUIDefaults.java
GUIDefaults.getFrameWidth
public static int getFrameWidth() { int result; String str; str = get("FrameWidth", "1200"); try { result = Integer.parseInt(str); } catch (Exception e) { result = 1200; } return result; }
java
public static int getFrameWidth() { int result; String str; str = get("FrameWidth", "1200"); try { result = Integer.parseInt(str); } catch (Exception e) { result = 1200; } return result; }
[ "public", "static", "int", "getFrameWidth", "(", ")", "{", "int", "result", ";", "String", "str", ";", "str", "=", "get", "(", "\"FrameWidth\"", ",", "\"1200\"", ")", ";", "try", "{", "result", "=", "Integer", ".", "parseInt", "(", "str", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "result", "=", "1200", ";", "}", "return", "result", ";", "}" ]
Returns the width for the frame. @return the width in pixel
[ "Returns", "the", "width", "for", "the", "frame", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/GUIDefaults.java#L176-L187
29,016
Waikato/moa
moa/src/main/java/moa/gui/GUIDefaults.java
GUIDefaults.main
public static void main(String[] args) { Enumeration names; String name; Vector sorted; System.out.println("\nMOA defaults:"); names = PROPERTIES.propertyNames(); // sort names sorted = new Vector(); while (names.hasMoreElements()) { sorted.add(names.nextElement()); } Collections.sort(sorted); names = sorted.elements(); // output while (names.hasMoreElements()) { name = names.nextElement().toString(); System.out.println("- " + name + ": " + PROPERTIES.getProperty(name, "")); } System.out.println(); }
java
public static void main(String[] args) { Enumeration names; String name; Vector sorted; System.out.println("\nMOA defaults:"); names = PROPERTIES.propertyNames(); // sort names sorted = new Vector(); while (names.hasMoreElements()) { sorted.add(names.nextElement()); } Collections.sort(sorted); names = sorted.elements(); // output while (names.hasMoreElements()) { name = names.nextElement().toString(); System.out.println("- " + name + ": " + PROPERTIES.getProperty(name, "")); } System.out.println(); }
[ "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "Enumeration", "names", ";", "String", "name", ";", "Vector", "sorted", ";", "System", ".", "out", ".", "println", "(", "\"\\nMOA defaults:\"", ")", ";", "names", "=", "PROPERTIES", ".", "propertyNames", "(", ")", ";", "// sort names", "sorted", "=", "new", "Vector", "(", ")", ";", "while", "(", "names", ".", "hasMoreElements", "(", ")", ")", "{", "sorted", ".", "add", "(", "names", ".", "nextElement", "(", ")", ")", ";", "}", "Collections", ".", "sort", "(", "sorted", ")", ";", "names", "=", "sorted", ".", "elements", "(", ")", ";", "// output", "while", "(", "names", ".", "hasMoreElements", "(", ")", ")", "{", "name", "=", "names", ".", "nextElement", "(", ")", ".", "toString", "(", ")", ";", "System", ".", "out", ".", "println", "(", "\"- \"", "+", "name", "+", "\": \"", "+", "PROPERTIES", ".", "getProperty", "(", "name", ",", "\"\"", ")", ")", ";", "}", "System", ".", "out", ".", "println", "(", ")", ";", "}" ]
only for testing - prints the content of the props file. @param args commandline parameters - ignored
[ "only", "for", "testing", "-", "prints", "the", "content", "of", "the", "props", "file", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/GUIDefaults.java#L248-L270
29,017
Waikato/moa
moa/src/main/java/moa/clusterers/clustream/ClustreamKernel.java
ClustreamKernel.inverseError
public static double inverseError(double x) { double z = Math.sqrt(Math.PI) * x; double res = (z) / 2; double z2 = z * z; double zProd = z * z2; // z^3 res += (1.0 / 24) * zProd; zProd *= z2; // z^5 res += (7.0 / 960) * zProd; zProd *= z2; // z^7 res += (127 * zProd) / 80640; zProd *= z2; // z^9 res += (4369 * zProd) / 11612160; zProd *= z2; // z^11 res += (34807 * zProd) / 364953600; zProd *= z2; // z^13 res += (20036983 * zProd) / 797058662400d; return res; }
java
public static double inverseError(double x) { double z = Math.sqrt(Math.PI) * x; double res = (z) / 2; double z2 = z * z; double zProd = z * z2; // z^3 res += (1.0 / 24) * zProd; zProd *= z2; // z^5 res += (7.0 / 960) * zProd; zProd *= z2; // z^7 res += (127 * zProd) / 80640; zProd *= z2; // z^9 res += (4369 * zProd) / 11612160; zProd *= z2; // z^11 res += (34807 * zProd) / 364953600; zProd *= z2; // z^13 res += (20036983 * zProd) / 797058662400d; return res; }
[ "public", "static", "double", "inverseError", "(", "double", "x", ")", "{", "double", "z", "=", "Math", ".", "sqrt", "(", "Math", ".", "PI", ")", "*", "x", ";", "double", "res", "=", "(", "z", ")", "/", "2", ";", "double", "z2", "=", "z", "*", "z", ";", "double", "zProd", "=", "z", "*", "z2", ";", "// z^3", "res", "+=", "(", "1.0", "/", "24", ")", "*", "zProd", ";", "zProd", "*=", "z2", ";", "// z^5", "res", "+=", "(", "7.0", "/", "960", ")", "*", "zProd", ";", "zProd", "*=", "z2", ";", "// z^7", "res", "+=", "(", "127", "*", "zProd", ")", "/", "80640", ";", "zProd", "*=", "z2", ";", "// z^9", "res", "+=", "(", "4369", "*", "zProd", ")", "/", "11612160", ";", "zProd", "*=", "z2", ";", "// z^11", "res", "+=", "(", "34807", "*", "zProd", ")", "/", "364953600", ";", "zProd", "*=", "z2", ";", "// z^13", "res", "+=", "(", "20036983", "*", "zProd", ")", "/", "797058662400d", ";", "return", "res", ";", "}" ]
Approximates the inverse error function. Clustream needs this. @param z
[ "Approximates", "the", "inverse", "error", "function", ".", "Clustream", "needs", "this", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustream/ClustreamKernel.java#L231-L255
29,018
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/BICO.java
BICO.bicoUpdate
protected void bicoUpdate(double[] x) { assert (!this.bufferPhase && this.numDimensions == x.length); // Starts with the global root node as the current root node ClusteringTreeNode r = this.root; int i = 1; while (true) { ClusteringTreeNode y = r.nearestChild(x); // Checks if the point can not be added to the current level if (r.hasNoChildren() || y == null || Metric.distanceSquared(x, y.getCenter()) > calcRSquared(i)) { // Creates a new node for the point and adds it to the current // root node r.addChild(new ClusteringTreeNode(x, new ClusteringFeature(x, calcR(i)))); this.rootCount++; break; } else { // Checks if the point can be added to the nearest node without // exceeding the global threshold if (y.getClusteringFeature().calcKMeansCosts(y.getCenter(), x) <= this.T) { // Adds the point to the ClusteringFeature y.getClusteringFeature().add(1, x, Metric.distanceSquared(x)); break; } else { // Navigates one level down in the tree r = y; i++; } } } // Checks if the number of nodes in the tree exceeds the maximum number if (this.rootCount > this.maxNumClusterFeatures) { rebuild(); } }
java
protected void bicoUpdate(double[] x) { assert (!this.bufferPhase && this.numDimensions == x.length); // Starts with the global root node as the current root node ClusteringTreeNode r = this.root; int i = 1; while (true) { ClusteringTreeNode y = r.nearestChild(x); // Checks if the point can not be added to the current level if (r.hasNoChildren() || y == null || Metric.distanceSquared(x, y.getCenter()) > calcRSquared(i)) { // Creates a new node for the point and adds it to the current // root node r.addChild(new ClusteringTreeNode(x, new ClusteringFeature(x, calcR(i)))); this.rootCount++; break; } else { // Checks if the point can be added to the nearest node without // exceeding the global threshold if (y.getClusteringFeature().calcKMeansCosts(y.getCenter(), x) <= this.T) { // Adds the point to the ClusteringFeature y.getClusteringFeature().add(1, x, Metric.distanceSquared(x)); break; } else { // Navigates one level down in the tree r = y; i++; } } } // Checks if the number of nodes in the tree exceeds the maximum number if (this.rootCount > this.maxNumClusterFeatures) { rebuild(); } }
[ "protected", "void", "bicoUpdate", "(", "double", "[", "]", "x", ")", "{", "assert", "(", "!", "this", ".", "bufferPhase", "&&", "this", ".", "numDimensions", "==", "x", ".", "length", ")", ";", "// Starts with the global root node as the current root node", "ClusteringTreeNode", "r", "=", "this", ".", "root", ";", "int", "i", "=", "1", ";", "while", "(", "true", ")", "{", "ClusteringTreeNode", "y", "=", "r", ".", "nearestChild", "(", "x", ")", ";", "// Checks if the point can not be added to the current level", "if", "(", "r", ".", "hasNoChildren", "(", ")", "||", "y", "==", "null", "||", "Metric", ".", "distanceSquared", "(", "x", ",", "y", ".", "getCenter", "(", ")", ")", ">", "calcRSquared", "(", "i", ")", ")", "{", "// Creates a new node for the point and adds it to the current", "// root node", "r", ".", "addChild", "(", "new", "ClusteringTreeNode", "(", "x", ",", "new", "ClusteringFeature", "(", "x", ",", "calcR", "(", "i", ")", ")", ")", ")", ";", "this", ".", "rootCount", "++", ";", "break", ";", "}", "else", "{", "// Checks if the point can be added to the nearest node without", "// exceeding the global threshold", "if", "(", "y", ".", "getClusteringFeature", "(", ")", ".", "calcKMeansCosts", "(", "y", ".", "getCenter", "(", ")", ",", "x", ")", "<=", "this", ".", "T", ")", "{", "// Adds the point to the ClusteringFeature", "y", ".", "getClusteringFeature", "(", ")", ".", "add", "(", "1", ",", "x", ",", "Metric", ".", "distanceSquared", "(", "x", ")", ")", ";", "break", ";", "}", "else", "{", "// Navigates one level down in the tree", "r", "=", "y", ";", "i", "++", ";", "}", "}", "}", "// Checks if the number of nodes in the tree exceeds the maximum number", "if", "(", "this", ".", "rootCount", ">", "this", ".", "maxNumClusterFeatures", ")", "{", "rebuild", "(", ")", ";", "}", "}" ]
Inserts a new point into the ClusteringFeature tree. @param x the point
[ "Inserts", "a", "new", "point", "into", "the", "ClusteringFeature", "tree", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/BICO.java#L294-L328
29,019
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/BICO.java
BICO.rebuild
protected void rebuild() { // Checks if the number of nodes in the tree exceeds the maximum number while (this.rootCount > this.maxNumClusterFeatures) { // Doubles the global threshold this.T *= 2.0; this.root.setThreshold(calcRSquared(1)); // Adds all nodes to the ClusteringFeature tree again Queue<ClusteringTreeNode> Q = new LinkedList<ClusteringTreeNode>(); Q.addAll(this.root.getChildren()); this.root.clearChildren(); this.rootCount = 0; while (!Q.isEmpty()) { ClusteringTreeNode x = Q.element(); Q.addAll(x.getChildren()); x.clearChildren(); bicoCFUpdate(x); Q.remove(); } } }
java
protected void rebuild() { // Checks if the number of nodes in the tree exceeds the maximum number while (this.rootCount > this.maxNumClusterFeatures) { // Doubles the global threshold this.T *= 2.0; this.root.setThreshold(calcRSquared(1)); // Adds all nodes to the ClusteringFeature tree again Queue<ClusteringTreeNode> Q = new LinkedList<ClusteringTreeNode>(); Q.addAll(this.root.getChildren()); this.root.clearChildren(); this.rootCount = 0; while (!Q.isEmpty()) { ClusteringTreeNode x = Q.element(); Q.addAll(x.getChildren()); x.clearChildren(); bicoCFUpdate(x); Q.remove(); } } }
[ "protected", "void", "rebuild", "(", ")", "{", "// Checks if the number of nodes in the tree exceeds the maximum number", "while", "(", "this", ".", "rootCount", ">", "this", ".", "maxNumClusterFeatures", ")", "{", "// Doubles the global threshold", "this", ".", "T", "*=", "2.0", ";", "this", ".", "root", ".", "setThreshold", "(", "calcRSquared", "(", "1", ")", ")", ";", "// Adds all nodes to the ClusteringFeature tree again", "Queue", "<", "ClusteringTreeNode", ">", "Q", "=", "new", "LinkedList", "<", "ClusteringTreeNode", ">", "(", ")", ";", "Q", ".", "addAll", "(", "this", ".", "root", ".", "getChildren", "(", ")", ")", ";", "this", ".", "root", ".", "clearChildren", "(", ")", ";", "this", ".", "rootCount", "=", "0", ";", "while", "(", "!", "Q", ".", "isEmpty", "(", ")", ")", "{", "ClusteringTreeNode", "x", "=", "Q", ".", "element", "(", ")", ";", "Q", ".", "addAll", "(", "x", ".", "getChildren", "(", ")", ")", ";", "x", ".", "clearChildren", "(", ")", ";", "bicoCFUpdate", "(", "x", ")", ";", "Q", ".", "remove", "(", ")", ";", "}", "}", "}" ]
If the number of ClusteringTreeNodes exceeds the maximum bound, the global threshold T will be doubled and the tree will be rebuild with the new threshold.
[ "If", "the", "number", "of", "ClusteringTreeNodes", "exceeds", "the", "maximum", "bound", "the", "global", "threshold", "T", "will", "be", "doubled", "and", "the", "tree", "will", "be", "rebuild", "with", "the", "new", "threshold", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/BICO.java#L336-L355
29,020
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/BICO.java
BICO.bicoCFUpdate
protected void bicoCFUpdate(ClusteringTreeNode x) { // Starts with the global root node as the current root node ClusteringTreeNode r = this.root; int i = 1; while (true) { ClusteringTreeNode y = r.nearestChild(x.getCenter()); // Checks if the node can not be merged to the current level if (r.hasNoChildren() || y == null || Metric.distanceSquared(x.getCenter(), y.getCenter()) > calcRSquared(i)) { // Adds the node to the current root node x.setThreshold(calcR(i)); r.addChild(x); this.rootCount++; break; } else { // Checks if the node can be merged to the nearest node without // exceeding the global threshold if (y.getClusteringFeature().calcKMeansCosts(y.getCenter(), x.getClusteringFeature()) <= this.T) { // Merges the ClusteringFeature of the node to the // ClusteringFeature of the nearest node y.getClusteringFeature().merge(x.getClusteringFeature()); break; } else { // Navigates one level down in the tree r = y; i++; } } } }
java
protected void bicoCFUpdate(ClusteringTreeNode x) { // Starts with the global root node as the current root node ClusteringTreeNode r = this.root; int i = 1; while (true) { ClusteringTreeNode y = r.nearestChild(x.getCenter()); // Checks if the node can not be merged to the current level if (r.hasNoChildren() || y == null || Metric.distanceSquared(x.getCenter(), y.getCenter()) > calcRSquared(i)) { // Adds the node to the current root node x.setThreshold(calcR(i)); r.addChild(x); this.rootCount++; break; } else { // Checks if the node can be merged to the nearest node without // exceeding the global threshold if (y.getClusteringFeature().calcKMeansCosts(y.getCenter(), x.getClusteringFeature()) <= this.T) { // Merges the ClusteringFeature of the node to the // ClusteringFeature of the nearest node y.getClusteringFeature().merge(x.getClusteringFeature()); break; } else { // Navigates one level down in the tree r = y; i++; } } } }
[ "protected", "void", "bicoCFUpdate", "(", "ClusteringTreeNode", "x", ")", "{", "// Starts with the global root node as the current root node", "ClusteringTreeNode", "r", "=", "this", ".", "root", ";", "int", "i", "=", "1", ";", "while", "(", "true", ")", "{", "ClusteringTreeNode", "y", "=", "r", ".", "nearestChild", "(", "x", ".", "getCenter", "(", ")", ")", ";", "// Checks if the node can not be merged to the current level", "if", "(", "r", ".", "hasNoChildren", "(", ")", "||", "y", "==", "null", "||", "Metric", ".", "distanceSquared", "(", "x", ".", "getCenter", "(", ")", ",", "y", ".", "getCenter", "(", ")", ")", ">", "calcRSquared", "(", "i", ")", ")", "{", "// Adds the node to the current root node", "x", ".", "setThreshold", "(", "calcR", "(", "i", ")", ")", ";", "r", ".", "addChild", "(", "x", ")", ";", "this", ".", "rootCount", "++", ";", "break", ";", "}", "else", "{", "// Checks if the node can be merged to the nearest node without", "// exceeding the global threshold", "if", "(", "y", ".", "getClusteringFeature", "(", ")", ".", "calcKMeansCosts", "(", "y", ".", "getCenter", "(", ")", ",", "x", ".", "getClusteringFeature", "(", ")", ")", "<=", "this", ".", "T", ")", "{", "// Merges the ClusteringFeature of the node to the", "// ClusteringFeature of the nearest node", "y", ".", "getClusteringFeature", "(", ")", ".", "merge", "(", "x", ".", "getClusteringFeature", "(", ")", ")", ";", "break", ";", "}", "else", "{", "// Navigates one level down in the tree", "r", "=", "y", ";", "i", "++", ";", "}", "}", "}", "}" ]
Inserts a ClusteringTreeNode into the ClusteringFeature tree. @param x the ClusteringTreeNode
[ "Inserts", "a", "ClusteringTreeNode", "into", "the", "ClusteringFeature", "tree", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/BICO.java#L363-L394
29,021
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NearestNeighbourSearch.java
NearestNeighbourSearch.combSort11
public static void combSort11(double arrayToSort[], int linkedArray[]) { int switches, j, top, gap; double hold1; int hold2; gap = arrayToSort.length; do { gap=(int)(gap/1.3); switch(gap) { case 0: gap = 1; break; case 9: case 10: gap=11; break; default: break; } switches=0; top = arrayToSort.length-gap; for(int i=0; i<top; i++) { j=i+gap; if(arrayToSort[i] > arrayToSort[j]) { hold1=arrayToSort[i]; hold2=linkedArray[i]; arrayToSort[i]=arrayToSort[j]; linkedArray[i]=linkedArray[j]; arrayToSort[j]=hold1; linkedArray[j]=hold2; switches++; }//endif }//endfor } while(switches>0 || gap>1); }
java
public static void combSort11(double arrayToSort[], int linkedArray[]) { int switches, j, top, gap; double hold1; int hold2; gap = arrayToSort.length; do { gap=(int)(gap/1.3); switch(gap) { case 0: gap = 1; break; case 9: case 10: gap=11; break; default: break; } switches=0; top = arrayToSort.length-gap; for(int i=0; i<top; i++) { j=i+gap; if(arrayToSort[i] > arrayToSort[j]) { hold1=arrayToSort[i]; hold2=linkedArray[i]; arrayToSort[i]=arrayToSort[j]; linkedArray[i]=linkedArray[j]; arrayToSort[j]=hold1; linkedArray[j]=hold2; switches++; }//endif }//endfor } while(switches>0 || gap>1); }
[ "public", "static", "void", "combSort11", "(", "double", "arrayToSort", "[", "]", ",", "int", "linkedArray", "[", "]", ")", "{", "int", "switches", ",", "j", ",", "top", ",", "gap", ";", "double", "hold1", ";", "int", "hold2", ";", "gap", "=", "arrayToSort", ".", "length", ";", "do", "{", "gap", "=", "(", "int", ")", "(", "gap", "/", "1.3", ")", ";", "switch", "(", "gap", ")", "{", "case", "0", ":", "gap", "=", "1", ";", "break", ";", "case", "9", ":", "case", "10", ":", "gap", "=", "11", ";", "break", ";", "default", ":", "break", ";", "}", "switches", "=", "0", ";", "top", "=", "arrayToSort", ".", "length", "-", "gap", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "top", ";", "i", "++", ")", "{", "j", "=", "i", "+", "gap", ";", "if", "(", "arrayToSort", "[", "i", "]", ">", "arrayToSort", "[", "j", "]", ")", "{", "hold1", "=", "arrayToSort", "[", "i", "]", ";", "hold2", "=", "linkedArray", "[", "i", "]", ";", "arrayToSort", "[", "i", "]", "=", "arrayToSort", "[", "j", "]", ";", "linkedArray", "[", "i", "]", "=", "linkedArray", "[", "j", "]", ";", "arrayToSort", "[", "j", "]", "=", "hold1", ";", "linkedArray", "[", "j", "]", "=", "hold2", ";", "switches", "++", ";", "}", "//endif", "}", "//endfor", "}", "while", "(", "switches", ">", "0", "||", "gap", ">", "1", ")", ";", "}" ]
sorts the two given arrays. @param arrayToSort The array sorting should be based on. @param linkedArray The array that should have the same ordering as arrayToSort.
[ "sorts", "the", "two", "given", "arrays", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NearestNeighbourSearch.java#L653-L685
29,022
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/NearestNeighbourSearch.java
NearestNeighbourSearch.quickSort
public static void quickSort(double[] arrayToSort, double[] linkedArray, int left, int right) { if (left < right) { int middle = partition(arrayToSort, linkedArray, left, right); quickSort(arrayToSort, linkedArray, left, middle); quickSort(arrayToSort, linkedArray, middle + 1, right); } }
java
public static void quickSort(double[] arrayToSort, double[] linkedArray, int left, int right) { if (left < right) { int middle = partition(arrayToSort, linkedArray, left, right); quickSort(arrayToSort, linkedArray, left, middle); quickSort(arrayToSort, linkedArray, middle + 1, right); } }
[ "public", "static", "void", "quickSort", "(", "double", "[", "]", "arrayToSort", ",", "double", "[", "]", "linkedArray", ",", "int", "left", ",", "int", "right", ")", "{", "if", "(", "left", "<", "right", ")", "{", "int", "middle", "=", "partition", "(", "arrayToSort", ",", "linkedArray", ",", "left", ",", "right", ")", ";", "quickSort", "(", "arrayToSort", ",", "linkedArray", ",", "left", ",", "middle", ")", ";", "quickSort", "(", "arrayToSort", ",", "linkedArray", ",", "middle", "+", "1", ",", "right", ")", ";", "}", "}" ]
performs quicksort. @param arrayToSort the array to sort @param linkedArray the linked array @param left the first index of the subset @param right the last index of the subset
[ "performs", "quicksort", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/NearestNeighbourSearch.java#L734-L740
29,023
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.kNearestNeighbours
public Instances kNearestNeighbours(Instance target, int k) throws Exception { checkMissing(target); MyHeap heap = new MyHeap(k); findNearestNeighbours(target, m_Root, k, heap, 0.0); Instances neighbours = new Instances(m_Instances, (heap.size() + heap .noOfKthNearest())); m_DistanceList = new double[heap.size() + heap.noOfKthNearest()]; int[] indices = new int[heap.size() + heap.noOfKthNearest()]; int i = indices.length - 1; MyHeapElement h; while (heap.noOfKthNearest() > 0) { h = heap.getKthNearest(); indices[i] = h.index; m_DistanceList[i] = h.distance; i--; } while (heap.size() > 0) { h = heap.get(); indices[i] = h.index; m_DistanceList[i] = h.distance; i--; } m_DistanceFunction.postProcessDistances(m_DistanceList); for (int idx = 0; idx < indices.length; idx++) { neighbours.add(m_Instances.instance(indices[idx])); } return neighbours; }
java
public Instances kNearestNeighbours(Instance target, int k) throws Exception { checkMissing(target); MyHeap heap = new MyHeap(k); findNearestNeighbours(target, m_Root, k, heap, 0.0); Instances neighbours = new Instances(m_Instances, (heap.size() + heap .noOfKthNearest())); m_DistanceList = new double[heap.size() + heap.noOfKthNearest()]; int[] indices = new int[heap.size() + heap.noOfKthNearest()]; int i = indices.length - 1; MyHeapElement h; while (heap.noOfKthNearest() > 0) { h = heap.getKthNearest(); indices[i] = h.index; m_DistanceList[i] = h.distance; i--; } while (heap.size() > 0) { h = heap.get(); indices[i] = h.index; m_DistanceList[i] = h.distance; i--; } m_DistanceFunction.postProcessDistances(m_DistanceList); for (int idx = 0; idx < indices.length; idx++) { neighbours.add(m_Instances.instance(indices[idx])); } return neighbours; }
[ "public", "Instances", "kNearestNeighbours", "(", "Instance", "target", ",", "int", "k", ")", "throws", "Exception", "{", "checkMissing", "(", "target", ")", ";", "MyHeap", "heap", "=", "new", "MyHeap", "(", "k", ")", ";", "findNearestNeighbours", "(", "target", ",", "m_Root", ",", "k", ",", "heap", ",", "0.0", ")", ";", "Instances", "neighbours", "=", "new", "Instances", "(", "m_Instances", ",", "(", "heap", ".", "size", "(", ")", "+", "heap", ".", "noOfKthNearest", "(", ")", ")", ")", ";", "m_DistanceList", "=", "new", "double", "[", "heap", ".", "size", "(", ")", "+", "heap", ".", "noOfKthNearest", "(", ")", "]", ";", "int", "[", "]", "indices", "=", "new", "int", "[", "heap", ".", "size", "(", ")", "+", "heap", ".", "noOfKthNearest", "(", ")", "]", ";", "int", "i", "=", "indices", ".", "length", "-", "1", ";", "MyHeapElement", "h", ";", "while", "(", "heap", ".", "noOfKthNearest", "(", ")", ">", "0", ")", "{", "h", "=", "heap", ".", "getKthNearest", "(", ")", ";", "indices", "[", "i", "]", "=", "h", ".", "index", ";", "m_DistanceList", "[", "i", "]", "=", "h", ".", "distance", ";", "i", "--", ";", "}", "while", "(", "heap", ".", "size", "(", ")", ">", "0", ")", "{", "h", "=", "heap", ".", "get", "(", ")", ";", "indices", "[", "i", "]", "=", "h", ".", "index", ";", "m_DistanceList", "[", "i", "]", "=", "h", ".", "distance", ";", "i", "--", ";", "}", "m_DistanceFunction", ".", "postProcessDistances", "(", "m_DistanceList", ")", ";", "for", "(", "int", "idx", "=", "0", ";", "idx", "<", "indices", ".", "length", ";", "idx", "++", ")", "{", "neighbours", ".", "add", "(", "m_Instances", ".", "instance", "(", "indices", "[", "idx", "]", ")", ")", ";", "}", "return", "neighbours", ";", "}" ]
Returns the k nearest neighbours of the supplied instance. &gt;k neighbours are returned if there are more than one neighbours at the kth boundary. @param target The instance to find the nearest neighbours for. @param k The number of neighbours to find. @return The k nearest neighbours (or &gt;k if more there are than one neighbours at the kth boundary). @throws Exception if the nearest neighbour could not be found.
[ "Returns", "the", "k", "nearest", "neighbours", "of", "the", "supplied", "instance", ".", "&gt", ";", "k", "neighbours", "are", "returned", "if", "there", "are", "more", "than", "one", "neighbours", "at", "the", "kth", "boundary", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L328-L359
29,024
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.update
public void update(Instance instance) throws Exception { // better to change // to addInstance if (m_Instances == null) throw new Exception("No instances supplied yet. Have to call " + "setInstances(instances) with a set of Instances " + "first."); addInstanceInfo(instance); addInstanceToTree(instance, m_Root); }
java
public void update(Instance instance) throws Exception { // better to change // to addInstance if (m_Instances == null) throw new Exception("No instances supplied yet. Have to call " + "setInstances(instances) with a set of Instances " + "first."); addInstanceInfo(instance); addInstanceToTree(instance, m_Root); }
[ "public", "void", "update", "(", "Instance", "instance", ")", "throws", "Exception", "{", "// better to change", "// to addInstance", "if", "(", "m_Instances", "==", "null", ")", "throw", "new", "Exception", "(", "\"No instances supplied yet. Have to call \"", "+", "\"setInstances(instances) with a set of Instances \"", "+", "\"first.\"", ")", ";", "addInstanceInfo", "(", "instance", ")", ";", "addInstanceToTree", "(", "instance", ",", "m_Root", ")", ";", "}" ]
Adds one instance to the KDTree. This updates the KDTree structure to take into account the newly added training instance. @param instance the instance to be added. Usually the newly added instance in the training set. @throws Exception If the instance cannot be added.
[ "Adds", "one", "instance", "to", "the", "KDTree", ".", "This", "updates", "the", "KDTree", "structure", "to", "take", "into", "account", "the", "newly", "added", "training", "instance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L416-L424
29,025
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.checkMissing
protected void checkMissing(Instances instances) throws Exception { for (int i = 0; i < instances.numInstances(); i++) { Instance ins = instances.instance(i); for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } } }
java
protected void checkMissing(Instances instances) throws Exception { for (int i = 0; i < instances.numInstances(); i++) { Instance ins = instances.instance(i); for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } } }
[ "protected", "void", "checkMissing", "(", "Instances", "instances", ")", "throws", "Exception", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "instances", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "Instance", "ins", "=", "instances", ".", "instance", "(", "i", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "ins", ".", "numValues", "(", ")", ";", "j", "++", ")", "{", "if", "(", "ins", ".", "index", "(", "j", ")", "!=", "ins", ".", "classIndex", "(", ")", ")", "if", "(", "ins", ".", "isMissingSparse", "(", "j", ")", ")", "{", "throw", "new", "Exception", "(", "\"ERROR: KDTree can not deal with missing \"", "+", "\"values. Please run ReplaceMissingValues filter \"", "+", "\"on the dataset before passing it on to the KDTree.\"", ")", ";", "}", "}", "}", "}" ]
Checks if there is any instance with missing values. Throws an exception if there is, as KDTree does not handle missing values. @param instances the instances to check @throws Exception if missing values are encountered
[ "Checks", "if", "there", "is", "any", "instance", "with", "missing", "values", ".", "Throws", "an", "exception", "if", "there", "is", "as", "KDTree", "does", "not", "handle", "missing", "values", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L530-L542
29,026
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.checkMissing
protected void checkMissing(Instance ins) throws Exception { for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } }
java
protected void checkMissing(Instance ins) throws Exception { for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } }
[ "protected", "void", "checkMissing", "(", "Instance", "ins", ")", "throws", "Exception", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "ins", ".", "numValues", "(", ")", ";", "j", "++", ")", "{", "if", "(", "ins", ".", "index", "(", "j", ")", "!=", "ins", ".", "classIndex", "(", ")", ")", "if", "(", "ins", ".", "isMissingSparse", "(", "j", ")", ")", "{", "throw", "new", "Exception", "(", "\"ERROR: KDTree can not deal with missing \"", "+", "\"values. Please run ReplaceMissingValues filter \"", "+", "\"on the dataset before passing it on to the KDTree.\"", ")", ";", "}", "}", "}" ]
Checks if there is any missing value in the given instance. @param ins The instance to check missing values in. @throws Exception If there is a missing value in the instance.
[ "Checks", "if", "there", "is", "any", "missing", "value", "in", "the", "given", "instance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L551-L560
29,027
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.enumerateMeasures
public Enumeration enumerateMeasures() { Vector<String> newVector = new Vector<String>(); newVector.addElement("measureTreeSize"); newVector.addElement("measureNumLeaves"); newVector.addElement("measureMaxDepth"); return newVector.elements(); }
java
public Enumeration enumerateMeasures() { Vector<String> newVector = new Vector<String>(); newVector.addElement("measureTreeSize"); newVector.addElement("measureNumLeaves"); newVector.addElement("measureMaxDepth"); return newVector.elements(); }
[ "public", "Enumeration", "enumerateMeasures", "(", ")", "{", "Vector", "<", "String", ">", "newVector", "=", "new", "Vector", "<", "String", ">", "(", ")", ";", "newVector", ".", "addElement", "(", "\"measureTreeSize\"", ")", ";", "newVector", ".", "addElement", "(", "\"measureNumLeaves\"", ")", ";", "newVector", ".", "addElement", "(", "\"measureMaxDepth\"", ")", ";", "return", "newVector", ".", "elements", "(", ")", ";", "}" ]
Returns an enumeration of the additional measure names. @return an enumeration of the measure names
[ "Returns", "an", "enumeration", "of", "the", "additional", "measure", "names", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L653-L659
29,028
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.getMeasure
public double getMeasure(String additionalMeasureName) { if (additionalMeasureName.compareToIgnoreCase("measureMaxDepth") == 0) { return measureMaxDepth(); } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) { return measureTreeSize(); } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) { return measureNumLeaves(); } else { throw new IllegalArgumentException(additionalMeasureName + " not supported (KDTree)"); } }
java
public double getMeasure(String additionalMeasureName) { if (additionalMeasureName.compareToIgnoreCase("measureMaxDepth") == 0) { return measureMaxDepth(); } else if (additionalMeasureName.compareToIgnoreCase("measureTreeSize") == 0) { return measureTreeSize(); } else if (additionalMeasureName.compareToIgnoreCase("measureNumLeaves") == 0) { return measureNumLeaves(); } else { throw new IllegalArgumentException(additionalMeasureName + " not supported (KDTree)"); } }
[ "public", "double", "getMeasure", "(", "String", "additionalMeasureName", ")", "{", "if", "(", "additionalMeasureName", ".", "compareToIgnoreCase", "(", "\"measureMaxDepth\"", ")", "==", "0", ")", "{", "return", "measureMaxDepth", "(", ")", ";", "}", "else", "if", "(", "additionalMeasureName", ".", "compareToIgnoreCase", "(", "\"measureTreeSize\"", ")", "==", "0", ")", "{", "return", "measureTreeSize", "(", ")", ";", "}", "else", "if", "(", "additionalMeasureName", ".", "compareToIgnoreCase", "(", "\"measureNumLeaves\"", ")", "==", "0", ")", "{", "return", "measureNumLeaves", "(", ")", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "additionalMeasureName", "+", "\" not supported (KDTree)\"", ")", ";", "}", "}" ]
Returns the value of the named measure. @param additionalMeasureName the name of the measure to query for its value. @return The value of the named measure @throws IllegalArgumentException If the named measure is not supported.
[ "Returns", "the", "value", "of", "the", "named", "measure", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L670-L681
29,029
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.centerInstances
public void centerInstances(Instances centers, int[] assignments, double pc) throws Exception { int[] centList = new int[centers.numInstances()]; for (int i = 0; i < centers.numInstances(); i++) centList[i] = i; determineAssignments(m_Root, centers, centList, assignments, pc); }
java
public void centerInstances(Instances centers, int[] assignments, double pc) throws Exception { int[] centList = new int[centers.numInstances()]; for (int i = 0; i < centers.numInstances(); i++) centList[i] = i; determineAssignments(m_Root, centers, centList, assignments, pc); }
[ "public", "void", "centerInstances", "(", "Instances", "centers", ",", "int", "[", "]", "assignments", ",", "double", "pc", ")", "throws", "Exception", "{", "int", "[", "]", "centList", "=", "new", "int", "[", "centers", ".", "numInstances", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "centers", ".", "numInstances", "(", ")", ";", "i", "++", ")", "centList", "[", "i", "]", "=", "i", ";", "determineAssignments", "(", "m_Root", ",", "centers", ",", "centList", ",", "assignments", ",", "pc", ")", ";", "}" ]
Assigns instances to centers using KDTree. @param centers the current centers @param assignments the centerindex for each instance @param pc the threshold value for pruning. @throws Exception If there is some problem assigning instances to centers.
[ "Assigns", "instances", "to", "centers", "using", "KDTree", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L701-L709
29,030
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.determineAssignments
protected void determineAssignments(KDTreeNode node, Instances centers, int[] candidates, int[] assignments, double pc) throws Exception { // reduce number of owners for current hyper rectangle int[] owners = refineOwners(node, centers, candidates); // only one owner if (owners.length == 1) { // all instances of this node are owned by one center for (int i = node.m_Start; i <= node.m_End; i++) { assignments[m_InstList[i]] // the assignment of this instance = owners[0]; // is the current owner } } else if (!node.isALeaf()) { // more than one owner and it is not a leaf determineAssignments(node.m_Left, centers, owners, assignments, pc); determineAssignments(node.m_Right, centers, owners, assignments, pc); } else { // this is a leaf and there are more than 1 owner // XMeans. assignSubToCenters(node, centers, owners, assignments); } }
java
protected void determineAssignments(KDTreeNode node, Instances centers, int[] candidates, int[] assignments, double pc) throws Exception { // reduce number of owners for current hyper rectangle int[] owners = refineOwners(node, centers, candidates); // only one owner if (owners.length == 1) { // all instances of this node are owned by one center for (int i = node.m_Start; i <= node.m_End; i++) { assignments[m_InstList[i]] // the assignment of this instance = owners[0]; // is the current owner } } else if (!node.isALeaf()) { // more than one owner and it is not a leaf determineAssignments(node.m_Left, centers, owners, assignments, pc); determineAssignments(node.m_Right, centers, owners, assignments, pc); } else { // this is a leaf and there are more than 1 owner // XMeans. assignSubToCenters(node, centers, owners, assignments); } }
[ "protected", "void", "determineAssignments", "(", "KDTreeNode", "node", ",", "Instances", "centers", ",", "int", "[", "]", "candidates", ",", "int", "[", "]", "assignments", ",", "double", "pc", ")", "throws", "Exception", "{", "// reduce number of owners for current hyper rectangle", "int", "[", "]", "owners", "=", "refineOwners", "(", "node", ",", "centers", ",", "candidates", ")", ";", "// only one owner", "if", "(", "owners", ".", "length", "==", "1", ")", "{", "// all instances of this node are owned by one center", "for", "(", "int", "i", "=", "node", ".", "m_Start", ";", "i", "<=", "node", ".", "m_End", ";", "i", "++", ")", "{", "assignments", "[", "m_InstList", "[", "i", "]", "]", "// the assignment of this instance", "=", "owners", "[", "0", "]", ";", "// is the current owner", "}", "}", "else", "if", "(", "!", "node", ".", "isALeaf", "(", ")", ")", "{", "// more than one owner and it is not a leaf", "determineAssignments", "(", "node", ".", "m_Left", ",", "centers", ",", "owners", ",", "assignments", ",", "pc", ")", ";", "determineAssignments", "(", "node", ".", "m_Right", ",", "centers", ",", "owners", ",", "assignments", ",", "pc", ")", ";", "}", "else", "{", "// this is a leaf and there are more than 1 owner", "// XMeans.", "assignSubToCenters", "(", "node", ",", "centers", ",", "owners", ",", "assignments", ")", ";", "}", "}" ]
Assigns instances to the current centers called candidates. @param node The node to start assigning the instances from. @param centers all the current centers. @param candidates the current centers the method works on. @param assignments the center index for each instance. @param pc the threshold value for pruning. @throws Exception If there is some problem assigning instances to centers.
[ "Assigns", "instances", "to", "the", "current", "centers", "called", "candidates", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L722-L744
29,031
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.refineOwners
protected int[] refineOwners(KDTreeNode node, Instances centers, int[] candidates) throws Exception { int[] owners = new int[candidates.length]; double minDistance = Double.POSITIVE_INFINITY; int ownerIndex = -1; Instance owner; int numCand = candidates.length; double[] distance = new double[numCand]; boolean[] inside = new boolean[numCand]; for (int i = 0; i < numCand; i++) { distance[i] = distanceToHrect(node, centers.instance(candidates[i])); inside[i] = (distance[i] == 0.0); if (distance[i] < minDistance) { minDistance = distance[i]; ownerIndex = i; } } owner = (Instance)centers.instance(candidates[ownerIndex]).copy(); // are there other owners // loop also goes over already found owner, keeps order // in owner list int index = 0; for (int i = 0; i < numCand; i++) { // 1. all centers that are points within rectangle are owners if ((inside[i]) // 2. take all points with same distance to the rect. as the owner || (distance[i] == distance[ownerIndex])) { // add competitor to owners list owners[index++] = candidates[i]; } else { Instance competitor = (Instance)centers.instance(candidates[i]).copy(); if // 3. point has larger distance to rectangle but still can compete // with owner for some points in the rectangle (!candidateIsFullOwner(node, owner, competitor)) { // also add competitor to owners list owners[index++] = candidates[i]; } } } int[] result = new int[index]; for (int i = 0; i < index; i++) result[i] = owners[i]; return result; }
java
protected int[] refineOwners(KDTreeNode node, Instances centers, int[] candidates) throws Exception { int[] owners = new int[candidates.length]; double minDistance = Double.POSITIVE_INFINITY; int ownerIndex = -1; Instance owner; int numCand = candidates.length; double[] distance = new double[numCand]; boolean[] inside = new boolean[numCand]; for (int i = 0; i < numCand; i++) { distance[i] = distanceToHrect(node, centers.instance(candidates[i])); inside[i] = (distance[i] == 0.0); if (distance[i] < minDistance) { minDistance = distance[i]; ownerIndex = i; } } owner = (Instance)centers.instance(candidates[ownerIndex]).copy(); // are there other owners // loop also goes over already found owner, keeps order // in owner list int index = 0; for (int i = 0; i < numCand; i++) { // 1. all centers that are points within rectangle are owners if ((inside[i]) // 2. take all points with same distance to the rect. as the owner || (distance[i] == distance[ownerIndex])) { // add competitor to owners list owners[index++] = candidates[i]; } else { Instance competitor = (Instance)centers.instance(candidates[i]).copy(); if // 3. point has larger distance to rectangle but still can compete // with owner for some points in the rectangle (!candidateIsFullOwner(node, owner, competitor)) { // also add competitor to owners list owners[index++] = candidates[i]; } } } int[] result = new int[index]; for (int i = 0; i < index; i++) result[i] = owners[i]; return result; }
[ "protected", "int", "[", "]", "refineOwners", "(", "KDTreeNode", "node", ",", "Instances", "centers", ",", "int", "[", "]", "candidates", ")", "throws", "Exception", "{", "int", "[", "]", "owners", "=", "new", "int", "[", "candidates", ".", "length", "]", ";", "double", "minDistance", "=", "Double", ".", "POSITIVE_INFINITY", ";", "int", "ownerIndex", "=", "-", "1", ";", "Instance", "owner", ";", "int", "numCand", "=", "candidates", ".", "length", ";", "double", "[", "]", "distance", "=", "new", "double", "[", "numCand", "]", ";", "boolean", "[", "]", "inside", "=", "new", "boolean", "[", "numCand", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numCand", ";", "i", "++", ")", "{", "distance", "[", "i", "]", "=", "distanceToHrect", "(", "node", ",", "centers", ".", "instance", "(", "candidates", "[", "i", "]", ")", ")", ";", "inside", "[", "i", "]", "=", "(", "distance", "[", "i", "]", "==", "0.0", ")", ";", "if", "(", "distance", "[", "i", "]", "<", "minDistance", ")", "{", "minDistance", "=", "distance", "[", "i", "]", ";", "ownerIndex", "=", "i", ";", "}", "}", "owner", "=", "(", "Instance", ")", "centers", ".", "instance", "(", "candidates", "[", "ownerIndex", "]", ")", ".", "copy", "(", ")", ";", "// are there other owners", "// loop also goes over already found owner, keeps order", "// in owner list", "int", "index", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numCand", ";", "i", "++", ")", "{", "// 1. all centers that are points within rectangle are owners", "if", "(", "(", "inside", "[", "i", "]", ")", "// 2. take all points with same distance to the rect. as the owner", "||", "(", "distance", "[", "i", "]", "==", "distance", "[", "ownerIndex", "]", ")", ")", "{", "// add competitor to owners list", "owners", "[", "index", "++", "]", "=", "candidates", "[", "i", "]", ";", "}", "else", "{", "Instance", "competitor", "=", "(", "Instance", ")", "centers", ".", "instance", "(", "candidates", "[", "i", "]", ")", ".", "copy", "(", ")", ";", "if", "// 3. point has larger distance to rectangle but still can compete", "// with owner for some points in the rectangle", "(", "!", "candidateIsFullOwner", "(", "node", ",", "owner", ",", "competitor", ")", ")", "{", "// also add competitor to owners list", "owners", "[", "index", "++", "]", "=", "candidates", "[", "i", "]", ";", "}", "}", "}", "int", "[", "]", "result", "=", "new", "int", "[", "index", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "index", ";", "i", "++", ")", "result", "[", "i", "]", "=", "owners", "[", "i", "]", ";", "return", "result", ";", "}" ]
Refines the ownerlist. @param node The current tree node. @param centers all centers @param candidates the indexes of those centers that are candidates. @return list of owners @throws Exception If some problem occurs in refining.
[ "Refines", "the", "ownerlist", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L755-L807
29,032
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.distanceToHrect
protected double distanceToHrect(KDTreeNode node, Instance x) throws Exception { double distance = 0.0; Instance closestPoint = (Instance)x.copy(); boolean inside; inside = clipToInsideHrect(node, closestPoint); if (!inside) distance = m_EuclideanDistance.distance(closestPoint, x); return distance; }
java
protected double distanceToHrect(KDTreeNode node, Instance x) throws Exception { double distance = 0.0; Instance closestPoint = (Instance)x.copy(); boolean inside; inside = clipToInsideHrect(node, closestPoint); if (!inside) distance = m_EuclideanDistance.distance(closestPoint, x); return distance; }
[ "protected", "double", "distanceToHrect", "(", "KDTreeNode", "node", ",", "Instance", "x", ")", "throws", "Exception", "{", "double", "distance", "=", "0.0", ";", "Instance", "closestPoint", "=", "(", "Instance", ")", "x", ".", "copy", "(", ")", ";", "boolean", "inside", ";", "inside", "=", "clipToInsideHrect", "(", "node", ",", "closestPoint", ")", ";", "if", "(", "!", "inside", ")", "distance", "=", "m_EuclideanDistance", ".", "distance", "(", "closestPoint", ",", "x", ")", ";", "return", "distance", ";", "}" ]
Returns the distance between a point and an hyperrectangle. @param node The current node from whose hyperrectangle the distance is to be measured. @param x the point @return the distance @throws Exception If some problem occurs in determining the distance to the hyperrectangle.
[ "Returns", "the", "distance", "between", "a", "point", "and", "an", "hyperrectangle", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L819-L828
29,033
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.clipToInsideHrect
protected boolean clipToInsideHrect(KDTreeNode node, Instance x) { boolean inside = true; for (int i = 0; i < m_Instances.numAttributes(); i++) { // TODO treat nominals differently!?? if (x.value(i) < node.m_NodeRanges[i][MIN]) { x.setValue(i, node.m_NodeRanges[i][MIN]); inside = false; } else if (x.value(i) > node.m_NodeRanges[i][MAX]) { x.setValue(i, node.m_NodeRanges[i][MAX]); inside = false; } } return inside; }
java
protected boolean clipToInsideHrect(KDTreeNode node, Instance x) { boolean inside = true; for (int i = 0; i < m_Instances.numAttributes(); i++) { // TODO treat nominals differently!?? if (x.value(i) < node.m_NodeRanges[i][MIN]) { x.setValue(i, node.m_NodeRanges[i][MIN]); inside = false; } else if (x.value(i) > node.m_NodeRanges[i][MAX]) { x.setValue(i, node.m_NodeRanges[i][MAX]); inside = false; } } return inside; }
[ "protected", "boolean", "clipToInsideHrect", "(", "KDTreeNode", "node", ",", "Instance", "x", ")", "{", "boolean", "inside", "=", "true", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "m_Instances", ".", "numAttributes", "(", ")", ";", "i", "++", ")", "{", "// TODO treat nominals differently!??", "if", "(", "x", ".", "value", "(", "i", ")", "<", "node", ".", "m_NodeRanges", "[", "i", "]", "[", "MIN", "]", ")", "{", "x", ".", "setValue", "(", "i", ",", "node", ".", "m_NodeRanges", "[", "i", "]", "[", "MIN", "]", ")", ";", "inside", "=", "false", ";", "}", "else", "if", "(", "x", ".", "value", "(", "i", ")", ">", "node", ".", "m_NodeRanges", "[", "i", "]", "[", "MAX", "]", ")", "{", "x", ".", "setValue", "(", "i", ",", "node", ".", "m_NodeRanges", "[", "i", "]", "[", "MAX", "]", ")", ";", "inside", "=", "false", ";", "}", "}", "return", "inside", ";", "}" ]
Finds the closest point in the hyper rectangle to a given point. Change the given point to this closest point by clipping of at all the dimensions to be clipped of. If the point is inside the rectangle it stays unchanged. The return value is true if the point was not changed, so the the return value is true if the point was inside the rectangle. @param node The current KDTreeNode in whose hyperrectangle the closest point is to be found. @param x a point @return true if the input point stayed unchanged.
[ "Finds", "the", "closest", "point", "in", "the", "hyper", "rectangle", "to", "a", "given", "point", ".", "Change", "the", "given", "point", "to", "this", "closest", "point", "by", "clipping", "of", "at", "all", "the", "dimensions", "to", "be", "clipped", "of", ".", "If", "the", "point", "is", "inside", "the", "rectangle", "it", "stays", "unchanged", ".", "The", "return", "value", "is", "true", "if", "the", "point", "was", "not", "changed", "so", "the", "the", "return", "value", "is", "true", "if", "the", "point", "was", "inside", "the", "rectangle", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L842-L856
29,034
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.assignSubToCenters
public void assignSubToCenters(KDTreeNode node, Instances centers, int[] centList, int[] assignments) throws Exception { // todo: undecided situations int numCent = centList.length; // WARNING: assignments is "input/output-parameter" // should not be null and the following should not happen if (assignments == null) { assignments = new int[m_Instances.numInstances()]; for (int i = 0; i < assignments.length; i++) { assignments[i] = -1; } } // set assignments for all instances of this node for (int i = node.m_Start; i <= node.m_End; i++) { int instIndex = m_InstList[i]; Instance inst = m_Instances.instance(instIndex); // if (instList[i] == 664) System.out.println("664***"); int newC = m_EuclideanDistance.closestPoint(inst, centers, centList); // int newC = clusterProcessedInstance(inst, centers); assignments[instIndex] = newC; } }
java
public void assignSubToCenters(KDTreeNode node, Instances centers, int[] centList, int[] assignments) throws Exception { // todo: undecided situations int numCent = centList.length; // WARNING: assignments is "input/output-parameter" // should not be null and the following should not happen if (assignments == null) { assignments = new int[m_Instances.numInstances()]; for (int i = 0; i < assignments.length; i++) { assignments[i] = -1; } } // set assignments for all instances of this node for (int i = node.m_Start; i <= node.m_End; i++) { int instIndex = m_InstList[i]; Instance inst = m_Instances.instance(instIndex); // if (instList[i] == 664) System.out.println("664***"); int newC = m_EuclideanDistance.closestPoint(inst, centers, centList); // int newC = clusterProcessedInstance(inst, centers); assignments[instIndex] = newC; } }
[ "public", "void", "assignSubToCenters", "(", "KDTreeNode", "node", ",", "Instances", "centers", ",", "int", "[", "]", "centList", ",", "int", "[", "]", "assignments", ")", "throws", "Exception", "{", "// todo: undecided situations", "int", "numCent", "=", "centList", ".", "length", ";", "// WARNING: assignments is \"input/output-parameter\"", "// should not be null and the following should not happen", "if", "(", "assignments", "==", "null", ")", "{", "assignments", "=", "new", "int", "[", "m_Instances", ".", "numInstances", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "assignments", ".", "length", ";", "i", "++", ")", "{", "assignments", "[", "i", "]", "=", "-", "1", ";", "}", "}", "// set assignments for all instances of this node", "for", "(", "int", "i", "=", "node", ".", "m_Start", ";", "i", "<=", "node", ".", "m_End", ";", "i", "++", ")", "{", "int", "instIndex", "=", "m_InstList", "[", "i", "]", ";", "Instance", "inst", "=", "m_Instances", ".", "instance", "(", "instIndex", ")", ";", "// if (instList[i] == 664) System.out.println(\"664***\");", "int", "newC", "=", "m_EuclideanDistance", ".", "closestPoint", "(", "inst", ",", "centers", ",", "centList", ")", ";", "// int newC = clusterProcessedInstance(inst, centers);", "assignments", "[", "instIndex", "]", "=", "newC", ";", "}", "}" ]
Assigns instances of this node to center. Center to be assign to is decided by the distance function. @param node The KDTreeNode whose instances are to be assigned. @param centers all the input centers @param centList the list of centers to work with @param assignments index list of last assignments @throws Exception If there is error assigning the instances.
[ "Assigns", "instances", "of", "this", "node", "to", "center", ".", "Center", "to", "be", "assign", "to", "is", "decided", "by", "the", "distance", "function", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L910-L933
29,035
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java
KDTree.setDistanceFunction
public void setDistanceFunction(DistanceFunction df) throws Exception { if (!(df instanceof EuclideanDistance)) throw new Exception("KDTree currently only works with " + "EuclideanDistanceFunction."); m_DistanceFunction = m_EuclideanDistance = (EuclideanDistance) df; }
java
public void setDistanceFunction(DistanceFunction df) throws Exception { if (!(df instanceof EuclideanDistance)) throw new Exception("KDTree currently only works with " + "EuclideanDistanceFunction."); m_DistanceFunction = m_EuclideanDistance = (EuclideanDistance) df; }
[ "public", "void", "setDistanceFunction", "(", "DistanceFunction", "df", ")", "throws", "Exception", "{", "if", "(", "!", "(", "df", "instanceof", "EuclideanDistance", ")", ")", "throw", "new", "Exception", "(", "\"KDTree currently only works with \"", "+", "\"EuclideanDistanceFunction.\"", ")", ";", "m_DistanceFunction", "=", "m_EuclideanDistance", "=", "(", "EuclideanDistance", ")", "df", ";", "}" ]
sets the distance function to use for nearest neighbour search. @param df the distance function to use @throws Exception if not EuclideanDistance
[ "sets", "the", "distance", "function", "to", "use", "for", "nearest", "neighbour", "search", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/neighboursearch/KDTree.java#L1066-L1071
29,036
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.count
@Deprecated public int count() { int count = (clusteringFeature != null) ? 1 : 0; for (ClusteringTreeNode child : children) { count += child.count(); } return count; }
java
@Deprecated public int count() { int count = (clusteringFeature != null) ? 1 : 0; for (ClusteringTreeNode child : children) { count += child.count(); } return count; }
[ "@", "Deprecated", "public", "int", "count", "(", ")", "{", "int", "count", "=", "(", "clusteringFeature", "!=", "null", ")", "?", "1", ":", "0", ";", "for", "(", "ClusteringTreeNode", "child", ":", "children", ")", "{", "count", "+=", "child", ".", "count", "(", ")", ";", "}", "return", "count", ";", "}" ]
Counts the elements in tree with this node as the root. @deprecated @return the number of elements
[ "Counts", "the", "elements", "in", "tree", "with", "this", "node", "as", "the", "root", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L70-L77
29,037
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.addToClustering
public Clustering addToClustering(Clustering clustering) { if (center != null && getClusteringFeature() != null) { clustering.add(getClusteringFeature().toCluster()); } for (ClusteringTreeNode child : children) { child.addToClustering(clustering); } return clustering; }
java
public Clustering addToClustering(Clustering clustering) { if (center != null && getClusteringFeature() != null) { clustering.add(getClusteringFeature().toCluster()); } for (ClusteringTreeNode child : children) { child.addToClustering(clustering); } return clustering; }
[ "public", "Clustering", "addToClustering", "(", "Clustering", "clustering", ")", "{", "if", "(", "center", "!=", "null", "&&", "getClusteringFeature", "(", ")", "!=", "null", ")", "{", "clustering", ".", "add", "(", "getClusteringFeature", "(", ")", ".", "toCluster", "(", ")", ")", ";", "}", "for", "(", "ClusteringTreeNode", "child", ":", "children", ")", "{", "child", ".", "addToClustering", "(", "clustering", ")", ";", "}", "return", "clustering", ";", "}" ]
Adds all ClusterFeatures of the tree with this node as the root to a Clustering. @param clustering the Clustering to add the ClusterFeatures too. @return the input Clustering
[ "Adds", "all", "ClusterFeatures", "of", "the", "tree", "with", "this", "node", "as", "the", "root", "to", "a", "Clustering", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L87-L95
29,038
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.addToClusteringCenters
public List<double[]> addToClusteringCenters(List<double[]> clustering) { if (center != null && getClusteringFeature() != null) { clustering.add(getClusteringFeature().toClusterCenter()); } for (ClusteringTreeNode child : children) { child.addToClusteringCenters(clustering); } return clustering; }
java
public List<double[]> addToClusteringCenters(List<double[]> clustering) { if (center != null && getClusteringFeature() != null) { clustering.add(getClusteringFeature().toClusterCenter()); } for (ClusteringTreeNode child : children) { child.addToClusteringCenters(clustering); } return clustering; }
[ "public", "List", "<", "double", "[", "]", ">", "addToClusteringCenters", "(", "List", "<", "double", "[", "]", ">", "clustering", ")", "{", "if", "(", "center", "!=", "null", "&&", "getClusteringFeature", "(", ")", "!=", "null", ")", "{", "clustering", ".", "add", "(", "getClusteringFeature", "(", ")", ".", "toClusterCenter", "(", ")", ")", ";", "}", "for", "(", "ClusteringTreeNode", "child", ":", "children", ")", "{", "child", ".", "addToClusteringCenters", "(", "clustering", ")", ";", "}", "return", "clustering", ";", "}" ]
Adds all clustering centers of the ClusterFeatures of the tree with this node as the root to a List of points. @param clustering the List to add the clustering centers too. @return the input List
[ "Adds", "all", "clustering", "centers", "of", "the", "ClusterFeatures", "of", "the", "tree", "with", "this", "node", "as", "the", "root", "to", "a", "List", "of", "points", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L105-L113
29,039
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.printClusteringCenters
public void printClusteringCenters(Writer stream) throws IOException { if (center != null && getClusteringFeature() != null) { getClusteringFeature().printClusterCenter(stream); } for (ClusteringTreeNode child : children) { child.printClusteringCenters(stream); } }
java
public void printClusteringCenters(Writer stream) throws IOException { if (center != null && getClusteringFeature() != null) { getClusteringFeature().printClusterCenter(stream); } for (ClusteringTreeNode child : children) { child.printClusteringCenters(stream); } }
[ "public", "void", "printClusteringCenters", "(", "Writer", "stream", ")", "throws", "IOException", "{", "if", "(", "center", "!=", "null", "&&", "getClusteringFeature", "(", ")", "!=", "null", ")", "{", "getClusteringFeature", "(", ")", ".", "printClusterCenter", "(", "stream", ")", ";", "}", "for", "(", "ClusteringTreeNode", "child", ":", "children", ")", "{", "child", ".", "printClusteringCenters", "(", "stream", ")", ";", "}", "}" ]
Writes all clustering centers of the ClusterFeatures of the tree with this node as the root to a given stream. @param stream the stream @throws IOException If an I/O error occurs
[ "Writes", "all", "clustering", "centers", "of", "the", "ClusterFeatures", "of", "the", "tree", "with", "this", "node", "as", "the", "root", "to", "a", "given", "stream", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L124-L131
29,040
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.nearestChild
public ClusteringTreeNode nearestChild(double[] pointA) { assert (this.center.length == pointA.length); double minDistance = Double.POSITIVE_INFINITY; ClusteringTreeNode min = null; for (ClusteringTreeNode node : this.getChildren()) { double d = Metric.distance(pointA, node.getCenter()); if (d < minDistance) { minDistance = d; min = node; } } return min; }
java
public ClusteringTreeNode nearestChild(double[] pointA) { assert (this.center.length == pointA.length); double minDistance = Double.POSITIVE_INFINITY; ClusteringTreeNode min = null; for (ClusteringTreeNode node : this.getChildren()) { double d = Metric.distance(pointA, node.getCenter()); if (d < minDistance) { minDistance = d; min = node; } } return min; }
[ "public", "ClusteringTreeNode", "nearestChild", "(", "double", "[", "]", "pointA", ")", "{", "assert", "(", "this", ".", "center", ".", "length", "==", "pointA", ".", "length", ")", ";", "double", "minDistance", "=", "Double", ".", "POSITIVE_INFINITY", ";", "ClusteringTreeNode", "min", "=", "null", ";", "for", "(", "ClusteringTreeNode", "node", ":", "this", ".", "getChildren", "(", ")", ")", "{", "double", "d", "=", "Metric", ".", "distance", "(", "pointA", ",", "node", ".", "getCenter", "(", ")", ")", ";", "if", "(", "d", "<", "minDistance", ")", "{", "minDistance", "=", "d", ";", "min", "=", "node", ";", "}", "}", "return", "min", ";", "}" ]
Searches for the nearest child node by comparing each representation. @param pointA to find the nearest child for @return the child node which is the nearest
[ "Searches", "for", "the", "nearest", "child", "node", "by", "comparing", "each", "representation", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L188-L200
29,041
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java
ClusteringTreeNode.addChild
public boolean addChild(ClusteringTreeNode e) { assert (this.center.length == e.center.length); return this.children.add(e); }
java
public boolean addChild(ClusteringTreeNode e) { assert (this.center.length == e.center.length); return this.children.add(e); }
[ "public", "boolean", "addChild", "(", "ClusteringTreeNode", "e", ")", "{", "assert", "(", "this", ".", "center", ".", "length", "==", "e", ".", "center", ".", "length", ")", ";", "return", "this", ".", "children", ".", "add", "(", "e", ")", ";", "}" ]
Adds a child node. @param e the child node to add @return <code>true</code> @see java.util.List#add(java.lang.Object)
[ "Adds", "a", "child", "node", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringTreeNode.java#L210-L213
29,042
Waikato/moa
moa/src/main/java/moa/classifiers/meta/RCD.java
RCD.getPreviousClassifier
private ClassifierKS getPreviousClassifier(Classifier classifier, List<Instance> instances) { ExecutorService threadPool = Executors.newFixedThreadPool(this.threadSizeOption.getValue()); int SIZE = this.classifiers.size(); Map<Integer, Future<Double>> futures = new HashMap<>(); for (int i = 0; i < SIZE; i++) { ClassifierKS cs = this.classifiers.get(i); if (cs != null) { if (cs.getClassifier() != classifier) { StatisticalTest st = (StatisticalTest) getPreparedClassOption(this.statisticalTestOption); StatisticalTest temp = (StatisticalTest) st.copy(); temp.set(instances, cs.getInstances()); futures.put(i, threadPool.submit(temp)); } } else { break; } } ClassifierKS cks = null; int qtd = this.quantityClassifiersTestOption.getValue(); double maxPValue = this.similarityBetweenDistributionsOption.getValue(); try { for (int i = 0; i < SIZE && qtd > 0; i++) { Future<Double> f = futures.get(i); if (f != null) { double p = f.get(); if (p < maxPValue) { maxPValue = p; cks = this.classifiers.get(i); qtd--; } } } } catch (InterruptedException e) { System.out.println("Processing interrupted."); } catch (ExecutionException e) { throw new RuntimeException("Error computing statistical test.", e); } threadPool.shutdownNow(); return cks; }
java
private ClassifierKS getPreviousClassifier(Classifier classifier, List<Instance> instances) { ExecutorService threadPool = Executors.newFixedThreadPool(this.threadSizeOption.getValue()); int SIZE = this.classifiers.size(); Map<Integer, Future<Double>> futures = new HashMap<>(); for (int i = 0; i < SIZE; i++) { ClassifierKS cs = this.classifiers.get(i); if (cs != null) { if (cs.getClassifier() != classifier) { StatisticalTest st = (StatisticalTest) getPreparedClassOption(this.statisticalTestOption); StatisticalTest temp = (StatisticalTest) st.copy(); temp.set(instances, cs.getInstances()); futures.put(i, threadPool.submit(temp)); } } else { break; } } ClassifierKS cks = null; int qtd = this.quantityClassifiersTestOption.getValue(); double maxPValue = this.similarityBetweenDistributionsOption.getValue(); try { for (int i = 0; i < SIZE && qtd > 0; i++) { Future<Double> f = futures.get(i); if (f != null) { double p = f.get(); if (p < maxPValue) { maxPValue = p; cks = this.classifiers.get(i); qtd--; } } } } catch (InterruptedException e) { System.out.println("Processing interrupted."); } catch (ExecutionException e) { throw new RuntimeException("Error computing statistical test.", e); } threadPool.shutdownNow(); return cks; }
[ "private", "ClassifierKS", "getPreviousClassifier", "(", "Classifier", "classifier", ",", "List", "<", "Instance", ">", "instances", ")", "{", "ExecutorService", "threadPool", "=", "Executors", ".", "newFixedThreadPool", "(", "this", ".", "threadSizeOption", ".", "getValue", "(", ")", ")", ";", "int", "SIZE", "=", "this", ".", "classifiers", ".", "size", "(", ")", ";", "Map", "<", "Integer", ",", "Future", "<", "Double", ">", ">", "futures", "=", "new", "HashMap", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "SIZE", ";", "i", "++", ")", "{", "ClassifierKS", "cs", "=", "this", ".", "classifiers", ".", "get", "(", "i", ")", ";", "if", "(", "cs", "!=", "null", ")", "{", "if", "(", "cs", ".", "getClassifier", "(", ")", "!=", "classifier", ")", "{", "StatisticalTest", "st", "=", "(", "StatisticalTest", ")", "getPreparedClassOption", "(", "this", ".", "statisticalTestOption", ")", ";", "StatisticalTest", "temp", "=", "(", "StatisticalTest", ")", "st", ".", "copy", "(", ")", ";", "temp", ".", "set", "(", "instances", ",", "cs", ".", "getInstances", "(", ")", ")", ";", "futures", ".", "put", "(", "i", ",", "threadPool", ".", "submit", "(", "temp", ")", ")", ";", "}", "}", "else", "{", "break", ";", "}", "}", "ClassifierKS", "cks", "=", "null", ";", "int", "qtd", "=", "this", ".", "quantityClassifiersTestOption", ".", "getValue", "(", ")", ";", "double", "maxPValue", "=", "this", ".", "similarityBetweenDistributionsOption", ".", "getValue", "(", ")", ";", "try", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "SIZE", "&&", "qtd", ">", "0", ";", "i", "++", ")", "{", "Future", "<", "Double", ">", "f", "=", "futures", ".", "get", "(", "i", ")", ";", "if", "(", "f", "!=", "null", ")", "{", "double", "p", "=", "f", ".", "get", "(", ")", ";", "if", "(", "p", "<", "maxPValue", ")", "{", "maxPValue", "=", "p", ";", "cks", "=", "this", ".", "classifiers", ".", "get", "(", "i", ")", ";", "qtd", "--", ";", "}", "}", "}", "}", "catch", "(", "InterruptedException", "e", ")", "{", "System", ".", "out", ".", "println", "(", "\"Processing interrupted.\"", ")", ";", "}", "catch", "(", "ExecutionException", "e", ")", "{", "throw", "new", "RuntimeException", "(", "\"Error computing statistical test.\"", ",", "e", ")", ";", "}", "threadPool", ".", "shutdownNow", "(", ")", ";", "return", "cks", ";", "}" ]
Searches for the classifier best suited for actual data. All statistical tests are performed in parallel. @param classifier Classifier to be added @param instances Instances used to build the classifier @return
[ "Searches", "for", "the", "classifier", "best", "suited", "for", "actual", "data", ".", "All", "statistical", "tests", "are", "performed", "in", "parallel", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/RCD.java#L244-L284
29,043
Waikato/moa
moa/src/main/java/moa/clusterers/clustree/ClusKernel.java
ClusKernel.makeOlder
protected void makeOlder(long timeDifference, double negLambda) { if (timeDifference == 0) { return; } //double weightFactor = AuxiliaryFunctions.weight(negLambda, timeDifference); assert (negLambda < 0); assert (timeDifference > 0); double weightFactor = Math.pow(2.0, negLambda * timeDifference); this.N *= weightFactor; for (int i = 0; i < LS.length; i++) { LS[i] *= weightFactor; SS[i] *= weightFactor; } }
java
protected void makeOlder(long timeDifference, double negLambda) { if (timeDifference == 0) { return; } //double weightFactor = AuxiliaryFunctions.weight(negLambda, timeDifference); assert (negLambda < 0); assert (timeDifference > 0); double weightFactor = Math.pow(2.0, negLambda * timeDifference); this.N *= weightFactor; for (int i = 0; i < LS.length; i++) { LS[i] *= weightFactor; SS[i] *= weightFactor; } }
[ "protected", "void", "makeOlder", "(", "long", "timeDifference", ",", "double", "negLambda", ")", "{", "if", "(", "timeDifference", "==", "0", ")", "{", "return", ";", "}", "//double weightFactor = AuxiliaryFunctions.weight(negLambda, timeDifference);", "assert", "(", "negLambda", "<", "0", ")", ";", "assert", "(", "timeDifference", ">", "0", ")", ";", "double", "weightFactor", "=", "Math", ".", "pow", "(", "2.0", ",", "negLambda", "*", "timeDifference", ")", ";", "this", ".", "N", "*=", "weightFactor", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "LS", ".", "length", ";", "i", "++", ")", "{", "LS", "[", "i", "]", "*=", "weightFactor", ";", "SS", "[", "i", "]", "*=", "weightFactor", ";", "}", "}" ]
Make this cluster older. This means multiplying weighted N, LS and SS with a weight factor given by the time difference and the parameter negLambda. @param timeDifference The time elapsed between this current update and the last one. @param negLambda
[ "Make", "this", "cluster", "older", ".", "This", "means", "multiplying", "weighted", "N", "LS", "and", "SS", "with", "a", "weight", "factor", "given", "by", "the", "time", "difference", "and", "the", "parameter", "negLambda", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusKernel.java#L114-L129
29,044
Waikato/moa
moa/src/main/java/moa/clusterers/clustree/ClusKernel.java
ClusKernel.overwriteOldCluster
protected void overwriteOldCluster(ClusKernel other) { this.totalN = other.totalN; this.N = other.N; //AuxiliaryFunctions.overwriteDoubleArray(this.LS, other.LS); //AuxiliaryFunctions.overwriteDoubleArray(this.SS, other.SS); assert (LS.length == other.LS.length); System.arraycopy(other.LS, 0, LS, 0, LS.length); assert (SS.length == other.SS.length); System.arraycopy(other.SS, 0, SS, 0, SS.length); }
java
protected void overwriteOldCluster(ClusKernel other) { this.totalN = other.totalN; this.N = other.N; //AuxiliaryFunctions.overwriteDoubleArray(this.LS, other.LS); //AuxiliaryFunctions.overwriteDoubleArray(this.SS, other.SS); assert (LS.length == other.LS.length); System.arraycopy(other.LS, 0, LS, 0, LS.length); assert (SS.length == other.SS.length); System.arraycopy(other.SS, 0, SS, 0, SS.length); }
[ "protected", "void", "overwriteOldCluster", "(", "ClusKernel", "other", ")", "{", "this", ".", "totalN", "=", "other", ".", "totalN", ";", "this", ".", "N", "=", "other", ".", "N", ";", "//AuxiliaryFunctions.overwriteDoubleArray(this.LS, other.LS);", "//AuxiliaryFunctions.overwriteDoubleArray(this.SS, other.SS);", "assert", "(", "LS", ".", "length", "==", "other", ".", "LS", ".", "length", ")", ";", "System", ".", "arraycopy", "(", "other", ".", "LS", ",", "0", ",", "LS", ",", "0", ",", "LS", ".", "length", ")", ";", "assert", "(", "SS", ".", "length", "==", "other", ".", "SS", ".", "length", ")", ";", "System", ".", "arraycopy", "(", "other", ".", "SS", ",", "0", ",", "SS", ",", "0", ",", "SS", ".", "length", ")", ";", "}" ]
Overwrites the LS, SS and weightedN in this cluster to the values of the given cluster but adds N and classCount of the given cluster to this one. This function is useful when the weight of an entry becomes to small, and we want to forget the information of the old points. @param other The cluster that should overwrite the information.
[ "Overwrites", "the", "LS", "SS", "and", "weightedN", "in", "this", "cluster", "to", "the", "values", "of", "the", "given", "cluster", "but", "adds", "N", "and", "classCount", "of", "the", "given", "cluster", "to", "this", "one", ".", "This", "function", "is", "useful", "when", "the", "weight", "of", "an", "entry", "becomes", "to", "small", "and", "we", "want", "to", "forget", "the", "information", "of", "the", "old", "points", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusKernel.java#L190-L199
29,045
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.getVotesForInstance
@Override public double[] getVotesForInstance(Instance inst) { double vSTM[]; double vLTM[]; double vCM[]; double v[]; double distancesSTM[]; double distancesLTM[]; int predClassSTM = 0; int predClassLTM = 0; int predClassCM = 0; try { if (this.stm.numInstances()>0) { distancesSTM = get1ToNDistances(inst, this.stm); int nnIndicesSTM[] = nArgMin(Math.min(distancesSTM.length, this.kOption.getValue()), distancesSTM); vSTM = getDistanceWeightedVotes(distancesSTM, nnIndicesSTM, this.stm); predClassSTM = this.getClassFromVotes(vSTM); distancesLTM = get1ToNDistances(inst, this.ltm); vCM = getCMVotes(distancesSTM, this.stm, distancesLTM, this.ltm); predClassCM = this.getClassFromVotes(vCM); if (this.ltm.numInstances() >= 0) { int nnIndicesLTM[] = nArgMin(Math.min(distancesLTM.length, this.kOption.getValue()), distancesLTM); vLTM = getDistanceWeightedVotes(distancesLTM, nnIndicesLTM, this.ltm); predClassLTM = this.getClassFromVotes(vLTM); }else{ vLTM = new double[inst.numClasses()]; } int correctSTM = historySum(this.stmHistory); int correctLTM = historySum(this.ltmHistory); int correctCM = historySum(this.cmHistory); if(correctSTM>=correctLTM && correctSTM>=correctCM){ v=vSTM; }else if(correctLTM>correctSTM && correctLTM>=correctCM){ v=vLTM; }else{ v=vCM; } }else { v = new double[inst.numClasses()]; } this.stmHistory.add((predClassSTM==inst.classValue()) ? 1 : 0); this.ltmHistory.add((predClassLTM==inst.classValue()) ? 1 : 0); this.cmHistory.add((predClassCM==inst.classValue()) ? 1 : 0); } catch(Exception e) { return new double[inst.numClasses()]; } return v; }
java
@Override public double[] getVotesForInstance(Instance inst) { double vSTM[]; double vLTM[]; double vCM[]; double v[]; double distancesSTM[]; double distancesLTM[]; int predClassSTM = 0; int predClassLTM = 0; int predClassCM = 0; try { if (this.stm.numInstances()>0) { distancesSTM = get1ToNDistances(inst, this.stm); int nnIndicesSTM[] = nArgMin(Math.min(distancesSTM.length, this.kOption.getValue()), distancesSTM); vSTM = getDistanceWeightedVotes(distancesSTM, nnIndicesSTM, this.stm); predClassSTM = this.getClassFromVotes(vSTM); distancesLTM = get1ToNDistances(inst, this.ltm); vCM = getCMVotes(distancesSTM, this.stm, distancesLTM, this.ltm); predClassCM = this.getClassFromVotes(vCM); if (this.ltm.numInstances() >= 0) { int nnIndicesLTM[] = nArgMin(Math.min(distancesLTM.length, this.kOption.getValue()), distancesLTM); vLTM = getDistanceWeightedVotes(distancesLTM, nnIndicesLTM, this.ltm); predClassLTM = this.getClassFromVotes(vLTM); }else{ vLTM = new double[inst.numClasses()]; } int correctSTM = historySum(this.stmHistory); int correctLTM = historySum(this.ltmHistory); int correctCM = historySum(this.cmHistory); if(correctSTM>=correctLTM && correctSTM>=correctCM){ v=vSTM; }else if(correctLTM>correctSTM && correctLTM>=correctCM){ v=vLTM; }else{ v=vCM; } }else { v = new double[inst.numClasses()]; } this.stmHistory.add((predClassSTM==inst.classValue()) ? 1 : 0); this.ltmHistory.add((predClassLTM==inst.classValue()) ? 1 : 0); this.cmHistory.add((predClassCM==inst.classValue()) ? 1 : 0); } catch(Exception e) { return new double[inst.numClasses()]; } return v; }
[ "@", "Override", "public", "double", "[", "]", "getVotesForInstance", "(", "Instance", "inst", ")", "{", "double", "vSTM", "[", "]", ";", "double", "vLTM", "[", "]", ";", "double", "vCM", "[", "]", ";", "double", "v", "[", "]", ";", "double", "distancesSTM", "[", "]", ";", "double", "distancesLTM", "[", "]", ";", "int", "predClassSTM", "=", "0", ";", "int", "predClassLTM", "=", "0", ";", "int", "predClassCM", "=", "0", ";", "try", "{", "if", "(", "this", ".", "stm", ".", "numInstances", "(", ")", ">", "0", ")", "{", "distancesSTM", "=", "get1ToNDistances", "(", "inst", ",", "this", ".", "stm", ")", ";", "int", "nnIndicesSTM", "[", "]", "=", "nArgMin", "(", "Math", ".", "min", "(", "distancesSTM", ".", "length", ",", "this", ".", "kOption", ".", "getValue", "(", ")", ")", ",", "distancesSTM", ")", ";", "vSTM", "=", "getDistanceWeightedVotes", "(", "distancesSTM", ",", "nnIndicesSTM", ",", "this", ".", "stm", ")", ";", "predClassSTM", "=", "this", ".", "getClassFromVotes", "(", "vSTM", ")", ";", "distancesLTM", "=", "get1ToNDistances", "(", "inst", ",", "this", ".", "ltm", ")", ";", "vCM", "=", "getCMVotes", "(", "distancesSTM", ",", "this", ".", "stm", ",", "distancesLTM", ",", "this", ".", "ltm", ")", ";", "predClassCM", "=", "this", ".", "getClassFromVotes", "(", "vCM", ")", ";", "if", "(", "this", ".", "ltm", ".", "numInstances", "(", ")", ">=", "0", ")", "{", "int", "nnIndicesLTM", "[", "]", "=", "nArgMin", "(", "Math", ".", "min", "(", "distancesLTM", ".", "length", ",", "this", ".", "kOption", ".", "getValue", "(", ")", ")", ",", "distancesLTM", ")", ";", "vLTM", "=", "getDistanceWeightedVotes", "(", "distancesLTM", ",", "nnIndicesLTM", ",", "this", ".", "ltm", ")", ";", "predClassLTM", "=", "this", ".", "getClassFromVotes", "(", "vLTM", ")", ";", "}", "else", "{", "vLTM", "=", "new", "double", "[", "inst", ".", "numClasses", "(", ")", "]", ";", "}", "int", "correctSTM", "=", "historySum", "(", "this", ".", "stmHistory", ")", ";", "int", "correctLTM", "=", "historySum", "(", "this", ".", "ltmHistory", ")", ";", "int", "correctCM", "=", "historySum", "(", "this", ".", "cmHistory", ")", ";", "if", "(", "correctSTM", ">=", "correctLTM", "&&", "correctSTM", ">=", "correctCM", ")", "{", "v", "=", "vSTM", ";", "}", "else", "if", "(", "correctLTM", ">", "correctSTM", "&&", "correctLTM", ">=", "correctCM", ")", "{", "v", "=", "vLTM", ";", "}", "else", "{", "v", "=", "vCM", ";", "}", "}", "else", "{", "v", "=", "new", "double", "[", "inst", ".", "numClasses", "(", ")", "]", ";", "}", "this", ".", "stmHistory", ".", "add", "(", "(", "predClassSTM", "==", "inst", ".", "classValue", "(", ")", ")", "?", "1", ":", "0", ")", ";", "this", ".", "ltmHistory", ".", "add", "(", "(", "predClassLTM", "==", "inst", ".", "classValue", "(", ")", ")", "?", "1", ":", "0", ")", ";", "this", ".", "cmHistory", ".", "add", "(", "(", "predClassCM", "==", "inst", ".", "classValue", "(", ")", ")", "?", "1", ":", "0", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "return", "new", "double", "[", "inst", ".", "numClasses", "(", ")", "]", ";", "}", "return", "v", ";", "}" ]
Predicts the label of a given sample by using the STM, LTM and the CM.
[ "Predicts", "the", "label", "of", "a", "given", "sample", "by", "using", "the", "STM", "LTM", "and", "the", "CM", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L178-L226
29,046
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.clusterDown
private void clusterDown(){ int classIndex = this.ltm.classIndex(); for (int c = 0; c <= this.maxClassValue; c++){ List<double[]> classSamples = new ArrayList<>(); for (int i = this.ltm.numInstances()-1; i >-1 ; i--) { if (this.ltm.get(i).classValue() == c) { classSamples.add(this.ltm.get(i).toDoubleArray()); this.ltm.delete(i); } } if (classSamples.size() > 0) { //used kMeans++ implementation expects the weight of each sample at the first index, // make sure that the first value gets the uniform weight 1, overwrite class value for (double[] sample : classSamples) { if (classIndex != 0) { sample[classIndex] = sample[0]; } sample[0] = 1; } List<double[]> centroids = this.kMeans(classSamples, Math.max(classSamples.size() / 2, 1)); for (double[] centroid : centroids) { double[] attributes = new double[this.ltm.numAttributes()]; //returned centroids do not contain the weight anymore, but simply the data System.arraycopy(centroid, 0, attributes, 1, this.ltm.numAttributes() - 1); //switch back if necessary if (classIndex != 0) { attributes[0] = attributes[classIndex]; } attributes[classIndex] = c; Instance inst = new InstanceImpl(1, attributes); inst.setDataset(this.ltm); this.ltm.add(inst); } } } }
java
private void clusterDown(){ int classIndex = this.ltm.classIndex(); for (int c = 0; c <= this.maxClassValue; c++){ List<double[]> classSamples = new ArrayList<>(); for (int i = this.ltm.numInstances()-1; i >-1 ; i--) { if (this.ltm.get(i).classValue() == c) { classSamples.add(this.ltm.get(i).toDoubleArray()); this.ltm.delete(i); } } if (classSamples.size() > 0) { //used kMeans++ implementation expects the weight of each sample at the first index, // make sure that the first value gets the uniform weight 1, overwrite class value for (double[] sample : classSamples) { if (classIndex != 0) { sample[classIndex] = sample[0]; } sample[0] = 1; } List<double[]> centroids = this.kMeans(classSamples, Math.max(classSamples.size() / 2, 1)); for (double[] centroid : centroids) { double[] attributes = new double[this.ltm.numAttributes()]; //returned centroids do not contain the weight anymore, but simply the data System.arraycopy(centroid, 0, attributes, 1, this.ltm.numAttributes() - 1); //switch back if necessary if (classIndex != 0) { attributes[0] = attributes[classIndex]; } attributes[classIndex] = c; Instance inst = new InstanceImpl(1, attributes); inst.setDataset(this.ltm); this.ltm.add(inst); } } } }
[ "private", "void", "clusterDown", "(", ")", "{", "int", "classIndex", "=", "this", ".", "ltm", ".", "classIndex", "(", ")", ";", "for", "(", "int", "c", "=", "0", ";", "c", "<=", "this", ".", "maxClassValue", ";", "c", "++", ")", "{", "List", "<", "double", "[", "]", ">", "classSamples", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "this", ".", "ltm", ".", "numInstances", "(", ")", "-", "1", ";", "i", ">", "-", "1", ";", "i", "--", ")", "{", "if", "(", "this", ".", "ltm", ".", "get", "(", "i", ")", ".", "classValue", "(", ")", "==", "c", ")", "{", "classSamples", ".", "add", "(", "this", ".", "ltm", ".", "get", "(", "i", ")", ".", "toDoubleArray", "(", ")", ")", ";", "this", ".", "ltm", ".", "delete", "(", "i", ")", ";", "}", "}", "if", "(", "classSamples", ".", "size", "(", ")", ">", "0", ")", "{", "//used kMeans++ implementation expects the weight of each sample at the first index,", "// make sure that the first value gets the uniform weight 1, overwrite class value", "for", "(", "double", "[", "]", "sample", ":", "classSamples", ")", "{", "if", "(", "classIndex", "!=", "0", ")", "{", "sample", "[", "classIndex", "]", "=", "sample", "[", "0", "]", ";", "}", "sample", "[", "0", "]", "=", "1", ";", "}", "List", "<", "double", "[", "]", ">", "centroids", "=", "this", ".", "kMeans", "(", "classSamples", ",", "Math", ".", "max", "(", "classSamples", ".", "size", "(", ")", "/", "2", ",", "1", ")", ")", ";", "for", "(", "double", "[", "]", "centroid", ":", "centroids", ")", "{", "double", "[", "]", "attributes", "=", "new", "double", "[", "this", ".", "ltm", ".", "numAttributes", "(", ")", "]", ";", "//returned centroids do not contain the weight anymore, but simply the data", "System", ".", "arraycopy", "(", "centroid", ",", "0", ",", "attributes", ",", "1", ",", "this", ".", "ltm", ".", "numAttributes", "(", ")", "-", "1", ")", ";", "//switch back if necessary", "if", "(", "classIndex", "!=", "0", ")", "{", "attributes", "[", "0", "]", "=", "attributes", "[", "classIndex", "]", ";", "}", "attributes", "[", "classIndex", "]", "=", "c", ";", "Instance", "inst", "=", "new", "InstanceImpl", "(", "1", ",", "attributes", ")", ";", "inst", ".", "setDataset", "(", "this", ".", "ltm", ")", ";", "this", ".", "ltm", ".", "add", "(", "inst", ")", ";", "}", "}", "}", "}" ]
Performs classwise kMeans++ clustering for given samples with corresponding labels. The number of samples is halved per class.
[ "Performs", "classwise", "kMeans", "++", "clustering", "for", "given", "samples", "with", "corresponding", "labels", ".", "The", "number", "of", "samples", "is", "halved", "per", "class", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L260-L299
29,047
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.memorySizeCheck
private void memorySizeCheck(){ if (this.stm.numInstances() + this.ltm.numInstances() > this.maxSTMSize + this.maxLTMSize){ if (this.ltm.numInstances() > this.maxLTMSize){ this.clusterDown(); }else{ //shift values from STM directly to LTM since STM is full int numShifts = this.maxLTMSize - this.ltm.numInstances() + 1; for (int i = 0; i < numShifts; i++){ this.ltm.add(this.stm.get(0).copy()); this.stm.delete(0); this.stmHistory.remove(0); this.ltmHistory.remove(0); this.cmHistory.remove(0); } this.clusterDown(); this.predictionHistories.clear(); for (int i = 0; i < this.stm.numInstances(); i++){ for (int j = 0; j < this.stm.numInstances(); j++){ this.distanceMatrixSTM[i][j] = this.distanceMatrixSTM[numShifts+i][numShifts+j]; } } } } }
java
private void memorySizeCheck(){ if (this.stm.numInstances() + this.ltm.numInstances() > this.maxSTMSize + this.maxLTMSize){ if (this.ltm.numInstances() > this.maxLTMSize){ this.clusterDown(); }else{ //shift values from STM directly to LTM since STM is full int numShifts = this.maxLTMSize - this.ltm.numInstances() + 1; for (int i = 0; i < numShifts; i++){ this.ltm.add(this.stm.get(0).copy()); this.stm.delete(0); this.stmHistory.remove(0); this.ltmHistory.remove(0); this.cmHistory.remove(0); } this.clusterDown(); this.predictionHistories.clear(); for (int i = 0; i < this.stm.numInstances(); i++){ for (int j = 0; j < this.stm.numInstances(); j++){ this.distanceMatrixSTM[i][j] = this.distanceMatrixSTM[numShifts+i][numShifts+j]; } } } } }
[ "private", "void", "memorySizeCheck", "(", ")", "{", "if", "(", "this", ".", "stm", ".", "numInstances", "(", ")", "+", "this", ".", "ltm", ".", "numInstances", "(", ")", ">", "this", ".", "maxSTMSize", "+", "this", ".", "maxLTMSize", ")", "{", "if", "(", "this", ".", "ltm", ".", "numInstances", "(", ")", ">", "this", ".", "maxLTMSize", ")", "{", "this", ".", "clusterDown", "(", ")", ";", "}", "else", "{", "//shift values from STM directly to LTM since STM is full", "int", "numShifts", "=", "this", ".", "maxLTMSize", "-", "this", ".", "ltm", ".", "numInstances", "(", ")", "+", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numShifts", ";", "i", "++", ")", "{", "this", ".", "ltm", ".", "add", "(", "this", ".", "stm", ".", "get", "(", "0", ")", ".", "copy", "(", ")", ")", ";", "this", ".", "stm", ".", "delete", "(", "0", ")", ";", "this", ".", "stmHistory", ".", "remove", "(", "0", ")", ";", "this", ".", "ltmHistory", ".", "remove", "(", "0", ")", ";", "this", ".", "cmHistory", ".", "remove", "(", "0", ")", ";", "}", "this", ".", "clusterDown", "(", ")", ";", "this", ".", "predictionHistories", ".", "clear", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "stm", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "for", "(", "int", "j", "=", "0", ";", "j", "<", "this", ".", "stm", ".", "numInstances", "(", ")", ";", "j", "++", ")", "{", "this", ".", "distanceMatrixSTM", "[", "i", "]", "[", "j", "]", "=", "this", ".", "distanceMatrixSTM", "[", "numShifts", "+", "i", "]", "[", "numShifts", "+", "j", "]", ";", "}", "}", "}", "}", "}" ]
Makes sure that the STM and LTM combined doe not surpass the maximum size.
[ "Makes", "sure", "that", "the", "STM", "and", "LTM", "combined", "doe", "not", "surpass", "the", "maximum", "size", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L304-L326
29,048
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.clean
private void clean(Instances cleanAgainst, Instances toClean, boolean onlyLast) { if (cleanAgainst.numInstances() > this.kOption.getValue() && toClean.numInstances() > 0){ if (onlyLast){ cleanSingle(cleanAgainst, (cleanAgainst.numInstances()-1), toClean); }else{ for (int i=0; i < cleanAgainst.numInstances(); i++){ cleanSingle(cleanAgainst, i, toClean); } } } }
java
private void clean(Instances cleanAgainst, Instances toClean, boolean onlyLast) { if (cleanAgainst.numInstances() > this.kOption.getValue() && toClean.numInstances() > 0){ if (onlyLast){ cleanSingle(cleanAgainst, (cleanAgainst.numInstances()-1), toClean); }else{ for (int i=0; i < cleanAgainst.numInstances(); i++){ cleanSingle(cleanAgainst, i, toClean); } } } }
[ "private", "void", "clean", "(", "Instances", "cleanAgainst", ",", "Instances", "toClean", ",", "boolean", "onlyLast", ")", "{", "if", "(", "cleanAgainst", ".", "numInstances", "(", ")", ">", "this", ".", "kOption", ".", "getValue", "(", ")", "&&", "toClean", ".", "numInstances", "(", ")", ">", "0", ")", "{", "if", "(", "onlyLast", ")", "{", "cleanSingle", "(", "cleanAgainst", ",", "(", "cleanAgainst", ".", "numInstances", "(", ")", "-", "1", ")", ",", "toClean", ")", ";", "}", "else", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "cleanAgainst", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "cleanSingle", "(", "cleanAgainst", ",", "i", ",", "toClean", ")", ";", "}", "}", "}", "}" ]
Removes distance-based all instances from the input samples that contradict those in the STM.
[ "Removes", "distance", "-", "based", "all", "instances", "from", "the", "input", "samples", "that", "contradict", "those", "in", "the", "STM", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L359-L369
29,049
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.getDistanceWeightedVotes
private double [] getDistanceWeightedVotes(double distances[], int[] nnIndices, Instances instances){ double v[] = new double[this.maxClassValue +1]; for (int nnIdx : nnIndices) { v[(int)instances.instance(nnIdx).classValue()] += 1./Math.max(distances[nnIdx], 0.000000001); } return v; }
java
private double [] getDistanceWeightedVotes(double distances[], int[] nnIndices, Instances instances){ double v[] = new double[this.maxClassValue +1]; for (int nnIdx : nnIndices) { v[(int)instances.instance(nnIdx).classValue()] += 1./Math.max(distances[nnIdx], 0.000000001); } return v; }
[ "private", "double", "[", "]", "getDistanceWeightedVotes", "(", "double", "distances", "[", "]", ",", "int", "[", "]", "nnIndices", ",", "Instances", "instances", ")", "{", "double", "v", "[", "]", "=", "new", "double", "[", "this", ".", "maxClassValue", "+", "1", "]", ";", "for", "(", "int", "nnIdx", ":", "nnIndices", ")", "{", "v", "[", "(", "int", ")", "instances", ".", "instance", "(", "nnIdx", ")", ".", "classValue", "(", ")", "]", "+=", "1.", "/", "Math", ".", "max", "(", "distances", "[", "nnIdx", "]", ",", "0.000000001", ")", ";", "}", "return", "v", ";", "}" ]
Returns the distance weighted votes.
[ "Returns", "the", "distance", "weighted", "votes", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L373-L380
29,050
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.getClassFromVotes
private int getClassFromVotes(double votes[]){ double maxVote = -1; int maxVoteClass = -1; for (int i = 0; i < votes.length; i++){ if (votes[i] > maxVote){ maxVote = votes[i]; maxVoteClass = i; } } return maxVoteClass; }
java
private int getClassFromVotes(double votes[]){ double maxVote = -1; int maxVoteClass = -1; for (int i = 0; i < votes.length; i++){ if (votes[i] > maxVote){ maxVote = votes[i]; maxVoteClass = i; } } return maxVoteClass; }
[ "private", "int", "getClassFromVotes", "(", "double", "votes", "[", "]", ")", "{", "double", "maxVote", "=", "-", "1", ";", "int", "maxVoteClass", "=", "-", "1", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "votes", ".", "length", ";", "i", "++", ")", "{", "if", "(", "votes", "[", "i", "]", ">", "maxVote", ")", "{", "maxVote", "=", "votes", "[", "i", "]", ";", "maxVoteClass", "=", "i", ";", "}", "}", "return", "maxVoteClass", ";", "}" ]
Returns the class with maximum vote.
[ "Returns", "the", "class", "with", "maximum", "vote", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L408-L418
29,051
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.getDistance
private double getDistance(Instance sample, Instance sample2) { double sum=0; for (int i=0; i<sample.numInputAttributes(); i++) { double diff = sample.valueInputAttribute(i)-sample2.valueInputAttribute(i); sum += diff*diff; } return Math.sqrt(sum); }
java
private double getDistance(Instance sample, Instance sample2) { double sum=0; for (int i=0; i<sample.numInputAttributes(); i++) { double diff = sample.valueInputAttribute(i)-sample2.valueInputAttribute(i); sum += diff*diff; } return Math.sqrt(sum); }
[ "private", "double", "getDistance", "(", "Instance", "sample", ",", "Instance", "sample2", ")", "{", "double", "sum", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "sample", ".", "numInputAttributes", "(", ")", ";", "i", "++", ")", "{", "double", "diff", "=", "sample", ".", "valueInputAttribute", "(", "i", ")", "-", "sample2", ".", "valueInputAttribute", "(", "i", ")", ";", "sum", "+=", "diff", "*", "diff", ";", "}", "return", "Math", ".", "sqrt", "(", "sum", ")", ";", "}" ]
Returns the Euclidean distance.
[ "Returns", "the", "Euclidean", "distance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L429-L438
29,052
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.get1ToNDistances
private double[] get1ToNDistances(Instance sample, Instances samples){ double distances[] = new double[samples.numInstances()]; for (int i=0; i<samples.numInstances(); i++){ distances[i] = this.getDistance(sample, samples.get(i)); } return distances; }
java
private double[] get1ToNDistances(Instance sample, Instances samples){ double distances[] = new double[samples.numInstances()]; for (int i=0; i<samples.numInstances(); i++){ distances[i] = this.getDistance(sample, samples.get(i)); } return distances; }
[ "private", "double", "[", "]", "get1ToNDistances", "(", "Instance", "sample", ",", "Instances", "samples", ")", "{", "double", "distances", "[", "]", "=", "new", "double", "[", "samples", ".", "numInstances", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "samples", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "distances", "[", "i", "]", "=", "this", ".", "getDistance", "(", "sample", ",", "samples", ".", "get", "(", "i", ")", ")", ";", "}", "return", "distances", ";", "}" ]
Returns the Euclidean distance between one sample and a collection of samples in an 1D-array.
[ "Returns", "the", "Euclidean", "distance", "between", "one", "sample", "and", "a", "collection", "of", "samples", "in", "an", "1D", "-", "array", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L443-L449
29,053
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.adaptHistories
private void adaptHistories(int numberOfDeletions){ for (int i = 0; i < numberOfDeletions; i++){ SortedSet<Integer> keys = new TreeSet<>(this.predictionHistories.keySet()); this.predictionHistories.remove(keys.first()); keys = new TreeSet<>(this.predictionHistories.keySet()); for (Integer key : keys){ List<Integer> predHistory = this.predictionHistories.remove(key); this.predictionHistories.put(key-keys.first(), predHistory); } } }
java
private void adaptHistories(int numberOfDeletions){ for (int i = 0; i < numberOfDeletions; i++){ SortedSet<Integer> keys = new TreeSet<>(this.predictionHistories.keySet()); this.predictionHistories.remove(keys.first()); keys = new TreeSet<>(this.predictionHistories.keySet()); for (Integer key : keys){ List<Integer> predHistory = this.predictionHistories.remove(key); this.predictionHistories.put(key-keys.first(), predHistory); } } }
[ "private", "void", "adaptHistories", "(", "int", "numberOfDeletions", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfDeletions", ";", "i", "++", ")", "{", "SortedSet", "<", "Integer", ">", "keys", "=", "new", "TreeSet", "<>", "(", "this", ".", "predictionHistories", ".", "keySet", "(", ")", ")", ";", "this", ".", "predictionHistories", ".", "remove", "(", "keys", ".", "first", "(", ")", ")", ";", "keys", "=", "new", "TreeSet", "<>", "(", "this", ".", "predictionHistories", ".", "keySet", "(", ")", ")", ";", "for", "(", "Integer", "key", ":", "keys", ")", "{", "List", "<", "Integer", ">", "predHistory", "=", "this", ".", "predictionHistories", ".", "remove", "(", "key", ")", ";", "this", ".", "predictionHistories", ".", "put", "(", "key", "-", "keys", ".", "first", "(", ")", ",", "predHistory", ")", ";", "}", "}", "}" ]
Removes predictions of the largest window size and shifts the remaining ones accordingly.
[ "Removes", "predictions", "of", "the", "largest", "window", "size", "and", "shifts", "the", "remaining", "ones", "accordingly", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L483-L493
29,054
Waikato/moa
moa/src/main/java/moa/classifiers/lazy/SAMkNN.java
SAMkNN.getHistoryErrorRate
private double getHistoryErrorRate(List<Integer> predHistory){ double sumCorrect = 0; for (Integer e : predHistory) { sumCorrect += e; } return 1. - (sumCorrect / predHistory.size()); }
java
private double getHistoryErrorRate(List<Integer> predHistory){ double sumCorrect = 0; for (Integer e : predHistory) { sumCorrect += e; } return 1. - (sumCorrect / predHistory.size()); }
[ "private", "double", "getHistoryErrorRate", "(", "List", "<", "Integer", ">", "predHistory", ")", "{", "double", "sumCorrect", "=", "0", ";", "for", "(", "Integer", "e", ":", "predHistory", ")", "{", "sumCorrect", "+=", "e", ";", "}", "return", "1.", "-", "(", "sumCorrect", "/", "predHistory", ".", "size", "(", ")", ")", ";", "}" ]
Calculates the achieved error rate of a history.
[ "Calculates", "the", "achieved", "error", "rate", "of", "a", "history", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/lazy/SAMkNN.java#L558-L564
29,055
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.distanceSquared
public static double distanceSquared(double[] pointA) { double distance = 0.0; for (int i = 0; i < pointA.length; i++) { distance += pointA[i] * pointA[i]; } return distance; }
java
public static double distanceSquared(double[] pointA) { double distance = 0.0; for (int i = 0; i < pointA.length; i++) { distance += pointA[i] * pointA[i]; } return distance; }
[ "public", "static", "double", "distanceSquared", "(", "double", "[", "]", "pointA", ")", "{", "double", "distance", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA", ".", "length", ";", "i", "++", ")", "{", "distance", "+=", "pointA", "[", "i", "]", "*", "pointA", "[", "i", "]", ";", "}", "return", "distance", ";", "}" ]
Calculates the squared Euclidean length of a point. @param pointA point @return the squared Euclidean length
[ "Calculates", "the", "squared", "Euclidean", "length", "of", "a", "point", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L35-L41
29,056
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.distanceSquared
public static double distanceSquared(double[] pointA, double[] pointB, int offsetB) { assert (pointA.length == pointB.length + offsetB); double distance = 0.0; for (int i = 0; i < pointA.length; i++) { double d = pointA[i] - pointB[i + offsetB]; distance += d * d; } return distance; }
java
public static double distanceSquared(double[] pointA, double[] pointB, int offsetB) { assert (pointA.length == pointB.length + offsetB); double distance = 0.0; for (int i = 0; i < pointA.length; i++) { double d = pointA[i] - pointB[i + offsetB]; distance += d * d; } return distance; }
[ "public", "static", "double", "distanceSquared", "(", "double", "[", "]", "pointA", ",", "double", "[", "]", "pointB", ",", "int", "offsetB", ")", "{", "assert", "(", "pointA", ".", "length", "==", "pointB", ".", "length", "+", "offsetB", ")", ";", "double", "distance", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA", ".", "length", ";", "i", "++", ")", "{", "double", "d", "=", "pointA", "[", "i", "]", "-", "pointB", "[", "i", "+", "offsetB", "]", ";", "distance", "+=", "d", "*", "d", ";", "}", "return", "distance", ";", "}" ]
Calculates the squared Euclidean distance of two points. Starts at dimension offset + 1 of pointB. @param pointA first point @param pointB second point @param offsetB start dimension - 1 of pointB @return the squared Euclidean distance
[ "Calculates", "the", "squared", "Euclidean", "distance", "of", "two", "points", ".", "Starts", "at", "dimension", "offset", "+", "1", "of", "pointB", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L66-L75
29,057
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.distance
public static double distance(double[] pointA, double[] pointB, int offsetB) { return Math.sqrt(distanceSquared(pointA, pointB, offsetB)); }
java
public static double distance(double[] pointA, double[] pointB, int offsetB) { return Math.sqrt(distanceSquared(pointA, pointB, offsetB)); }
[ "public", "static", "double", "distance", "(", "double", "[", "]", "pointA", ",", "double", "[", "]", "pointB", ",", "int", "offsetB", ")", "{", "return", "Math", ".", "sqrt", "(", "distanceSquared", "(", "pointA", ",", "pointB", ",", "offsetB", ")", ")", ";", "}" ]
Calculates the Euclidean distance of two points. Starts at dimension offset + 1 of pointB. @param pointA first point @param pointB second point @param offsetB start dimension - 1 of pointB @return the Euclidean distance
[ "Calculates", "the", "Euclidean", "distance", "of", "two", "points", ".", "Starts", "at", "dimension", "offset", "+", "1", "of", "pointB", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L89-L91
29,058
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.distanceWithDivisionSquared
public static double distanceWithDivisionSquared(double[] pointA, double dA) { double distance = 0.0; for (int i = 0; i < pointA.length; i++) { double d = pointA[i] / dA; distance += d * d; } return distance; }
java
public static double distanceWithDivisionSquared(double[] pointA, double dA) { double distance = 0.0; for (int i = 0; i < pointA.length; i++) { double d = pointA[i] / dA; distance += d * d; } return distance; }
[ "public", "static", "double", "distanceWithDivisionSquared", "(", "double", "[", "]", "pointA", ",", "double", "dA", ")", "{", "double", "distance", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA", ".", "length", ";", "i", "++", ")", "{", "double", "d", "=", "pointA", "[", "i", "]", "/", "dA", ";", "distance", "+=", "d", "*", "d", ";", "}", "return", "distance", ";", "}" ]
Calculates the squared Euclidean length of a point divided by a scalar. @param pointA point @param dA scalar @return the squared Euclidean length
[ "Calculates", "the", "squared", "Euclidean", "length", "of", "a", "point", "divided", "by", "a", "scalar", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L134-L141
29,059
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.distanceWithDivision
public static double distanceWithDivision(double[] pointA, double dA, double[] pointB) { return Math.sqrt(distanceWithDivisionSquared(pointA, dA, pointB)); }
java
public static double distanceWithDivision(double[] pointA, double dA, double[] pointB) { return Math.sqrt(distanceWithDivisionSquared(pointA, dA, pointB)); }
[ "public", "static", "double", "distanceWithDivision", "(", "double", "[", "]", "pointA", ",", "double", "dA", ",", "double", "[", "]", "pointB", ")", "{", "return", "Math", ".", "sqrt", "(", "distanceWithDivisionSquared", "(", "pointA", ",", "dA", ",", "pointB", ")", ")", ";", "}" ]
Calculates the Euclidean distance of the first point divided by a scalar and another second point. @param pointA first point @param dA scalar @param pointB second point @return the Euclidean distance
[ "Calculates", "the", "Euclidean", "distance", "of", "the", "first", "point", "divided", "by", "a", "scalar", "and", "another", "second", "point", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L191-L194
29,060
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.dotProduct
public static double dotProduct(double[] pointA) { double product = 0.0; for (int i = 0; i < pointA.length; i++) { product += pointA[i] * pointA[i]; } return product; }
java
public static double dotProduct(double[] pointA) { double product = 0.0; for (int i = 0; i < pointA.length; i++) { product += pointA[i] * pointA[i]; } return product; }
[ "public", "static", "double", "dotProduct", "(", "double", "[", "]", "pointA", ")", "{", "double", "product", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA", ".", "length", ";", "i", "++", ")", "{", "product", "+=", "pointA", "[", "i", "]", "*", "pointA", "[", "i", "]", ";", "}", "return", "product", ";", "}" ]
Calculates the dot product of the point with itself. @param pointA point @return the dot product
[ "Calculates", "the", "dot", "product", "of", "the", "point", "with", "itself", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L247-L253
29,061
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.dotProductWithAddition
public static double dotProductWithAddition(double[] pointA1, double[] pointA2, double[] pointB) { assert (pointA1.length == pointA2.length && pointA1.length == pointB.length); double product = 0.0; for (int i = 0; i < pointA1.length; i++) { product += (pointA1[i] + pointA2[i]) * pointB[i]; } return product; }
java
public static double dotProductWithAddition(double[] pointA1, double[] pointA2, double[] pointB) { assert (pointA1.length == pointA2.length && pointA1.length == pointB.length); double product = 0.0; for (int i = 0; i < pointA1.length; i++) { product += (pointA1[i] + pointA2[i]) * pointB[i]; } return product; }
[ "public", "static", "double", "dotProductWithAddition", "(", "double", "[", "]", "pointA1", ",", "double", "[", "]", "pointA2", ",", "double", "[", "]", "pointB", ")", "{", "assert", "(", "pointA1", ".", "length", "==", "pointA2", ".", "length", "&&", "pointA1", ".", "length", "==", "pointB", ".", "length", ")", ";", "double", "product", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA1", ".", "length", ";", "i", "++", ")", "{", "product", "+=", "(", "pointA1", "[", "i", "]", "+", "pointA2", "[", "i", "]", ")", "*", "pointB", "[", "i", "]", ";", "}", "return", "product", ";", "}" ]
Calculates the dot product of the addition of the first and the second point with the third point. @param pointA1 first point @param pointA2 second point @param pointB third point @return the dot product
[ "Calculates", "the", "dot", "product", "of", "the", "addition", "of", "the", "first", "and", "the", "second", "point", "with", "the", "third", "point", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L285-L293
29,062
Waikato/moa
moa/src/main/java/moa/clusterers/kmeanspm/Metric.java
Metric.dotProductWithAddition
public static double dotProductWithAddition(double[] pointA1, double[] pointA2, double[] pointB1, double[] pointB2) { assert (pointA1.length == pointA2.length && pointB1.length == pointB2.length && pointA1.length == pointB1.length); double product = 0.0; for (int i = 0; i < pointA1.length; i++) { product += (pointA1[i] + pointA2[i]) * (pointB1[i] + pointB2[i]); } return product; }
java
public static double dotProductWithAddition(double[] pointA1, double[] pointA2, double[] pointB1, double[] pointB2) { assert (pointA1.length == pointA2.length && pointB1.length == pointB2.length && pointA1.length == pointB1.length); double product = 0.0; for (int i = 0; i < pointA1.length; i++) { product += (pointA1[i] + pointA2[i]) * (pointB1[i] + pointB2[i]); } return product; }
[ "public", "static", "double", "dotProductWithAddition", "(", "double", "[", "]", "pointA1", ",", "double", "[", "]", "pointA2", ",", "double", "[", "]", "pointB1", ",", "double", "[", "]", "pointB2", ")", "{", "assert", "(", "pointA1", ".", "length", "==", "pointA2", ".", "length", "&&", "pointB1", ".", "length", "==", "pointB2", ".", "length", "&&", "pointA1", ".", "length", "==", "pointB1", ".", "length", ")", ";", "double", "product", "=", "0.0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "pointA1", ".", "length", ";", "i", "++", ")", "{", "product", "+=", "(", "pointA1", "[", "i", "]", "+", "pointA2", "[", "i", "]", ")", "*", "(", "pointB1", "[", "i", "]", "+", "pointB2", "[", "i", "]", ")", ";", "}", "return", "product", ";", "}" ]
Calculates the dot product of the addition of the first and the second point with the addition of the third and the fourth point. @param pointA1 first point @param pointA2 second point @param pointB1 third point @param pointB2 fourth point @return the dot product
[ "Calculates", "the", "dot", "product", "of", "the", "addition", "of", "the", "first", "and", "the", "second", "point", "with", "the", "addition", "of", "the", "third", "and", "the", "fourth", "point", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/Metric.java#L309-L318
29,063
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java
WekaToSamoaInstanceConverter.samoaInstance
public Instance samoaInstance(weka.core.Instance inst) { Instance samoaInstance; if (inst instanceof weka.core.SparseInstance) { double[] attributeValues = new double[inst.numValues()]; int[] indexValues = new int[inst.numValues()]; for (int i = 0; i < inst.numValues(); i++) { if (inst.index(i) != inst.classIndex()) { attributeValues[i] = inst.valueSparse(i); indexValues[i] = inst.index(i); } } samoaInstance = new SparseInstance(inst.weight(), attributeValues, indexValues, inst.numAttributes()); } else { samoaInstance = new DenseInstance(inst.weight(), inst.toDoubleArray()); //samoaInstance.deleteAttributeAt(inst.classIndex()); } if (this.samoaInstanceInformation == null) { this.samoaInstanceInformation = this.samoaInstancesInformation(inst.dataset()); } samoaInstance.setDataset(samoaInstanceInformation); if(inst.classIndex() >= 0) { // class attribute is present samoaInstance.setClassValue(inst.classValue()); } return samoaInstance; }
java
public Instance samoaInstance(weka.core.Instance inst) { Instance samoaInstance; if (inst instanceof weka.core.SparseInstance) { double[] attributeValues = new double[inst.numValues()]; int[] indexValues = new int[inst.numValues()]; for (int i = 0; i < inst.numValues(); i++) { if (inst.index(i) != inst.classIndex()) { attributeValues[i] = inst.valueSparse(i); indexValues[i] = inst.index(i); } } samoaInstance = new SparseInstance(inst.weight(), attributeValues, indexValues, inst.numAttributes()); } else { samoaInstance = new DenseInstance(inst.weight(), inst.toDoubleArray()); //samoaInstance.deleteAttributeAt(inst.classIndex()); } if (this.samoaInstanceInformation == null) { this.samoaInstanceInformation = this.samoaInstancesInformation(inst.dataset()); } samoaInstance.setDataset(samoaInstanceInformation); if(inst.classIndex() >= 0) { // class attribute is present samoaInstance.setClassValue(inst.classValue()); } return samoaInstance; }
[ "public", "Instance", "samoaInstance", "(", "weka", ".", "core", ".", "Instance", "inst", ")", "{", "Instance", "samoaInstance", ";", "if", "(", "inst", "instanceof", "weka", ".", "core", ".", "SparseInstance", ")", "{", "double", "[", "]", "attributeValues", "=", "new", "double", "[", "inst", ".", "numValues", "(", ")", "]", ";", "int", "[", "]", "indexValues", "=", "new", "int", "[", "inst", ".", "numValues", "(", ")", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "inst", ".", "numValues", "(", ")", ";", "i", "++", ")", "{", "if", "(", "inst", ".", "index", "(", "i", ")", "!=", "inst", ".", "classIndex", "(", ")", ")", "{", "attributeValues", "[", "i", "]", "=", "inst", ".", "valueSparse", "(", "i", ")", ";", "indexValues", "[", "i", "]", "=", "inst", ".", "index", "(", "i", ")", ";", "}", "}", "samoaInstance", "=", "new", "SparseInstance", "(", "inst", ".", "weight", "(", ")", ",", "attributeValues", ",", "indexValues", ",", "inst", ".", "numAttributes", "(", ")", ")", ";", "}", "else", "{", "samoaInstance", "=", "new", "DenseInstance", "(", "inst", ".", "weight", "(", ")", ",", "inst", ".", "toDoubleArray", "(", ")", ")", ";", "//samoaInstance.deleteAttributeAt(inst.classIndex());", "}", "if", "(", "this", ".", "samoaInstanceInformation", "==", "null", ")", "{", "this", ".", "samoaInstanceInformation", "=", "this", ".", "samoaInstancesInformation", "(", "inst", ".", "dataset", "(", ")", ")", ";", "}", "samoaInstance", ".", "setDataset", "(", "samoaInstanceInformation", ")", ";", "if", "(", "inst", ".", "classIndex", "(", ")", ">=", "0", ")", "{", "// class attribute is present", "samoaInstance", ".", "setClassValue", "(", "inst", ".", "classValue", "(", ")", ")", ";", "}", "return", "samoaInstance", ";", "}" ]
Samoa instance from weka instance. @param inst the inst @return the instance
[ "Samoa", "instance", "from", "weka", "instance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java#L37-L64
29,064
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java
WekaToSamoaInstanceConverter.samoaInstances
public Instances samoaInstances(weka.core.Instances instances) { Instances samoaInstances = samoaInstancesInformation(instances); //We assume that we have only one samoaInstanceInformation for WekaToSamoaInstanceConverter this.samoaInstanceInformation = samoaInstances; for (int i = 0; i < instances.numInstances(); i++) { samoaInstances.add(samoaInstance(instances.instance(i))); } return samoaInstances; }
java
public Instances samoaInstances(weka.core.Instances instances) { Instances samoaInstances = samoaInstancesInformation(instances); //We assume that we have only one samoaInstanceInformation for WekaToSamoaInstanceConverter this.samoaInstanceInformation = samoaInstances; for (int i = 0; i < instances.numInstances(); i++) { samoaInstances.add(samoaInstance(instances.instance(i))); } return samoaInstances; }
[ "public", "Instances", "samoaInstances", "(", "weka", ".", "core", ".", "Instances", "instances", ")", "{", "Instances", "samoaInstances", "=", "samoaInstancesInformation", "(", "instances", ")", ";", "//We assume that we have only one samoaInstanceInformation for WekaToSamoaInstanceConverter", "this", ".", "samoaInstanceInformation", "=", "samoaInstances", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "instances", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "samoaInstances", ".", "add", "(", "samoaInstance", "(", "instances", ".", "instance", "(", "i", ")", ")", ")", ";", "}", "return", "samoaInstances", ";", "}" ]
Samoa instances from weka instances. @param instances the instances @return the instances
[ "Samoa", "instances", "from", "weka", "instances", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java#L72-L80
29,065
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java
WekaToSamoaInstanceConverter.samoaInstancesInformation
public Instances samoaInstancesInformation(weka.core.Instances instances) { Instances samoaInstances; List<Attribute> attInfo = new ArrayList<Attribute>(); for (int i = 0; i < instances.numAttributes(); i++) { attInfo.add(samoaAttribute(i, instances.attribute(i))); } samoaInstances = new Instances(instances.relationName(), attInfo, 0); if(instances.classIndex() >= 0) { // class attribute is present samoaInstances.setClassIndex(instances.classIndex()); } return samoaInstances; }
java
public Instances samoaInstancesInformation(weka.core.Instances instances) { Instances samoaInstances; List<Attribute> attInfo = new ArrayList<Attribute>(); for (int i = 0; i < instances.numAttributes(); i++) { attInfo.add(samoaAttribute(i, instances.attribute(i))); } samoaInstances = new Instances(instances.relationName(), attInfo, 0); if(instances.classIndex() >= 0) { // class attribute is present samoaInstances.setClassIndex(instances.classIndex()); } return samoaInstances; }
[ "public", "Instances", "samoaInstancesInformation", "(", "weka", ".", "core", ".", "Instances", "instances", ")", "{", "Instances", "samoaInstances", ";", "List", "<", "Attribute", ">", "attInfo", "=", "new", "ArrayList", "<", "Attribute", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "instances", ".", "numAttributes", "(", ")", ";", "i", "++", ")", "{", "attInfo", ".", "add", "(", "samoaAttribute", "(", "i", ",", "instances", ".", "attribute", "(", "i", ")", ")", ")", ";", "}", "samoaInstances", "=", "new", "Instances", "(", "instances", ".", "relationName", "(", ")", ",", "attInfo", ",", "0", ")", ";", "if", "(", "instances", ".", "classIndex", "(", ")", ">=", "0", ")", "{", "// class attribute is present", "samoaInstances", ".", "setClassIndex", "(", "instances", ".", "classIndex", "(", ")", ")", ";", "}", "return", "samoaInstances", ";", "}" ]
Samoa instances information. @param instances the instances @return the instances
[ "Samoa", "instances", "information", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java#L88-L101
29,066
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java
WekaToSamoaInstanceConverter.samoaAttribute
protected Attribute samoaAttribute(int index, weka.core.Attribute attribute) { Attribute samoaAttribute; if (attribute.isNominal()) { Enumeration enu = attribute.enumerateValues(); List<String> attributeValues = new ArrayList<String>(); while (enu.hasMoreElements()) { attributeValues.add((String) enu.nextElement()); } samoaAttribute = new Attribute(attribute.name(), attributeValues); } else { samoaAttribute = new Attribute(attribute.name()); } return samoaAttribute; }
java
protected Attribute samoaAttribute(int index, weka.core.Attribute attribute) { Attribute samoaAttribute; if (attribute.isNominal()) { Enumeration enu = attribute.enumerateValues(); List<String> attributeValues = new ArrayList<String>(); while (enu.hasMoreElements()) { attributeValues.add((String) enu.nextElement()); } samoaAttribute = new Attribute(attribute.name(), attributeValues); } else { samoaAttribute = new Attribute(attribute.name()); } return samoaAttribute; }
[ "protected", "Attribute", "samoaAttribute", "(", "int", "index", ",", "weka", ".", "core", ".", "Attribute", "attribute", ")", "{", "Attribute", "samoaAttribute", ";", "if", "(", "attribute", ".", "isNominal", "(", ")", ")", "{", "Enumeration", "enu", "=", "attribute", ".", "enumerateValues", "(", ")", ";", "List", "<", "String", ">", "attributeValues", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "while", "(", "enu", ".", "hasMoreElements", "(", ")", ")", "{", "attributeValues", ".", "add", "(", "(", "String", ")", "enu", ".", "nextElement", "(", ")", ")", ";", "}", "samoaAttribute", "=", "new", "Attribute", "(", "attribute", ".", "name", "(", ")", ",", "attributeValues", ")", ";", "}", "else", "{", "samoaAttribute", "=", "new", "Attribute", "(", "attribute", ".", "name", "(", ")", ")", ";", "}", "return", "samoaAttribute", ";", "}" ]
Get Samoa attribute from a weka attribute. @param index the index @param attribute the attribute @return the attribute
[ "Get", "Samoa", "attribute", "from", "a", "weka", "attribute", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/WekaToSamoaInstanceConverter.java#L111-L124
29,067
Waikato/moa
moa/src/main/java/moa/gui/experimentertab/ImagePanel.java
ImagePanel.doSaveAs
@Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filterPNG = new ExtensionFileFilter("PNG Image Files", ".png"); fileChooser.addChoosableFileFilter(filterPNG); ExtensionFileFilter filterJPG = new ExtensionFileFilter("JPG Image Files", ".jpg"); fileChooser.addChoosableFileFilter(filterJPG); ExtensionFileFilter filterEPS = new ExtensionFileFilter("EPS Image Files", ".eps"); fileChooser.addChoosableFileFilter(filterEPS); ExtensionFileFilter filterSVG = new ExtensionFileFilter("SVG Image Files", ".svg"); fileChooser.addChoosableFileFilter(filterSVG); fileChooser.setCurrentDirectory(null); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String fileDesc = fileChooser.getFileFilter().getDescription(); if (fileDesc.startsWith("PNG")) { if (!fileChooser.getSelectedFile().getName().toUpperCase().endsWith("PNG")) { ChartUtilities.saveChartAsPNG(new File(fileChooser.getSelectedFile().getAbsolutePath() + ".png"), this.chart, this.getWidth(), this.getHeight()); } else { ChartUtilities.saveChartAsPNG(fileChooser.getSelectedFile(), this.chart, this.getWidth(), this.getHeight()); } } else if (fileDesc.startsWith("JPG")) { if (!fileChooser.getSelectedFile().getName().toUpperCase().endsWith("JPG")) { ChartUtilities.saveChartAsJPEG(new File(fileChooser.getSelectedFile().getAbsolutePath() + ".jpg"), this.chart, this.getWidth(), this.getHeight()); } else { ChartUtilities.saveChartAsJPEG(fileChooser.getSelectedFile(), this.chart, this.getWidth(), this.getHeight()); } } }//else }
java
@Override public void doSaveAs() throws IOException { JFileChooser fileChooser = new JFileChooser(); ExtensionFileFilter filterPNG = new ExtensionFileFilter("PNG Image Files", ".png"); fileChooser.addChoosableFileFilter(filterPNG); ExtensionFileFilter filterJPG = new ExtensionFileFilter("JPG Image Files", ".jpg"); fileChooser.addChoosableFileFilter(filterJPG); ExtensionFileFilter filterEPS = new ExtensionFileFilter("EPS Image Files", ".eps"); fileChooser.addChoosableFileFilter(filterEPS); ExtensionFileFilter filterSVG = new ExtensionFileFilter("SVG Image Files", ".svg"); fileChooser.addChoosableFileFilter(filterSVG); fileChooser.setCurrentDirectory(null); int option = fileChooser.showSaveDialog(this); if (option == JFileChooser.APPROVE_OPTION) { String fileDesc = fileChooser.getFileFilter().getDescription(); if (fileDesc.startsWith("PNG")) { if (!fileChooser.getSelectedFile().getName().toUpperCase().endsWith("PNG")) { ChartUtilities.saveChartAsPNG(new File(fileChooser.getSelectedFile().getAbsolutePath() + ".png"), this.chart, this.getWidth(), this.getHeight()); } else { ChartUtilities.saveChartAsPNG(fileChooser.getSelectedFile(), this.chart, this.getWidth(), this.getHeight()); } } else if (fileDesc.startsWith("JPG")) { if (!fileChooser.getSelectedFile().getName().toUpperCase().endsWith("JPG")) { ChartUtilities.saveChartAsJPEG(new File(fileChooser.getSelectedFile().getAbsolutePath() + ".jpg"), this.chart, this.getWidth(), this.getHeight()); } else { ChartUtilities.saveChartAsJPEG(fileChooser.getSelectedFile(), this.chart, this.getWidth(), this.getHeight()); } } }//else }
[ "@", "Override", "public", "void", "doSaveAs", "(", ")", "throws", "IOException", "{", "JFileChooser", "fileChooser", "=", "new", "JFileChooser", "(", ")", ";", "ExtensionFileFilter", "filterPNG", "=", "new", "ExtensionFileFilter", "(", "\"PNG Image Files\"", ",", "\".png\"", ")", ";", "fileChooser", ".", "addChoosableFileFilter", "(", "filterPNG", ")", ";", "ExtensionFileFilter", "filterJPG", "=", "new", "ExtensionFileFilter", "(", "\"JPG Image Files\"", ",", "\".jpg\"", ")", ";", "fileChooser", ".", "addChoosableFileFilter", "(", "filterJPG", ")", ";", "ExtensionFileFilter", "filterEPS", "=", "new", "ExtensionFileFilter", "(", "\"EPS Image Files\"", ",", "\".eps\"", ")", ";", "fileChooser", ".", "addChoosableFileFilter", "(", "filterEPS", ")", ";", "ExtensionFileFilter", "filterSVG", "=", "new", "ExtensionFileFilter", "(", "\"SVG Image Files\"", ",", "\".svg\"", ")", ";", "fileChooser", ".", "addChoosableFileFilter", "(", "filterSVG", ")", ";", "fileChooser", ".", "setCurrentDirectory", "(", "null", ")", ";", "int", "option", "=", "fileChooser", ".", "showSaveDialog", "(", "this", ")", ";", "if", "(", "option", "==", "JFileChooser", ".", "APPROVE_OPTION", ")", "{", "String", "fileDesc", "=", "fileChooser", ".", "getFileFilter", "(", ")", ".", "getDescription", "(", ")", ";", "if", "(", "fileDesc", ".", "startsWith", "(", "\"PNG\"", ")", ")", "{", "if", "(", "!", "fileChooser", ".", "getSelectedFile", "(", ")", ".", "getName", "(", ")", ".", "toUpperCase", "(", ")", ".", "endsWith", "(", "\"PNG\"", ")", ")", "{", "ChartUtilities", ".", "saveChartAsPNG", "(", "new", "File", "(", "fileChooser", ".", "getSelectedFile", "(", ")", ".", "getAbsolutePath", "(", ")", "+", "\".png\"", ")", ",", "this", ".", "chart", ",", "this", ".", "getWidth", "(", ")", ",", "this", ".", "getHeight", "(", ")", ")", ";", "}", "else", "{", "ChartUtilities", ".", "saveChartAsPNG", "(", "fileChooser", ".", "getSelectedFile", "(", ")", ",", "this", ".", "chart", ",", "this", ".", "getWidth", "(", ")", ",", "this", ".", "getHeight", "(", ")", ")", ";", "}", "}", "else", "if", "(", "fileDesc", ".", "startsWith", "(", "\"JPG\"", ")", ")", "{", "if", "(", "!", "fileChooser", ".", "getSelectedFile", "(", ")", ".", "getName", "(", ")", ".", "toUpperCase", "(", ")", ".", "endsWith", "(", "\"JPG\"", ")", ")", "{", "ChartUtilities", ".", "saveChartAsJPEG", "(", "new", "File", "(", "fileChooser", ".", "getSelectedFile", "(", ")", ".", "getAbsolutePath", "(", ")", "+", "\".jpg\"", ")", ",", "this", ".", "chart", ",", "this", ".", "getWidth", "(", ")", ",", "this", ".", "getHeight", "(", ")", ")", ";", "}", "else", "{", "ChartUtilities", ".", "saveChartAsJPEG", "(", "fileChooser", ".", "getSelectedFile", "(", ")", ",", "this", ".", "chart", ",", "this", ".", "getWidth", "(", ")", ",", "this", ".", "getHeight", "(", ")", ")", ";", "}", "}", "}", "//else", "}" ]
Method for save the images. @throws IOException
[ "Method", "for", "save", "the", "images", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/ImagePanel.java#L57-L91
29,068
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.round
protected BigDecimal round(double val){ BigDecimal value = new BigDecimal(val); if(val!=0.0){ value = value.setScale(3, BigDecimal.ROUND_DOWN); } return value; }
java
protected BigDecimal round(double val){ BigDecimal value = new BigDecimal(val); if(val!=0.0){ value = value.setScale(3, BigDecimal.ROUND_DOWN); } return value; }
[ "protected", "BigDecimal", "round", "(", "double", "val", ")", "{", "BigDecimal", "value", "=", "new", "BigDecimal", "(", "val", ")", ";", "if", "(", "val", "!=", "0.0", ")", "{", "value", "=", "value", ".", "setScale", "(", "3", ",", "BigDecimal", ".", "ROUND_DOWN", ")", ";", "}", "return", "value", ";", "}" ]
Round an number
[ "Round", "an", "number" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L551-L557
29,069
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.initializeRuleStatistics
public void initializeRuleStatistics(RuleClassification rl, Predicates pred, Instance inst) { rl.predicateSet.add(pred); rl.obserClassDistrib=new DoubleVector(); rl.observers=new AutoExpandVector<AttributeClassObserver>(); rl.observersGauss=new AutoExpandVector<AttributeClassObserver>(); rl.instancesSeen = 0; rl.attributeStatistics = new DoubleVector(); rl.squaredAttributeStatistics = new DoubleVector(); rl.attributeStatisticsSupervised = new ArrayList<ArrayList<Double>>(); rl.squaredAttributeStatisticsSupervised = new ArrayList<ArrayList<Double>>(); rl.attributeMissingValues = new DoubleVector(); }
java
public void initializeRuleStatistics(RuleClassification rl, Predicates pred, Instance inst) { rl.predicateSet.add(pred); rl.obserClassDistrib=new DoubleVector(); rl.observers=new AutoExpandVector<AttributeClassObserver>(); rl.observersGauss=new AutoExpandVector<AttributeClassObserver>(); rl.instancesSeen = 0; rl.attributeStatistics = new DoubleVector(); rl.squaredAttributeStatistics = new DoubleVector(); rl.attributeStatisticsSupervised = new ArrayList<ArrayList<Double>>(); rl.squaredAttributeStatisticsSupervised = new ArrayList<ArrayList<Double>>(); rl.attributeMissingValues = new DoubleVector(); }
[ "public", "void", "initializeRuleStatistics", "(", "RuleClassification", "rl", ",", "Predicates", "pred", ",", "Instance", "inst", ")", "{", "rl", ".", "predicateSet", ".", "add", "(", "pred", ")", ";", "rl", ".", "obserClassDistrib", "=", "new", "DoubleVector", "(", ")", ";", "rl", ".", "observers", "=", "new", "AutoExpandVector", "<", "AttributeClassObserver", ">", "(", ")", ";", "rl", ".", "observersGauss", "=", "new", "AutoExpandVector", "<", "AttributeClassObserver", ">", "(", ")", ";", "rl", ".", "instancesSeen", "=", "0", ";", "rl", ".", "attributeStatistics", "=", "new", "DoubleVector", "(", ")", ";", "rl", ".", "squaredAttributeStatistics", "=", "new", "DoubleVector", "(", ")", ";", "rl", ".", "attributeStatisticsSupervised", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "rl", ".", "squaredAttributeStatisticsSupervised", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "rl", ".", "attributeMissingValues", "=", "new", "DoubleVector", "(", ")", ";", "}" ]
This function initializes the statistics of a rule
[ "This", "function", "initializes", "the", "statistics", "of", "a", "rule" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L561-L572
29,070
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.updateRuleAttribStatistics
public void updateRuleAttribStatistics(Instance inst, RuleClassification rl, int ruleIndex){ rl.instancesSeen++; if(rl.squaredAttributeStatisticsSupervised.size() == 0 && rl.attributeStatisticsSupervised.size() == 0){ for (int s = 0; s < inst.numAttributes() -1; s++) { ArrayList<Double> temp1 = new ArrayList<Double>(); ArrayList<Double> temp2 = new ArrayList<Double>(); rl.attributeStatisticsSupervised.add(temp1); rl.squaredAttributeStatisticsSupervised.add(temp2); int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst); if(instance.attribute(instAttIndex).isNumeric()){ for(int i=0; i<inst.numClasses(); i++){ rl.attributeStatisticsSupervised.get(s).add(0.0); rl.squaredAttributeStatisticsSupervised.get(s).add(1.0); } } } } for (int s = 0; s < inst.numAttributes() -1; s++) { int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst); if(!inst.isMissing(instAttIndex)){ if(instance.attribute(instAttIndex).isNumeric()){ rl.attributeStatistics.addToValue(s, inst.value(s)); rl.squaredAttributeStatistics.addToValue(s, inst.value(s) * inst.value(s)); double sumValue = rl.attributeStatisticsSupervised.get(s).get((int)inst.classValue()) + inst.value(s); rl.attributeStatisticsSupervised.get(s).set((int)inst.classValue(), sumValue); double squaredSumvalue = rl.squaredAttributeStatisticsSupervised.get(s).get((int)inst.classValue()) + (inst.value(s) * inst.value(s)); rl.squaredAttributeStatisticsSupervised.get(s).set((int)inst.classValue(), squaredSumvalue); } }else{ rl.attributeMissingValues.addToValue(s, 1); } } }
java
public void updateRuleAttribStatistics(Instance inst, RuleClassification rl, int ruleIndex){ rl.instancesSeen++; if(rl.squaredAttributeStatisticsSupervised.size() == 0 && rl.attributeStatisticsSupervised.size() == 0){ for (int s = 0; s < inst.numAttributes() -1; s++) { ArrayList<Double> temp1 = new ArrayList<Double>(); ArrayList<Double> temp2 = new ArrayList<Double>(); rl.attributeStatisticsSupervised.add(temp1); rl.squaredAttributeStatisticsSupervised.add(temp2); int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst); if(instance.attribute(instAttIndex).isNumeric()){ for(int i=0; i<inst.numClasses(); i++){ rl.attributeStatisticsSupervised.get(s).add(0.0); rl.squaredAttributeStatisticsSupervised.get(s).add(1.0); } } } } for (int s = 0; s < inst.numAttributes() -1; s++) { int instAttIndex = modelAttIndexToInstanceAttIndex(s, inst); if(!inst.isMissing(instAttIndex)){ if(instance.attribute(instAttIndex).isNumeric()){ rl.attributeStatistics.addToValue(s, inst.value(s)); rl.squaredAttributeStatistics.addToValue(s, inst.value(s) * inst.value(s)); double sumValue = rl.attributeStatisticsSupervised.get(s).get((int)inst.classValue()) + inst.value(s); rl.attributeStatisticsSupervised.get(s).set((int)inst.classValue(), sumValue); double squaredSumvalue = rl.squaredAttributeStatisticsSupervised.get(s).get((int)inst.classValue()) + (inst.value(s) * inst.value(s)); rl.squaredAttributeStatisticsSupervised.get(s).set((int)inst.classValue(), squaredSumvalue); } }else{ rl.attributeMissingValues.addToValue(s, 1); } } }
[ "public", "void", "updateRuleAttribStatistics", "(", "Instance", "inst", ",", "RuleClassification", "rl", ",", "int", "ruleIndex", ")", "{", "rl", ".", "instancesSeen", "++", ";", "if", "(", "rl", ".", "squaredAttributeStatisticsSupervised", ".", "size", "(", ")", "==", "0", "&&", "rl", ".", "attributeStatisticsSupervised", ".", "size", "(", ")", "==", "0", ")", "{", "for", "(", "int", "s", "=", "0", ";", "s", "<", "inst", ".", "numAttributes", "(", ")", "-", "1", ";", "s", "++", ")", "{", "ArrayList", "<", "Double", ">", "temp1", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "ArrayList", "<", "Double", ">", "temp2", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "rl", ".", "attributeStatisticsSupervised", ".", "add", "(", "temp1", ")", ";", "rl", ".", "squaredAttributeStatisticsSupervised", ".", "add", "(", "temp2", ")", ";", "int", "instAttIndex", "=", "modelAttIndexToInstanceAttIndex", "(", "s", ",", "inst", ")", ";", "if", "(", "instance", ".", "attribute", "(", "instAttIndex", ")", ".", "isNumeric", "(", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "inst", ".", "numClasses", "(", ")", ";", "i", "++", ")", "{", "rl", ".", "attributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "add", "(", "0.0", ")", ";", "rl", ".", "squaredAttributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "add", "(", "1.0", ")", ";", "}", "}", "}", "}", "for", "(", "int", "s", "=", "0", ";", "s", "<", "inst", ".", "numAttributes", "(", ")", "-", "1", ";", "s", "++", ")", "{", "int", "instAttIndex", "=", "modelAttIndexToInstanceAttIndex", "(", "s", ",", "inst", ")", ";", "if", "(", "!", "inst", ".", "isMissing", "(", "instAttIndex", ")", ")", "{", "if", "(", "instance", ".", "attribute", "(", "instAttIndex", ")", ".", "isNumeric", "(", ")", ")", "{", "rl", ".", "attributeStatistics", ".", "addToValue", "(", "s", ",", "inst", ".", "value", "(", "s", ")", ")", ";", "rl", ".", "squaredAttributeStatistics", ".", "addToValue", "(", "s", ",", "inst", ".", "value", "(", "s", ")", "*", "inst", ".", "value", "(", "s", ")", ")", ";", "double", "sumValue", "=", "rl", ".", "attributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "get", "(", "(", "int", ")", "inst", ".", "classValue", "(", ")", ")", "+", "inst", ".", "value", "(", "s", ")", ";", "rl", ".", "attributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "set", "(", "(", "int", ")", "inst", ".", "classValue", "(", ")", ",", "sumValue", ")", ";", "double", "squaredSumvalue", "=", "rl", ".", "squaredAttributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "get", "(", "(", "int", ")", "inst", ".", "classValue", "(", ")", ")", "+", "(", "inst", ".", "value", "(", "s", ")", "*", "inst", ".", "value", "(", "s", ")", ")", ";", "rl", ".", "squaredAttributeStatisticsSupervised", ".", "get", "(", "s", ")", ".", "set", "(", "(", "int", ")", "inst", ".", "classValue", "(", ")", ",", "squaredSumvalue", ")", ";", "}", "}", "else", "{", "rl", ".", "attributeMissingValues", ".", "addToValue", "(", "s", ",", "1", ")", ";", "}", "}", "}" ]
Update rule statistics
[ "Update", "rule", "statistics" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L575-L607
29,071
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.createRule
public void createRule(Instance inst) { int remainder = (int)Double.MAX_VALUE; int numInstanciaObservers = (int)this.observedClassDistribution.sumOfValues(); if (numInstanciaObservers != 0 && this.gracePeriodOption.getValue() != 0) { remainder = (numInstanciaObservers) % (this.gracePeriodOption.getValue()); } if (remainder == 0) { this.saveBestValGlobalEntropy = new ArrayList<ArrayList<Double>>(); this.saveBestGlobalEntropy = new DoubleVector(); this.saveTheBest = new ArrayList<Double>(); this.minEntropyTemp = Double.MAX_VALUE; this.minEntropyNominalAttrib = Double.MAX_VALUE; theBestAttributes(inst, this.attributeObservers); boolean HB = checkBestAttrib(numInstanciaObservers, this.attributeObservers, this.observedClassDistribution); if (HB == true) { // System.out.print("this.saveTheBest"+this.saveTheBest+"\n"); double attributeValue = this.saveTheBest.get(3); double symbol = this.saveTheBest.get(2); // =, <=, > : (0.0, -1.0, 1.0). double value = this.saveTheBest.get(0); // Value of the attribute this.pred = new Predicates(attributeValue, symbol, value); RuleClassification Rl = new RuleClassification(); // Create RuleClassification. Rl.predicateSet.add(pred); this.ruleSet.add(Rl); if (Rl.predicateSet.get(0).getSymbol() == -1.0 ||Rl.predicateSet.get(0).getSymbol() == 1.0) { double posClassDouble = this.saveTheBest.get(4); this.ruleClassIndex.setValue(this.ruleSet.size()-1, posClassDouble); }else{ this.ruleClassIndex.setValue(ruleSet.size()-1, 0.0); } this.observedClassDistribution = new DoubleVector(); this.attributeObservers = new AutoExpandVector<AttributeClassObserver>(); this.attributeObserversGauss = new AutoExpandVector<AttributeClassObserver>(); } } }
java
public void createRule(Instance inst) { int remainder = (int)Double.MAX_VALUE; int numInstanciaObservers = (int)this.observedClassDistribution.sumOfValues(); if (numInstanciaObservers != 0 && this.gracePeriodOption.getValue() != 0) { remainder = (numInstanciaObservers) % (this.gracePeriodOption.getValue()); } if (remainder == 0) { this.saveBestValGlobalEntropy = new ArrayList<ArrayList<Double>>(); this.saveBestGlobalEntropy = new DoubleVector(); this.saveTheBest = new ArrayList<Double>(); this.minEntropyTemp = Double.MAX_VALUE; this.minEntropyNominalAttrib = Double.MAX_VALUE; theBestAttributes(inst, this.attributeObservers); boolean HB = checkBestAttrib(numInstanciaObservers, this.attributeObservers, this.observedClassDistribution); if (HB == true) { // System.out.print("this.saveTheBest"+this.saveTheBest+"\n"); double attributeValue = this.saveTheBest.get(3); double symbol = this.saveTheBest.get(2); // =, <=, > : (0.0, -1.0, 1.0). double value = this.saveTheBest.get(0); // Value of the attribute this.pred = new Predicates(attributeValue, symbol, value); RuleClassification Rl = new RuleClassification(); // Create RuleClassification. Rl.predicateSet.add(pred); this.ruleSet.add(Rl); if (Rl.predicateSet.get(0).getSymbol() == -1.0 ||Rl.predicateSet.get(0).getSymbol() == 1.0) { double posClassDouble = this.saveTheBest.get(4); this.ruleClassIndex.setValue(this.ruleSet.size()-1, posClassDouble); }else{ this.ruleClassIndex.setValue(ruleSet.size()-1, 0.0); } this.observedClassDistribution = new DoubleVector(); this.attributeObservers = new AutoExpandVector<AttributeClassObserver>(); this.attributeObserversGauss = new AutoExpandVector<AttributeClassObserver>(); } } }
[ "public", "void", "createRule", "(", "Instance", "inst", ")", "{", "int", "remainder", "=", "(", "int", ")", "Double", ".", "MAX_VALUE", ";", "int", "numInstanciaObservers", "=", "(", "int", ")", "this", ".", "observedClassDistribution", ".", "sumOfValues", "(", ")", ";", "if", "(", "numInstanciaObservers", "!=", "0", "&&", "this", ".", "gracePeriodOption", ".", "getValue", "(", ")", "!=", "0", ")", "{", "remainder", "=", "(", "numInstanciaObservers", ")", "%", "(", "this", ".", "gracePeriodOption", ".", "getValue", "(", ")", ")", ";", "}", "if", "(", "remainder", "==", "0", ")", "{", "this", ".", "saveBestValGlobalEntropy", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "this", ".", "saveBestGlobalEntropy", "=", "new", "DoubleVector", "(", ")", ";", "this", ".", "saveTheBest", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "this", ".", "minEntropyTemp", "=", "Double", ".", "MAX_VALUE", ";", "this", ".", "minEntropyNominalAttrib", "=", "Double", ".", "MAX_VALUE", ";", "theBestAttributes", "(", "inst", ",", "this", ".", "attributeObservers", ")", ";", "boolean", "HB", "=", "checkBestAttrib", "(", "numInstanciaObservers", ",", "this", ".", "attributeObservers", ",", "this", ".", "observedClassDistribution", ")", ";", "if", "(", "HB", "==", "true", ")", "{", "//\tSystem.out.print(\"this.saveTheBest\"+this.saveTheBest+\"\\n\");", "double", "attributeValue", "=", "this", ".", "saveTheBest", ".", "get", "(", "3", ")", ";", "double", "symbol", "=", "this", ".", "saveTheBest", ".", "get", "(", "2", ")", ";", "// =, <=, > : (0.0, -1.0, 1.0).", "double", "value", "=", "this", ".", "saveTheBest", ".", "get", "(", "0", ")", ";", "// Value of the attribute", "this", ".", "pred", "=", "new", "Predicates", "(", "attributeValue", ",", "symbol", ",", "value", ")", ";", "RuleClassification", "Rl", "=", "new", "RuleClassification", "(", ")", ";", "// Create RuleClassification.", "Rl", ".", "predicateSet", ".", "add", "(", "pred", ")", ";", "this", ".", "ruleSet", ".", "add", "(", "Rl", ")", ";", "if", "(", "Rl", ".", "predicateSet", ".", "get", "(", "0", ")", ".", "getSymbol", "(", ")", "==", "-", "1.0", "||", "Rl", ".", "predicateSet", ".", "get", "(", "0", ")", ".", "getSymbol", "(", ")", "==", "1.0", ")", "{", "double", "posClassDouble", "=", "this", ".", "saveTheBest", ".", "get", "(", "4", ")", ";", "this", ".", "ruleClassIndex", ".", "setValue", "(", "this", ".", "ruleSet", ".", "size", "(", ")", "-", "1", ",", "posClassDouble", ")", ";", "}", "else", "{", "this", ".", "ruleClassIndex", ".", "setValue", "(", "ruleSet", ".", "size", "(", ")", "-", "1", ",", "0.0", ")", ";", "}", "this", ".", "observedClassDistribution", "=", "new", "DoubleVector", "(", ")", ";", "this", ".", "attributeObservers", "=", "new", "AutoExpandVector", "<", "AttributeClassObserver", ">", "(", ")", ";", "this", ".", "attributeObserversGauss", "=", "new", "AutoExpandVector", "<", "AttributeClassObserver", ">", "(", ")", ";", "}", "}", "}" ]
This function creates a rule
[ "This", "function", "creates", "a", "rule" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L775-L809
29,072
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.theBestAttributes
public void theBestAttributes(Instance instance, AutoExpandVector<AttributeClassObserver> observersParameter) { for(int z = 0; z < instance.numAttributes() - 1; z++){ if(!instance.isMissing(z)){ int instAttIndex = modelAttIndexToInstanceAttIndex(z, instance); ArrayList<Double> attribBest = new ArrayList<Double>(); if(instance.attribute(instAttIndex).isNominal()){ this.minEntropyNominalAttrib=Double.MAX_VALUE; AutoExpandVector<DoubleVector> attribNominal = ((NominalAttributeClassObserver)observersParameter.get(z)).attValDistPerClass; findBestValEntropyNominalAtt(attribNominal, instance.attribute(z).numValues()); // The best value (lowest entropy) of a nominal attribute. attribBest.add(this.saveBestEntropyNominalAttrib.getValue(0)); attribBest.add(this.saveBestEntropyNominalAttrib.getValue(1)); attribBest.add(this.saveBestEntropyNominalAttrib.getValue(2)); this.saveBestValGlobalEntropy.add(attribBest); this.saveBestGlobalEntropy.setValue(z, this.saveBestEntropyNominalAttrib.getValue(1)); } else { this.root=((BinaryTreeNumericAttributeClassObserver)observersParameter.get(z)).root; mainFindBestValEntropy(this.root); // The best value (lowest entropy) of a numeric attribute. attribBest.add(this.saveBestEntropy.getValue(0)); attribBest.add(this.saveBestEntropy.getValue(1)); attribBest.add(this.saveBestEntropy.getValue(2)); attribBest.add(this.saveBestEntropy.getValue(4)); this.saveBestValGlobalEntropy.add(attribBest); this.saveBestGlobalEntropy.setValue(z, this.saveBestEntropy.getValue(1)); } }else{ double value = Double.MAX_VALUE; this.saveBestGlobalEntropy.setValue(z, value); } } }
java
public void theBestAttributes(Instance instance, AutoExpandVector<AttributeClassObserver> observersParameter) { for(int z = 0; z < instance.numAttributes() - 1; z++){ if(!instance.isMissing(z)){ int instAttIndex = modelAttIndexToInstanceAttIndex(z, instance); ArrayList<Double> attribBest = new ArrayList<Double>(); if(instance.attribute(instAttIndex).isNominal()){ this.minEntropyNominalAttrib=Double.MAX_VALUE; AutoExpandVector<DoubleVector> attribNominal = ((NominalAttributeClassObserver)observersParameter.get(z)).attValDistPerClass; findBestValEntropyNominalAtt(attribNominal, instance.attribute(z).numValues()); // The best value (lowest entropy) of a nominal attribute. attribBest.add(this.saveBestEntropyNominalAttrib.getValue(0)); attribBest.add(this.saveBestEntropyNominalAttrib.getValue(1)); attribBest.add(this.saveBestEntropyNominalAttrib.getValue(2)); this.saveBestValGlobalEntropy.add(attribBest); this.saveBestGlobalEntropy.setValue(z, this.saveBestEntropyNominalAttrib.getValue(1)); } else { this.root=((BinaryTreeNumericAttributeClassObserver)observersParameter.get(z)).root; mainFindBestValEntropy(this.root); // The best value (lowest entropy) of a numeric attribute. attribBest.add(this.saveBestEntropy.getValue(0)); attribBest.add(this.saveBestEntropy.getValue(1)); attribBest.add(this.saveBestEntropy.getValue(2)); attribBest.add(this.saveBestEntropy.getValue(4)); this.saveBestValGlobalEntropy.add(attribBest); this.saveBestGlobalEntropy.setValue(z, this.saveBestEntropy.getValue(1)); } }else{ double value = Double.MAX_VALUE; this.saveBestGlobalEntropy.setValue(z, value); } } }
[ "public", "void", "theBestAttributes", "(", "Instance", "instance", ",", "AutoExpandVector", "<", "AttributeClassObserver", ">", "observersParameter", ")", "{", "for", "(", "int", "z", "=", "0", ";", "z", "<", "instance", ".", "numAttributes", "(", ")", "-", "1", ";", "z", "++", ")", "{", "if", "(", "!", "instance", ".", "isMissing", "(", "z", ")", ")", "{", "int", "instAttIndex", "=", "modelAttIndexToInstanceAttIndex", "(", "z", ",", "instance", ")", ";", "ArrayList", "<", "Double", ">", "attribBest", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "if", "(", "instance", ".", "attribute", "(", "instAttIndex", ")", ".", "isNominal", "(", ")", ")", "{", "this", ".", "minEntropyNominalAttrib", "=", "Double", ".", "MAX_VALUE", ";", "AutoExpandVector", "<", "DoubleVector", ">", "attribNominal", "=", "(", "(", "NominalAttributeClassObserver", ")", "observersParameter", ".", "get", "(", "z", ")", ")", ".", "attValDistPerClass", ";", "findBestValEntropyNominalAtt", "(", "attribNominal", ",", "instance", ".", "attribute", "(", "z", ")", ".", "numValues", "(", ")", ")", ";", "// The best value (lowest entropy) of a nominal attribute.", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropyNominalAttrib", ".", "getValue", "(", "0", ")", ")", ";", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropyNominalAttrib", ".", "getValue", "(", "1", ")", ")", ";", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropyNominalAttrib", ".", "getValue", "(", "2", ")", ")", ";", "this", ".", "saveBestValGlobalEntropy", ".", "add", "(", "attribBest", ")", ";", "this", ".", "saveBestGlobalEntropy", ".", "setValue", "(", "z", ",", "this", ".", "saveBestEntropyNominalAttrib", ".", "getValue", "(", "1", ")", ")", ";", "}", "else", "{", "this", ".", "root", "=", "(", "(", "BinaryTreeNumericAttributeClassObserver", ")", "observersParameter", ".", "get", "(", "z", ")", ")", ".", "root", ";", "mainFindBestValEntropy", "(", "this", ".", "root", ")", ";", "// The best value (lowest entropy) of a numeric attribute.", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropy", ".", "getValue", "(", "0", ")", ")", ";", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropy", ".", "getValue", "(", "1", ")", ")", ";", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropy", ".", "getValue", "(", "2", ")", ")", ";", "attribBest", ".", "add", "(", "this", ".", "saveBestEntropy", ".", "getValue", "(", "4", ")", ")", ";", "this", ".", "saveBestValGlobalEntropy", ".", "add", "(", "attribBest", ")", ";", "this", ".", "saveBestGlobalEntropy", ".", "setValue", "(", "z", ",", "this", ".", "saveBestEntropy", ".", "getValue", "(", "1", ")", ")", ";", "}", "}", "else", "{", "double", "value", "=", "Double", ".", "MAX_VALUE", ";", "this", ".", "saveBestGlobalEntropy", ".", "setValue", "(", "z", ",", "value", ")", ";", "}", "}", "}" ]
This function gives the best value of entropy for each attribute
[ "This", "function", "gives", "the", "best", "value", "of", "entropy", "for", "each", "attribute" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L914-L944
29,073
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.mainFindBestValEntropy
public void mainFindBestValEntropy(Node root) { if (root != null) { DoubleVector parentClassCL = new DoubleVector(); DoubleVector classCountL = root.classCountsLeft; //class count left DoubleVector classCountR = root.classCountsRight; //class count left double numInst = root.classCountsLeft.sumOfValues() + root.classCountsRight.sumOfValues(); double classCountLSum = root.classCountsLeft.sumOfValues(); double classCountRSum = root.classCountsRight.sumOfValues(); double classCountLEntropy = entropy(classCountL); double classCountREntropy = entropy(classCountR); this.minEntropyTemp = ( classCountLSum / numInst) * classCountLEntropy + (classCountRSum / numInst)* classCountREntropy; for (int f = 0; f < root.classCountsLeft.numValues(); f++) { parentClassCL.setValue(f, root.classCountsLeft.getValue(f)); } findBestValEntropy(root ,classCountL , classCountR, true, this.minEntropyTemp, parentClassCL); } }
java
public void mainFindBestValEntropy(Node root) { if (root != null) { DoubleVector parentClassCL = new DoubleVector(); DoubleVector classCountL = root.classCountsLeft; //class count left DoubleVector classCountR = root.classCountsRight; //class count left double numInst = root.classCountsLeft.sumOfValues() + root.classCountsRight.sumOfValues(); double classCountLSum = root.classCountsLeft.sumOfValues(); double classCountRSum = root.classCountsRight.sumOfValues(); double classCountLEntropy = entropy(classCountL); double classCountREntropy = entropy(classCountR); this.minEntropyTemp = ( classCountLSum / numInst) * classCountLEntropy + (classCountRSum / numInst)* classCountREntropy; for (int f = 0; f < root.classCountsLeft.numValues(); f++) { parentClassCL.setValue(f, root.classCountsLeft.getValue(f)); } findBestValEntropy(root ,classCountL , classCountR, true, this.minEntropyTemp, parentClassCL); } }
[ "public", "void", "mainFindBestValEntropy", "(", "Node", "root", ")", "{", "if", "(", "root", "!=", "null", ")", "{", "DoubleVector", "parentClassCL", "=", "new", "DoubleVector", "(", ")", ";", "DoubleVector", "classCountL", "=", "root", ".", "classCountsLeft", ";", "//class count left", "DoubleVector", "classCountR", "=", "root", ".", "classCountsRight", ";", "//class count left", "double", "numInst", "=", "root", ".", "classCountsLeft", ".", "sumOfValues", "(", ")", "+", "root", ".", "classCountsRight", ".", "sumOfValues", "(", ")", ";", "double", "classCountLSum", "=", "root", ".", "classCountsLeft", ".", "sumOfValues", "(", ")", ";", "double", "classCountRSum", "=", "root", ".", "classCountsRight", ".", "sumOfValues", "(", ")", ";", "double", "classCountLEntropy", "=", "entropy", "(", "classCountL", ")", ";", "double", "classCountREntropy", "=", "entropy", "(", "classCountR", ")", ";", "this", ".", "minEntropyTemp", "=", "(", "classCountLSum", "/", "numInst", ")", "*", "classCountLEntropy", "+", "(", "classCountRSum", "/", "numInst", ")", "*", "classCountREntropy", ";", "for", "(", "int", "f", "=", "0", ";", "f", "<", "root", ".", "classCountsLeft", ".", "numValues", "(", ")", ";", "f", "++", ")", "{", "parentClassCL", ".", "setValue", "(", "f", ",", "root", ".", "classCountsLeft", ".", "getValue", "(", "f", ")", ")", ";", "}", "findBestValEntropy", "(", "root", ",", "classCountL", ",", "classCountR", ",", "true", ",", "this", ".", "minEntropyTemp", ",", "parentClassCL", ")", ";", "}", "}" ]
Best value of entropy
[ "Best", "value", "of", "entropy" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1056-L1073
29,074
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.findBestValEntropyNominalAtt
public void findBestValEntropyNominalAtt(AutoExpandVector<DoubleVector> attrib, int attNumValues) { ArrayList<ArrayList<Double>> distClassValue = new ArrayList<ArrayList<Double>>(); // System.out.print("attrib"+attrib+"\n"); for (int z = 0; z < attrib.size(); z++) { distClassValue.add(new ArrayList<Double>()); } for (int v = 0; v < attNumValues; v++) { DoubleVector saveVal = new DoubleVector(); for (int z = 0; z < attrib.size(); z++) { if (attrib.get(z) != null) { distClassValue.get(z).add(attrib.get(z).getValue(v)); } else { distClassValue.get(z).add(0.0); } if(distClassValue.get(z).get(v).isNaN()) { distClassValue.get(z).add(0.0); } saveVal.setValue(z, distClassValue.get(z).get(v)); } double sumValue = saveVal.sumOfValues(); if (sumValue > 0.0) { double entropyVal = entropy(saveVal); if (entropyVal <= this.minEntropyNominalAttrib) { this.minEntropyNominalAttrib = entropyVal; this.saveBestEntropyNominalAttrib.setValue(0, v); this.saveBestEntropyNominalAttrib.setValue(1, entropyVal); this.saveBestEntropyNominalAttrib.setValue(2, 0.0); } } } }
java
public void findBestValEntropyNominalAtt(AutoExpandVector<DoubleVector> attrib, int attNumValues) { ArrayList<ArrayList<Double>> distClassValue = new ArrayList<ArrayList<Double>>(); // System.out.print("attrib"+attrib+"\n"); for (int z = 0; z < attrib.size(); z++) { distClassValue.add(new ArrayList<Double>()); } for (int v = 0; v < attNumValues; v++) { DoubleVector saveVal = new DoubleVector(); for (int z = 0; z < attrib.size(); z++) { if (attrib.get(z) != null) { distClassValue.get(z).add(attrib.get(z).getValue(v)); } else { distClassValue.get(z).add(0.0); } if(distClassValue.get(z).get(v).isNaN()) { distClassValue.get(z).add(0.0); } saveVal.setValue(z, distClassValue.get(z).get(v)); } double sumValue = saveVal.sumOfValues(); if (sumValue > 0.0) { double entropyVal = entropy(saveVal); if (entropyVal <= this.minEntropyNominalAttrib) { this.minEntropyNominalAttrib = entropyVal; this.saveBestEntropyNominalAttrib.setValue(0, v); this.saveBestEntropyNominalAttrib.setValue(1, entropyVal); this.saveBestEntropyNominalAttrib.setValue(2, 0.0); } } } }
[ "public", "void", "findBestValEntropyNominalAtt", "(", "AutoExpandVector", "<", "DoubleVector", ">", "attrib", ",", "int", "attNumValues", ")", "{", "ArrayList", "<", "ArrayList", "<", "Double", ">>", "distClassValue", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "//\tSystem.out.print(\"attrib\"+attrib+\"\\n\");", "for", "(", "int", "z", "=", "0", ";", "z", "<", "attrib", ".", "size", "(", ")", ";", "z", "++", ")", "{", "distClassValue", ".", "add", "(", "new", "ArrayList", "<", "Double", ">", "(", ")", ")", ";", "}", "for", "(", "int", "v", "=", "0", ";", "v", "<", "attNumValues", ";", "v", "++", ")", "{", "DoubleVector", "saveVal", "=", "new", "DoubleVector", "(", ")", ";", "for", "(", "int", "z", "=", "0", ";", "z", "<", "attrib", ".", "size", "(", ")", ";", "z", "++", ")", "{", "if", "(", "attrib", ".", "get", "(", "z", ")", "!=", "null", ")", "{", "distClassValue", ".", "get", "(", "z", ")", ".", "add", "(", "attrib", ".", "get", "(", "z", ")", ".", "getValue", "(", "v", ")", ")", ";", "}", "else", "{", "distClassValue", ".", "get", "(", "z", ")", ".", "add", "(", "0.0", ")", ";", "}", "if", "(", "distClassValue", ".", "get", "(", "z", ")", ".", "get", "(", "v", ")", ".", "isNaN", "(", ")", ")", "{", "distClassValue", ".", "get", "(", "z", ")", ".", "add", "(", "0.0", ")", ";", "}", "saveVal", ".", "setValue", "(", "z", ",", "distClassValue", ".", "get", "(", "z", ")", ".", "get", "(", "v", ")", ")", ";", "}", "double", "sumValue", "=", "saveVal", ".", "sumOfValues", "(", ")", ";", "if", "(", "sumValue", ">", "0.0", ")", "{", "double", "entropyVal", "=", "entropy", "(", "saveVal", ")", ";", "if", "(", "entropyVal", "<=", "this", ".", "minEntropyNominalAttrib", ")", "{", "this", ".", "minEntropyNominalAttrib", "=", "entropyVal", ";", "this", ".", "saveBestEntropyNominalAttrib", ".", "setValue", "(", "0", ",", "v", ")", ";", "this", ".", "saveBestEntropyNominalAttrib", ".", "setValue", "(", "1", ",", "entropyVal", ")", ";", "this", ".", "saveBestEntropyNominalAttrib", ".", "setValue", "(", "2", ",", "0.0", ")", ";", "}", "}", "}", "}" ]
Find best value of entropy for nominal attributes
[ "Find", "best", "value", "of", "entropy", "for", "nominal", "attributes" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1076-L1106
29,075
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.checkBestAttrib
public boolean checkBestAttrib(double n, AutoExpandVector<AttributeClassObserver> observerss, DoubleVector observedClassDistribution){ double h0 = entropy(observedClassDistribution); boolean isTheBest = false; double[] entropyValues = getBestSecondBestEntropy(this.saveBestGlobalEntropy); double bestEntropy = entropyValues[0]; double secondBestEntropy = entropyValues[1]; double range = Utils.log2(this.numClass); double hoeffdingBound = ComputeHoeffdingBound(range, this.splitConfidenceOption.getValue(), n); if ((h0 > bestEntropy) && ((secondBestEntropy - bestEntropy > hoeffdingBound) || (hoeffdingBound < this.tieThresholdOption.getValue()))) { for (int i = 0; i < this.saveBestValGlobalEntropy.size(); i++) { if (bestEntropy ==(this.saveBestValGlobalEntropy.get(i).get(1))) { this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(0)); this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(1)); this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(2)); this.saveTheBest.add((double)i); if (this.saveTheBest.get(2) != 0.0) { this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(3)); } break; } } isTheBest = true; } else { isTheBest = false; } return isTheBest; }
java
public boolean checkBestAttrib(double n, AutoExpandVector<AttributeClassObserver> observerss, DoubleVector observedClassDistribution){ double h0 = entropy(observedClassDistribution); boolean isTheBest = false; double[] entropyValues = getBestSecondBestEntropy(this.saveBestGlobalEntropy); double bestEntropy = entropyValues[0]; double secondBestEntropy = entropyValues[1]; double range = Utils.log2(this.numClass); double hoeffdingBound = ComputeHoeffdingBound(range, this.splitConfidenceOption.getValue(), n); if ((h0 > bestEntropy) && ((secondBestEntropy - bestEntropy > hoeffdingBound) || (hoeffdingBound < this.tieThresholdOption.getValue()))) { for (int i = 0; i < this.saveBestValGlobalEntropy.size(); i++) { if (bestEntropy ==(this.saveBestValGlobalEntropy.get(i).get(1))) { this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(0)); this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(1)); this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(2)); this.saveTheBest.add((double)i); if (this.saveTheBest.get(2) != 0.0) { this.saveTheBest.add(this.saveBestValGlobalEntropy.get(i).get(3)); } break; } } isTheBest = true; } else { isTheBest = false; } return isTheBest; }
[ "public", "boolean", "checkBestAttrib", "(", "double", "n", ",", "AutoExpandVector", "<", "AttributeClassObserver", ">", "observerss", ",", "DoubleVector", "observedClassDistribution", ")", "{", "double", "h0", "=", "entropy", "(", "observedClassDistribution", ")", ";", "boolean", "isTheBest", "=", "false", ";", "double", "[", "]", "entropyValues", "=", "getBestSecondBestEntropy", "(", "this", ".", "saveBestGlobalEntropy", ")", ";", "double", "bestEntropy", "=", "entropyValues", "[", "0", "]", ";", "double", "secondBestEntropy", "=", "entropyValues", "[", "1", "]", ";", "double", "range", "=", "Utils", ".", "log2", "(", "this", ".", "numClass", ")", ";", "double", "hoeffdingBound", "=", "ComputeHoeffdingBound", "(", "range", ",", "this", ".", "splitConfidenceOption", ".", "getValue", "(", ")", ",", "n", ")", ";", "if", "(", "(", "h0", ">", "bestEntropy", ")", "&&", "(", "(", "secondBestEntropy", "-", "bestEntropy", ">", "hoeffdingBound", ")", "||", "(", "hoeffdingBound", "<", "this", ".", "tieThresholdOption", ".", "getValue", "(", ")", ")", ")", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "saveBestValGlobalEntropy", ".", "size", "(", ")", ";", "i", "++", ")", "{", "if", "(", "bestEntropy", "==", "(", "this", ".", "saveBestValGlobalEntropy", ".", "get", "(", "i", ")", ".", "get", "(", "1", ")", ")", ")", "{", "this", ".", "saveTheBest", ".", "add", "(", "this", ".", "saveBestValGlobalEntropy", ".", "get", "(", "i", ")", ".", "get", "(", "0", ")", ")", ";", "this", ".", "saveTheBest", ".", "add", "(", "this", ".", "saveBestValGlobalEntropy", ".", "get", "(", "i", ")", ".", "get", "(", "1", ")", ")", ";", "this", ".", "saveTheBest", ".", "add", "(", "this", ".", "saveBestValGlobalEntropy", ".", "get", "(", "i", ")", ".", "get", "(", "2", ")", ")", ";", "this", ".", "saveTheBest", ".", "add", "(", "(", "double", ")", "i", ")", ";", "if", "(", "this", ".", "saveTheBest", ".", "get", "(", "2", ")", "!=", "0.0", ")", "{", "this", ".", "saveTheBest", ".", "add", "(", "this", ".", "saveBestValGlobalEntropy", ".", "get", "(", "i", ")", ".", "get", "(", "3", ")", ")", ";", "}", "break", ";", "}", "}", "isTheBest", "=", "true", ";", "}", "else", "{", "isTheBest", "=", "false", ";", "}", "return", "isTheBest", ";", "}" ]
Check if the best attribute is really the best
[ "Check", "if", "the", "best", "attribute", "is", "really", "the", "best" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1117-L1145
29,076
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.getBestSecondBestEntropy
protected double [] getBestSecondBestEntropy(DoubleVector entropy){ double[] entropyValues = new double[2]; double best = Double.MAX_VALUE; double secondBest = Double.MAX_VALUE; for (int i = 0; i < entropy.numValues(); i++) { if (entropy.getValue(i) < best) { secondBest = best; best = entropy.getValue(i); } else{ if (entropy.getValue(i) < secondBest) { secondBest = entropy.getValue(i); } } } entropyValues[0] = best; entropyValues[1] = secondBest; return entropyValues; }
java
protected double [] getBestSecondBestEntropy(DoubleVector entropy){ double[] entropyValues = new double[2]; double best = Double.MAX_VALUE; double secondBest = Double.MAX_VALUE; for (int i = 0; i < entropy.numValues(); i++) { if (entropy.getValue(i) < best) { secondBest = best; best = entropy.getValue(i); } else{ if (entropy.getValue(i) < secondBest) { secondBest = entropy.getValue(i); } } } entropyValues[0] = best; entropyValues[1] = secondBest; return entropyValues; }
[ "protected", "double", "[", "]", "getBestSecondBestEntropy", "(", "DoubleVector", "entropy", ")", "{", "double", "[", "]", "entropyValues", "=", "new", "double", "[", "2", "]", ";", "double", "best", "=", "Double", ".", "MAX_VALUE", ";", "double", "secondBest", "=", "Double", ".", "MAX_VALUE", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "entropy", ".", "numValues", "(", ")", ";", "i", "++", ")", "{", "if", "(", "entropy", ".", "getValue", "(", "i", ")", "<", "best", ")", "{", "secondBest", "=", "best", ";", "best", "=", "entropy", ".", "getValue", "(", "i", ")", ";", "}", "else", "{", "if", "(", "entropy", ".", "getValue", "(", "i", ")", "<", "secondBest", ")", "{", "secondBest", "=", "entropy", ".", "getValue", "(", "i", ")", ";", "}", "}", "}", "entropyValues", "[", "0", "]", "=", "best", ";", "entropyValues", "[", "1", "]", "=", "secondBest", ";", "return", "entropyValues", ";", "}" ]
Get best and second best attributes
[ "Get", "best", "and", "second", "best", "attributes" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1148-L1166
29,077
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.getRuleMajorityClassIndex
protected double getRuleMajorityClassIndex(RuleClassification r) { double maxvalue = 0.0; int posMaxValue = 0; for (int i = 0; i < r.obserClassDistrib.numValues(); i++) { if (r.obserClassDistrib.getValue(i) > maxvalue) { maxvalue = r.obserClassDistrib.getValue(i); posMaxValue = i; } } return (double)posMaxValue; }
java
protected double getRuleMajorityClassIndex(RuleClassification r) { double maxvalue = 0.0; int posMaxValue = 0; for (int i = 0; i < r.obserClassDistrib.numValues(); i++) { if (r.obserClassDistrib.getValue(i) > maxvalue) { maxvalue = r.obserClassDistrib.getValue(i); posMaxValue = i; } } return (double)posMaxValue; }
[ "protected", "double", "getRuleMajorityClassIndex", "(", "RuleClassification", "r", ")", "{", "double", "maxvalue", "=", "0.0", ";", "int", "posMaxValue", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "r", ".", "obserClassDistrib", ".", "numValues", "(", ")", ";", "i", "++", ")", "{", "if", "(", "r", ".", "obserClassDistrib", ".", "getValue", "(", "i", ")", ">", "maxvalue", ")", "{", "maxvalue", "=", "r", ".", "obserClassDistrib", ".", "getValue", "(", "i", ")", ";", "posMaxValue", "=", "i", ";", "}", "}", "return", "(", "double", ")", "posMaxValue", ";", "}" ]
Get rule majority class index
[ "Get", "rule", "majority", "class", "index" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1169-L1179
29,078
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.oberversDistribProb
protected double[] oberversDistribProb(Instance inst, DoubleVector classDistrib) { double[] votes = new double[this.numClass]; double sum = classDistrib.sumOfValues(); for (int z = 0; z < this.numClass; z++) { votes[z] = classDistrib.getValue(z) / sum; } return votes; }
java
protected double[] oberversDistribProb(Instance inst, DoubleVector classDistrib) { double[] votes = new double[this.numClass]; double sum = classDistrib.sumOfValues(); for (int z = 0; z < this.numClass; z++) { votes[z] = classDistrib.getValue(z) / sum; } return votes; }
[ "protected", "double", "[", "]", "oberversDistribProb", "(", "Instance", "inst", ",", "DoubleVector", "classDistrib", ")", "{", "double", "[", "]", "votes", "=", "new", "double", "[", "this", ".", "numClass", "]", ";", "double", "sum", "=", "classDistrib", ".", "sumOfValues", "(", ")", ";", "for", "(", "int", "z", "=", "0", ";", "z", "<", "this", ".", "numClass", ";", "z", "++", ")", "{", "votes", "[", "z", "]", "=", "classDistrib", ".", "getValue", "(", "z", ")", "/", "sum", ";", "}", "return", "votes", ";", "}" ]
Get observers class distribution probability
[ "Get", "observers", "class", "distribution", "probability" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1182-L1190
29,079
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.weightedMax
protected double[] weightedMax(Instance inst) { int countFired = 0; boolean fired = false; double highest = 0.0; double[] votes = new double[this.numClass]; ArrayList<Double> ruleSetVotes = new ArrayList<Double>(); ArrayList<ArrayList<Double>> majorityProb = new ArrayList<ArrayList<Double>>(); for (int j = 0; j < this.ruleSet.size(); j++) { ArrayList<Double> ruleProb = new ArrayList<Double>(); if (this.ruleSet.get(j).ruleEvaluate(inst) == true) { countFired = countFired+1; for (int z = 0; z < this.numClass; z++) { ruleSetVotes.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); ruleProb.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); } majorityProb.add(ruleProb); } } if (countFired > 0) { fired = true; Collections.sort(ruleSetVotes); highest = ruleSetVotes.get(ruleSetVotes.size() - 1); for (int t = 0; t < majorityProb.size(); t++) { for(int m = 0; m < majorityProb.get(t).size(); m++) { if (majorityProb.get(t).get(m) == highest) { for (int h = 0; h < majorityProb.get(t).size(); h++) { votes[h] = majorityProb.get(t).get(h); } break; } } } } else { fired = false; } if (fired == false) { votes = oberversDistribProb(inst, this.observedClassDistribution); } return votes; }
java
protected double[] weightedMax(Instance inst) { int countFired = 0; boolean fired = false; double highest = 0.0; double[] votes = new double[this.numClass]; ArrayList<Double> ruleSetVotes = new ArrayList<Double>(); ArrayList<ArrayList<Double>> majorityProb = new ArrayList<ArrayList<Double>>(); for (int j = 0; j < this.ruleSet.size(); j++) { ArrayList<Double> ruleProb = new ArrayList<Double>(); if (this.ruleSet.get(j).ruleEvaluate(inst) == true) { countFired = countFired+1; for (int z = 0; z < this.numClass; z++) { ruleSetVotes.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); ruleProb.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); } majorityProb.add(ruleProb); } } if (countFired > 0) { fired = true; Collections.sort(ruleSetVotes); highest = ruleSetVotes.get(ruleSetVotes.size() - 1); for (int t = 0; t < majorityProb.size(); t++) { for(int m = 0; m < majorityProb.get(t).size(); m++) { if (majorityProb.get(t).get(m) == highest) { for (int h = 0; h < majorityProb.get(t).size(); h++) { votes[h] = majorityProb.get(t).get(h); } break; } } } } else { fired = false; } if (fired == false) { votes = oberversDistribProb(inst, this.observedClassDistribution); } return votes; }
[ "protected", "double", "[", "]", "weightedMax", "(", "Instance", "inst", ")", "{", "int", "countFired", "=", "0", ";", "boolean", "fired", "=", "false", ";", "double", "highest", "=", "0.0", ";", "double", "[", "]", "votes", "=", "new", "double", "[", "this", ".", "numClass", "]", ";", "ArrayList", "<", "Double", ">", "ruleSetVotes", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "majorityProb", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "this", ".", "ruleSet", ".", "size", "(", ")", ";", "j", "++", ")", "{", "ArrayList", "<", "Double", ">", "ruleProb", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "if", "(", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "ruleEvaluate", "(", "inst", ")", "==", "true", ")", "{", "countFired", "=", "countFired", "+", "1", ";", "for", "(", "int", "z", "=", "0", ";", "z", "<", "this", ".", "numClass", ";", "z", "++", ")", "{", "ruleSetVotes", ".", "add", "(", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "getValue", "(", "z", ")", "/", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "sumOfValues", "(", ")", ")", ";", "ruleProb", ".", "add", "(", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "getValue", "(", "z", ")", "/", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "sumOfValues", "(", ")", ")", ";", "}", "majorityProb", ".", "add", "(", "ruleProb", ")", ";", "}", "}", "if", "(", "countFired", ">", "0", ")", "{", "fired", "=", "true", ";", "Collections", ".", "sort", "(", "ruleSetVotes", ")", ";", "highest", "=", "ruleSetVotes", ".", "get", "(", "ruleSetVotes", ".", "size", "(", ")", "-", "1", ")", ";", "for", "(", "int", "t", "=", "0", ";", "t", "<", "majorityProb", ".", "size", "(", ")", ";", "t", "++", ")", "{", "for", "(", "int", "m", "=", "0", ";", "m", "<", "majorityProb", ".", "get", "(", "t", ")", ".", "size", "(", ")", ";", "m", "++", ")", "{", "if", "(", "majorityProb", ".", "get", "(", "t", ")", ".", "get", "(", "m", ")", "==", "highest", ")", "{", "for", "(", "int", "h", "=", "0", ";", "h", "<", "majorityProb", ".", "get", "(", "t", ")", ".", "size", "(", ")", ";", "h", "++", ")", "{", "votes", "[", "h", "]", "=", "majorityProb", ".", "get", "(", "t", ")", ".", "get", "(", "h", ")", ";", "}", "break", ";", "}", "}", "}", "}", "else", "{", "fired", "=", "false", ";", "}", "if", "(", "fired", "==", "false", ")", "{", "votes", "=", "oberversDistribProb", "(", "inst", ",", "this", ".", "observedClassDistribution", ")", ";", "}", "return", "votes", ";", "}" ]
Get the votes using weighted Max
[ "Get", "the", "votes", "using", "weighted", "Max" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1219-L1258
29,080
Waikato/moa
moa/src/main/java/moa/classifiers/rules/RuleClassifier.java
RuleClassifier.weightedSum
protected double[] weightedSum(Instance inst) { boolean fired = false; int countFired = 0; double[] votes = new double[this.numClass]; ArrayList<Double> weightSum = new ArrayList<Double>(); ArrayList<ArrayList<Double>> majorityProb = new ArrayList<ArrayList<Double>>(); for (int j = 0; j < this.ruleSet.size(); j++) { ArrayList<Double> ruleProb = new ArrayList<Double>(); if (this.ruleSet.get(j).ruleEvaluate(inst) == true) { countFired = countFired + 1; for (int z = 0; z < this.numClass; z++) { ruleProb.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); } majorityProb.add(ruleProb); } } if (countFired > 0) { fired = true; for (int m = 0; m < majorityProb.get(0).size(); m++) { double sum = 0.0; for (int t = 0; t < majorityProb.size(); t++){ sum = sum + majorityProb.get(t).get(m); } weightSum.add(sum); } for (int h = 0; h < weightSum.size(); h++) { votes[h] = weightSum.get(h) / majorityProb.size(); } } else { fired = false; } if (fired == false) { votes = oberversDistribProb(inst, this.observedClassDistribution); } return votes; }
java
protected double[] weightedSum(Instance inst) { boolean fired = false; int countFired = 0; double[] votes = new double[this.numClass]; ArrayList<Double> weightSum = new ArrayList<Double>(); ArrayList<ArrayList<Double>> majorityProb = new ArrayList<ArrayList<Double>>(); for (int j = 0; j < this.ruleSet.size(); j++) { ArrayList<Double> ruleProb = new ArrayList<Double>(); if (this.ruleSet.get(j).ruleEvaluate(inst) == true) { countFired = countFired + 1; for (int z = 0; z < this.numClass; z++) { ruleProb.add(this.ruleSet.get(j).obserClassDistrib.getValue(z) / this.ruleSet.get(j).obserClassDistrib.sumOfValues()); } majorityProb.add(ruleProb); } } if (countFired > 0) { fired = true; for (int m = 0; m < majorityProb.get(0).size(); m++) { double sum = 0.0; for (int t = 0; t < majorityProb.size(); t++){ sum = sum + majorityProb.get(t).get(m); } weightSum.add(sum); } for (int h = 0; h < weightSum.size(); h++) { votes[h] = weightSum.get(h) / majorityProb.size(); } } else { fired = false; } if (fired == false) { votes = oberversDistribProb(inst, this.observedClassDistribution); } return votes; }
[ "protected", "double", "[", "]", "weightedSum", "(", "Instance", "inst", ")", "{", "boolean", "fired", "=", "false", ";", "int", "countFired", "=", "0", ";", "double", "[", "]", "votes", "=", "new", "double", "[", "this", ".", "numClass", "]", ";", "ArrayList", "<", "Double", ">", "weightSum", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "majorityProb", "=", "new", "ArrayList", "<", "ArrayList", "<", "Double", ">", ">", "(", ")", ";", "for", "(", "int", "j", "=", "0", ";", "j", "<", "this", ".", "ruleSet", ".", "size", "(", ")", ";", "j", "++", ")", "{", "ArrayList", "<", "Double", ">", "ruleProb", "=", "new", "ArrayList", "<", "Double", ">", "(", ")", ";", "if", "(", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "ruleEvaluate", "(", "inst", ")", "==", "true", ")", "{", "countFired", "=", "countFired", "+", "1", ";", "for", "(", "int", "z", "=", "0", ";", "z", "<", "this", ".", "numClass", ";", "z", "++", ")", "{", "ruleProb", ".", "add", "(", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "getValue", "(", "z", ")", "/", "this", ".", "ruleSet", ".", "get", "(", "j", ")", ".", "obserClassDistrib", ".", "sumOfValues", "(", ")", ")", ";", "}", "majorityProb", ".", "add", "(", "ruleProb", ")", ";", "}", "}", "if", "(", "countFired", ">", "0", ")", "{", "fired", "=", "true", ";", "for", "(", "int", "m", "=", "0", ";", "m", "<", "majorityProb", ".", "get", "(", "0", ")", ".", "size", "(", ")", ";", "m", "++", ")", "{", "double", "sum", "=", "0.0", ";", "for", "(", "int", "t", "=", "0", ";", "t", "<", "majorityProb", ".", "size", "(", ")", ";", "t", "++", ")", "{", "sum", "=", "sum", "+", "majorityProb", ".", "get", "(", "t", ")", ".", "get", "(", "m", ")", ";", "}", "weightSum", ".", "add", "(", "sum", ")", ";", "}", "for", "(", "int", "h", "=", "0", ";", "h", "<", "weightSum", ".", "size", "(", ")", ";", "h", "++", ")", "{", "votes", "[", "h", "]", "=", "weightSum", ".", "get", "(", "h", ")", "/", "majorityProb", ".", "size", "(", ")", ";", "}", "}", "else", "{", "fired", "=", "false", ";", "}", "if", "(", "fired", "==", "false", ")", "{", "votes", "=", "oberversDistribProb", "(", "inst", ",", "this", ".", "observedClassDistribution", ")", ";", "}", "return", "votes", ";", "}" ]
Get the votes using weighted Sum
[ "Get", "the", "votes", "using", "weighted", "Sum" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/RuleClassifier.java#L1261-L1296
29,081
Waikato/moa
moa/src/main/java/weka/gui/MOAClassOptionEditor.java
MOAClassOptionEditor.closeDialog
protected void closeDialog() { if (m_CustomEditor instanceof Container) { Dialog dlg = PropertyDialog.getParentDialog((Container) m_CustomEditor); if (dlg != null) dlg.setVisible(false); } }
java
protected void closeDialog() { if (m_CustomEditor instanceof Container) { Dialog dlg = PropertyDialog.getParentDialog((Container) m_CustomEditor); if (dlg != null) dlg.setVisible(false); } }
[ "protected", "void", "closeDialog", "(", ")", "{", "if", "(", "m_CustomEditor", "instanceof", "Container", ")", "{", "Dialog", "dlg", "=", "PropertyDialog", ".", "getParentDialog", "(", "(", "Container", ")", "m_CustomEditor", ")", ";", "if", "(", "dlg", "!=", "null", ")", "dlg", ".", "setVisible", "(", "false", ")", ";", "}", "}" ]
Closes the dialog.
[ "Closes", "the", "dialog", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/weka/gui/MOAClassOptionEditor.java#L65-L71
29,082
Waikato/moa
moa/src/main/java/weka/gui/MOAClassOptionEditor.java
MOAClassOptionEditor.createCustomEditor
protected Component createCustomEditor() { JPanel panel; panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_EditComponent = (ClassOptionEditComponent) getEditComponent((ClassOption) getValue()); m_EditComponent.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { m_EditComponent.applyState(); setValue(m_EditComponent.getEditedOption()); } }); panel.add(m_EditComponent, BorderLayout.CENTER); return panel; }
java
protected Component createCustomEditor() { JPanel panel; panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); m_EditComponent = (ClassOptionEditComponent) getEditComponent((ClassOption) getValue()); m_EditComponent.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { m_EditComponent.applyState(); setValue(m_EditComponent.getEditedOption()); } }); panel.add(m_EditComponent, BorderLayout.CENTER); return panel; }
[ "protected", "Component", "createCustomEditor", "(", ")", "{", "JPanel", "panel", ";", "panel", "=", "new", "JPanel", "(", "new", "BorderLayout", "(", ")", ")", ";", "panel", ".", "setBorder", "(", "BorderFactory", ".", "createEmptyBorder", "(", "5", ",", "5", ",", "5", ",", "5", ")", ")", ";", "m_EditComponent", "=", "(", "ClassOptionEditComponent", ")", "getEditComponent", "(", "(", "ClassOption", ")", "getValue", "(", ")", ")", ";", "m_EditComponent", ".", "addChangeListener", "(", "new", "ChangeListener", "(", ")", "{", "public", "void", "stateChanged", "(", "ChangeEvent", "e", ")", "{", "m_EditComponent", ".", "applyState", "(", ")", ";", "setValue", "(", "m_EditComponent", ".", "getEditedOption", "(", ")", ")", ";", "}", "}", ")", ";", "panel", ".", "add", "(", "m_EditComponent", ",", "BorderLayout", ".", "CENTER", ")", ";", "return", "panel", ";", "}" ]
Creates the custom editor. @return the editor
[ "Creates", "the", "custom", "editor", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/weka/gui/MOAClassOptionEditor.java#L78-L93
29,083
Waikato/moa
moa/src/main/java/weka/gui/MOAClassOptionEditor.java
MOAClassOptionEditor.paintValue
public void paintValue(Graphics gfx, Rectangle box) { FontMetrics fm; int vpad; String val; fm = gfx.getFontMetrics(); vpad = (box.height - fm.getHeight()) / 2 ; val = ((ClassOption) getValue()).getValueAsCLIString(); gfx.drawString(val, 2, fm.getHeight() + vpad); }
java
public void paintValue(Graphics gfx, Rectangle box) { FontMetrics fm; int vpad; String val; fm = gfx.getFontMetrics(); vpad = (box.height - fm.getHeight()) / 2 ; val = ((ClassOption) getValue()).getValueAsCLIString(); gfx.drawString(val, 2, fm.getHeight() + vpad); }
[ "public", "void", "paintValue", "(", "Graphics", "gfx", ",", "Rectangle", "box", ")", "{", "FontMetrics", "fm", ";", "int", "vpad", ";", "String", "val", ";", "fm", "=", "gfx", ".", "getFontMetrics", "(", ")", ";", "vpad", "=", "(", "box", ".", "height", "-", "fm", ".", "getHeight", "(", ")", ")", "/", "2", ";", "val", "=", "(", "(", "ClassOption", ")", "getValue", "(", ")", ")", ".", "getValueAsCLIString", "(", ")", ";", "gfx", ".", "drawString", "(", "val", ",", "2", ",", "fm", ".", "getHeight", "(", ")", "+", "vpad", ")", ";", "}" ]
Paints a representation of the current Object. @param gfx the graphics context to use @param box the area we are allowed to paint into
[ "Paints", "a", "representation", "of", "the", "current", "Object", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/weka/gui/MOAClassOptionEditor.java#L117-L126
29,084
Waikato/moa
moa/src/main/java/moa/classifiers/rules/functions/Perceptron.java
Perceptron.prediction
private double prediction(Instance inst) { if(this.initialisePerceptron){ return 0; }else{ double[] normalizedInstance = normalizedInstance(inst); double normalizedPrediction = prediction(normalizedInstance); return denormalizedPrediction(normalizedPrediction); } }
java
private double prediction(Instance inst) { if(this.initialisePerceptron){ return 0; }else{ double[] normalizedInstance = normalizedInstance(inst); double normalizedPrediction = prediction(normalizedInstance); return denormalizedPrediction(normalizedPrediction); } }
[ "private", "double", "prediction", "(", "Instance", "inst", ")", "{", "if", "(", "this", ".", "initialisePerceptron", ")", "{", "return", "0", ";", "}", "else", "{", "double", "[", "]", "normalizedInstance", "=", "normalizedInstance", "(", "inst", ")", ";", "double", "normalizedPrediction", "=", "prediction", "(", "normalizedInstance", ")", ";", "return", "denormalizedPrediction", "(", "normalizedPrediction", ")", ";", "}", "}" ]
Output the prediction made by this perceptron on the given instance
[ "Output", "the", "prediction", "made", "by", "this", "perceptron", "on", "the", "given", "instance" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/functions/Perceptron.java#L231-L240
29,085
Waikato/moa
moa/src/main/java/moa/clusterers/streamkm/BucketManager.java
BucketManager.insertPoint
void insertPoint(Point p){ //check if there is enough space in the first bucket int cursize = this.buckets[0].cursize; if(cursize >= this.maxBucketsize) { //printf("Bucket 0 full \n"); //start spillover process int curbucket = 0; int nextbucket = 1; //check if the next bucket is empty if(this.buckets[nextbucket].cursize == 0){ //copy the bucket int i; for(i=0; i<this.maxBucketsize; i++){ this.buckets[nextbucket].points[i] = this.buckets[curbucket].points[i].clone(); //copyPointWithoutInit: we should not copy coordinates? } //bucket is now full this.buckets[nextbucket].cursize = this.maxBucketsize; //first bucket is now empty this.buckets[curbucket].cursize = 0; cursize = 0; } else { //printf("Bucket %d full \n",nextbucket); //copy bucket to spillover and continue int i; for(i=0;i<this.maxBucketsize;i++){ this.buckets[nextbucket].spillover[i] = this.buckets[curbucket].points[i].clone(); //copyPointWithoutInit: we should not copy coordinates? } this.buckets[0].cursize=0; cursize = 0; curbucket++; nextbucket++; /* as long as the next bucket is full output the coreset to the spillover of the next bucket */ while(this.buckets[nextbucket].cursize == this.maxBucketsize){ //printf("Bucket %d full \n",nextbucket); this.treeCoreset.unionTreeCoreset(this.maxBucketsize,this.maxBucketsize, this.maxBucketsize,p.dimension, this.buckets[curbucket].points,this.buckets[curbucket].spillover, this.buckets[nextbucket].spillover, this.clustererRandom); //bucket now empty this.buckets[curbucket].cursize = 0; curbucket++; nextbucket++; } this.treeCoreset.unionTreeCoreset(this.maxBucketsize,this.maxBucketsize, this.maxBucketsize,p.dimension, this.buckets[curbucket].points,this.buckets[curbucket].spillover, this.buckets[nextbucket].points, this.clustererRandom); this.buckets[curbucket].cursize = 0; this.buckets[nextbucket].cursize = this.maxBucketsize; } } //insert point into the first bucket this.buckets[0].points[cursize] = p.clone(); //copyPointWithoutInit: we should not copy coordinates? this.buckets[0].cursize++; }
java
void insertPoint(Point p){ //check if there is enough space in the first bucket int cursize = this.buckets[0].cursize; if(cursize >= this.maxBucketsize) { //printf("Bucket 0 full \n"); //start spillover process int curbucket = 0; int nextbucket = 1; //check if the next bucket is empty if(this.buckets[nextbucket].cursize == 0){ //copy the bucket int i; for(i=0; i<this.maxBucketsize; i++){ this.buckets[nextbucket].points[i] = this.buckets[curbucket].points[i].clone(); //copyPointWithoutInit: we should not copy coordinates? } //bucket is now full this.buckets[nextbucket].cursize = this.maxBucketsize; //first bucket is now empty this.buckets[curbucket].cursize = 0; cursize = 0; } else { //printf("Bucket %d full \n",nextbucket); //copy bucket to spillover and continue int i; for(i=0;i<this.maxBucketsize;i++){ this.buckets[nextbucket].spillover[i] = this.buckets[curbucket].points[i].clone(); //copyPointWithoutInit: we should not copy coordinates? } this.buckets[0].cursize=0; cursize = 0; curbucket++; nextbucket++; /* as long as the next bucket is full output the coreset to the spillover of the next bucket */ while(this.buckets[nextbucket].cursize == this.maxBucketsize){ //printf("Bucket %d full \n",nextbucket); this.treeCoreset.unionTreeCoreset(this.maxBucketsize,this.maxBucketsize, this.maxBucketsize,p.dimension, this.buckets[curbucket].points,this.buckets[curbucket].spillover, this.buckets[nextbucket].spillover, this.clustererRandom); //bucket now empty this.buckets[curbucket].cursize = 0; curbucket++; nextbucket++; } this.treeCoreset.unionTreeCoreset(this.maxBucketsize,this.maxBucketsize, this.maxBucketsize,p.dimension, this.buckets[curbucket].points,this.buckets[curbucket].spillover, this.buckets[nextbucket].points, this.clustererRandom); this.buckets[curbucket].cursize = 0; this.buckets[nextbucket].cursize = this.maxBucketsize; } } //insert point into the first bucket this.buckets[0].points[cursize] = p.clone(); //copyPointWithoutInit: we should not copy coordinates? this.buckets[0].cursize++; }
[ "void", "insertPoint", "(", "Point", "p", ")", "{", "//check if there is enough space in the first bucket", "int", "cursize", "=", "this", ".", "buckets", "[", "0", "]", ".", "cursize", ";", "if", "(", "cursize", ">=", "this", ".", "maxBucketsize", ")", "{", "//printf(\"Bucket 0 full \\n\");", "//start spillover process", "int", "curbucket", "=", "0", ";", "int", "nextbucket", "=", "1", ";", "//check if the next bucket is empty", "if", "(", "this", ".", "buckets", "[", "nextbucket", "]", ".", "cursize", "==", "0", ")", "{", "//copy the bucket\t", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "this", ".", "maxBucketsize", ";", "i", "++", ")", "{", "this", ".", "buckets", "[", "nextbucket", "]", ".", "points", "[", "i", "]", "=", "this", ".", "buckets", "[", "curbucket", "]", ".", "points", "[", "i", "]", ".", "clone", "(", ")", ";", "//copyPointWithoutInit: we should not copy coordinates? ", "}", "//bucket is now full", "this", ".", "buckets", "[", "nextbucket", "]", ".", "cursize", "=", "this", ".", "maxBucketsize", ";", "//first bucket is now empty", "this", ".", "buckets", "[", "curbucket", "]", ".", "cursize", "=", "0", ";", "cursize", "=", "0", ";", "}", "else", "{", "//printf(\"Bucket %d full \\n\",nextbucket);", "//copy bucket to spillover and continue", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "this", ".", "maxBucketsize", ";", "i", "++", ")", "{", "this", ".", "buckets", "[", "nextbucket", "]", ".", "spillover", "[", "i", "]", "=", "this", ".", "buckets", "[", "curbucket", "]", ".", "points", "[", "i", "]", ".", "clone", "(", ")", ";", "//copyPointWithoutInit: we should not copy coordinates? ", "}", "this", ".", "buckets", "[", "0", "]", ".", "cursize", "=", "0", ";", "cursize", "=", "0", ";", "curbucket", "++", ";", "nextbucket", "++", ";", "/*\n\t\t\t\tas long as the next bucket is full output the coreset to the spillover of the next bucket\n\t\t\t\t*/", "while", "(", "this", ".", "buckets", "[", "nextbucket", "]", ".", "cursize", "==", "this", ".", "maxBucketsize", ")", "{", "//printf(\"Bucket %d full \\n\",nextbucket);", "this", ".", "treeCoreset", ".", "unionTreeCoreset", "(", "this", ".", "maxBucketsize", ",", "this", ".", "maxBucketsize", ",", "this", ".", "maxBucketsize", ",", "p", ".", "dimension", ",", "this", ".", "buckets", "[", "curbucket", "]", ".", "points", ",", "this", ".", "buckets", "[", "curbucket", "]", ".", "spillover", ",", "this", ".", "buckets", "[", "nextbucket", "]", ".", "spillover", ",", "this", ".", "clustererRandom", ")", ";", "//bucket now empty", "this", ".", "buckets", "[", "curbucket", "]", ".", "cursize", "=", "0", ";", "curbucket", "++", ";", "nextbucket", "++", ";", "}", "this", ".", "treeCoreset", ".", "unionTreeCoreset", "(", "this", ".", "maxBucketsize", ",", "this", ".", "maxBucketsize", ",", "this", ".", "maxBucketsize", ",", "p", ".", "dimension", ",", "this", ".", "buckets", "[", "curbucket", "]", ".", "points", ",", "this", ".", "buckets", "[", "curbucket", "]", ".", "spillover", ",", "this", ".", "buckets", "[", "nextbucket", "]", ".", "points", ",", "this", ".", "clustererRandom", ")", ";", "this", ".", "buckets", "[", "curbucket", "]", ".", "cursize", "=", "0", ";", "this", ".", "buckets", "[", "nextbucket", "]", ".", "cursize", "=", "this", ".", "maxBucketsize", ";", "}", "}", "//insert point into the first bucket", "this", ".", "buckets", "[", "0", "]", ".", "points", "[", "cursize", "]", "=", "p", ".", "clone", "(", ")", ";", "//copyPointWithoutInit: we should not copy coordinates? ", "this", ".", "buckets", "[", "0", "]", ".", "cursize", "++", ";", "}" ]
inserts a single point into the bucketmanager
[ "inserts", "a", "single", "point", "into", "the", "bucketmanager" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/BucketManager.java#L55-L116
29,086
Waikato/moa
moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java
AccuracyUpdatedEnsemble.processChunk
protected void processChunk() { Classifier addedClassifier = null; double mse_r = this.computeMseR(); // Compute weights double candidateClassifierWeight = 1.0 / (mse_r + Double.MIN_VALUE); for (int i = 0; i < this.learners.length; i++) { this.weights[i][0] = 1.0 / (mse_r + this.computeMse(this.learners[(int) this.weights[i][1]], this.currentChunk) + Double.MIN_VALUE); } if (this.learners.length < this.memberCountOption.getValue()) { // Train and add classifier addedClassifier = this.addToStored(this.candidate, candidateClassifierWeight); } else { // Substitute poorest classifier int poorestClassifier = this.getPoorestClassifierIndex(); if (this.weights[poorestClassifier][0] < candidateClassifierWeight) { this.weights[poorestClassifier][0] = candidateClassifierWeight; addedClassifier = this.candidate.copy(); this.learners[(int) this.weights[poorestClassifier][1]] = addedClassifier; } } // train classifiers for (int i = 0; i < this.learners.length; i++) { this.trainOnChunk(this.learners[(int) this.weights[i][1]]); } this.classDistributions = null; this.currentChunk = null; this.candidate = (Classifier) getPreparedClassOption(this.learnerOption); this.candidate.resetLearning(); this.enforceMemoryLimit(); }
java
protected void processChunk() { Classifier addedClassifier = null; double mse_r = this.computeMseR(); // Compute weights double candidateClassifierWeight = 1.0 / (mse_r + Double.MIN_VALUE); for (int i = 0; i < this.learners.length; i++) { this.weights[i][0] = 1.0 / (mse_r + this.computeMse(this.learners[(int) this.weights[i][1]], this.currentChunk) + Double.MIN_VALUE); } if (this.learners.length < this.memberCountOption.getValue()) { // Train and add classifier addedClassifier = this.addToStored(this.candidate, candidateClassifierWeight); } else { // Substitute poorest classifier int poorestClassifier = this.getPoorestClassifierIndex(); if (this.weights[poorestClassifier][0] < candidateClassifierWeight) { this.weights[poorestClassifier][0] = candidateClassifierWeight; addedClassifier = this.candidate.copy(); this.learners[(int) this.weights[poorestClassifier][1]] = addedClassifier; } } // train classifiers for (int i = 0; i < this.learners.length; i++) { this.trainOnChunk(this.learners[(int) this.weights[i][1]]); } this.classDistributions = null; this.currentChunk = null; this.candidate = (Classifier) getPreparedClassOption(this.learnerOption); this.candidate.resetLearning(); this.enforceMemoryLimit(); }
[ "protected", "void", "processChunk", "(", ")", "{", "Classifier", "addedClassifier", "=", "null", ";", "double", "mse_r", "=", "this", ".", "computeMseR", "(", ")", ";", "// Compute weights\r", "double", "candidateClassifierWeight", "=", "1.0", "/", "(", "mse_r", "+", "Double", ".", "MIN_VALUE", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "learners", ".", "length", ";", "i", "++", ")", "{", "this", ".", "weights", "[", "i", "]", "[", "0", "]", "=", "1.0", "/", "(", "mse_r", "+", "this", ".", "computeMse", "(", "this", ".", "learners", "[", "(", "int", ")", "this", ".", "weights", "[", "i", "]", "[", "1", "]", "]", ",", "this", ".", "currentChunk", ")", "+", "Double", ".", "MIN_VALUE", ")", ";", "}", "if", "(", "this", ".", "learners", ".", "length", "<", "this", ".", "memberCountOption", ".", "getValue", "(", ")", ")", "{", "// Train and add classifier\r", "addedClassifier", "=", "this", ".", "addToStored", "(", "this", ".", "candidate", ",", "candidateClassifierWeight", ")", ";", "}", "else", "{", "// Substitute poorest classifier\r", "int", "poorestClassifier", "=", "this", ".", "getPoorestClassifierIndex", "(", ")", ";", "if", "(", "this", ".", "weights", "[", "poorestClassifier", "]", "[", "0", "]", "<", "candidateClassifierWeight", ")", "{", "this", ".", "weights", "[", "poorestClassifier", "]", "[", "0", "]", "=", "candidateClassifierWeight", ";", "addedClassifier", "=", "this", ".", "candidate", ".", "copy", "(", ")", ";", "this", ".", "learners", "[", "(", "int", ")", "this", ".", "weights", "[", "poorestClassifier", "]", "[", "1", "]", "]", "=", "addedClassifier", ";", "}", "}", "// train classifiers\r", "for", "(", "int", "i", "=", "0", ";", "i", "<", "this", ".", "learners", ".", "length", ";", "i", "++", ")", "{", "this", ".", "trainOnChunk", "(", "this", ".", "learners", "[", "(", "int", ")", "this", ".", "weights", "[", "i", "]", "[", "1", "]", "]", ")", ";", "}", "this", ".", "classDistributions", "=", "null", ";", "this", ".", "currentChunk", "=", "null", ";", "this", ".", "candidate", "=", "(", "Classifier", ")", "getPreparedClassOption", "(", "this", ".", "learnerOption", ")", ";", "this", ".", "candidate", ".", "resetLearning", "(", ")", ";", "this", ".", "enforceMemoryLimit", "(", ")", ";", "}" ]
Processes a chunk of instances. This method is called after collecting a chunk of examples.
[ "Processes", "a", "chunk", "of", "instances", ".", "This", "method", "is", "called", "after", "collecting", "a", "chunk", "of", "examples", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java#L177-L213
29,087
Waikato/moa
moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java
AccuracyUpdatedEnsemble.computeMse
protected double computeMse(Classifier learner, Instances chunk) { double mse_i = 0; double f_ci; double voteSum; for (int i = 0; i < chunk.numInstances(); i++) { try { voteSum = 0; for (double element : learner.getVotesForInstance(chunk.instance(i))) { voteSum += element; } if (voteSum > 0) { f_ci = learner.getVotesForInstance(chunk.instance(i))[(int) chunk.instance(i).classValue()] / voteSum; mse_i += (1 - f_ci) * (1 - f_ci); } else { mse_i += 1; } } catch (Exception e) { mse_i += 1; } } mse_i /= this.chunkSizeOption.getValue(); return mse_i; }
java
protected double computeMse(Classifier learner, Instances chunk) { double mse_i = 0; double f_ci; double voteSum; for (int i = 0; i < chunk.numInstances(); i++) { try { voteSum = 0; for (double element : learner.getVotesForInstance(chunk.instance(i))) { voteSum += element; } if (voteSum > 0) { f_ci = learner.getVotesForInstance(chunk.instance(i))[(int) chunk.instance(i).classValue()] / voteSum; mse_i += (1 - f_ci) * (1 - f_ci); } else { mse_i += 1; } } catch (Exception e) { mse_i += 1; } } mse_i /= this.chunkSizeOption.getValue(); return mse_i; }
[ "protected", "double", "computeMse", "(", "Classifier", "learner", ",", "Instances", "chunk", ")", "{", "double", "mse_i", "=", "0", ";", "double", "f_ci", ";", "double", "voteSum", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "chunk", ".", "numInstances", "(", ")", ";", "i", "++", ")", "{", "try", "{", "voteSum", "=", "0", ";", "for", "(", "double", "element", ":", "learner", ".", "getVotesForInstance", "(", "chunk", ".", "instance", "(", "i", ")", ")", ")", "{", "voteSum", "+=", "element", ";", "}", "if", "(", "voteSum", ">", "0", ")", "{", "f_ci", "=", "learner", ".", "getVotesForInstance", "(", "chunk", ".", "instance", "(", "i", ")", ")", "[", "(", "int", ")", "chunk", ".", "instance", "(", "i", ")", ".", "classValue", "(", ")", "]", "/", "voteSum", ";", "mse_i", "+=", "(", "1", "-", "f_ci", ")", "*", "(", "1", "-", "f_ci", ")", ";", "}", "else", "{", "mse_i", "+=", "1", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "mse_i", "+=", "1", ";", "}", "}", "mse_i", "/=", "this", ".", "chunkSizeOption", ".", "getValue", "(", ")", ";", "return", "mse_i", ";", "}" ]
Computes the MSE of a learner for a given chunk of examples. @param learner classifier to compute error @param chunk chunk of examples @return the computed error.
[ "Computes", "the", "MSE", "of", "a", "learner", "for", "a", "given", "chunk", "of", "examples", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java#L251-L279
29,088
Waikato/moa
moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java
AccuracyUpdatedEnsemble.trainOnChunk
private void trainOnChunk(Classifier classifierToTrain) { for (int num = 0; num < this.chunkSizeOption.getValue(); num++) { classifierToTrain.trainOnInstance(this.currentChunk.instance(num)); } }
java
private void trainOnChunk(Classifier classifierToTrain) { for (int num = 0; num < this.chunkSizeOption.getValue(); num++) { classifierToTrain.trainOnInstance(this.currentChunk.instance(num)); } }
[ "private", "void", "trainOnChunk", "(", "Classifier", "classifierToTrain", ")", "{", "for", "(", "int", "num", "=", "0", ";", "num", "<", "this", ".", "chunkSizeOption", ".", "getValue", "(", ")", ";", "num", "++", ")", "{", "classifierToTrain", ".", "trainOnInstance", "(", "this", ".", "currentChunk", ".", "instance", "(", "num", ")", ")", ";", "}", "}" ]
Trains a component classifier on the most recent chunk of data. @param classifierToTrain Classifier being trained.
[ "Trains", "a", "component", "classifier", "on", "the", "most", "recent", "chunk", "of", "data", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/AccuracyUpdatedEnsemble.java#L370-L374
29,089
Waikato/moa
moa/src/main/java/moa/cluster/Clustering.java
Clustering.get
public Cluster get(int index){ if(index < clusters.size()){ return clusters.get(index); } return null; }
java
public Cluster get(int index){ if(index < clusters.size()){ return clusters.get(index); } return null; }
[ "public", "Cluster", "get", "(", "int", "index", ")", "{", "if", "(", "index", "<", "clusters", ".", "size", "(", ")", ")", "{", "return", "clusters", ".", "get", "(", "index", ")", ";", "}", "return", "null", ";", "}" ]
get a cluster from the clustering
[ "get", "a", "cluster", "from", "the", "clustering" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/cluster/Clustering.java#L224-L229
29,090
Waikato/moa
moa/src/main/java/moa/classifiers/trees/HoeffdingAdaptiveTree.java
HoeffdingAdaptiveTree.filterInstanceToLeaves
public FoundNode[] filterInstanceToLeaves(Instance inst, SplitNode parent, int parentBranch, boolean updateSplitterCounts) { List<FoundNode> nodes = new LinkedList<FoundNode>(); ((NewNode) this.treeRoot).filterInstanceToLeaves(inst, parent, parentBranch, nodes, updateSplitterCounts); return nodes.toArray(new FoundNode[nodes.size()]); }
java
public FoundNode[] filterInstanceToLeaves(Instance inst, SplitNode parent, int parentBranch, boolean updateSplitterCounts) { List<FoundNode> nodes = new LinkedList<FoundNode>(); ((NewNode) this.treeRoot).filterInstanceToLeaves(inst, parent, parentBranch, nodes, updateSplitterCounts); return nodes.toArray(new FoundNode[nodes.size()]); }
[ "public", "FoundNode", "[", "]", "filterInstanceToLeaves", "(", "Instance", "inst", ",", "SplitNode", "parent", ",", "int", "parentBranch", ",", "boolean", "updateSplitterCounts", ")", "{", "List", "<", "FoundNode", ">", "nodes", "=", "new", "LinkedList", "<", "FoundNode", ">", "(", ")", ";", "(", "(", "NewNode", ")", "this", ".", "treeRoot", ")", ".", "filterInstanceToLeaves", "(", "inst", ",", "parent", ",", "parentBranch", ",", "nodes", ",", "updateSplitterCounts", ")", ";", "return", "nodes", ".", "toArray", "(", "new", "FoundNode", "[", "nodes", ".", "size", "(", ")", "]", ")", ";", "}" ]
New for options vote
[ "New", "for", "options", "vote" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/trees/HoeffdingAdaptiveTree.java#L473-L479
29,091
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/Range.java
Range.setRange
public void setRange(String range) { String single = range.trim(); int hyphenIndex = range.indexOf('-'); if (hyphenIndex > 0) { this.start = rangeSingle(range.substring(0, hyphenIndex)); this.end = rangeSingle(range.substring(hyphenIndex + 1)); } else { int number = rangeSingle(range); if (number >= 0) { // first n attributes this.start = 0; this.end = number; } else { // last n attributes this.start = this.upperLimit + number > 0 ? this.upperLimit + number : 0; this.end = this.upperLimit - 1; } } }
java
public void setRange(String range) { String single = range.trim(); int hyphenIndex = range.indexOf('-'); if (hyphenIndex > 0) { this.start = rangeSingle(range.substring(0, hyphenIndex)); this.end = rangeSingle(range.substring(hyphenIndex + 1)); } else { int number = rangeSingle(range); if (number >= 0) { // first n attributes this.start = 0; this.end = number; } else { // last n attributes this.start = this.upperLimit + number > 0 ? this.upperLimit + number : 0; this.end = this.upperLimit - 1; } } }
[ "public", "void", "setRange", "(", "String", "range", ")", "{", "String", "single", "=", "range", ".", "trim", "(", ")", ";", "int", "hyphenIndex", "=", "range", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "hyphenIndex", ">", "0", ")", "{", "this", ".", "start", "=", "rangeSingle", "(", "range", ".", "substring", "(", "0", ",", "hyphenIndex", ")", ")", ";", "this", ".", "end", "=", "rangeSingle", "(", "range", ".", "substring", "(", "hyphenIndex", "+", "1", ")", ")", ";", "}", "else", "{", "int", "number", "=", "rangeSingle", "(", "range", ")", ";", "if", "(", "number", ">=", "0", ")", "{", "// first n attributes", "this", ".", "start", "=", "0", ";", "this", ".", "end", "=", "number", ";", "}", "else", "{", "// last n attributes", "this", ".", "start", "=", "this", ".", "upperLimit", "+", "number", ">", "0", "?", "this", ".", "upperLimit", "+", "number", ":", "0", ";", "this", ".", "end", "=", "this", ".", "upperLimit", "-", "1", ";", "}", "}", "}" ]
Sets the range from a string representation. @param range the start and end string
[ "Sets", "the", "range", "from", "a", "string", "representation", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/Range.java#L39-L56
29,092
Waikato/moa
moa/src/main/java/com/yahoo/labs/samoa/instances/Range.java
Range.rangeSingle
protected /*@pure@*/ int rangeSingle(/*@non_null@*/String singleSelection) { String single = singleSelection.trim(); if (single.toLowerCase().equals("first")) { return 0; } if (single.toLowerCase().equals("last") || single.toLowerCase().equals("-1")) { return -1; } int index = Integer.parseInt(single); if (index >= 1) { //Non for negatives index--; } return index; }
java
protected /*@pure@*/ int rangeSingle(/*@non_null@*/String singleSelection) { String single = singleSelection.trim(); if (single.toLowerCase().equals("first")) { return 0; } if (single.toLowerCase().equals("last") || single.toLowerCase().equals("-1")) { return -1; } int index = Integer.parseInt(single); if (index >= 1) { //Non for negatives index--; } return index; }
[ "protected", "/*@pure@*/", "int", "rangeSingle", "(", "/*@non_null@*/", "String", "singleSelection", ")", "{", "String", "single", "=", "singleSelection", ".", "trim", "(", ")", ";", "if", "(", "single", ".", "toLowerCase", "(", ")", ".", "equals", "(", "\"first\"", ")", ")", "{", "return", "0", ";", "}", "if", "(", "single", ".", "toLowerCase", "(", ")", ".", "equals", "(", "\"last\"", ")", "||", "single", ".", "toLowerCase", "(", ")", ".", "equals", "(", "\"-1\"", ")", ")", "{", "return", "-", "1", ";", "}", "int", "index", "=", "Integer", ".", "parseInt", "(", "single", ")", ";", "if", "(", "index", ">=", "1", ")", "{", "//Non for negatives", "index", "--", ";", "}", "return", "index", ";", "}" ]
Translates a single string selection into it's internal 0-based equivalent. @param single the string representing the selection (eg: 1 first last) @return the number corresponding to the selected value
[ "Translates", "a", "single", "string", "selection", "into", "it", "s", "internal", "0", "-", "based", "equivalent", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/Range.java#L65-L79
29,093
Waikato/moa
moa/src/main/java/moa/clusterers/outliers/utils/mtree/utils/Utils.java
Utils.minMax
public static <T extends Comparable<T>> Pair<T> minMax(Iterable<T> items) { Iterator<T> iterator = items.iterator(); if(!iterator.hasNext()) { return null; } T min = iterator.next(); T max = min; while(iterator.hasNext()) { T item = iterator.next(); if(item.compareTo(min) < 0) { min = item; } if(item.compareTo(max) > 0) { max = item; } } return new Pair<T>(min, max); }
java
public static <T extends Comparable<T>> Pair<T> minMax(Iterable<T> items) { Iterator<T> iterator = items.iterator(); if(!iterator.hasNext()) { return null; } T min = iterator.next(); T max = min; while(iterator.hasNext()) { T item = iterator.next(); if(item.compareTo(min) < 0) { min = item; } if(item.compareTo(max) > 0) { max = item; } } return new Pair<T>(min, max); }
[ "public", "static", "<", "T", "extends", "Comparable", "<", "T", ">", ">", "Pair", "<", "T", ">", "minMax", "(", "Iterable", "<", "T", ">", "items", ")", "{", "Iterator", "<", "T", ">", "iterator", "=", "items", ".", "iterator", "(", ")", ";", "if", "(", "!", "iterator", ".", "hasNext", "(", ")", ")", "{", "return", "null", ";", "}", "T", "min", "=", "iterator", ".", "next", "(", ")", ";", "T", "max", "=", "min", ";", "while", "(", "iterator", ".", "hasNext", "(", ")", ")", "{", "T", "item", "=", "iterator", ".", "next", "(", ")", ";", "if", "(", "item", ".", "compareTo", "(", "min", ")", "<", "0", ")", "{", "min", "=", "item", ";", "}", "if", "(", "item", ".", "compareTo", "(", "max", ")", ">", "0", ")", "{", "max", "=", "item", ";", "}", "}", "return", "new", "Pair", "<", "T", ">", "(", "min", ",", "max", ")", ";", "}" ]
Identifies the minimum and maximum elements from an iterable, according to the natural ordering of the elements. @param items An {@link Iterable} object with the elements @param <T> The type of the elements. @return A pair with the minimum and maximum elements.
[ "Identifies", "the", "minimum", "and", "maximum", "elements", "from", "an", "iterable", "according", "to", "the", "natural", "ordering", "of", "the", "elements", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/utils/mtree/utils/Utils.java#L43-L63
29,094
Waikato/moa
moa/src/main/java/moa/clusterers/outliers/utils/mtree/utils/Utils.java
Utils.randomSample
public static <T> List<T> randomSample(Collection<T> collection, int n) { List<T> list = new ArrayList<T>(collection); List<T> sample = new ArrayList<T>(n); Random random = new Random(); while(n > 0 && !list.isEmpty()) { int index = random.nextInt(list.size()); sample.add(list.get(index)); int indexLast = list.size() - 1; T last = list.remove(indexLast); if(index < indexLast) { list.set(index, last); } n--; } return sample; }
java
public static <T> List<T> randomSample(Collection<T> collection, int n) { List<T> list = new ArrayList<T>(collection); List<T> sample = new ArrayList<T>(n); Random random = new Random(); while(n > 0 && !list.isEmpty()) { int index = random.nextInt(list.size()); sample.add(list.get(index)); int indexLast = list.size() - 1; T last = list.remove(indexLast); if(index < indexLast) { list.set(index, last); } n--; } return sample; }
[ "public", "static", "<", "T", ">", "List", "<", "T", ">", "randomSample", "(", "Collection", "<", "T", ">", "collection", ",", "int", "n", ")", "{", "List", "<", "T", ">", "list", "=", "new", "ArrayList", "<", "T", ">", "(", "collection", ")", ";", "List", "<", "T", ">", "sample", "=", "new", "ArrayList", "<", "T", ">", "(", "n", ")", ";", "Random", "random", "=", "new", "Random", "(", ")", ";", "while", "(", "n", ">", "0", "&&", "!", "list", ".", "isEmpty", "(", ")", ")", "{", "int", "index", "=", "random", ".", "nextInt", "(", "list", ".", "size", "(", ")", ")", ";", "sample", ".", "add", "(", "list", ".", "get", "(", "index", ")", ")", ";", "int", "indexLast", "=", "list", ".", "size", "(", ")", "-", "1", ";", "T", "last", "=", "list", ".", "remove", "(", "indexLast", ")", ";", "if", "(", "index", "<", "indexLast", ")", "{", "list", ".", "set", "(", "index", ",", "last", ")", ";", "}", "n", "--", ";", "}", "return", "sample", ";", "}" ]
Randomly chooses elements from the collection. @param collection The collection. @param n The number of elements to choose. @param <T> The type of the elements. @return A list with the chosen elements.
[ "Randomly", "chooses", "elements", "from", "the", "collection", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/utils/mtree/utils/Utils.java#L73-L88
29,095
Waikato/moa
moa/src/main/java/moa/gui/visualization/GraphCanvas.java
GraphCanvas.updateMinMaxValues
private boolean updateMinMaxValues() { double min_y_value_new = min_y_value; double max_y_value_new = max_y_value; double max_x_value_new = max_x_value; if (measure0 != null && measure1 != null) { min_y_value_new = Math.min(measure0.getMinValue(measureSelected), measure1.getMinValue(measureSelected)); max_y_value_new = Math.max(measure0.getMaxValue(measureSelected), measure1.getMaxValue(measureSelected)); max_x_value_new = Math.max(measure0.getNumberOfValues(measureSelected), max_x_value); } else { if (measure0 != null) { min_y_value_new = measure0.getMinValue(measureSelected); max_y_value_new = measure0.getMaxValue(measureSelected); max_x_value_new = Math.max(measure0.getNumberOfValues(measureSelected), max_x_value); } } //resizing needed? if (max_x_value_new != max_x_value || max_y_value_new != max_y_value || min_y_value_new != min_y_value) { min_y_value = min_y_value_new; max_y_value = max_y_value_new; max_x_value = max_x_value_new; return true; } return false; }
java
private boolean updateMinMaxValues() { double min_y_value_new = min_y_value; double max_y_value_new = max_y_value; double max_x_value_new = max_x_value; if (measure0 != null && measure1 != null) { min_y_value_new = Math.min(measure0.getMinValue(measureSelected), measure1.getMinValue(measureSelected)); max_y_value_new = Math.max(measure0.getMaxValue(measureSelected), measure1.getMaxValue(measureSelected)); max_x_value_new = Math.max(measure0.getNumberOfValues(measureSelected), max_x_value); } else { if (measure0 != null) { min_y_value_new = measure0.getMinValue(measureSelected); max_y_value_new = measure0.getMaxValue(measureSelected); max_x_value_new = Math.max(measure0.getNumberOfValues(measureSelected), max_x_value); } } //resizing needed? if (max_x_value_new != max_x_value || max_y_value_new != max_y_value || min_y_value_new != min_y_value) { min_y_value = min_y_value_new; max_y_value = max_y_value_new; max_x_value = max_x_value_new; return true; } return false; }
[ "private", "boolean", "updateMinMaxValues", "(", ")", "{", "double", "min_y_value_new", "=", "min_y_value", ";", "double", "max_y_value_new", "=", "max_y_value", ";", "double", "max_x_value_new", "=", "max_x_value", ";", "if", "(", "measure0", "!=", "null", "&&", "measure1", "!=", "null", ")", "{", "min_y_value_new", "=", "Math", ".", "min", "(", "measure0", ".", "getMinValue", "(", "measureSelected", ")", ",", "measure1", ".", "getMinValue", "(", "measureSelected", ")", ")", ";", "max_y_value_new", "=", "Math", ".", "max", "(", "measure0", ".", "getMaxValue", "(", "measureSelected", ")", ",", "measure1", ".", "getMaxValue", "(", "measureSelected", ")", ")", ";", "max_x_value_new", "=", "Math", ".", "max", "(", "measure0", ".", "getNumberOfValues", "(", "measureSelected", ")", ",", "max_x_value", ")", ";", "}", "else", "{", "if", "(", "measure0", "!=", "null", ")", "{", "min_y_value_new", "=", "measure0", ".", "getMinValue", "(", "measureSelected", ")", ";", "max_y_value_new", "=", "measure0", ".", "getMaxValue", "(", "measureSelected", ")", ";", "max_x_value_new", "=", "Math", ".", "max", "(", "measure0", ".", "getNumberOfValues", "(", "measureSelected", ")", ",", "max_x_value", ")", ";", "}", "}", "//resizing needed?", "if", "(", "max_x_value_new", "!=", "max_x_value", "||", "max_y_value_new", "!=", "max_y_value", "||", "min_y_value_new", "!=", "min_y_value", ")", "{", "min_y_value", "=", "min_y_value_new", ";", "max_y_value", "=", "max_y_value_new", ";", "max_x_value", "=", "max_x_value_new", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
returns true when values have changed
[ "returns", "true", "when", "values", "have", "changed" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/visualization/GraphCanvas.java#L148-L173
29,096
Waikato/moa
moa/src/main/java/moa/gui/visualization/GraphCanvas.java
GraphCanvas.addEvents
private void addEvents() { if (clusterEvents != null && clusterEvents.size() > eventCounter) { ClusterEvent ev = clusterEvents.get(eventCounter); eventCounter++; JLabel eventMarker = new JLabel(ev.getType().substring(0, 1)); eventMarker.setPreferredSize(new Dimension(20, y_offset_top)); eventMarker.setSize(new Dimension(20, y_offset_top)); eventMarker.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); int x = (int) (ev.getTimestamp() / processFrequency / x_resolution); eventMarker.setLocation(x - 10, 0); eventMarker.setToolTipText(ev.getType() + " at " + ev.getTimestamp() + ": " + ev.getMessage()); eventPanel.add(eventMarker); eventLabelList.add(eventMarker); eventPanel.repaint(); } }
java
private void addEvents() { if (clusterEvents != null && clusterEvents.size() > eventCounter) { ClusterEvent ev = clusterEvents.get(eventCounter); eventCounter++; JLabel eventMarker = new JLabel(ev.getType().substring(0, 1)); eventMarker.setPreferredSize(new Dimension(20, y_offset_top)); eventMarker.setSize(new Dimension(20, y_offset_top)); eventMarker.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); int x = (int) (ev.getTimestamp() / processFrequency / x_resolution); eventMarker.setLocation(x - 10, 0); eventMarker.setToolTipText(ev.getType() + " at " + ev.getTimestamp() + ": " + ev.getMessage()); eventPanel.add(eventMarker); eventLabelList.add(eventMarker); eventPanel.repaint(); } }
[ "private", "void", "addEvents", "(", ")", "{", "if", "(", "clusterEvents", "!=", "null", "&&", "clusterEvents", ".", "size", "(", ")", ">", "eventCounter", ")", "{", "ClusterEvent", "ev", "=", "clusterEvents", ".", "get", "(", "eventCounter", ")", ";", "eventCounter", "++", ";", "JLabel", "eventMarker", "=", "new", "JLabel", "(", "ev", ".", "getType", "(", ")", ".", "substring", "(", "0", ",", "1", ")", ")", ";", "eventMarker", ".", "setPreferredSize", "(", "new", "Dimension", "(", "20", ",", "y_offset_top", ")", ")", ";", "eventMarker", ".", "setSize", "(", "new", "Dimension", "(", "20", ",", "y_offset_top", ")", ")", ";", "eventMarker", ".", "setHorizontalAlignment", "(", "javax", ".", "swing", ".", "SwingConstants", ".", "CENTER", ")", ";", "int", "x", "=", "(", "int", ")", "(", "ev", ".", "getTimestamp", "(", ")", "/", "processFrequency", "/", "x_resolution", ")", ";", "eventMarker", ".", "setLocation", "(", "x", "-", "10", ",", "0", ")", ";", "eventMarker", ".", "setToolTipText", "(", "ev", ".", "getType", "(", ")", "+", "\" at \"", "+", "ev", ".", "getTimestamp", "(", ")", "+", "\": \"", "+", "ev", ".", "getMessage", "(", ")", ")", ";", "eventPanel", ".", "add", "(", "eventMarker", ")", ";", "eventLabelList", ".", "add", "(", "eventMarker", ")", ";", "eventPanel", ".", "repaint", "(", ")", ";", "}", "}" ]
check if there are any new events in the event list and add them to the plot
[ "check", "if", "there", "are", "any", "new", "events", "in", "the", "event", "list", "and", "add", "them", "to", "the", "plot" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/visualization/GraphCanvas.java#L203-L220
29,097
Waikato/moa
moa/src/main/java/moa/evaluation/BasicMultiTargetPerformanceRelativeMeasuresEvaluator.java
BasicMultiTargetPerformanceRelativeMeasuresEvaluator.addResult
@Override public void addResult(Example<Instance> example, double[] classVotes) { Prediction p=new MultiLabelPrediction(1); p.setVotes(classVotes); addResult(example, p); }
java
@Override public void addResult(Example<Instance> example, double[] classVotes) { Prediction p=new MultiLabelPrediction(1); p.setVotes(classVotes); addResult(example, p); }
[ "@", "Override", "public", "void", "addResult", "(", "Example", "<", "Instance", ">", "example", ",", "double", "[", "]", "classVotes", ")", "{", "Prediction", "p", "=", "new", "MultiLabelPrediction", "(", "1", ")", ";", "p", ".", "setVotes", "(", "classVotes", ")", ";", "addResult", "(", "example", ",", "p", ")", ";", "}" ]
only for one output
[ "only", "for", "one", "output" ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/BasicMultiTargetPerformanceRelativeMeasuresEvaluator.java#L152-L157
29,098
Waikato/moa
moa/src/main/java/moa/gui/visualization/ParamGraphCanvas.java
ParamGraphCanvas.setGraph
public void setGraph(MeasureCollection[] measures, MeasureCollection[] measureStds, double[] variedParamValues, Color[] colors) { this.measures = measures; this.variedParamValues = variedParamValues; ((GraphScatter) this.plotPanel).setGraph(measures, measureStds, variedParamValues, colors); updateCanvas(false); }
java
public void setGraph(MeasureCollection[] measures, MeasureCollection[] measureStds, double[] variedParamValues, Color[] colors) { this.measures = measures; this.variedParamValues = variedParamValues; ((GraphScatter) this.plotPanel).setGraph(measures, measureStds, variedParamValues, colors); updateCanvas(false); }
[ "public", "void", "setGraph", "(", "MeasureCollection", "[", "]", "measures", ",", "MeasureCollection", "[", "]", "measureStds", ",", "double", "[", "]", "variedParamValues", ",", "Color", "[", "]", "colors", ")", "{", "this", ".", "measures", "=", "measures", ";", "this", ".", "variedParamValues", "=", "variedParamValues", ";", "(", "(", "GraphScatter", ")", "this", ".", "plotPanel", ")", ".", "setGraph", "(", "measures", ",", "measureStds", ",", "variedParamValues", ",", "colors", ")", ";", "updateCanvas", "(", "false", ")", ";", "}" ]
Sets the scatter graph. @param measures information about the curves @param measureStds standard deviation for the measures @param variedParamValues values of the varied parameter @param colors color encoding for the param array
[ "Sets", "the", "scatter", "graph", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/visualization/ParamGraphCanvas.java#L62-L69
29,099
Waikato/moa
moa/src/main/java/moa/clusterers/CobWeb.java
CobWeb.getVotesForInstance
public double[] getVotesForInstance(Instance instance) { //public int clusterInstance(Instance instance) {//throws Exception { CNode host = m_cobwebTree; CNode temp = null; determineNumberOfClusters(); if (this.m_numberOfClusters < 1) { return (new double[0]); } double[] ret = new double[this.m_numberOfClusters]; do { if (host.m_children == null) { temp = null; break; } host.updateStats(instance, false); temp = host.findHost(instance, true); host.updateStats(instance, true); if (temp != null) { host = temp; } } while (temp != null); ret[host.m_clusterNum] = 1.0; return ret; }
java
public double[] getVotesForInstance(Instance instance) { //public int clusterInstance(Instance instance) {//throws Exception { CNode host = m_cobwebTree; CNode temp = null; determineNumberOfClusters(); if (this.m_numberOfClusters < 1) { return (new double[0]); } double[] ret = new double[this.m_numberOfClusters]; do { if (host.m_children == null) { temp = null; break; } host.updateStats(instance, false); temp = host.findHost(instance, true); host.updateStats(instance, true); if (temp != null) { host = temp; } } while (temp != null); ret[host.m_clusterNum] = 1.0; return ret; }
[ "public", "double", "[", "]", "getVotesForInstance", "(", "Instance", "instance", ")", "{", "//public int clusterInstance(Instance instance) {//throws Exception {", "CNode", "host", "=", "m_cobwebTree", ";", "CNode", "temp", "=", "null", ";", "determineNumberOfClusters", "(", ")", ";", "if", "(", "this", ".", "m_numberOfClusters", "<", "1", ")", "{", "return", "(", "new", "double", "[", "0", "]", ")", ";", "}", "double", "[", "]", "ret", "=", "new", "double", "[", "this", ".", "m_numberOfClusters", "]", ";", "do", "{", "if", "(", "host", ".", "m_children", "==", "null", ")", "{", "temp", "=", "null", ";", "break", ";", "}", "host", ".", "updateStats", "(", "instance", ",", "false", ")", ";", "temp", "=", "host", ".", "findHost", "(", "instance", ",", "true", ")", ";", "host", ".", "updateStats", "(", "instance", ",", "true", ")", ";", "if", "(", "temp", "!=", "null", ")", "{", "host", "=", "temp", ";", "}", "}", "while", "(", "temp", "!=", "null", ")", ";", "ret", "[", "host", ".", "m_clusterNum", "]", "=", "1.0", ";", "return", "ret", ";", "}" ]
Classifies a given instance. @param instance the instance to be assigned to a cluster @return the number of the assigned cluster as an interger if the class is enumerated, otherwise the predicted value @throws Exception if instance could not be classified successfully
[ "Classifies", "a", "given", "instance", "." ]
395982e5100bfe75a3a4d26115462ce2cc74cbb0
https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/CobWeb.java#L815-L844