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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
28,900 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/HSTrees.java | HSTrees.initialize | @Override
public void initialize(Collection<Instance> trainingPoints)
{
Iterator<Instance> trgPtsIterator = trainingPoints.iterator();
if(trgPtsIterator.hasNext() && this.numInstances == 0)
{
Instance inst = trgPtsIterator.next();
this.buildForest(inst);
this.trainOnInstance(inst);
}
while(trgPtsIterator.hasNext())
{
this.trainOnInstance((Instance)trgPtsIterator.next());
}
} | java | @Override
public void initialize(Collection<Instance> trainingPoints)
{
Iterator<Instance> trgPtsIterator = trainingPoints.iterator();
if(trgPtsIterator.hasNext() && this.numInstances == 0)
{
Instance inst = trgPtsIterator.next();
this.buildForest(inst);
this.trainOnInstance(inst);
}
while(trgPtsIterator.hasNext())
{
this.trainOnInstance((Instance)trgPtsIterator.next());
}
} | [
"@",
"Override",
"public",
"void",
"initialize",
"(",
"Collection",
"<",
"Instance",
">",
"trainingPoints",
")",
"{",
"Iterator",
"<",
"Instance",
">",
"trgPtsIterator",
"=",
"trainingPoints",
".",
"iterator",
"(",
")",
";",
"if",
"(",
"trgPtsIterator",
".",
"hasNext",
"(",
")",
"&&",
"this",
".",
"numInstances",
"==",
"0",
")",
"{",
"Instance",
"inst",
"=",
"trgPtsIterator",
".",
"next",
"(",
")",
";",
"this",
".",
"buildForest",
"(",
"inst",
")",
";",
"this",
".",
"trainOnInstance",
"(",
"inst",
")",
";",
"}",
"while",
"(",
"trgPtsIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"this",
".",
"trainOnInstance",
"(",
"(",
"Instance",
")",
"trgPtsIterator",
".",
"next",
"(",
")",
")",
";",
"}",
"}"
] | Initializes the Streaming HS-Trees classifier on the argument trainingPoints.
@param trainingPoints the Collection of instance with which to initialize the Streaming Hs-Trees classifier. | [
"Initializes",
"the",
"Streaming",
"HS",
"-",
"Trees",
"classifier",
"on",
"the",
"argument",
"trainingPoints",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/HSTrees.java#L261-L277 |
28,901 | Waikato/moa | moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java | FIMTDDNumericAttributeClassObserver.searchForBestSplitOption | protected AttributeSplitSuggestion searchForBestSplitOption(Node currentNode, AttributeSplitSuggestion currentBestOption, SplitCriterion criterion, int attIndex) {
// Return null if the current node is null or we have finished looking through all the possible splits
if (currentNode == null || countRightTotal == 0.0) {
return currentBestOption;
}
if (currentNode.left != null) {
currentBestOption = searchForBestSplitOption(currentNode.left, currentBestOption, criterion, attIndex);
}
sumTotalLeft += currentNode.leftStatistics.getValue(1);
sumTotalRight -= currentNode.leftStatistics.getValue(1);
sumSqTotalLeft += currentNode.leftStatistics.getValue(2);
sumSqTotalRight -= currentNode.leftStatistics.getValue(2);
countLeftTotal += currentNode.leftStatistics.getValue(0);
countRightTotal -= currentNode.leftStatistics.getValue(0);
double[][] postSplitDists = new double[][]{{countLeftTotal, sumTotalLeft, sumSqTotalLeft}, {countRightTotal, sumTotalRight, sumSqTotalRight}};
double[] preSplitDist = new double[]{(countLeftTotal + countRightTotal), (sumTotalLeft + sumTotalRight), (sumSqTotalLeft + sumSqTotalRight)};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);
if ((currentBestOption == null) || (merit > currentBestOption.merit)) {
currentBestOption = new AttributeSplitSuggestion(
new NumericAttributeBinaryTest(attIndex,
currentNode.cut_point, true), postSplitDists, merit);
}
if (currentNode.right != null) {
currentBestOption = searchForBestSplitOption(currentNode.right, currentBestOption, criterion, attIndex);
}
sumTotalLeft -= currentNode.leftStatistics.getValue(1);
sumTotalRight += currentNode.leftStatistics.getValue(1);
sumSqTotalLeft -= currentNode.leftStatistics.getValue(2);
sumSqTotalRight += currentNode.leftStatistics.getValue(2);
countLeftTotal -= currentNode.leftStatistics.getValue(0);
countRightTotal += currentNode.leftStatistics.getValue(0);
return currentBestOption;
} | java | protected AttributeSplitSuggestion searchForBestSplitOption(Node currentNode, AttributeSplitSuggestion currentBestOption, SplitCriterion criterion, int attIndex) {
// Return null if the current node is null or we have finished looking through all the possible splits
if (currentNode == null || countRightTotal == 0.0) {
return currentBestOption;
}
if (currentNode.left != null) {
currentBestOption = searchForBestSplitOption(currentNode.left, currentBestOption, criterion, attIndex);
}
sumTotalLeft += currentNode.leftStatistics.getValue(1);
sumTotalRight -= currentNode.leftStatistics.getValue(1);
sumSqTotalLeft += currentNode.leftStatistics.getValue(2);
sumSqTotalRight -= currentNode.leftStatistics.getValue(2);
countLeftTotal += currentNode.leftStatistics.getValue(0);
countRightTotal -= currentNode.leftStatistics.getValue(0);
double[][] postSplitDists = new double[][]{{countLeftTotal, sumTotalLeft, sumSqTotalLeft}, {countRightTotal, sumTotalRight, sumSqTotalRight}};
double[] preSplitDist = new double[]{(countLeftTotal + countRightTotal), (sumTotalLeft + sumTotalRight), (sumSqTotalLeft + sumSqTotalRight)};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);
if ((currentBestOption == null) || (merit > currentBestOption.merit)) {
currentBestOption = new AttributeSplitSuggestion(
new NumericAttributeBinaryTest(attIndex,
currentNode.cut_point, true), postSplitDists, merit);
}
if (currentNode.right != null) {
currentBestOption = searchForBestSplitOption(currentNode.right, currentBestOption, criterion, attIndex);
}
sumTotalLeft -= currentNode.leftStatistics.getValue(1);
sumTotalRight += currentNode.leftStatistics.getValue(1);
sumSqTotalLeft -= currentNode.leftStatistics.getValue(2);
sumSqTotalRight += currentNode.leftStatistics.getValue(2);
countLeftTotal -= currentNode.leftStatistics.getValue(0);
countRightTotal += currentNode.leftStatistics.getValue(0);
return currentBestOption;
} | [
"protected",
"AttributeSplitSuggestion",
"searchForBestSplitOption",
"(",
"Node",
"currentNode",
",",
"AttributeSplitSuggestion",
"currentBestOption",
",",
"SplitCriterion",
"criterion",
",",
"int",
"attIndex",
")",
"{",
"// Return null if the current node is null or we have finished looking through all the possible splits",
"if",
"(",
"currentNode",
"==",
"null",
"||",
"countRightTotal",
"==",
"0.0",
")",
"{",
"return",
"currentBestOption",
";",
"}",
"if",
"(",
"currentNode",
".",
"left",
"!=",
"null",
")",
"{",
"currentBestOption",
"=",
"searchForBestSplitOption",
"(",
"currentNode",
".",
"left",
",",
"currentBestOption",
",",
"criterion",
",",
"attIndex",
")",
";",
"}",
"sumTotalLeft",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
";",
"sumTotalRight",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
";",
"sumSqTotalLeft",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
";",
"sumSqTotalRight",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
";",
"countLeftTotal",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
";",
"countRightTotal",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
";",
"double",
"[",
"]",
"[",
"]",
"postSplitDists",
"=",
"new",
"double",
"[",
"]",
"[",
"]",
"{",
"{",
"countLeftTotal",
",",
"sumTotalLeft",
",",
"sumSqTotalLeft",
"}",
",",
"{",
"countRightTotal",
",",
"sumTotalRight",
",",
"sumSqTotalRight",
"}",
"}",
";",
"double",
"[",
"]",
"preSplitDist",
"=",
"new",
"double",
"[",
"]",
"{",
"(",
"countLeftTotal",
"+",
"countRightTotal",
")",
",",
"(",
"sumTotalLeft",
"+",
"sumTotalRight",
")",
",",
"(",
"sumSqTotalLeft",
"+",
"sumSqTotalRight",
")",
"}",
";",
"double",
"merit",
"=",
"criterion",
".",
"getMeritOfSplit",
"(",
"preSplitDist",
",",
"postSplitDists",
")",
";",
"if",
"(",
"(",
"currentBestOption",
"==",
"null",
")",
"||",
"(",
"merit",
">",
"currentBestOption",
".",
"merit",
")",
")",
"{",
"currentBestOption",
"=",
"new",
"AttributeSplitSuggestion",
"(",
"new",
"NumericAttributeBinaryTest",
"(",
"attIndex",
",",
"currentNode",
".",
"cut_point",
",",
"true",
")",
",",
"postSplitDists",
",",
"merit",
")",
";",
"}",
"if",
"(",
"currentNode",
".",
"right",
"!=",
"null",
")",
"{",
"currentBestOption",
"=",
"searchForBestSplitOption",
"(",
"currentNode",
".",
"right",
",",
"currentBestOption",
",",
"criterion",
",",
"attIndex",
")",
";",
"}",
"sumTotalLeft",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
";",
"sumTotalRight",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
";",
"sumSqTotalLeft",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
";",
"sumSqTotalRight",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
";",
"countLeftTotal",
"-=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
";",
"countRightTotal",
"+=",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
";",
"return",
"currentBestOption",
";",
"}"
] | Implementation of the FindBestSplit algorithm from E.Ikonomovska et al. | [
"Implementation",
"of",
"the",
"FindBestSplit",
"algorithm",
"from",
"E",
".",
"Ikonomovska",
"et",
"al",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java#L148-L187 |
28,902 | Waikato/moa | moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java | FIMTDDNumericAttributeClassObserver.removeBadSplits | public void removeBadSplits(SplitCriterion criterion, double lastCheckRatio, double lastCheckSDR, double lastCheckE) {
removeBadSplitNodes(criterion, this.root, lastCheckRatio, lastCheckSDR, lastCheckE);
} | java | public void removeBadSplits(SplitCriterion criterion, double lastCheckRatio, double lastCheckSDR, double lastCheckE) {
removeBadSplitNodes(criterion, this.root, lastCheckRatio, lastCheckSDR, lastCheckE);
} | [
"public",
"void",
"removeBadSplits",
"(",
"SplitCriterion",
"criterion",
",",
"double",
"lastCheckRatio",
",",
"double",
"lastCheckSDR",
",",
"double",
"lastCheckE",
")",
"{",
"removeBadSplitNodes",
"(",
"criterion",
",",
"this",
".",
"root",
",",
"lastCheckRatio",
",",
"lastCheckSDR",
",",
"lastCheckE",
")",
";",
"}"
] | A method to remove all nodes in the E-BST in which it and all it's
children represent 'bad' split points | [
"A",
"method",
"to",
"remove",
"all",
"nodes",
"in",
"the",
"E",
"-",
"BST",
"in",
"which",
"it",
"and",
"all",
"it",
"s",
"children",
"represent",
"bad",
"split",
"points"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java#L193-L195 |
28,903 | Waikato/moa | moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java | FIMTDDNumericAttributeClassObserver.removeBadSplitNodes | private boolean removeBadSplitNodes(SplitCriterion criterion, Node currentNode, double lastCheckRatio, double lastCheckSDR, double lastCheckE) {
boolean isBad = false;
if (currentNode == null) {
return true;
}
if (currentNode.left != null) {
isBad = removeBadSplitNodes(criterion, currentNode.left, lastCheckRatio, lastCheckSDR, lastCheckE);
}
if (currentNode.right != null && isBad) {
isBad = removeBadSplitNodes(criterion, currentNode.left, lastCheckRatio, lastCheckSDR, lastCheckE);
}
if (isBad) {
double[][] postSplitDists = new double[][]{{currentNode.leftStatistics.getValue(0), currentNode.leftStatistics.getValue(1), currentNode.leftStatistics.getValue(2)}, {currentNode.rightStatistics.getValue(0), currentNode.rightStatistics.getValue(1), currentNode.rightStatistics.getValue(2)}};
double[] preSplitDist = new double[]{(currentNode.leftStatistics.getValue(0) + currentNode.rightStatistics.getValue(0)), (currentNode.leftStatistics.getValue(1) + currentNode.rightStatistics.getValue(1)), (currentNode.leftStatistics.getValue(2) + currentNode.rightStatistics.getValue(2))};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);
if ((merit / lastCheckSDR) < (lastCheckRatio - (2 * lastCheckE))) {
currentNode = null;
return true;
}
}
return false;
} | java | private boolean removeBadSplitNodes(SplitCriterion criterion, Node currentNode, double lastCheckRatio, double lastCheckSDR, double lastCheckE) {
boolean isBad = false;
if (currentNode == null) {
return true;
}
if (currentNode.left != null) {
isBad = removeBadSplitNodes(criterion, currentNode.left, lastCheckRatio, lastCheckSDR, lastCheckE);
}
if (currentNode.right != null && isBad) {
isBad = removeBadSplitNodes(criterion, currentNode.left, lastCheckRatio, lastCheckSDR, lastCheckE);
}
if (isBad) {
double[][] postSplitDists = new double[][]{{currentNode.leftStatistics.getValue(0), currentNode.leftStatistics.getValue(1), currentNode.leftStatistics.getValue(2)}, {currentNode.rightStatistics.getValue(0), currentNode.rightStatistics.getValue(1), currentNode.rightStatistics.getValue(2)}};
double[] preSplitDist = new double[]{(currentNode.leftStatistics.getValue(0) + currentNode.rightStatistics.getValue(0)), (currentNode.leftStatistics.getValue(1) + currentNode.rightStatistics.getValue(1)), (currentNode.leftStatistics.getValue(2) + currentNode.rightStatistics.getValue(2))};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);
if ((merit / lastCheckSDR) < (lastCheckRatio - (2 * lastCheckE))) {
currentNode = null;
return true;
}
}
return false;
} | [
"private",
"boolean",
"removeBadSplitNodes",
"(",
"SplitCriterion",
"criterion",
",",
"Node",
"currentNode",
",",
"double",
"lastCheckRatio",
",",
"double",
"lastCheckSDR",
",",
"double",
"lastCheckE",
")",
"{",
"boolean",
"isBad",
"=",
"false",
";",
"if",
"(",
"currentNode",
"==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"currentNode",
".",
"left",
"!=",
"null",
")",
"{",
"isBad",
"=",
"removeBadSplitNodes",
"(",
"criterion",
",",
"currentNode",
".",
"left",
",",
"lastCheckRatio",
",",
"lastCheckSDR",
",",
"lastCheckE",
")",
";",
"}",
"if",
"(",
"currentNode",
".",
"right",
"!=",
"null",
"&&",
"isBad",
")",
"{",
"isBad",
"=",
"removeBadSplitNodes",
"(",
"criterion",
",",
"currentNode",
".",
"left",
",",
"lastCheckRatio",
",",
"lastCheckSDR",
",",
"lastCheckE",
")",
";",
"}",
"if",
"(",
"isBad",
")",
"{",
"double",
"[",
"]",
"[",
"]",
"postSplitDists",
"=",
"new",
"double",
"[",
"]",
"[",
"]",
"{",
"{",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
",",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
",",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
"}",
",",
"{",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"0",
")",
",",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"1",
")",
",",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"2",
")",
"}",
"}",
";",
"double",
"[",
"]",
"preSplitDist",
"=",
"new",
"double",
"[",
"]",
"{",
"(",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"0",
")",
"+",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"0",
")",
")",
",",
"(",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"1",
")",
"+",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"1",
")",
")",
",",
"(",
"currentNode",
".",
"leftStatistics",
".",
"getValue",
"(",
"2",
")",
"+",
"currentNode",
".",
"rightStatistics",
".",
"getValue",
"(",
"2",
")",
")",
"}",
";",
"double",
"merit",
"=",
"criterion",
".",
"getMeritOfSplit",
"(",
"preSplitDist",
",",
"postSplitDists",
")",
";",
"if",
"(",
"(",
"merit",
"/",
"lastCheckSDR",
")",
"<",
"(",
"lastCheckRatio",
"-",
"(",
"2",
"*",
"lastCheckE",
")",
")",
")",
"{",
"currentNode",
"=",
"null",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Recursive method that first checks all of a node's children before
deciding if it is 'bad' and may be removed | [
"Recursive",
"method",
"that",
"first",
"checks",
"all",
"of",
"a",
"node",
"s",
"children",
"before",
"deciding",
"if",
"it",
"is",
"bad",
"and",
"may",
"be",
"removed"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/core/attributeclassobservers/FIMTDDNumericAttributeClassObserver.java#L201-L229 |
28,904 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java | NearestNeighbourDescription.resetLearningImpl | @Override
public void resetLearningImpl()
{
this.nbhdSize = this.neighbourhoodSizeOption.getValue();
//this.k = this.kOption.getValue(); //NOT IMPLEMENTED//
//this.m = this.mOption.getValue(); //NOT IMPLEMENTED//
this.tau = this.thresholdOption.getValue();
this.neighbourhood = new FixedLengthList<Instance>(nbhdSize);
} | java | @Override
public void resetLearningImpl()
{
this.nbhdSize = this.neighbourhoodSizeOption.getValue();
//this.k = this.kOption.getValue(); //NOT IMPLEMENTED//
//this.m = this.mOption.getValue(); //NOT IMPLEMENTED//
this.tau = this.thresholdOption.getValue();
this.neighbourhood = new FixedLengthList<Instance>(nbhdSize);
} | [
"@",
"Override",
"public",
"void",
"resetLearningImpl",
"(",
")",
"{",
"this",
".",
"nbhdSize",
"=",
"this",
".",
"neighbourhoodSizeOption",
".",
"getValue",
"(",
")",
";",
"//this.k = this.kOption.getValue(); //NOT IMPLEMENTED//",
"//this.m = this.mOption.getValue(); //NOT IMPLEMENTED//",
"this",
".",
"tau",
"=",
"this",
".",
"thresholdOption",
".",
"getValue",
"(",
")",
";",
"this",
".",
"neighbourhood",
"=",
"new",
"FixedLengthList",
"<",
"Instance",
">",
"(",
"nbhdSize",
")",
";",
"}"
] | Resets the implementation's parameters and data structures. | [
"Resets",
"the",
"implementation",
"s",
"parameters",
"and",
"data",
"structures",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java#L93-L103 |
28,905 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java | NearestNeighbourDescription.getVotesForInstance | @Override
public double[] getVotesForInstance(Instance inst)
{
double[] votes = {0.5, 0.5};
if(this.neighbourhood.size() > 2)
{
votes[1] = Math.pow(2.0, -1.0 * this.getAnomalyScore(inst) / this.tau);
votes[0] = 1.0 - votes[1];
}
return votes;
} | java | @Override
public double[] getVotesForInstance(Instance inst)
{
double[] votes = {0.5, 0.5};
if(this.neighbourhood.size() > 2)
{
votes[1] = Math.pow(2.0, -1.0 * this.getAnomalyScore(inst) / this.tau);
votes[0] = 1.0 - votes[1];
}
return votes;
} | [
"@",
"Override",
"public",
"double",
"[",
"]",
"getVotesForInstance",
"(",
"Instance",
"inst",
")",
"{",
"double",
"[",
"]",
"votes",
"=",
"{",
"0.5",
",",
"0.5",
"}",
";",
"if",
"(",
"this",
".",
"neighbourhood",
".",
"size",
"(",
")",
">",
"2",
")",
"{",
"votes",
"[",
"1",
"]",
"=",
"Math",
".",
"pow",
"(",
"2.0",
",",
"-",
"1.0",
"*",
"this",
".",
"getAnomalyScore",
"(",
"inst",
")",
"/",
"this",
".",
"tau",
")",
";",
"votes",
"[",
"0",
"]",
"=",
"1.0",
"-",
"votes",
"[",
"1",
"]",
";",
"}",
"return",
"votes",
";",
"}"
] | Calculates the distance between the argument instance and its nearest neighbour as well as the distance between that
nearest neighbour and its own nearest neighbour. The ratio of these distances is compared to the threshold value, tau,
and converted into a vote score.
@param inst the instance to get votes for.
@return the votes for the instance's label [normal, outlier] | [
"Calculates",
"the",
"distance",
"between",
"the",
"argument",
"instance",
"and",
"its",
"nearest",
"neighbour",
"as",
"well",
"as",
"the",
"distance",
"between",
"that",
"nearest",
"neighbour",
"and",
"its",
"own",
"nearest",
"neighbour",
".",
"The",
"ratio",
"of",
"these",
"distances",
"is",
"compared",
"to",
"the",
"threshold",
"value",
"tau",
"and",
"converted",
"into",
"a",
"vote",
"score",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java#L126-L138 |
28,906 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java | NearestNeighbourDescription.getAnomalyScore | public double getAnomalyScore(Instance inst)
{
if(this.neighbourhood.size() < 2)
return 1.0;
Instance nearestNeighbour = getNearestNeighbour(inst, this.neighbourhood, false);
Instance nnNearestNeighbour = getNearestNeighbour(nearestNeighbour, this.neighbourhood, true);
double indicatorArgument = distance(inst, nearestNeighbour) / distance(nearestNeighbour, nnNearestNeighbour);
return indicatorArgument;
} | java | public double getAnomalyScore(Instance inst)
{
if(this.neighbourhood.size() < 2)
return 1.0;
Instance nearestNeighbour = getNearestNeighbour(inst, this.neighbourhood, false);
Instance nnNearestNeighbour = getNearestNeighbour(nearestNeighbour, this.neighbourhood, true);
double indicatorArgument = distance(inst, nearestNeighbour) / distance(nearestNeighbour, nnNearestNeighbour);
return indicatorArgument;
} | [
"public",
"double",
"getAnomalyScore",
"(",
"Instance",
"inst",
")",
"{",
"if",
"(",
"this",
".",
"neighbourhood",
".",
"size",
"(",
")",
"<",
"2",
")",
"return",
"1.0",
";",
"Instance",
"nearestNeighbour",
"=",
"getNearestNeighbour",
"(",
"inst",
",",
"this",
".",
"neighbourhood",
",",
"false",
")",
";",
"Instance",
"nnNearestNeighbour",
"=",
"getNearestNeighbour",
"(",
"nearestNeighbour",
",",
"this",
".",
"neighbourhood",
",",
"true",
")",
";",
"double",
"indicatorArgument",
"=",
"distance",
"(",
"inst",
",",
"nearestNeighbour",
")",
"/",
"distance",
"(",
"nearestNeighbour",
",",
"nnNearestNeighbour",
")",
";",
"return",
"indicatorArgument",
";",
"}"
] | Returns the anomaly score for an argument instance based on the distance from it to its nearest neighbour compared
to the distance from its nearest neighbour to the neighbour's nearest neighbour.
@param inst the argument instance
@return d(inst, instNN) / d(instNN, instNNNN) | [
"Returns",
"the",
"anomaly",
"score",
"for",
"an",
"argument",
"instance",
"based",
"on",
"the",
"distance",
"from",
"it",
"to",
"its",
"nearest",
"neighbour",
"compared",
"to",
"the",
"distance",
"from",
"its",
"nearest",
"neighbour",
"to",
"the",
"neighbour",
"s",
"nearest",
"neighbour",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java#L148-L159 |
28,907 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java | NearestNeighbourDescription.getNearestNeighbour | private Instance getNearestNeighbour(Instance inst, List<Instance> neighbourhood2, boolean inNbhd)
{
double dist = Double.MAX_VALUE;
Instance nearestNeighbour = null;
for(Instance candidateNN : neighbourhood2)
{
// If inst is in neighbourhood2 and an identical instance is found, then it is no longer required to
// look for inst and the inNbhd flag can be set to FALSE.
if(inNbhd && (distance(inst, candidateNN) == 0))
{
inNbhd = false;
}
else
{
if(distance(inst, candidateNN) < dist)
{
nearestNeighbour = candidateNN.copy();
dist = distance(inst, candidateNN);
}
}
}
return nearestNeighbour;
} | java | private Instance getNearestNeighbour(Instance inst, List<Instance> neighbourhood2, boolean inNbhd)
{
double dist = Double.MAX_VALUE;
Instance nearestNeighbour = null;
for(Instance candidateNN : neighbourhood2)
{
// If inst is in neighbourhood2 and an identical instance is found, then it is no longer required to
// look for inst and the inNbhd flag can be set to FALSE.
if(inNbhd && (distance(inst, candidateNN) == 0))
{
inNbhd = false;
}
else
{
if(distance(inst, candidateNN) < dist)
{
nearestNeighbour = candidateNN.copy();
dist = distance(inst, candidateNN);
}
}
}
return nearestNeighbour;
} | [
"private",
"Instance",
"getNearestNeighbour",
"(",
"Instance",
"inst",
",",
"List",
"<",
"Instance",
">",
"neighbourhood2",
",",
"boolean",
"inNbhd",
")",
"{",
"double",
"dist",
"=",
"Double",
".",
"MAX_VALUE",
";",
"Instance",
"nearestNeighbour",
"=",
"null",
";",
"for",
"(",
"Instance",
"candidateNN",
":",
"neighbourhood2",
")",
"{",
"// If inst is in neighbourhood2 and an identical instance is found, then it is no longer required to",
"// look for inst and the inNbhd flag can be set to FALSE.",
"if",
"(",
"inNbhd",
"&&",
"(",
"distance",
"(",
"inst",
",",
"candidateNN",
")",
"==",
"0",
")",
")",
"{",
"inNbhd",
"=",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"distance",
"(",
"inst",
",",
"candidateNN",
")",
"<",
"dist",
")",
"{",
"nearestNeighbour",
"=",
"candidateNN",
".",
"copy",
"(",
")",
";",
"dist",
"=",
"distance",
"(",
"inst",
",",
"candidateNN",
")",
";",
"}",
"}",
"}",
"return",
"nearestNeighbour",
";",
"}"
] | Searches the neighbourhood in order to find the argument instance's nearest neighbour.
@param inst the instance whose nearest neighbour is sought
@param neighbourhood2 the neighbourhood to search for the nearest neighbour
@param inNbhd if inst is in neighbourhood2: <b>true</b>, else: <b>false</b>
@return the instance that is inst's nearest neighbour in neighbourhood2 | [
"Searches",
"the",
"neighbourhood",
"in",
"order",
"to",
"find",
"the",
"argument",
"instance",
"s",
"nearest",
"neighbour",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java#L170-L194 |
28,908 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java | NearestNeighbourDescription.distance | private double distance(Instance inst1, Instance inst2)
{
double dist = 0.0;
for(int i = 0 ; i < inst1.numAttributes() ; i++)
{
dist += Math.pow((inst1.value(i) - inst2.value(i)), 2.0);
}
return Math.sqrt(dist);
} | java | private double distance(Instance inst1, Instance inst2)
{
double dist = 0.0;
for(int i = 0 ; i < inst1.numAttributes() ; i++)
{
dist += Math.pow((inst1.value(i) - inst2.value(i)), 2.0);
}
return Math.sqrt(dist);
} | [
"private",
"double",
"distance",
"(",
"Instance",
"inst1",
",",
"Instance",
"inst2",
")",
"{",
"double",
"dist",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"inst1",
".",
"numAttributes",
"(",
")",
";",
"i",
"++",
")",
"{",
"dist",
"+=",
"Math",
".",
"pow",
"(",
"(",
"inst1",
".",
"value",
"(",
"i",
")",
"-",
"inst2",
".",
"value",
"(",
"i",
")",
")",
",",
"2.0",
")",
";",
"}",
"return",
"Math",
".",
"sqrt",
"(",
"dist",
")",
";",
"}"
] | Calculates the Euclidean distance between two instances.
@param inst1 the first instance
@param inst2 the second instance
@return the Euclidean distance between the two instances | [
"Calculates",
"the",
"Euclidean",
"distance",
"between",
"two",
"instances",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/NearestNeighbourDescription.java#L204-L214 |
28,909 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/Point.java | Point.costOfPointToCenter | public double costOfPointToCenter(Point centre){
if(this.weight == 0.0){
return 0.0;
}
//stores the distance between p and centre
double distance = 0.0;
//loop counter
for(int l=0; l<this.dimension; l++){
//Centroid coordinate of the point
double centroidCoordinatePoint;
if(this.weight != 0.0){
centroidCoordinatePoint = this.coordinates[l] / this.weight;
} else {
centroidCoordinatePoint = this.coordinates[l];
}
//Centroid coordinate of the centre
double centroidCoordinateCentre;
if(centre.weight != 0.0){
centroidCoordinateCentre = centre.coordinates[l] / centre.weight;
} else {
centroidCoordinateCentre = centre.coordinates[l];
}
distance += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
return distance * this.weight;
} | java | public double costOfPointToCenter(Point centre){
if(this.weight == 0.0){
return 0.0;
}
//stores the distance between p and centre
double distance = 0.0;
//loop counter
for(int l=0; l<this.dimension; l++){
//Centroid coordinate of the point
double centroidCoordinatePoint;
if(this.weight != 0.0){
centroidCoordinatePoint = this.coordinates[l] / this.weight;
} else {
centroidCoordinatePoint = this.coordinates[l];
}
//Centroid coordinate of the centre
double centroidCoordinateCentre;
if(centre.weight != 0.0){
centroidCoordinateCentre = centre.coordinates[l] / centre.weight;
} else {
centroidCoordinateCentre = centre.coordinates[l];
}
distance += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
return distance * this.weight;
} | [
"public",
"double",
"costOfPointToCenter",
"(",
"Point",
"centre",
")",
"{",
"if",
"(",
"this",
".",
"weight",
"==",
"0.0",
")",
"{",
"return",
"0.0",
";",
"}",
"//stores the distance between p and centre",
"double",
"distance",
"=",
"0.0",
";",
"//loop counter",
"for",
"(",
"int",
"l",
"=",
"0",
";",
"l",
"<",
"this",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//Centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"this",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"this",
".",
"coordinates",
"[",
"l",
"]",
"/",
"this",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"this",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//Centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"centre",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"centre",
".",
"coordinates",
"[",
"l",
"]",
"/",
"centre",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"centre",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distance",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"return",
"distance",
"*",
"this",
".",
"weight",
";",
"}"
] | Computes the cost of this point with centre centre | [
"Computes",
"the",
"cost",
"of",
"this",
"point",
"with",
"centre",
"centre"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/Point.java#L161-L190 |
28,910 | Waikato/moa | moa/src/main/java/weka/core/MOAUtils.java | MOAUtils.fromOption | public static MOAObject fromOption(ClassOption option) {
return MOAUtils.fromCommandLine(option.getRequiredType(), option.getValueAsCLIString());
} | java | public static MOAObject fromOption(ClassOption option) {
return MOAUtils.fromCommandLine(option.getRequiredType(), option.getValueAsCLIString());
} | [
"public",
"static",
"MOAObject",
"fromOption",
"(",
"ClassOption",
"option",
")",
"{",
"return",
"MOAUtils",
".",
"fromCommandLine",
"(",
"option",
".",
"getRequiredType",
"(",
")",
",",
"option",
".",
"getValueAsCLIString",
"(",
")",
")",
";",
"}"
] | Creates a MOA object from the specified class option.
@param option the option to build the object from
@return the created object | [
"Creates",
"a",
"MOA",
"object",
"from",
"the",
"specified",
"class",
"option",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/weka/core/MOAUtils.java#L89-L91 |
28,911 | Waikato/moa | moa/src/main/java/weka/core/MOAUtils.java | MOAUtils.toCommandLine | public static String toCommandLine(MOAObject obj) {
String result = obj.getClass().getName();
if (obj instanceof AbstractOptionHandler)
result += " " + ((AbstractOptionHandler) obj).getOptions().getAsCLIString();
return result.trim();
} | java | public static String toCommandLine(MOAObject obj) {
String result = obj.getClass().getName();
if (obj instanceof AbstractOptionHandler)
result += " " + ((AbstractOptionHandler) obj).getOptions().getAsCLIString();
return result.trim();
} | [
"public",
"static",
"String",
"toCommandLine",
"(",
"MOAObject",
"obj",
")",
"{",
"String",
"result",
"=",
"obj",
".",
"getClass",
"(",
")",
".",
"getName",
"(",
")",
";",
"if",
"(",
"obj",
"instanceof",
"AbstractOptionHandler",
")",
"result",
"+=",
"\" \"",
"+",
"(",
"(",
"AbstractOptionHandler",
")",
"obj",
")",
".",
"getOptions",
"(",
")",
".",
"getAsCLIString",
"(",
")",
";",
"return",
"result",
".",
"trim",
"(",
")",
";",
"}"
] | Returs the commandline for the given object. If the object is not
derived from AbstractOptionHandler, then only the classname. Otherwise
the classname and the options are returned.
@param obj the object to generate the commandline for
@return the commandline | [
"Returs",
"the",
"commandline",
"for",
"the",
"given",
"object",
".",
"If",
"the",
"object",
"is",
"not",
"derived",
"from",
"AbstractOptionHandler",
"then",
"only",
"the",
"classname",
".",
"Otherwise",
"the",
"classname",
"and",
"the",
"options",
"are",
"returned",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/weka/core/MOAUtils.java#L101-L106 |
28,912 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/ArffLoader.java | ArffLoader.readDenseInstanceSparse | private Instance readDenseInstanceSparse() {
//Returns a dense instance
Instance instance = newDenseInstance(this.instanceInformation.numAttributes());
//System.out.println(this.instanceInformation.numAttributes());
int numAttribute;
try {
//while (streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
streamTokenizer.nextToken(); // Remove the '{' char
//For each line
while (streamTokenizer.ttype != StreamTokenizer.TT_EOL
&& streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
while (streamTokenizer.ttype != '}') {
//For each item
//streamTokenizer.nextToken();
//while (streamTokenizer.ttype != '}'){
//System.out.print(streamTokenizer.nval+":");
numAttribute = (int) streamTokenizer.nval;
streamTokenizer.nextToken();
if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) {
//System.out.print(streamTokenizer.nval + " ");
this.setValue(instance, numAttribute, streamTokenizer.nval, true);
//numAttribute++;
} else if (streamTokenizer.sval != null && (streamTokenizer.ttype == StreamTokenizer.TT_WORD
|| streamTokenizer.ttype == 34)) {
//System.out.print(streamTokenizer.sval + "/"+this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval)+" ");
if (this.auxAttributes.get(numAttribute).isNumeric()) {
this.setValue(instance, numAttribute, Double.valueOf(streamTokenizer.sval).doubleValue(), true);
} else {
this.setValue(instance, numAttribute, this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval), false);
//numAttribute++;
}
}
streamTokenizer.nextToken();
}
streamTokenizer.nextToken(); //Remove the '}' char
}
streamTokenizer.nextToken();
//System.out.println("EOL");
//}
} catch (IOException ex) {
Logger.getLogger(ArffLoader.class.getName()).log(Level.SEVERE, null, ex);
}
return instance;
} | java | private Instance readDenseInstanceSparse() {
//Returns a dense instance
Instance instance = newDenseInstance(this.instanceInformation.numAttributes());
//System.out.println(this.instanceInformation.numAttributes());
int numAttribute;
try {
//while (streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
streamTokenizer.nextToken(); // Remove the '{' char
//For each line
while (streamTokenizer.ttype != StreamTokenizer.TT_EOL
&& streamTokenizer.ttype != StreamTokenizer.TT_EOF) {
while (streamTokenizer.ttype != '}') {
//For each item
//streamTokenizer.nextToken();
//while (streamTokenizer.ttype != '}'){
//System.out.print(streamTokenizer.nval+":");
numAttribute = (int) streamTokenizer.nval;
streamTokenizer.nextToken();
if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) {
//System.out.print(streamTokenizer.nval + " ");
this.setValue(instance, numAttribute, streamTokenizer.nval, true);
//numAttribute++;
} else if (streamTokenizer.sval != null && (streamTokenizer.ttype == StreamTokenizer.TT_WORD
|| streamTokenizer.ttype == 34)) {
//System.out.print(streamTokenizer.sval + "/"+this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval)+" ");
if (this.auxAttributes.get(numAttribute).isNumeric()) {
this.setValue(instance, numAttribute, Double.valueOf(streamTokenizer.sval).doubleValue(), true);
} else {
this.setValue(instance, numAttribute, this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval), false);
//numAttribute++;
}
}
streamTokenizer.nextToken();
}
streamTokenizer.nextToken(); //Remove the '}' char
}
streamTokenizer.nextToken();
//System.out.println("EOL");
//}
} catch (IOException ex) {
Logger.getLogger(ArffLoader.class.getName()).log(Level.SEVERE, null, ex);
}
return instance;
} | [
"private",
"Instance",
"readDenseInstanceSparse",
"(",
")",
"{",
"//Returns a dense instance",
"Instance",
"instance",
"=",
"newDenseInstance",
"(",
"this",
".",
"instanceInformation",
".",
"numAttributes",
"(",
")",
")",
";",
"//System.out.println(this.instanceInformation.numAttributes());",
"int",
"numAttribute",
";",
"try",
"{",
"//while (streamTokenizer.ttype != StreamTokenizer.TT_EOF) {",
"streamTokenizer",
".",
"nextToken",
"(",
")",
";",
"// Remove the '{' char",
"//For each line",
"while",
"(",
"streamTokenizer",
".",
"ttype",
"!=",
"StreamTokenizer",
".",
"TT_EOL",
"&&",
"streamTokenizer",
".",
"ttype",
"!=",
"StreamTokenizer",
".",
"TT_EOF",
")",
"{",
"while",
"(",
"streamTokenizer",
".",
"ttype",
"!=",
"'",
"'",
")",
"{",
"//For each item",
"//streamTokenizer.nextToken();",
"//while (streamTokenizer.ttype != '}'){",
"//System.out.print(streamTokenizer.nval+\":\");",
"numAttribute",
"=",
"(",
"int",
")",
"streamTokenizer",
".",
"nval",
";",
"streamTokenizer",
".",
"nextToken",
"(",
")",
";",
"if",
"(",
"streamTokenizer",
".",
"ttype",
"==",
"StreamTokenizer",
".",
"TT_NUMBER",
")",
"{",
"//System.out.print(streamTokenizer.nval + \" \");",
"this",
".",
"setValue",
"(",
"instance",
",",
"numAttribute",
",",
"streamTokenizer",
".",
"nval",
",",
"true",
")",
";",
"//numAttribute++;",
"}",
"else",
"if",
"(",
"streamTokenizer",
".",
"sval",
"!=",
"null",
"&&",
"(",
"streamTokenizer",
".",
"ttype",
"==",
"StreamTokenizer",
".",
"TT_WORD",
"||",
"streamTokenizer",
".",
"ttype",
"==",
"34",
")",
")",
"{",
"//System.out.print(streamTokenizer.sval + \"/\"+this.instanceInformation.attribute(numAttribute).indexOfValue(streamTokenizer.sval)+\" \");",
"if",
"(",
"this",
".",
"auxAttributes",
".",
"get",
"(",
"numAttribute",
")",
".",
"isNumeric",
"(",
")",
")",
"{",
"this",
".",
"setValue",
"(",
"instance",
",",
"numAttribute",
",",
"Double",
".",
"valueOf",
"(",
"streamTokenizer",
".",
"sval",
")",
".",
"doubleValue",
"(",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"this",
".",
"setValue",
"(",
"instance",
",",
"numAttribute",
",",
"this",
".",
"instanceInformation",
".",
"attribute",
"(",
"numAttribute",
")",
".",
"indexOfValue",
"(",
"streamTokenizer",
".",
"sval",
")",
",",
"false",
")",
";",
"//numAttribute++;",
"}",
"}",
"streamTokenizer",
".",
"nextToken",
"(",
")",
";",
"}",
"streamTokenizer",
".",
"nextToken",
"(",
")",
";",
"//Remove the '}' char",
"}",
"streamTokenizer",
".",
"nextToken",
"(",
")",
";",
"//System.out.println(\"EOL\");",
"//}",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"Logger",
".",
"getLogger",
"(",
"ArffLoader",
".",
"class",
".",
"getName",
"(",
")",
")",
".",
"log",
"(",
"Level",
".",
"SEVERE",
",",
"null",
",",
"ex",
")",
";",
"}",
"return",
"instance",
";",
"}"
] | Reads an instance sparse and returns a dense one.
@return the instance | [
"Reads",
"an",
"instance",
"sparse",
"and",
"returns",
"a",
"dense",
"one",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/ArffLoader.java#L298-L344 |
28,913 | Waikato/moa | moa/src/main/java/moa/MakeObject.java | MakeObject.main | public static void main(String[] args) {
try {
System.err.println();
System.err.println(Globals.getWorkbenchInfoString());
System.err.println();
if (args.length < 2) {
System.err.println("usage: java " + MakeObject.class.getName()
+ " outputfile.moa \"<object name> <options>\"");
System.err.println();
} else {
String filename = args[0];
// build a single string by concatenating cli options
StringBuilder cliString = new StringBuilder();
for (int i = 1; i < args.length; i++) {
cliString.append(" " + args[i]);
}
// parse options
System.err.println("Making object...");
Object result = ClassOption.cliStringToObject(cliString.toString(), Object.class, null);
System.err.println("Writing object to file: " + filename);
SerializeUtils.writeToFile(new File(filename),
(Serializable) result);
System.err.println("Done.");
}
} catch (Exception ex) {
ex.printStackTrace();
}
} | java | public static void main(String[] args) {
try {
System.err.println();
System.err.println(Globals.getWorkbenchInfoString());
System.err.println();
if (args.length < 2) {
System.err.println("usage: java " + MakeObject.class.getName()
+ " outputfile.moa \"<object name> <options>\"");
System.err.println();
} else {
String filename = args[0];
// build a single string by concatenating cli options
StringBuilder cliString = new StringBuilder();
for (int i = 1; i < args.length; i++) {
cliString.append(" " + args[i]);
}
// parse options
System.err.println("Making object...");
Object result = ClassOption.cliStringToObject(cliString.toString(), Object.class, null);
System.err.println("Writing object to file: " + filename);
SerializeUtils.writeToFile(new File(filename),
(Serializable) result);
System.err.println("Done.");
}
} catch (Exception ex) {
ex.printStackTrace();
}
} | [
"public",
"static",
"void",
"main",
"(",
"String",
"[",
"]",
"args",
")",
"{",
"try",
"{",
"System",
".",
"err",
".",
"println",
"(",
")",
";",
"System",
".",
"err",
".",
"println",
"(",
"Globals",
".",
"getWorkbenchInfoString",
"(",
")",
")",
";",
"System",
".",
"err",
".",
"println",
"(",
")",
";",
"if",
"(",
"args",
".",
"length",
"<",
"2",
")",
"{",
"System",
".",
"err",
".",
"println",
"(",
"\"usage: java \"",
"+",
"MakeObject",
".",
"class",
".",
"getName",
"(",
")",
"+",
"\" outputfile.moa \\\"<object name> <options>\\\"\"",
")",
";",
"System",
".",
"err",
".",
"println",
"(",
")",
";",
"}",
"else",
"{",
"String",
"filename",
"=",
"args",
"[",
"0",
"]",
";",
"// build a single string by concatenating cli options",
"StringBuilder",
"cliString",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"args",
".",
"length",
";",
"i",
"++",
")",
"{",
"cliString",
".",
"append",
"(",
"\" \"",
"+",
"args",
"[",
"i",
"]",
")",
";",
"}",
"// parse options",
"System",
".",
"err",
".",
"println",
"(",
"\"Making object...\"",
")",
";",
"Object",
"result",
"=",
"ClassOption",
".",
"cliStringToObject",
"(",
"cliString",
".",
"toString",
"(",
")",
",",
"Object",
".",
"class",
",",
"null",
")",
";",
"System",
".",
"err",
".",
"println",
"(",
"\"Writing object to file: \"",
"+",
"filename",
")",
";",
"SerializeUtils",
".",
"writeToFile",
"(",
"new",
"File",
"(",
"filename",
")",
",",
"(",
"Serializable",
")",
"result",
")",
";",
"System",
".",
"err",
".",
"println",
"(",
"\"Done.\"",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"ex",
")",
"{",
"ex",
".",
"printStackTrace",
"(",
")",
";",
"}",
"}"
] | Main method for writing an object to a file from the command line.
@param args the options | [
"Main",
"method",
"for",
"writing",
"an",
"object",
"to",
"a",
"file",
"from",
"the",
"command",
"line",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/MakeObject.java#L42-L69 |
28,914 | Waikato/moa | moa/src/main/java/moa/cluster/CFCluster.java | CFCluster.addVectors | public static void addVectors(double[] a1, double[] a2) {
assert (a1 != null);
assert (a2 != null);
assert (a1.length == a2.length) : "Adding two arrays of different "
+ "length";
for (int i = 0; i < a1.length; i++) {
a1[i] += a2[i];
}
} | java | public static void addVectors(double[] a1, double[] a2) {
assert (a1 != null);
assert (a2 != null);
assert (a1.length == a2.length) : "Adding two arrays of different "
+ "length";
for (int i = 0; i < a1.length; i++) {
a1[i] += a2[i];
}
} | [
"public",
"static",
"void",
"addVectors",
"(",
"double",
"[",
"]",
"a1",
",",
"double",
"[",
"]",
"a2",
")",
"{",
"assert",
"(",
"a1",
"!=",
"null",
")",
";",
"assert",
"(",
"a2",
"!=",
"null",
")",
";",
"assert",
"(",
"a1",
".",
"length",
"==",
"a2",
".",
"length",
")",
":",
"\"Adding two arrays of different \"",
"+",
"\"length\"",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"a1",
".",
"length",
";",
"i",
"++",
")",
"{",
"a1",
"[",
"i",
"]",
"+=",
"a2",
"[",
"i",
"]",
";",
"}",
"}"
] | Adds the second array to the first array element by element. The arrays
must have the same length.
@param a1 Vector to which the second vector is added.
@param a2 Vector to be added. This vector does not change. | [
"Adds",
"the",
"second",
"array",
"to",
"the",
"first",
"array",
"element",
"by",
"element",
".",
"The",
"arrays",
"must",
"have",
"the",
"same",
"length",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/cluster/CFCluster.java#L162-L171 |
28,915 | Waikato/moa | moa/src/main/java/moa/gui/active/ALPreviewPanel.java | ALPreviewPanel.refresh | private void refresh() {
if (this.previewedThread != null) {
if (this.previewedThread.isComplete()) {
setLatestPreview();
disableRefresh();
} else {
this.previewedThread.getPreview(ALPreviewPanel.this);
}
}
} | java | private void refresh() {
if (this.previewedThread != null) {
if (this.previewedThread.isComplete()) {
setLatestPreview();
disableRefresh();
} else {
this.previewedThread.getPreview(ALPreviewPanel.this);
}
}
} | [
"private",
"void",
"refresh",
"(",
")",
"{",
"if",
"(",
"this",
".",
"previewedThread",
"!=",
"null",
")",
"{",
"if",
"(",
"this",
".",
"previewedThread",
".",
"isComplete",
"(",
")",
")",
"{",
"setLatestPreview",
"(",
")",
";",
"disableRefresh",
"(",
")",
";",
"}",
"else",
"{",
"this",
".",
"previewedThread",
".",
"getPreview",
"(",
"ALPreviewPanel",
".",
"this",
")",
";",
"}",
"}",
"}"
] | Refreshes the preview. | [
"Refreshes",
"the",
"preview",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/ALPreviewPanel.java#L116-L125 |
28,916 | Waikato/moa | moa/src/main/java/moa/gui/active/ALPreviewPanel.java | ALPreviewPanel.setTaskThreadToPreview | public void setTaskThreadToPreview(ALTaskThread thread) {
this.previewedThread = thread;
setLatestPreview();
if (thread == null) {
disableRefresh();
} else if (!thread.isComplete()) {
enableRefresh();
}
} | java | public void setTaskThreadToPreview(ALTaskThread thread) {
this.previewedThread = thread;
setLatestPreview();
if (thread == null) {
disableRefresh();
} else if (!thread.isComplete()) {
enableRefresh();
}
} | [
"public",
"void",
"setTaskThreadToPreview",
"(",
"ALTaskThread",
"thread",
")",
"{",
"this",
".",
"previewedThread",
"=",
"thread",
";",
"setLatestPreview",
"(",
")",
";",
"if",
"(",
"thread",
"==",
"null",
")",
"{",
"disableRefresh",
"(",
")",
";",
"}",
"else",
"if",
"(",
"!",
"thread",
".",
"isComplete",
"(",
")",
")",
"{",
"enableRefresh",
"(",
")",
";",
"}",
"}"
] | Sets the TaskThread that will be previewed.
@param thread TaskThread to be previewed | [
"Sets",
"the",
"TaskThread",
"that",
"will",
"be",
"previewed",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/ALPreviewPanel.java#L131-L139 |
28,917 | Waikato/moa | moa/src/main/java/moa/gui/active/ALPreviewPanel.java | ALPreviewPanel.getColorCodings | private Color[] getColorCodings(ALTaskThread thread) {
if (thread == null) {
return null;
}
ALMainTask task = (ALMainTask) thread.getTask();
List<ALTaskThread> subtaskThreads = task.getSubtaskThreads();
if (subtaskThreads.size() == 0) {
// no hierarchical thread, e.g. ALPrequentialEvaluationTask
return new Color[]{task.getColorCoding()};
}
if (task.getClass() == ALPartitionEvaluationTask.class) {
// if the task is a cross validation task, it displays the mean
// over the underlying params. The color coding therefore
// corresponds to the color coding of each of its subtasks.
return getColorCodings(subtaskThreads.get(0));
}
Color[] colors = new Color[subtaskThreads.size()];
for (int i = 0; i < subtaskThreads.size(); i++) {
ALMainTask subtask = (ALMainTask) subtaskThreads.get(i).getTask();
colors[i] = subtask.getColorCoding();
}
return colors;
} | java | private Color[] getColorCodings(ALTaskThread thread) {
if (thread == null) {
return null;
}
ALMainTask task = (ALMainTask) thread.getTask();
List<ALTaskThread> subtaskThreads = task.getSubtaskThreads();
if (subtaskThreads.size() == 0) {
// no hierarchical thread, e.g. ALPrequentialEvaluationTask
return new Color[]{task.getColorCoding()};
}
if (task.getClass() == ALPartitionEvaluationTask.class) {
// if the task is a cross validation task, it displays the mean
// over the underlying params. The color coding therefore
// corresponds to the color coding of each of its subtasks.
return getColorCodings(subtaskThreads.get(0));
}
Color[] colors = new Color[subtaskThreads.size()];
for (int i = 0; i < subtaskThreads.size(); i++) {
ALMainTask subtask = (ALMainTask) subtaskThreads.get(i).getTask();
colors[i] = subtask.getColorCoding();
}
return colors;
} | [
"private",
"Color",
"[",
"]",
"getColorCodings",
"(",
"ALTaskThread",
"thread",
")",
"{",
"if",
"(",
"thread",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"ALMainTask",
"task",
"=",
"(",
"ALMainTask",
")",
"thread",
".",
"getTask",
"(",
")",
";",
"List",
"<",
"ALTaskThread",
">",
"subtaskThreads",
"=",
"task",
".",
"getSubtaskThreads",
"(",
")",
";",
"if",
"(",
"subtaskThreads",
".",
"size",
"(",
")",
"==",
"0",
")",
"{",
"// no hierarchical thread, e.g. ALPrequentialEvaluationTask",
"return",
"new",
"Color",
"[",
"]",
"{",
"task",
".",
"getColorCoding",
"(",
")",
"}",
";",
"}",
"if",
"(",
"task",
".",
"getClass",
"(",
")",
"==",
"ALPartitionEvaluationTask",
".",
"class",
")",
"{",
"// if the task is a cross validation task, it displays the mean",
"// over the underlying params. The color coding therefore ",
"// corresponds to the color coding of each of its subtasks.",
"return",
"getColorCodings",
"(",
"subtaskThreads",
".",
"get",
"(",
"0",
")",
")",
";",
"}",
"Color",
"[",
"]",
"colors",
"=",
"new",
"Color",
"[",
"subtaskThreads",
".",
"size",
"(",
")",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"subtaskThreads",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"{",
"ALMainTask",
"subtask",
"=",
"(",
"ALMainTask",
")",
"subtaskThreads",
".",
"get",
"(",
"i",
")",
".",
"getTask",
"(",
")",
";",
"colors",
"[",
"i",
"]",
"=",
"subtask",
".",
"getColorCoding",
"(",
")",
";",
"}",
"return",
"colors",
";",
"}"
] | Reads the color codings of the subtasks.
@return array of color codings, one for each subtask | [
"Reads",
"the",
"color",
"codings",
"of",
"the",
"subtasks",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/ALPreviewPanel.java#L187-L215 |
28,918 | Waikato/moa | moa/src/main/java/moa/gui/active/ALPreviewPanel.java | ALPreviewPanel.disableRefresh | private void disableRefresh() {
this.refreshButton.setEnabled(false);
this.autoRefreshLabel.setEnabled(false);
this.autoRefreshComboBox.setEnabled(false);
this.autoRefreshTimer.stop();
} | java | private void disableRefresh() {
this.refreshButton.setEnabled(false);
this.autoRefreshLabel.setEnabled(false);
this.autoRefreshComboBox.setEnabled(false);
this.autoRefreshTimer.stop();
} | [
"private",
"void",
"disableRefresh",
"(",
")",
"{",
"this",
".",
"refreshButton",
".",
"setEnabled",
"(",
"false",
")",
";",
"this",
".",
"autoRefreshLabel",
".",
"setEnabled",
"(",
"false",
")",
";",
"this",
".",
"autoRefreshComboBox",
".",
"setEnabled",
"(",
"false",
")",
";",
"this",
".",
"autoRefreshTimer",
".",
"stop",
"(",
")",
";",
"}"
] | Disables refreshing. | [
"Disables",
"refreshing",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/ALPreviewPanel.java#L236-L241 |
28,919 | Waikato/moa | moa/src/main/java/moa/gui/active/ALPreviewPanel.java | ALPreviewPanel.enableRefresh | private void enableRefresh() {
this.refreshButton.setEnabled(true);
this.autoRefreshLabel.setEnabled(true);
this.autoRefreshComboBox.setEnabled(true);
updateAutoRefreshTimer();
} | java | private void enableRefresh() {
this.refreshButton.setEnabled(true);
this.autoRefreshLabel.setEnabled(true);
this.autoRefreshComboBox.setEnabled(true);
updateAutoRefreshTimer();
} | [
"private",
"void",
"enableRefresh",
"(",
")",
"{",
"this",
".",
"refreshButton",
".",
"setEnabled",
"(",
"true",
")",
";",
"this",
".",
"autoRefreshLabel",
".",
"setEnabled",
"(",
"true",
")",
";",
"this",
".",
"autoRefreshComboBox",
".",
"setEnabled",
"(",
"true",
")",
";",
"updateAutoRefreshTimer",
"(",
")",
";",
"}"
] | Enables refreshing. | [
"Enables",
"refreshing",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/ALPreviewPanel.java#L246-L251 |
28,920 | Waikato/moa | moa/src/main/java/moa/streams/filters/ReLUFilter.java | ReLUFilter.filterInstance | public Instance filterInstance(Instance x) {
if(dataset==null){
initialize(x);
}
double z_[] = new double[H+1];
int d = x.numAttributes() - 1; // suppose one class attribute (at the end)
for(int k = 0; k < H; k++) {
// for each hidden unit ...
double a_k = 0.; // k-th activation (dot product)
for(int j = 0; j < d; j++) {
a_k += (x.value(j) * W[k][j]);
}
z_[k] = (a_k > 0. ? a_k : 0.); // <------- can change threshold here
}
z_[H] = x.classValue();
Instance z = new InstanceImpl(x.weight(),z_);
z.setDataset(dataset);
return z;
} | java | public Instance filterInstance(Instance x) {
if(dataset==null){
initialize(x);
}
double z_[] = new double[H+1];
int d = x.numAttributes() - 1; // suppose one class attribute (at the end)
for(int k = 0; k < H; k++) {
// for each hidden unit ...
double a_k = 0.; // k-th activation (dot product)
for(int j = 0; j < d; j++) {
a_k += (x.value(j) * W[k][j]);
}
z_[k] = (a_k > 0. ? a_k : 0.); // <------- can change threshold here
}
z_[H] = x.classValue();
Instance z = new InstanceImpl(x.weight(),z_);
z.setDataset(dataset);
return z;
} | [
"public",
"Instance",
"filterInstance",
"(",
"Instance",
"x",
")",
"{",
"if",
"(",
"dataset",
"==",
"null",
")",
"{",
"initialize",
"(",
"x",
")",
";",
"}",
"double",
"z_",
"[",
"]",
"=",
"new",
"double",
"[",
"H",
"+",
"1",
"]",
";",
"int",
"d",
"=",
"x",
".",
"numAttributes",
"(",
")",
"-",
"1",
";",
"// suppose one class attribute (at the end)",
"for",
"(",
"int",
"k",
"=",
"0",
";",
"k",
"<",
"H",
";",
"k",
"++",
")",
"{",
"// for each hidden unit ...",
"double",
"a_k",
"=",
"0.",
";",
"// k-th activation (dot product)",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"d",
";",
"j",
"++",
")",
"{",
"a_k",
"+=",
"(",
"x",
".",
"value",
"(",
"j",
")",
"*",
"W",
"[",
"k",
"]",
"[",
"j",
"]",
")",
";",
"}",
"z_",
"[",
"k",
"]",
"=",
"(",
"a_k",
">",
"0.",
"?",
"a_k",
":",
"0.",
")",
";",
"// <------- can change threshold here",
"}",
"z_",
"[",
"H",
"]",
"=",
"x",
".",
"classValue",
"(",
")",
";",
"Instance",
"z",
"=",
"new",
"InstanceImpl",
"(",
"x",
".",
"weight",
"(",
")",
",",
"z_",
")",
";",
"z",
".",
"setDataset",
"(",
"dataset",
")",
";",
"return",
"z",
";",
"}"
] | Filter an instance.
Assume that the instance has a single class label, as the final attribute. Note that this may not always be the case!
@param x input instance
@return output instance | [
"Filter",
"an",
"instance",
".",
"Assume",
"that",
"the",
"instance",
"has",
"a",
"single",
"class",
"label",
"as",
"the",
"final",
"attribute",
".",
"Note",
"that",
"this",
"may",
"not",
"always",
"be",
"the",
"case!"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/streams/filters/ReLUFilter.java#L49-L74 |
28,921 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.treeNodeSplitCost | double treeNodeSplitCost(treeNode node, Point centreA, Point centreB){
//loop counter variable
int i;
//stores the cost
double sum = 0.0;
for(i=0; i<node.n; i++){
//loop counter variable
int l;
//stores the distance between p and centreA
double distanceA = 0.0;
for(l=0;l<node.points[i].dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(node.points[i].weight != 0.0){
centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
} else {
centroidCoordinatePoint = node.points[i].coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreA.weight != 0.0){
centroidCoordinateCentre = centreA.coordinates[l] / centreA.weight;
} else {
centroidCoordinateCentre = centreA.coordinates[l];
}
distanceA += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//stores the distance between p and centreB
double distanceB = 0.0;
for(l=0;l<node.points[i].dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(node.points[i].weight != 0.0){
centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
} else {
centroidCoordinatePoint = node.points[i].coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreB.weight != 0.0){
centroidCoordinateCentre = centreB.coordinates[l] / centreB.weight;
} else {
centroidCoordinateCentre = centreB.coordinates[l];
}
distanceB += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//add the cost of the closest centre to the sum
if(distanceA < distanceB){
sum += distanceA*node.points[i].weight;
} else {
sum += distanceB*node.points[i].weight;
}
}
//return the total cost
return sum;
} | java | double treeNodeSplitCost(treeNode node, Point centreA, Point centreB){
//loop counter variable
int i;
//stores the cost
double sum = 0.0;
for(i=0; i<node.n; i++){
//loop counter variable
int l;
//stores the distance between p and centreA
double distanceA = 0.0;
for(l=0;l<node.points[i].dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(node.points[i].weight != 0.0){
centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
} else {
centroidCoordinatePoint = node.points[i].coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreA.weight != 0.0){
centroidCoordinateCentre = centreA.coordinates[l] / centreA.weight;
} else {
centroidCoordinateCentre = centreA.coordinates[l];
}
distanceA += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//stores the distance between p and centreB
double distanceB = 0.0;
for(l=0;l<node.points[i].dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(node.points[i].weight != 0.0){
centroidCoordinatePoint = node.points[i].coordinates[l] / node.points[i].weight;
} else {
centroidCoordinatePoint = node.points[i].coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreB.weight != 0.0){
centroidCoordinateCentre = centreB.coordinates[l] / centreB.weight;
} else {
centroidCoordinateCentre = centreB.coordinates[l];
}
distanceB += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//add the cost of the closest centre to the sum
if(distanceA < distanceB){
sum += distanceA*node.points[i].weight;
} else {
sum += distanceB*node.points[i].weight;
}
}
//return the total cost
return sum;
} | [
"double",
"treeNodeSplitCost",
"(",
"treeNode",
"node",
",",
"Point",
"centreA",
",",
"Point",
"centreB",
")",
"{",
"//loop counter variable",
"int",
"i",
";",
"//stores the cost",
"double",
"sum",
"=",
"0.0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"node",
".",
"n",
";",
"i",
"++",
")",
"{",
"//loop counter variable",
"int",
"l",
";",
"//stores the distance between p and centreA",
"double",
"distanceA",
"=",
"0.0",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"node",
".",
"points",
"[",
"i",
"]",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"node",
".",
"points",
"[",
"i",
"]",
".",
"coordinates",
"[",
"l",
"]",
"/",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"node",
".",
"points",
"[",
"i",
"]",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"centreA",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"centreA",
".",
"coordinates",
"[",
"l",
"]",
"/",
"centreA",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"centreA",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distanceA",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"//stores the distance between p and centreB",
"double",
"distanceB",
"=",
"0.0",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"node",
".",
"points",
"[",
"i",
"]",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"node",
".",
"points",
"[",
"i",
"]",
".",
"coordinates",
"[",
"l",
"]",
"/",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"node",
".",
"points",
"[",
"i",
"]",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"centreB",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"centreB",
".",
"coordinates",
"[",
"l",
"]",
"/",
"centreB",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"centreB",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distanceB",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"//add the cost of the closest centre to the sum",
"if",
"(",
"distanceA",
"<",
"distanceB",
")",
"{",
"sum",
"+=",
"distanceA",
"*",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
";",
"}",
"else",
"{",
"sum",
"+=",
"distanceB",
"*",
"node",
".",
"points",
"[",
"i",
"]",
".",
"weight",
";",
"}",
"}",
"//return the total cost",
"return",
"sum",
";",
"}"
] | computes the hypothetical cost if the node would be split with new centers centreA, centreB | [
"computes",
"the",
"hypothetical",
"cost",
"if",
"the",
"node",
"would",
"be",
"split",
"with",
"new",
"centers",
"centreA",
"centreB"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L138-L207 |
28,922 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.treeNodeCostOfPoint | double treeNodeCostOfPoint(treeNode node, Point p){
if(p.weight == 0.0){
return 0.0;
}
//stores the distance between centre and p
double distance = 0.0;
//loop counter variable
int l;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(node.centre.weight != 0.0){
centroidCoordinateCentre = node.centre.coordinates[l] / node.centre.weight;
} else {
centroidCoordinateCentre = node.centre.coordinates[l];
}
distance += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
return distance * p.weight;
} | java | double treeNodeCostOfPoint(treeNode node, Point p){
if(p.weight == 0.0){
return 0.0;
}
//stores the distance between centre and p
double distance = 0.0;
//loop counter variable
int l;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(node.centre.weight != 0.0){
centroidCoordinateCentre = node.centre.coordinates[l] / node.centre.weight;
} else {
centroidCoordinateCentre = node.centre.coordinates[l];
}
distance += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
return distance * p.weight;
} | [
"double",
"treeNodeCostOfPoint",
"(",
"treeNode",
"node",
",",
"Point",
"p",
")",
"{",
"if",
"(",
"p",
".",
"weight",
"==",
"0.0",
")",
"{",
"return",
"0.0",
";",
"}",
"//stores the distance between centre and p",
"double",
"distance",
"=",
"0.0",
";",
"//loop counter variable",
"int",
"l",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"p",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"p",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
"/",
"p",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"node",
".",
"centre",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"node",
".",
"centre",
".",
"coordinates",
"[",
"l",
"]",
"/",
"node",
".",
"centre",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"node",
".",
"centre",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distance",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"return",
"distance",
"*",
"p",
".",
"weight",
";",
"}"
] | computes the cost of point p with the centre of treenode node | [
"computes",
"the",
"cost",
"of",
"point",
"p",
"with",
"the",
"centre",
"of",
"treenode",
"node"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L213-L244 |
28,923 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.isLeaf | boolean isLeaf(treeNode node){
if(node.lc == null && node.rc == null){
return true;
} else {
return false;
}
} | java | boolean isLeaf(treeNode node){
if(node.lc == null && node.rc == null){
return true;
} else {
return false;
}
} | [
"boolean",
"isLeaf",
"(",
"treeNode",
"node",
")",
"{",
"if",
"(",
"node",
".",
"lc",
"==",
"null",
"&&",
"node",
".",
"rc",
"==",
"null",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | tests if a node is a leaf | [
"tests",
"if",
"a",
"node",
"is",
"a",
"leaf"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L249-L257 |
28,924 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.determineClosestCentre | Point determineClosestCentre(Point p, Point centreA, Point centreB){
//loop counter variable
int l;
//stores the distance between p and centreA
double distanceA = 0.0;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreA.weight != 0.0){
centroidCoordinateCentre = centreA.coordinates[l] / centreA.weight;
} else {
centroidCoordinateCentre = centreA.coordinates[l];
}
distanceA += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//stores the distance between p and centreB
double distanceB = 0.0;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreB.weight != 0.0){
centroidCoordinateCentre = centreB.coordinates[l] / centreB.weight;
} else {
centroidCoordinateCentre = centreB.coordinates[l];
}
distanceB += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//return the nearest centre
if(distanceA < distanceB){
return centreA;
} else {
return centreB;
}
} | java | Point determineClosestCentre(Point p, Point centreA, Point centreB){
//loop counter variable
int l;
//stores the distance between p and centreA
double distanceA = 0.0;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreA.weight != 0.0){
centroidCoordinateCentre = centreA.coordinates[l] / centreA.weight;
} else {
centroidCoordinateCentre = centreA.coordinates[l];
}
distanceA += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//stores the distance between p and centreB
double distanceB = 0.0;
for(l=0;l<p.dimension;l++){
//centroid coordinate of the point
double centroidCoordinatePoint;
if(p.weight != 0.0){
centroidCoordinatePoint = p.coordinates[l] / p.weight;
} else {
centroidCoordinatePoint = p.coordinates[l];
}
//centroid coordinate of the centre
double centroidCoordinateCentre;
if(centreB.weight != 0.0){
centroidCoordinateCentre = centreB.coordinates[l] / centreB.weight;
} else {
centroidCoordinateCentre = centreB.coordinates[l];
}
distanceB += (centroidCoordinatePoint-centroidCoordinateCentre) *
(centroidCoordinatePoint-centroidCoordinateCentre) ;
}
//return the nearest centre
if(distanceA < distanceB){
return centreA;
} else {
return centreB;
}
} | [
"Point",
"determineClosestCentre",
"(",
"Point",
"p",
",",
"Point",
"centreA",
",",
"Point",
"centreB",
")",
"{",
"//loop counter variable",
"int",
"l",
";",
"//stores the distance between p and centreA",
"double",
"distanceA",
"=",
"0.0",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"p",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"p",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
"/",
"p",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"centreA",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"centreA",
".",
"coordinates",
"[",
"l",
"]",
"/",
"centreA",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"centreA",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distanceA",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"//stores the distance between p and centreB",
"double",
"distanceB",
"=",
"0.0",
";",
"for",
"(",
"l",
"=",
"0",
";",
"l",
"<",
"p",
".",
"dimension",
";",
"l",
"++",
")",
"{",
"//centroid coordinate of the point",
"double",
"centroidCoordinatePoint",
";",
"if",
"(",
"p",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
"/",
"p",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinatePoint",
"=",
"p",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"//centroid coordinate of the centre",
"double",
"centroidCoordinateCentre",
";",
"if",
"(",
"centreB",
".",
"weight",
"!=",
"0.0",
")",
"{",
"centroidCoordinateCentre",
"=",
"centreB",
".",
"coordinates",
"[",
"l",
"]",
"/",
"centreB",
".",
"weight",
";",
"}",
"else",
"{",
"centroidCoordinateCentre",
"=",
"centreB",
".",
"coordinates",
"[",
"l",
"]",
";",
"}",
"distanceB",
"+=",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
"*",
"(",
"centroidCoordinatePoint",
"-",
"centroidCoordinateCentre",
")",
";",
"}",
"//return the nearest centre",
"if",
"(",
"distanceA",
"<",
"distanceB",
")",
"{",
"return",
"centreA",
";",
"}",
"else",
"{",
"return",
"centreB",
";",
"}",
"}"
] | returns the next centre | [
"returns",
"the",
"next",
"centre"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L344-L401 |
28,925 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.treeFinished | boolean treeFinished(treeNode root){
return (root.parent == null && root.lc == null && root.rc == null);
} | java | boolean treeFinished(treeNode root){
return (root.parent == null && root.lc == null && root.rc == null);
} | [
"boolean",
"treeFinished",
"(",
"treeNode",
"root",
")",
"{",
"return",
"(",
"root",
".",
"parent",
"==",
"null",
"&&",
"root",
".",
"lc",
"==",
"null",
"&&",
"root",
".",
"rc",
"==",
"null",
")",
";",
"}"
] | Checks if the storage is completly freed | [
"Checks",
"if",
"the",
"storage",
"is",
"completly",
"freed"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L489-L491 |
28,926 | Waikato/moa | moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java | TreeCoreset.freeTree | void freeTree(treeNode root){
while(!treeFinished(root)){
if(root.lc == null && root.rc == null){
root = root.parent;
} else if(root.lc == null && root.rc != null){
//Schau ob rc ein Blatt ist
if(isLeaf(root.rc)){
//Gebe rechtes Kind frei
root.rc.free();
root.rc = null;
} else {
//Fahre mit rechtem Kind fort
root = root.rc;
}
} else if(root.lc != null) {
if(isLeaf(root.lc)){
root.lc.free();
root.lc = null;
} else {
root = root.lc;
}
}
}
root.free();
} | java | void freeTree(treeNode root){
while(!treeFinished(root)){
if(root.lc == null && root.rc == null){
root = root.parent;
} else if(root.lc == null && root.rc != null){
//Schau ob rc ein Blatt ist
if(isLeaf(root.rc)){
//Gebe rechtes Kind frei
root.rc.free();
root.rc = null;
} else {
//Fahre mit rechtem Kind fort
root = root.rc;
}
} else if(root.lc != null) {
if(isLeaf(root.lc)){
root.lc.free();
root.lc = null;
} else {
root = root.lc;
}
}
}
root.free();
} | [
"void",
"freeTree",
"(",
"treeNode",
"root",
")",
"{",
"while",
"(",
"!",
"treeFinished",
"(",
"root",
")",
")",
"{",
"if",
"(",
"root",
".",
"lc",
"==",
"null",
"&&",
"root",
".",
"rc",
"==",
"null",
")",
"{",
"root",
"=",
"root",
".",
"parent",
";",
"}",
"else",
"if",
"(",
"root",
".",
"lc",
"==",
"null",
"&&",
"root",
".",
"rc",
"!=",
"null",
")",
"{",
"//Schau ob rc ein Blatt ist",
"if",
"(",
"isLeaf",
"(",
"root",
".",
"rc",
")",
")",
"{",
"//Gebe rechtes Kind frei",
"root",
".",
"rc",
".",
"free",
"(",
")",
";",
"root",
".",
"rc",
"=",
"null",
";",
"}",
"else",
"{",
"//Fahre mit rechtem Kind fort",
"root",
"=",
"root",
".",
"rc",
";",
"}",
"}",
"else",
"if",
"(",
"root",
".",
"lc",
"!=",
"null",
")",
"{",
"if",
"(",
"isLeaf",
"(",
"root",
".",
"lc",
")",
")",
"{",
"root",
".",
"lc",
".",
"free",
"(",
")",
";",
"root",
".",
"lc",
"=",
"null",
";",
"}",
"else",
"{",
"root",
"=",
"root",
".",
"lc",
";",
"}",
"}",
"}",
"root",
".",
"free",
"(",
")",
";",
"}"
] | frees a tree of its storage | [
"frees",
"a",
"tree",
"of",
"its",
"storage"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/streamkm/TreeCoreset.java#L496-L522 |
28,927 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.initializeNetwork | private void initializeNetwork()
{
this.hiddenLayerSize = this.hiddenLayerOption.getValue();
this.learningRate = this.learningRateOption.getValue();
this.threshold = this.thresholdOption.getValue();
double[][] randomWeightsOne = new double[this.hiddenLayerSize][this.numAttributes];
double[][] randomWeightsTwo = new double[this.numAttributes][this.hiddenLayerSize];
for(int i = 0 ; i < this.numAttributes ; i++)
{
for(int j = 0 ; j < this.hiddenLayerSize ; j++)
{
randomWeightsOne[j][i] = this.classifierRandom.nextDouble();
randomWeightsTwo[i][j] = this.classifierRandom.nextDouble();
}
}
this.weightsOne = new Array2DRowRealMatrix(randomWeightsOne);
this.weightsTwo = new Array2DRowRealMatrix(randomWeightsTwo);
this.biasOne = this.classifierRandom.nextDouble();
this.biasTwo = this.classifierRandom.nextDouble();
this.reset = false;
} | java | private void initializeNetwork()
{
this.hiddenLayerSize = this.hiddenLayerOption.getValue();
this.learningRate = this.learningRateOption.getValue();
this.threshold = this.thresholdOption.getValue();
double[][] randomWeightsOne = new double[this.hiddenLayerSize][this.numAttributes];
double[][] randomWeightsTwo = new double[this.numAttributes][this.hiddenLayerSize];
for(int i = 0 ; i < this.numAttributes ; i++)
{
for(int j = 0 ; j < this.hiddenLayerSize ; j++)
{
randomWeightsOne[j][i] = this.classifierRandom.nextDouble();
randomWeightsTwo[i][j] = this.classifierRandom.nextDouble();
}
}
this.weightsOne = new Array2DRowRealMatrix(randomWeightsOne);
this.weightsTwo = new Array2DRowRealMatrix(randomWeightsTwo);
this.biasOne = this.classifierRandom.nextDouble();
this.biasTwo = this.classifierRandom.nextDouble();
this.reset = false;
} | [
"private",
"void",
"initializeNetwork",
"(",
")",
"{",
"this",
".",
"hiddenLayerSize",
"=",
"this",
".",
"hiddenLayerOption",
".",
"getValue",
"(",
")",
";",
"this",
".",
"learningRate",
"=",
"this",
".",
"learningRateOption",
".",
"getValue",
"(",
")",
";",
"this",
".",
"threshold",
"=",
"this",
".",
"thresholdOption",
".",
"getValue",
"(",
")",
";",
"double",
"[",
"]",
"[",
"]",
"randomWeightsOne",
"=",
"new",
"double",
"[",
"this",
".",
"hiddenLayerSize",
"]",
"[",
"this",
".",
"numAttributes",
"]",
";",
"double",
"[",
"]",
"[",
"]",
"randomWeightsTwo",
"=",
"new",
"double",
"[",
"this",
".",
"numAttributes",
"]",
"[",
"this",
".",
"hiddenLayerSize",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"numAttributes",
";",
"i",
"++",
")",
"{",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"this",
".",
"hiddenLayerSize",
";",
"j",
"++",
")",
"{",
"randomWeightsOne",
"[",
"j",
"]",
"[",
"i",
"]",
"=",
"this",
".",
"classifierRandom",
".",
"nextDouble",
"(",
")",
";",
"randomWeightsTwo",
"[",
"i",
"]",
"[",
"j",
"]",
"=",
"this",
".",
"classifierRandom",
".",
"nextDouble",
"(",
")",
";",
"}",
"}",
"this",
".",
"weightsOne",
"=",
"new",
"Array2DRowRealMatrix",
"(",
"randomWeightsOne",
")",
";",
"this",
".",
"weightsTwo",
"=",
"new",
"Array2DRowRealMatrix",
"(",
"randomWeightsTwo",
")",
";",
"this",
".",
"biasOne",
"=",
"this",
".",
"classifierRandom",
".",
"nextDouble",
"(",
")",
";",
"this",
".",
"biasTwo",
"=",
"this",
".",
"classifierRandom",
".",
"nextDouble",
"(",
")",
";",
"this",
".",
"reset",
"=",
"false",
";",
"}"
] | Initializes the autoencoder network. | [
"Initializes",
"the",
"autoencoder",
"network",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L126-L149 |
28,928 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.trainOnInstanceImpl | @Override
public void trainOnInstanceImpl(Instance inst)
{
//Initialize
if(this.reset)
{
this.numAttributes = inst.numAttributes()-1;
this.initializeNetwork();
}
this.backpropagation(inst);
} | java | @Override
public void trainOnInstanceImpl(Instance inst)
{
//Initialize
if(this.reset)
{
this.numAttributes = inst.numAttributes()-1;
this.initializeNetwork();
}
this.backpropagation(inst);
} | [
"@",
"Override",
"public",
"void",
"trainOnInstanceImpl",
"(",
"Instance",
"inst",
")",
"{",
"//Initialize",
"if",
"(",
"this",
".",
"reset",
")",
"{",
"this",
".",
"numAttributes",
"=",
"inst",
".",
"numAttributes",
"(",
")",
"-",
"1",
";",
"this",
".",
"initializeNetwork",
"(",
")",
";",
"}",
"this",
".",
"backpropagation",
"(",
"inst",
")",
";",
"}"
] | Uses backpropagation to update the weights in the autoencoder. | [
"Uses",
"backpropagation",
"to",
"update",
"the",
"weights",
"in",
"the",
"autoencoder",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L154-L165 |
28,929 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.firstLayer | private RealMatrix firstLayer(RealMatrix input)
{
RealMatrix hidden = (this.weightsOne.multiply(input)).scalarAdd(this.biasOne);
double[] tempValues = new double[this.hiddenLayerSize];
// Logistic function used for hidden layer activation
for(int i = 0 ; i < this.hiddenLayerSize ; i++)
{
tempValues[i] = 1.0 / (1.0 + Math.pow(Math.E, -1.0*hidden.getEntry(i, 0)));
}
return new Array2DRowRealMatrix(tempValues);
} | java | private RealMatrix firstLayer(RealMatrix input)
{
RealMatrix hidden = (this.weightsOne.multiply(input)).scalarAdd(this.biasOne);
double[] tempValues = new double[this.hiddenLayerSize];
// Logistic function used for hidden layer activation
for(int i = 0 ; i < this.hiddenLayerSize ; i++)
{
tempValues[i] = 1.0 / (1.0 + Math.pow(Math.E, -1.0*hidden.getEntry(i, 0)));
}
return new Array2DRowRealMatrix(tempValues);
} | [
"private",
"RealMatrix",
"firstLayer",
"(",
"RealMatrix",
"input",
")",
"{",
"RealMatrix",
"hidden",
"=",
"(",
"this",
".",
"weightsOne",
".",
"multiply",
"(",
"input",
")",
")",
".",
"scalarAdd",
"(",
"this",
".",
"biasOne",
")",
";",
"double",
"[",
"]",
"tempValues",
"=",
"new",
"double",
"[",
"this",
".",
"hiddenLayerSize",
"]",
";",
"// Logistic function used for hidden layer activation",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"hiddenLayerSize",
";",
"i",
"++",
")",
"{",
"tempValues",
"[",
"i",
"]",
"=",
"1.0",
"/",
"(",
"1.0",
"+",
"Math",
".",
"pow",
"(",
"Math",
".",
"E",
",",
"-",
"1.0",
"*",
"hidden",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
")",
")",
";",
"}",
"return",
"new",
"Array2DRowRealMatrix",
"(",
"tempValues",
")",
";",
"}"
] | Performs the requisite calculations between the input layer and the hidden layer.
@param input the input values
@return the activations of the hidden units | [
"Performs",
"the",
"requisite",
"calculations",
"between",
"the",
"input",
"layer",
"and",
"the",
"hidden",
"layer",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L174-L186 |
28,930 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.secondLayer | private RealMatrix secondLayer(RealMatrix hidden)
{
RealMatrix output = (this.weightsTwo.multiply(hidden)).scalarAdd(this.biasTwo);
double[] tempValues = new double[this.numAttributes];
// Logistic function used for output layer activation
for(int i = 0 ; i < this.numAttributes ; i++)
{
tempValues[i] = 1.0 / (1.0 + Math.pow(Math.E, -1.0*output.getEntry(i, 0)));
}
return new Array2DRowRealMatrix(tempValues);
} | java | private RealMatrix secondLayer(RealMatrix hidden)
{
RealMatrix output = (this.weightsTwo.multiply(hidden)).scalarAdd(this.biasTwo);
double[] tempValues = new double[this.numAttributes];
// Logistic function used for output layer activation
for(int i = 0 ; i < this.numAttributes ; i++)
{
tempValues[i] = 1.0 / (1.0 + Math.pow(Math.E, -1.0*output.getEntry(i, 0)));
}
return new Array2DRowRealMatrix(tempValues);
} | [
"private",
"RealMatrix",
"secondLayer",
"(",
"RealMatrix",
"hidden",
")",
"{",
"RealMatrix",
"output",
"=",
"(",
"this",
".",
"weightsTwo",
".",
"multiply",
"(",
"hidden",
")",
")",
".",
"scalarAdd",
"(",
"this",
".",
"biasTwo",
")",
";",
"double",
"[",
"]",
"tempValues",
"=",
"new",
"double",
"[",
"this",
".",
"numAttributes",
"]",
";",
"// Logistic function used for output layer activation",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"numAttributes",
";",
"i",
"++",
")",
"{",
"tempValues",
"[",
"i",
"]",
"=",
"1.0",
"/",
"(",
"1.0",
"+",
"Math",
".",
"pow",
"(",
"Math",
".",
"E",
",",
"-",
"1.0",
"*",
"output",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
")",
")",
";",
"}",
"return",
"new",
"Array2DRowRealMatrix",
"(",
"tempValues",
")",
";",
"}"
] | Performs the requisite calculations between the hidden layer and the output layer.
@param hidden the activations of the hidden units
@return the activations of the output layer | [
"Performs",
"the",
"requisite",
"calculations",
"between",
"the",
"hidden",
"layer",
"and",
"the",
"output",
"layer",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L195-L208 |
28,931 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.backpropagation | private void backpropagation(Instance inst)
{
double [] attributeValues = new double[this.numAttributes];
for(int i = 0 ; i < this.numAttributes ; i++)
{
attributeValues[i] = inst.value(i);
}
RealMatrix input = new Array2DRowRealMatrix(attributeValues);
RealMatrix hidden = firstLayer(input);
RealMatrix output = secondLayer(hidden);
RealMatrix delta = new Array2DRowRealMatrix(this.numAttributes,1);
double adjustBiasTwo = 0.0;
// Backpropagation to adjust the weights in layer two
for(int i = 0 ; i < this.numAttributes ; i++)
{
double inputVal = input.getEntry(i, 0);
double outputVal = output.getEntry(i, 0);
delta.setEntry(i, 0, (outputVal-inputVal)*outputVal*(1.0-outputVal));
//squaredError += 0.5*Math.pow((outputVal-inputVal), 2.0);
adjustBiasTwo -= this.learningRate*delta.getEntry(i, 0)*this.biasTwo;
}
RealMatrix adjustmentTwo = (delta.multiply(hidden.transpose())).scalarMultiply(-1.0*this.learningRate);
// Back propagation to adjust the weights in layer one
RealMatrix hidden2 = hidden.scalarMultiply(-1.0).scalarAdd(1.0);
RealMatrix delta2 = delta.transpose().multiply(this.weightsTwo);
double adjustBiasOne = 0.0;
for (int i = 0 ; i < this.hiddenLayerSize ; i++)
{
delta2.setEntry(0, i, delta2.getEntry(0, i)*hidden2.getEntry(i, 0)*hidden.getEntry(i, 0));
adjustBiasOne -= this.learningRate*delta2.getEntry(0, i)*this.biasOne;
}
RealMatrix adjustmentOne = delta2.transpose().multiply(input.transpose()).scalarMultiply(-1.0*this.learningRate);
this.weightsOne = this.weightsOne.add(adjustmentOne);
this.biasOne += adjustBiasOne;
this.weightsTwo = this.weightsTwo.add(adjustmentTwo);
this.biasTwo += adjustBiasTwo;
} | java | private void backpropagation(Instance inst)
{
double [] attributeValues = new double[this.numAttributes];
for(int i = 0 ; i < this.numAttributes ; i++)
{
attributeValues[i] = inst.value(i);
}
RealMatrix input = new Array2DRowRealMatrix(attributeValues);
RealMatrix hidden = firstLayer(input);
RealMatrix output = secondLayer(hidden);
RealMatrix delta = new Array2DRowRealMatrix(this.numAttributes,1);
double adjustBiasTwo = 0.0;
// Backpropagation to adjust the weights in layer two
for(int i = 0 ; i < this.numAttributes ; i++)
{
double inputVal = input.getEntry(i, 0);
double outputVal = output.getEntry(i, 0);
delta.setEntry(i, 0, (outputVal-inputVal)*outputVal*(1.0-outputVal));
//squaredError += 0.5*Math.pow((outputVal-inputVal), 2.0);
adjustBiasTwo -= this.learningRate*delta.getEntry(i, 0)*this.biasTwo;
}
RealMatrix adjustmentTwo = (delta.multiply(hidden.transpose())).scalarMultiply(-1.0*this.learningRate);
// Back propagation to adjust the weights in layer one
RealMatrix hidden2 = hidden.scalarMultiply(-1.0).scalarAdd(1.0);
RealMatrix delta2 = delta.transpose().multiply(this.weightsTwo);
double adjustBiasOne = 0.0;
for (int i = 0 ; i < this.hiddenLayerSize ; i++)
{
delta2.setEntry(0, i, delta2.getEntry(0, i)*hidden2.getEntry(i, 0)*hidden.getEntry(i, 0));
adjustBiasOne -= this.learningRate*delta2.getEntry(0, i)*this.biasOne;
}
RealMatrix adjustmentOne = delta2.transpose().multiply(input.transpose()).scalarMultiply(-1.0*this.learningRate);
this.weightsOne = this.weightsOne.add(adjustmentOne);
this.biasOne += adjustBiasOne;
this.weightsTwo = this.weightsTwo.add(adjustmentTwo);
this.biasTwo += adjustBiasTwo;
} | [
"private",
"void",
"backpropagation",
"(",
"Instance",
"inst",
")",
"{",
"double",
"[",
"]",
"attributeValues",
"=",
"new",
"double",
"[",
"this",
".",
"numAttributes",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"numAttributes",
";",
"i",
"++",
")",
"{",
"attributeValues",
"[",
"i",
"]",
"=",
"inst",
".",
"value",
"(",
"i",
")",
";",
"}",
"RealMatrix",
"input",
"=",
"new",
"Array2DRowRealMatrix",
"(",
"attributeValues",
")",
";",
"RealMatrix",
"hidden",
"=",
"firstLayer",
"(",
"input",
")",
";",
"RealMatrix",
"output",
"=",
"secondLayer",
"(",
"hidden",
")",
";",
"RealMatrix",
"delta",
"=",
"new",
"Array2DRowRealMatrix",
"(",
"this",
".",
"numAttributes",
",",
"1",
")",
";",
"double",
"adjustBiasTwo",
"=",
"0.0",
";",
"// Backpropagation to adjust the weights in layer two",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"numAttributes",
";",
"i",
"++",
")",
"{",
"double",
"inputVal",
"=",
"input",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
";",
"double",
"outputVal",
"=",
"output",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
";",
"delta",
".",
"setEntry",
"(",
"i",
",",
"0",
",",
"(",
"outputVal",
"-",
"inputVal",
")",
"*",
"outputVal",
"*",
"(",
"1.0",
"-",
"outputVal",
")",
")",
";",
"//squaredError += 0.5*Math.pow((outputVal-inputVal), 2.0);",
"adjustBiasTwo",
"-=",
"this",
".",
"learningRate",
"*",
"delta",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
"*",
"this",
".",
"biasTwo",
";",
"}",
"RealMatrix",
"adjustmentTwo",
"=",
"(",
"delta",
".",
"multiply",
"(",
"hidden",
".",
"transpose",
"(",
")",
")",
")",
".",
"scalarMultiply",
"(",
"-",
"1.0",
"*",
"this",
".",
"learningRate",
")",
";",
"// Back propagation to adjust the weights in layer one",
"RealMatrix",
"hidden2",
"=",
"hidden",
".",
"scalarMultiply",
"(",
"-",
"1.0",
")",
".",
"scalarAdd",
"(",
"1.0",
")",
";",
"RealMatrix",
"delta2",
"=",
"delta",
".",
"transpose",
"(",
")",
".",
"multiply",
"(",
"this",
".",
"weightsTwo",
")",
";",
"double",
"adjustBiasOne",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"hiddenLayerSize",
";",
"i",
"++",
")",
"{",
"delta2",
".",
"setEntry",
"(",
"0",
",",
"i",
",",
"delta2",
".",
"getEntry",
"(",
"0",
",",
"i",
")",
"*",
"hidden2",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
"*",
"hidden",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
")",
";",
"adjustBiasOne",
"-=",
"this",
".",
"learningRate",
"*",
"delta2",
".",
"getEntry",
"(",
"0",
",",
"i",
")",
"*",
"this",
".",
"biasOne",
";",
"}",
"RealMatrix",
"adjustmentOne",
"=",
"delta2",
".",
"transpose",
"(",
")",
".",
"multiply",
"(",
"input",
".",
"transpose",
"(",
")",
")",
".",
"scalarMultiply",
"(",
"-",
"1.0",
"*",
"this",
".",
"learningRate",
")",
";",
"this",
".",
"weightsOne",
"=",
"this",
".",
"weightsOne",
".",
"add",
"(",
"adjustmentOne",
")",
";",
"this",
".",
"biasOne",
"+=",
"adjustBiasOne",
";",
"this",
".",
"weightsTwo",
"=",
"this",
".",
"weightsTwo",
".",
"add",
"(",
"adjustmentTwo",
")",
";",
"this",
".",
"biasTwo",
"+=",
"adjustBiasTwo",
";",
"}"
] | Performs backpropagation based on a training instance.
@param inst the training instance | [
"Performs",
"backpropagation",
"based",
"on",
"a",
"training",
"instance",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L215-L261 |
28,932 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.getVotesForInstance | @Override
public double[] getVotesForInstance(Instance inst)
{
double[] votes = new double[2];
if (this.reset == false)
{
double error = this.getAnomalyScore(inst);
// Exponential function to convert the error [0, +inf) into a vote [1,0].
votes[0] = Math.pow(2.0, -1.0 * (error / this.threshold));
votes[1] = 1.0 - votes[0];
}
return votes;
} | java | @Override
public double[] getVotesForInstance(Instance inst)
{
double[] votes = new double[2];
if (this.reset == false)
{
double error = this.getAnomalyScore(inst);
// Exponential function to convert the error [0, +inf) into a vote [1,0].
votes[0] = Math.pow(2.0, -1.0 * (error / this.threshold));
votes[1] = 1.0 - votes[0];
}
return votes;
} | [
"@",
"Override",
"public",
"double",
"[",
"]",
"getVotesForInstance",
"(",
"Instance",
"inst",
")",
"{",
"double",
"[",
"]",
"votes",
"=",
"new",
"double",
"[",
"2",
"]",
";",
"if",
"(",
"this",
".",
"reset",
"==",
"false",
")",
"{",
"double",
"error",
"=",
"this",
".",
"getAnomalyScore",
"(",
"inst",
")",
";",
"// Exponential function to convert the error [0, +inf) into a vote [1,0].",
"votes",
"[",
"0",
"]",
"=",
"Math",
".",
"pow",
"(",
"2.0",
",",
"-",
"1.0",
"*",
"(",
"error",
"/",
"this",
".",
"threshold",
")",
")",
";",
"votes",
"[",
"1",
"]",
"=",
"1.0",
"-",
"votes",
"[",
"0",
"]",
";",
"}",
"return",
"votes",
";",
"}"
] | Calculates the error between the autoencoder's reconstruction of the input and the argument instances.
This error is converted to vote scores.
@param inst the instance to get votes for
@return the votes for the instance's label [normal, outlier] | [
"Calculates",
"the",
"error",
"between",
"the",
"autoencoder",
"s",
"reconstruction",
"of",
"the",
"input",
"and",
"the",
"argument",
"instances",
".",
"This",
"error",
"is",
"converted",
"to",
"vote",
"scores",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L305-L320 |
28,933 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.getAnomalyScore | public double getAnomalyScore(Instance inst)
{
double error = 0.0;
if(!this.reset)
{
double [] attributeValues = new double[inst.numAttributes()-1];
for(int i = 0 ; i < attributeValues.length ; i++)
{
attributeValues[i] = inst.value(i);
}
RealMatrix input = new Array2DRowRealMatrix(attributeValues);
RealMatrix output = secondLayer(firstLayer(input));
for(int i = 0 ; i < this.numAttributes ; i++)
{
error += 0.5 * Math.pow(output.getEntry(i, 0) - input.getEntry(i, 0), 2.0);
}
}
return error;
} | java | public double getAnomalyScore(Instance inst)
{
double error = 0.0;
if(!this.reset)
{
double [] attributeValues = new double[inst.numAttributes()-1];
for(int i = 0 ; i < attributeValues.length ; i++)
{
attributeValues[i] = inst.value(i);
}
RealMatrix input = new Array2DRowRealMatrix(attributeValues);
RealMatrix output = secondLayer(firstLayer(input));
for(int i = 0 ; i < this.numAttributes ; i++)
{
error += 0.5 * Math.pow(output.getEntry(i, 0) - input.getEntry(i, 0), 2.0);
}
}
return error;
} | [
"public",
"double",
"getAnomalyScore",
"(",
"Instance",
"inst",
")",
"{",
"double",
"error",
"=",
"0.0",
";",
"if",
"(",
"!",
"this",
".",
"reset",
")",
"{",
"double",
"[",
"]",
"attributeValues",
"=",
"new",
"double",
"[",
"inst",
".",
"numAttributes",
"(",
")",
"-",
"1",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"attributeValues",
".",
"length",
";",
"i",
"++",
")",
"{",
"attributeValues",
"[",
"i",
"]",
"=",
"inst",
".",
"value",
"(",
"i",
")",
";",
"}",
"RealMatrix",
"input",
"=",
"new",
"Array2DRowRealMatrix",
"(",
"attributeValues",
")",
";",
"RealMatrix",
"output",
"=",
"secondLayer",
"(",
"firstLayer",
"(",
"input",
")",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"numAttributes",
";",
"i",
"++",
")",
"{",
"error",
"+=",
"0.5",
"*",
"Math",
".",
"pow",
"(",
"output",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
"-",
"input",
".",
"getEntry",
"(",
"i",
",",
"0",
")",
",",
"2.0",
")",
";",
"}",
"}",
"return",
"error",
";",
"}"
] | Returns the squared error between the input value and the reconstructed value as
the anomaly score for the argument instance.
@param inst the instance to score
@return the argument instance's anomaly score. | [
"Returns",
"the",
"squared",
"error",
"between",
"the",
"input",
"value",
"and",
"the",
"reconstructed",
"value",
"as",
"the",
"anomaly",
"score",
"for",
"the",
"argument",
"instance",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L330-L354 |
28,934 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java | Autoencoder.initialize | @Override
public void initialize(Collection<Instance> trainingPoints)
{
Iterator<Instance> trgPtsIterator = trainingPoints.iterator();
if(trgPtsIterator.hasNext() && this.reset)
{
Instance inst = (Instance)trgPtsIterator.next();
this.numAttributes = inst.numAttributes()-1;
this.initializeNetwork();
}
while(trgPtsIterator.hasNext())
{
this.trainOnInstance((Instance)trgPtsIterator.next());
}
} | java | @Override
public void initialize(Collection<Instance> trainingPoints)
{
Iterator<Instance> trgPtsIterator = trainingPoints.iterator();
if(trgPtsIterator.hasNext() && this.reset)
{
Instance inst = (Instance)trgPtsIterator.next();
this.numAttributes = inst.numAttributes()-1;
this.initializeNetwork();
}
while(trgPtsIterator.hasNext())
{
this.trainOnInstance((Instance)trgPtsIterator.next());
}
} | [
"@",
"Override",
"public",
"void",
"initialize",
"(",
"Collection",
"<",
"Instance",
">",
"trainingPoints",
")",
"{",
"Iterator",
"<",
"Instance",
">",
"trgPtsIterator",
"=",
"trainingPoints",
".",
"iterator",
"(",
")",
";",
"if",
"(",
"trgPtsIterator",
".",
"hasNext",
"(",
")",
"&&",
"this",
".",
"reset",
")",
"{",
"Instance",
"inst",
"=",
"(",
"Instance",
")",
"trgPtsIterator",
".",
"next",
"(",
")",
";",
"this",
".",
"numAttributes",
"=",
"inst",
".",
"numAttributes",
"(",
")",
"-",
"1",
";",
"this",
".",
"initializeNetwork",
"(",
")",
";",
"}",
"while",
"(",
"trgPtsIterator",
".",
"hasNext",
"(",
")",
")",
"{",
"this",
".",
"trainOnInstance",
"(",
"(",
"Instance",
")",
"trgPtsIterator",
".",
"next",
"(",
")",
")",
";",
"}",
"}"
] | Initializes the Autoencoder classifier on the argument trainingPoints.
@param trainingPoints the Collection of instances on which to initialize the Autoencoder classifier. | [
"Initializes",
"the",
"Autoencoder",
"classifier",
"on",
"the",
"argument",
"trainingPoints",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/Autoencoder.java#L382-L398 |
28,935 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/AttributesInformation.java | AttributesInformation.setAttributes | public void setAttributes(Attribute[] v) {
this.attributes = v;
this.numberAttributes=v.length;
this.indexValues = new int[numberAttributes];
for (int i = 0; i < numberAttributes; i++) {
this.indexValues[i]=i;
}
} | java | public void setAttributes(Attribute[] v) {
this.attributes = v;
this.numberAttributes=v.length;
this.indexValues = new int[numberAttributes];
for (int i = 0; i < numberAttributes; i++) {
this.indexValues[i]=i;
}
} | [
"public",
"void",
"setAttributes",
"(",
"Attribute",
"[",
"]",
"v",
")",
"{",
"this",
".",
"attributes",
"=",
"v",
";",
"this",
".",
"numberAttributes",
"=",
"v",
".",
"length",
";",
"this",
".",
"indexValues",
"=",
"new",
"int",
"[",
"numberAttributes",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numberAttributes",
";",
"i",
"++",
")",
"{",
"this",
".",
"indexValues",
"[",
"i",
"]",
"=",
"i",
";",
"}",
"}"
] | Sets the attribute information.
@param v the new attribute information | [
"Sets",
"the",
"attribute",
"information",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/AttributesInformation.java#L113-L120 |
28,936 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/AttributesInformation.java | AttributesInformation.locateIndex | public int locateIndex(int index) {
int min = 0;
int max = this.indexValues.length - 1;
if (max == -1) {
return -1;
}
// Binary search
while ((this.indexValues[min] <= index) && (this.indexValues[max] >= index)) {
int current = (max + min) / 2;
if (this.indexValues[current] > index) {
max = current - 1;
} else if (this.indexValues[current] < index) {
min = current + 1;
} else {
return current;
}
}
if (this.indexValues[max] < index) {
return max;
} else {
return min - 1;
}
} | java | public int locateIndex(int index) {
int min = 0;
int max = this.indexValues.length - 1;
if (max == -1) {
return -1;
}
// Binary search
while ((this.indexValues[min] <= index) && (this.indexValues[max] >= index)) {
int current = (max + min) / 2;
if (this.indexValues[current] > index) {
max = current - 1;
} else if (this.indexValues[current] < index) {
min = current + 1;
} else {
return current;
}
}
if (this.indexValues[max] < index) {
return max;
} else {
return min - 1;
}
} | [
"public",
"int",
"locateIndex",
"(",
"int",
"index",
")",
"{",
"int",
"min",
"=",
"0",
";",
"int",
"max",
"=",
"this",
".",
"indexValues",
".",
"length",
"-",
"1",
";",
"if",
"(",
"max",
"==",
"-",
"1",
")",
"{",
"return",
"-",
"1",
";",
"}",
"// Binary search",
"while",
"(",
"(",
"this",
".",
"indexValues",
"[",
"min",
"]",
"<=",
"index",
")",
"&&",
"(",
"this",
".",
"indexValues",
"[",
"max",
"]",
">=",
"index",
")",
")",
"{",
"int",
"current",
"=",
"(",
"max",
"+",
"min",
")",
"/",
"2",
";",
"if",
"(",
"this",
".",
"indexValues",
"[",
"current",
"]",
">",
"index",
")",
"{",
"max",
"=",
"current",
"-",
"1",
";",
"}",
"else",
"if",
"(",
"this",
".",
"indexValues",
"[",
"current",
"]",
"<",
"index",
")",
"{",
"min",
"=",
"current",
"+",
"1",
";",
"}",
"else",
"{",
"return",
"current",
";",
"}",
"}",
"if",
"(",
"this",
".",
"indexValues",
"[",
"max",
"]",
"<",
"index",
")",
"{",
"return",
"max",
";",
"}",
"else",
"{",
"return",
"min",
"-",
"1",
";",
"}",
"}"
] | Locates the greatest index that is not greater than the given index.
@return the internal index of the attribute index. Returns -1 if no index
with this property could be found | [
"Locates",
"the",
"greatest",
"index",
"that",
"is",
"not",
"greater",
"than",
"the",
"given",
"index",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/AttributesInformation.java#L128-L153 |
28,937 | Waikato/moa | moa/src/main/java/moa/tasks/meta/MetaMainTask.java | MetaMainTask.setIsLastSubtaskOnLevel | public void setIsLastSubtaskOnLevel(
boolean[] parentIsLastSubtaskList, boolean isLastSubtask)
{
this.isLastSubtaskOnLevel =
new boolean[parentIsLastSubtaskList.length + 1];
for (int i = 0; i < parentIsLastSubtaskList.length; i++) {
this.isLastSubtaskOnLevel[i] = parentIsLastSubtaskList[i];
}
this.isLastSubtaskOnLevel[parentIsLastSubtaskList.length] =
isLastSubtask;
} | java | public void setIsLastSubtaskOnLevel(
boolean[] parentIsLastSubtaskList, boolean isLastSubtask)
{
this.isLastSubtaskOnLevel =
new boolean[parentIsLastSubtaskList.length + 1];
for (int i = 0; i < parentIsLastSubtaskList.length; i++) {
this.isLastSubtaskOnLevel[i] = parentIsLastSubtaskList[i];
}
this.isLastSubtaskOnLevel[parentIsLastSubtaskList.length] =
isLastSubtask;
} | [
"public",
"void",
"setIsLastSubtaskOnLevel",
"(",
"boolean",
"[",
"]",
"parentIsLastSubtaskList",
",",
"boolean",
"isLastSubtask",
")",
"{",
"this",
".",
"isLastSubtaskOnLevel",
"=",
"new",
"boolean",
"[",
"parentIsLastSubtaskList",
".",
"length",
"+",
"1",
"]",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parentIsLastSubtaskList",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"isLastSubtaskOnLevel",
"[",
"i",
"]",
"=",
"parentIsLastSubtaskList",
"[",
"i",
"]",
";",
"}",
"this",
".",
"isLastSubtaskOnLevel",
"[",
"parentIsLastSubtaskList",
".",
"length",
"]",
"=",
"isLastSubtask",
";",
"}"
] | Set the list of booleans indicating if the current branch in the
subtask tree is the last one on its respective level.
@param parentIsLastSubtaskList the internal list of the parent
@param isLastSubtask if the current subtask is the parents last one | [
"Set",
"the",
"list",
"of",
"booleans",
"indicating",
"if",
"the",
"current",
"branch",
"in",
"the",
"subtask",
"tree",
"is",
"the",
"last",
"one",
"on",
"its",
"respective",
"level",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/tasks/meta/MetaMainTask.java#L107-L118 |
28,938 | Waikato/moa | moa/src/main/java/moa/gui/experimentertab/RankingGraph.java | RankingGraph.fontSelection | public void fontSelection() {
FontChooserPanel panel = new FontChooserPanel(textFont);
int result
= JOptionPane.showConfirmDialog(
this, panel, "Font Selection",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE
);
if (result == JOptionPane.OK_OPTION) {
textFont = panel.getSelectedFont();
}
} | java | public void fontSelection() {
FontChooserPanel panel = new FontChooserPanel(textFont);
int result
= JOptionPane.showConfirmDialog(
this, panel, "Font Selection",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE
);
if (result == JOptionPane.OK_OPTION) {
textFont = panel.getSelectedFont();
}
} | [
"public",
"void",
"fontSelection",
"(",
")",
"{",
"FontChooserPanel",
"panel",
"=",
"new",
"FontChooserPanel",
"(",
"textFont",
")",
";",
"int",
"result",
"=",
"JOptionPane",
".",
"showConfirmDialog",
"(",
"this",
",",
"panel",
",",
"\"Font Selection\"",
",",
"JOptionPane",
".",
"OK_CANCEL_OPTION",
",",
"JOptionPane",
".",
"PLAIN_MESSAGE",
")",
";",
"if",
"(",
"result",
"==",
"JOptionPane",
".",
"OK_OPTION",
")",
"{",
"textFont",
"=",
"panel",
".",
"getSelectedFont",
"(",
")",
";",
"}",
"}"
] | Allow to select the text font. | [
"Allow",
"to",
"select",
"the",
"text",
"font",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/RankingGraph.java#L242-L255 |
28,939 | Waikato/moa | moa/src/main/java/com/github/javacliparser/Options.java | Options.splitParameterFromRemainingOptions | protected static String[] splitParameterFromRemainingOptions(
String cliString) {
String[] paramSplit = new String[2];
cliString = cliString.trim();
if (cliString.startsWith("\"") || cliString.startsWith("'")) {
int endQuoteIndex = cliString.indexOf(cliString.charAt(0), 1);
if (endQuoteIndex < 0) {
throw new IllegalArgumentException(
"Quotes not terminated correctly.");
}
paramSplit[0] = cliString.substring(1, endQuoteIndex);
paramSplit[1] = cliString.substring(endQuoteIndex + 1, cliString.length());
} else if (cliString.startsWith("(")) {
int bracketsOpen = 1;
int currPos = 1;
int nextCloseIndex = cliString.indexOf(")", currPos);
int nextOpenIndex = cliString.indexOf("(", currPos);
while (bracketsOpen != 0) {
if (nextCloseIndex < 0) {
throw new IllegalArgumentException("Brackets do not match.");
} else if ((nextOpenIndex < 0)
|| (nextCloseIndex < nextOpenIndex)) {
bracketsOpen--;
currPos = nextCloseIndex + 1;
nextCloseIndex = cliString.indexOf(")", currPos);
} else {
bracketsOpen++;
currPos = nextOpenIndex + 1;
nextOpenIndex = cliString.indexOf("(", currPos);
}
}
paramSplit[0] = cliString.substring(1, currPos - 1);
paramSplit[1] = cliString.substring(currPos, cliString.length());
} else {
int firstSpaceIndex = cliString.indexOf(" ", 0);
if (firstSpaceIndex >= 0) {
paramSplit[0] = cliString.substring(0, firstSpaceIndex);
paramSplit[1] = cliString.substring(firstSpaceIndex + 1,
cliString.length());
} else {
paramSplit[0] = cliString;
paramSplit[1] = "";
}
}
return paramSplit;
} | java | protected static String[] splitParameterFromRemainingOptions(
String cliString) {
String[] paramSplit = new String[2];
cliString = cliString.trim();
if (cliString.startsWith("\"") || cliString.startsWith("'")) {
int endQuoteIndex = cliString.indexOf(cliString.charAt(0), 1);
if (endQuoteIndex < 0) {
throw new IllegalArgumentException(
"Quotes not terminated correctly.");
}
paramSplit[0] = cliString.substring(1, endQuoteIndex);
paramSplit[1] = cliString.substring(endQuoteIndex + 1, cliString.length());
} else if (cliString.startsWith("(")) {
int bracketsOpen = 1;
int currPos = 1;
int nextCloseIndex = cliString.indexOf(")", currPos);
int nextOpenIndex = cliString.indexOf("(", currPos);
while (bracketsOpen != 0) {
if (nextCloseIndex < 0) {
throw new IllegalArgumentException("Brackets do not match.");
} else if ((nextOpenIndex < 0)
|| (nextCloseIndex < nextOpenIndex)) {
bracketsOpen--;
currPos = nextCloseIndex + 1;
nextCloseIndex = cliString.indexOf(")", currPos);
} else {
bracketsOpen++;
currPos = nextOpenIndex + 1;
nextOpenIndex = cliString.indexOf("(", currPos);
}
}
paramSplit[0] = cliString.substring(1, currPos - 1);
paramSplit[1] = cliString.substring(currPos, cliString.length());
} else {
int firstSpaceIndex = cliString.indexOf(" ", 0);
if (firstSpaceIndex >= 0) {
paramSplit[0] = cliString.substring(0, firstSpaceIndex);
paramSplit[1] = cliString.substring(firstSpaceIndex + 1,
cliString.length());
} else {
paramSplit[0] = cliString;
paramSplit[1] = "";
}
}
return paramSplit;
} | [
"protected",
"static",
"String",
"[",
"]",
"splitParameterFromRemainingOptions",
"(",
"String",
"cliString",
")",
"{",
"String",
"[",
"]",
"paramSplit",
"=",
"new",
"String",
"[",
"2",
"]",
";",
"cliString",
"=",
"cliString",
".",
"trim",
"(",
")",
";",
"if",
"(",
"cliString",
".",
"startsWith",
"(",
"\"\\\"\"",
")",
"||",
"cliString",
".",
"startsWith",
"(",
"\"'\"",
")",
")",
"{",
"int",
"endQuoteIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"cliString",
".",
"charAt",
"(",
"0",
")",
",",
"1",
")",
";",
"if",
"(",
"endQuoteIndex",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Quotes not terminated correctly.\"",
")",
";",
"}",
"paramSplit",
"[",
"0",
"]",
"=",
"cliString",
".",
"substring",
"(",
"1",
",",
"endQuoteIndex",
")",
";",
"paramSplit",
"[",
"1",
"]",
"=",
"cliString",
".",
"substring",
"(",
"endQuoteIndex",
"+",
"1",
",",
"cliString",
".",
"length",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"cliString",
".",
"startsWith",
"(",
"\"(\"",
")",
")",
"{",
"int",
"bracketsOpen",
"=",
"1",
";",
"int",
"currPos",
"=",
"1",
";",
"int",
"nextCloseIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"\")\"",
",",
"currPos",
")",
";",
"int",
"nextOpenIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"\"(\"",
",",
"currPos",
")",
";",
"while",
"(",
"bracketsOpen",
"!=",
"0",
")",
"{",
"if",
"(",
"nextCloseIndex",
"<",
"0",
")",
"{",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Brackets do not match.\"",
")",
";",
"}",
"else",
"if",
"(",
"(",
"nextOpenIndex",
"<",
"0",
")",
"||",
"(",
"nextCloseIndex",
"<",
"nextOpenIndex",
")",
")",
"{",
"bracketsOpen",
"--",
";",
"currPos",
"=",
"nextCloseIndex",
"+",
"1",
";",
"nextCloseIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"\")\"",
",",
"currPos",
")",
";",
"}",
"else",
"{",
"bracketsOpen",
"++",
";",
"currPos",
"=",
"nextOpenIndex",
"+",
"1",
";",
"nextOpenIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"\"(\"",
",",
"currPos",
")",
";",
"}",
"}",
"paramSplit",
"[",
"0",
"]",
"=",
"cliString",
".",
"substring",
"(",
"1",
",",
"currPos",
"-",
"1",
")",
";",
"paramSplit",
"[",
"1",
"]",
"=",
"cliString",
".",
"substring",
"(",
"currPos",
",",
"cliString",
".",
"length",
"(",
")",
")",
";",
"}",
"else",
"{",
"int",
"firstSpaceIndex",
"=",
"cliString",
".",
"indexOf",
"(",
"\" \"",
",",
"0",
")",
";",
"if",
"(",
"firstSpaceIndex",
">=",
"0",
")",
"{",
"paramSplit",
"[",
"0",
"]",
"=",
"cliString",
".",
"substring",
"(",
"0",
",",
"firstSpaceIndex",
")",
";",
"paramSplit",
"[",
"1",
"]",
"=",
"cliString",
".",
"substring",
"(",
"firstSpaceIndex",
"+",
"1",
",",
"cliString",
".",
"length",
"(",
")",
")",
";",
"}",
"else",
"{",
"paramSplit",
"[",
"0",
"]",
"=",
"cliString",
";",
"paramSplit",
"[",
"1",
"]",
"=",
"\"\"",
";",
"}",
"}",
"return",
"paramSplit",
";",
"}"
] | Internal method that splits a string into two parts - the parameter for
the current option, and the remaining options.
@param cliString
the command line string, beginning at an option parameter
@return an array of two strings - the first is the option paramter, the
second is the remaining cli string | [
"Internal",
"method",
"that",
"splits",
"a",
"string",
"into",
"two",
"parts",
"-",
"the",
"parameter",
"for",
"the",
"current",
"option",
"and",
"the",
"remaining",
"options",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/github/javacliparser/Options.java#L217-L262 |
28,940 | Waikato/moa | moa/src/main/java/moa/clusterers/clustree/ClusTree.java | ClusTree.updateToTop | private void updateToTop(Node toUpdate) {
while(toUpdate!=null){
for (Entry e: toUpdate.getEntries())
e.recalculateData();
if (toUpdate.getEntries()[0].getParentEntry()==null)
break;
toUpdate=toUpdate.getEntries()[0].getParentEntry().getNode();
}
} | java | private void updateToTop(Node toUpdate) {
while(toUpdate!=null){
for (Entry e: toUpdate.getEntries())
e.recalculateData();
if (toUpdate.getEntries()[0].getParentEntry()==null)
break;
toUpdate=toUpdate.getEntries()[0].getParentEntry().getNode();
}
} | [
"private",
"void",
"updateToTop",
"(",
"Node",
"toUpdate",
")",
"{",
"while",
"(",
"toUpdate",
"!=",
"null",
")",
"{",
"for",
"(",
"Entry",
"e",
":",
"toUpdate",
".",
"getEntries",
"(",
")",
")",
"e",
".",
"recalculateData",
"(",
")",
";",
"if",
"(",
"toUpdate",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
".",
"getParentEntry",
"(",
")",
"==",
"null",
")",
"break",
";",
"toUpdate",
"=",
"toUpdate",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
".",
"getParentEntry",
"(",
")",
".",
"getNode",
"(",
")",
";",
"}",
"}"
] | recalculates data for all entries, that lie on the path from the root to the
Entry toUpdate. | [
"recalculates",
"data",
"for",
"all",
"entries",
"that",
"lie",
"on",
"the",
"path",
"from",
"the",
"root",
"to",
"the",
"Entry",
"toUpdate",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusTree.java#L277-L285 |
28,941 | Waikato/moa | moa/src/main/java/moa/clusterers/clustree/ClusTree.java | ClusTree.insertHereWithSplit | private Entry insertHereWithSplit(Entry toInsert, Node insertNode,
long timestamp) {
//Handle root split
if (insertNode.getEntries()[0].getParentEntry()==null){
root.makeOlder(timestamp, negLambda);
Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
int numFreeEntries = insertNode.numFreeEntries();
if (irrelevantEntry != null) {
irrelevantEntry.overwriteOldEntry(toInsert);
}
else if (numFreeEntries>0){
insertNode.addEntry(toInsert, timestamp);
}
else{
this.numRootSplits++;
this.height += this.height < this.maxHeight ? 1 : 0;
Entry oldRootEntry = new Entry(this.numberDimensions,
root, timestamp, null, null);
Node newRoot = new Node(this.numberDimensions,
this.height);
Entry newRootEntry = split(toInsert, root, oldRootEntry, timestamp);
newRoot.addEntry(oldRootEntry, timestamp);
newRoot.addEntry(newRootEntry, timestamp);
this.root = newRoot;
for (Entry c : oldRootEntry.getChild().getEntries())
c.setParentEntry(root.getEntries()[0]);
for (Entry c : newRootEntry.getChild().getEntries())
c.setParentEntry(root.getEntries()[1]);
}
return null;
}
insertNode.makeOlder(timestamp, negLambda);
Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
int numFreeEntries = insertNode.numFreeEntries();
if (irrelevantEntry != null) {
irrelevantEntry.overwriteOldEntry(toInsert);
}
else if (numFreeEntries>0){
insertNode.addEntry(toInsert, timestamp);
}
else {
// We have to split.
Entry parentEntry = insertNode.getEntries()[0].getParentEntry();
Entry residualEntry = split(toInsert, insertNode, parentEntry, timestamp);
if (alsoUpdate!=null){
alsoUpdate = residualEntry;
}
Node nodeForResidualEntry = insertNode.getEntries()[0].getParentEntry().getNode();
//recursive call
return insertHereWithSplit(residualEntry, nodeForResidualEntry, timestamp);
}
//no Split
return null;
} | java | private Entry insertHereWithSplit(Entry toInsert, Node insertNode,
long timestamp) {
//Handle root split
if (insertNode.getEntries()[0].getParentEntry()==null){
root.makeOlder(timestamp, negLambda);
Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
int numFreeEntries = insertNode.numFreeEntries();
if (irrelevantEntry != null) {
irrelevantEntry.overwriteOldEntry(toInsert);
}
else if (numFreeEntries>0){
insertNode.addEntry(toInsert, timestamp);
}
else{
this.numRootSplits++;
this.height += this.height < this.maxHeight ? 1 : 0;
Entry oldRootEntry = new Entry(this.numberDimensions,
root, timestamp, null, null);
Node newRoot = new Node(this.numberDimensions,
this.height);
Entry newRootEntry = split(toInsert, root, oldRootEntry, timestamp);
newRoot.addEntry(oldRootEntry, timestamp);
newRoot.addEntry(newRootEntry, timestamp);
this.root = newRoot;
for (Entry c : oldRootEntry.getChild().getEntries())
c.setParentEntry(root.getEntries()[0]);
for (Entry c : newRootEntry.getChild().getEntries())
c.setParentEntry(root.getEntries()[1]);
}
return null;
}
insertNode.makeOlder(timestamp, negLambda);
Entry irrelevantEntry = insertNode.getIrrelevantEntry(this.weightThreshold);
int numFreeEntries = insertNode.numFreeEntries();
if (irrelevantEntry != null) {
irrelevantEntry.overwriteOldEntry(toInsert);
}
else if (numFreeEntries>0){
insertNode.addEntry(toInsert, timestamp);
}
else {
// We have to split.
Entry parentEntry = insertNode.getEntries()[0].getParentEntry();
Entry residualEntry = split(toInsert, insertNode, parentEntry, timestamp);
if (alsoUpdate!=null){
alsoUpdate = residualEntry;
}
Node nodeForResidualEntry = insertNode.getEntries()[0].getParentEntry().getNode();
//recursive call
return insertHereWithSplit(residualEntry, nodeForResidualEntry, timestamp);
}
//no Split
return null;
} | [
"private",
"Entry",
"insertHereWithSplit",
"(",
"Entry",
"toInsert",
",",
"Node",
"insertNode",
",",
"long",
"timestamp",
")",
"{",
"//Handle root split",
"if",
"(",
"insertNode",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
".",
"getParentEntry",
"(",
")",
"==",
"null",
")",
"{",
"root",
".",
"makeOlder",
"(",
"timestamp",
",",
"negLambda",
")",
";",
"Entry",
"irrelevantEntry",
"=",
"insertNode",
".",
"getIrrelevantEntry",
"(",
"this",
".",
"weightThreshold",
")",
";",
"int",
"numFreeEntries",
"=",
"insertNode",
".",
"numFreeEntries",
"(",
")",
";",
"if",
"(",
"irrelevantEntry",
"!=",
"null",
")",
"{",
"irrelevantEntry",
".",
"overwriteOldEntry",
"(",
"toInsert",
")",
";",
"}",
"else",
"if",
"(",
"numFreeEntries",
">",
"0",
")",
"{",
"insertNode",
".",
"addEntry",
"(",
"toInsert",
",",
"timestamp",
")",
";",
"}",
"else",
"{",
"this",
".",
"numRootSplits",
"++",
";",
"this",
".",
"height",
"+=",
"this",
".",
"height",
"<",
"this",
".",
"maxHeight",
"?",
"1",
":",
"0",
";",
"Entry",
"oldRootEntry",
"=",
"new",
"Entry",
"(",
"this",
".",
"numberDimensions",
",",
"root",
",",
"timestamp",
",",
"null",
",",
"null",
")",
";",
"Node",
"newRoot",
"=",
"new",
"Node",
"(",
"this",
".",
"numberDimensions",
",",
"this",
".",
"height",
")",
";",
"Entry",
"newRootEntry",
"=",
"split",
"(",
"toInsert",
",",
"root",
",",
"oldRootEntry",
",",
"timestamp",
")",
";",
"newRoot",
".",
"addEntry",
"(",
"oldRootEntry",
",",
"timestamp",
")",
";",
"newRoot",
".",
"addEntry",
"(",
"newRootEntry",
",",
"timestamp",
")",
";",
"this",
".",
"root",
"=",
"newRoot",
";",
"for",
"(",
"Entry",
"c",
":",
"oldRootEntry",
".",
"getChild",
"(",
")",
".",
"getEntries",
"(",
")",
")",
"c",
".",
"setParentEntry",
"(",
"root",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
")",
";",
"for",
"(",
"Entry",
"c",
":",
"newRootEntry",
".",
"getChild",
"(",
")",
".",
"getEntries",
"(",
")",
")",
"c",
".",
"setParentEntry",
"(",
"root",
".",
"getEntries",
"(",
")",
"[",
"1",
"]",
")",
";",
"}",
"return",
"null",
";",
"}",
"insertNode",
".",
"makeOlder",
"(",
"timestamp",
",",
"negLambda",
")",
";",
"Entry",
"irrelevantEntry",
"=",
"insertNode",
".",
"getIrrelevantEntry",
"(",
"this",
".",
"weightThreshold",
")",
";",
"int",
"numFreeEntries",
"=",
"insertNode",
".",
"numFreeEntries",
"(",
")",
";",
"if",
"(",
"irrelevantEntry",
"!=",
"null",
")",
"{",
"irrelevantEntry",
".",
"overwriteOldEntry",
"(",
"toInsert",
")",
";",
"}",
"else",
"if",
"(",
"numFreeEntries",
">",
"0",
")",
"{",
"insertNode",
".",
"addEntry",
"(",
"toInsert",
",",
"timestamp",
")",
";",
"}",
"else",
"{",
"// We have to split.",
"Entry",
"parentEntry",
"=",
"insertNode",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
".",
"getParentEntry",
"(",
")",
";",
"Entry",
"residualEntry",
"=",
"split",
"(",
"toInsert",
",",
"insertNode",
",",
"parentEntry",
",",
"timestamp",
")",
";",
"if",
"(",
"alsoUpdate",
"!=",
"null",
")",
"{",
"alsoUpdate",
"=",
"residualEntry",
";",
"}",
"Node",
"nodeForResidualEntry",
"=",
"insertNode",
".",
"getEntries",
"(",
")",
"[",
"0",
"]",
".",
"getParentEntry",
"(",
")",
".",
"getNode",
"(",
")",
";",
"//recursive call",
"return",
"insertHereWithSplit",
"(",
"residualEntry",
",",
"nodeForResidualEntry",
",",
"timestamp",
")",
";",
"}",
"//no Split",
"return",
"null",
";",
"}"
] | Method called by insertBreadthFirst.
@param toInsert
@param insertNode
@param timestamp
@return | [
"Method",
"called",
"by",
"insertBreadthFirst",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusTree.java#L294-L348 |
28,942 | Waikato/moa | moa/src/main/java/moa/clusterers/clustree/ClusTree.java | ClusTree.findBestLeafNode | private Node findBestLeafNode(ClusKernel newPoint) {
double minDist = Double.MAX_VALUE;
Node bestFit = null;
for (Node e: collectLeafNodes(root)){
if (newPoint.calcDistance(e.nearestEntry(newPoint).getData())<minDist){
bestFit = e;
minDist = newPoint.calcDistance(e.nearestEntry(newPoint).getData());
}
}
if (bestFit!=null)
return bestFit;
else
return root;
} | java | private Node findBestLeafNode(ClusKernel newPoint) {
double minDist = Double.MAX_VALUE;
Node bestFit = null;
for (Node e: collectLeafNodes(root)){
if (newPoint.calcDistance(e.nearestEntry(newPoint).getData())<minDist){
bestFit = e;
minDist = newPoint.calcDistance(e.nearestEntry(newPoint).getData());
}
}
if (bestFit!=null)
return bestFit;
else
return root;
} | [
"private",
"Node",
"findBestLeafNode",
"(",
"ClusKernel",
"newPoint",
")",
"{",
"double",
"minDist",
"=",
"Double",
".",
"MAX_VALUE",
";",
"Node",
"bestFit",
"=",
"null",
";",
"for",
"(",
"Node",
"e",
":",
"collectLeafNodes",
"(",
"root",
")",
")",
"{",
"if",
"(",
"newPoint",
".",
"calcDistance",
"(",
"e",
".",
"nearestEntry",
"(",
"newPoint",
")",
".",
"getData",
"(",
")",
")",
"<",
"minDist",
")",
"{",
"bestFit",
"=",
"e",
";",
"minDist",
"=",
"newPoint",
".",
"calcDistance",
"(",
"e",
".",
"nearestEntry",
"(",
"newPoint",
")",
".",
"getData",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"bestFit",
"!=",
"null",
")",
"return",
"bestFit",
";",
"else",
"return",
"root",
";",
"}"
] | This method calculates the distances between the new point and each Entry in a leaf node.
It returns the node that contains the entry with the smallest distance
to the new point.
@param newPoint
@return best fitting node | [
"This",
"method",
"calculates",
"the",
"distances",
"between",
"the",
"new",
"point",
"and",
"each",
"Entry",
"in",
"a",
"leaf",
"node",
".",
"It",
"returns",
"the",
"node",
"that",
"contains",
"the",
"entry",
"with",
"the",
"smallest",
"distance",
"to",
"the",
"new",
"point",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusTree.java#L432-L445 |
28,943 | Waikato/moa | moa/src/main/java/moa/clusterers/clustree/ClusTree.java | ClusTree.calculateBestMergeInNode | private BestMergeInNode calculateBestMergeInNode(Node node) {
assert (node.numFreeEntries() == 0);
Entry[] entries = node.getEntries();
int toMerge1 = -1;
int toMerge2 = -1;
double distanceBetweenMergeEntries = Double.NaN;
double minDistance = Double.MAX_VALUE;
for (int i = 0; i < entries.length; i++) {
Entry e1 = entries[i];
for (int j = i + 1; j < entries.length; j++) {
Entry e2 = entries[j];
double distance = e1.calcDistance(e2);
if (distance < minDistance) {
toMerge1 = i;
toMerge2 = j;
distanceBetweenMergeEntries = distance;
}
}
}
assert (toMerge1 != -1 && toMerge2 != -1);
if (Double.isNaN(distanceBetweenMergeEntries)) {
throw new RuntimeException("The minimal distance between two "
+ "Entrys in a Node was Double.MAX_VAUE. That can hardly "
+ "be right.");
}
return new BestMergeInNode(toMerge1, toMerge2,
distanceBetweenMergeEntries);
} | java | private BestMergeInNode calculateBestMergeInNode(Node node) {
assert (node.numFreeEntries() == 0);
Entry[] entries = node.getEntries();
int toMerge1 = -1;
int toMerge2 = -1;
double distanceBetweenMergeEntries = Double.NaN;
double minDistance = Double.MAX_VALUE;
for (int i = 0; i < entries.length; i++) {
Entry e1 = entries[i];
for (int j = i + 1; j < entries.length; j++) {
Entry e2 = entries[j];
double distance = e1.calcDistance(e2);
if (distance < minDistance) {
toMerge1 = i;
toMerge2 = j;
distanceBetweenMergeEntries = distance;
}
}
}
assert (toMerge1 != -1 && toMerge2 != -1);
if (Double.isNaN(distanceBetweenMergeEntries)) {
throw new RuntimeException("The minimal distance between two "
+ "Entrys in a Node was Double.MAX_VAUE. That can hardly "
+ "be right.");
}
return new BestMergeInNode(toMerge1, toMerge2,
distanceBetweenMergeEntries);
} | [
"private",
"BestMergeInNode",
"calculateBestMergeInNode",
"(",
"Node",
"node",
")",
"{",
"assert",
"(",
"node",
".",
"numFreeEntries",
"(",
")",
"==",
"0",
")",
";",
"Entry",
"[",
"]",
"entries",
"=",
"node",
".",
"getEntries",
"(",
")",
";",
"int",
"toMerge1",
"=",
"-",
"1",
";",
"int",
"toMerge2",
"=",
"-",
"1",
";",
"double",
"distanceBetweenMergeEntries",
"=",
"Double",
".",
"NaN",
";",
"double",
"minDistance",
"=",
"Double",
".",
"MAX_VALUE",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"entries",
".",
"length",
";",
"i",
"++",
")",
"{",
"Entry",
"e1",
"=",
"entries",
"[",
"i",
"]",
";",
"for",
"(",
"int",
"j",
"=",
"i",
"+",
"1",
";",
"j",
"<",
"entries",
".",
"length",
";",
"j",
"++",
")",
"{",
"Entry",
"e2",
"=",
"entries",
"[",
"j",
"]",
";",
"double",
"distance",
"=",
"e1",
".",
"calcDistance",
"(",
"e2",
")",
";",
"if",
"(",
"distance",
"<",
"minDistance",
")",
"{",
"toMerge1",
"=",
"i",
";",
"toMerge2",
"=",
"j",
";",
"distanceBetweenMergeEntries",
"=",
"distance",
";",
"}",
"}",
"}",
"assert",
"(",
"toMerge1",
"!=",
"-",
"1",
"&&",
"toMerge2",
"!=",
"-",
"1",
")",
";",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"distanceBetweenMergeEntries",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The minimal distance between two \"",
"+",
"\"Entrys in a Node was Double.MAX_VAUE. That can hardly \"",
"+",
"\"be right.\"",
")",
";",
"}",
"return",
"new",
"BestMergeInNode",
"(",
"toMerge1",
",",
"toMerge2",
",",
"distanceBetweenMergeEntries",
")",
";",
"}"
] | Calculates the best merge possible between two nodes in a node. This
means that the pair with the smallest distance is found.
@param node The node in which these two entries have to be found.
@return An object which encodes the two position of the entries with the
smallest distance in the node and the distance between them.
@see BestMergeInNode
@see Entry#calcDistance(tree.Entry) | [
"Calculates",
"the",
"best",
"merge",
"possible",
"between",
"two",
"nodes",
"in",
"a",
"node",
".",
"This",
"means",
"that",
"the",
"pair",
"with",
"the",
"smallest",
"distance",
"is",
"found",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/clustree/ClusTree.java#L571-L603 |
28,944 | Waikato/moa | moa/src/main/java/moa/tasks/EvaluateClustering.java | EvaluateClustering.setMeasures | protected void setMeasures(boolean[] measures)
{
this.generalEvalOption.setValue(measures[0]);
this.f1Option.setValue(measures[1]);
this.entropyOption.setValue(measures[2]);
this.cmmOption.setValue(measures[3]);
this.ssqOption.setValue(measures[4]);
this.separationOption.setValue(measures[5]);
this.silhouetteOption.setValue(measures[6]);
this.statisticalOption.setValue(measures[7]);
} | java | protected void setMeasures(boolean[] measures)
{
this.generalEvalOption.setValue(measures[0]);
this.f1Option.setValue(measures[1]);
this.entropyOption.setValue(measures[2]);
this.cmmOption.setValue(measures[3]);
this.ssqOption.setValue(measures[4]);
this.separationOption.setValue(measures[5]);
this.silhouetteOption.setValue(measures[6]);
this.statisticalOption.setValue(measures[7]);
} | [
"protected",
"void",
"setMeasures",
"(",
"boolean",
"[",
"]",
"measures",
")",
"{",
"this",
".",
"generalEvalOption",
".",
"setValue",
"(",
"measures",
"[",
"0",
"]",
")",
";",
"this",
".",
"f1Option",
".",
"setValue",
"(",
"measures",
"[",
"1",
"]",
")",
";",
"this",
".",
"entropyOption",
".",
"setValue",
"(",
"measures",
"[",
"2",
"]",
")",
";",
"this",
".",
"cmmOption",
".",
"setValue",
"(",
"measures",
"[",
"3",
"]",
")",
";",
"this",
".",
"ssqOption",
".",
"setValue",
"(",
"measures",
"[",
"4",
"]",
")",
";",
"this",
".",
"separationOption",
".",
"setValue",
"(",
"measures",
"[",
"5",
"]",
")",
";",
"this",
".",
"silhouetteOption",
".",
"setValue",
"(",
"measures",
"[",
"6",
"]",
")",
";",
"this",
".",
"statisticalOption",
".",
"setValue",
"(",
"measures",
"[",
"7",
"]",
")",
";",
"}"
] | Given an array summarizing selected measures, set the appropriate flag options | [
"Given",
"an",
"array",
"summarizing",
"selected",
"measures",
"set",
"the",
"appropriate",
"flag",
"options"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/tasks/EvaluateClustering.java#L97-L107 |
28,945 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/GridCluster.java | GridCluster.isConnected | public boolean isConnected()
{
this.visited = new HashMap<DensityGrid, Boolean>();
Iterator<DensityGrid> initIter = this.grids.keySet().iterator();
DensityGrid dg;
if (initIter.hasNext())
{
dg = initIter.next();
visited.put(dg, this.grids.get(dg));
boolean changesMade;
do{
changesMade = false;
Iterator<Map.Entry<DensityGrid, Boolean>> visIter = this.visited.entrySet().iterator();
HashMap<DensityGrid, Boolean> toAdd = new HashMap<DensityGrid, Boolean>();
while(visIter.hasNext() && toAdd.isEmpty())
{
Map.Entry<DensityGrid, Boolean> toVisit = visIter.next();
DensityGrid dg2V = toVisit.getKey();
Iterator<DensityGrid> dg2VNeighbourhood = dg2V.getNeighbours().iterator();
while(dg2VNeighbourhood.hasNext())
{
DensityGrid dg2VN = dg2VNeighbourhood.next();
if(this.grids.containsKey(dg2VN) && !this.visited.containsKey(dg2VN))
toAdd.put(dg2VN, this.grids.get(dg2VN));
}
}
if(!toAdd.isEmpty())
{
this.visited.putAll(toAdd);
changesMade = true;
}
}while(changesMade);
}
if (this.visited.size() == this.grids.size())
{
//System.out.println("The cluster is still connected. "+this.visited.size()+" of "+this.grids.size()+" reached.");
return true;
}
else
{
//System.out.println("The cluster is no longer connected. "+this.visited.size()+" of "+this.grids.size()+" reached.");
return false;
}
} | java | public boolean isConnected()
{
this.visited = new HashMap<DensityGrid, Boolean>();
Iterator<DensityGrid> initIter = this.grids.keySet().iterator();
DensityGrid dg;
if (initIter.hasNext())
{
dg = initIter.next();
visited.put(dg, this.grids.get(dg));
boolean changesMade;
do{
changesMade = false;
Iterator<Map.Entry<DensityGrid, Boolean>> visIter = this.visited.entrySet().iterator();
HashMap<DensityGrid, Boolean> toAdd = new HashMap<DensityGrid, Boolean>();
while(visIter.hasNext() && toAdd.isEmpty())
{
Map.Entry<DensityGrid, Boolean> toVisit = visIter.next();
DensityGrid dg2V = toVisit.getKey();
Iterator<DensityGrid> dg2VNeighbourhood = dg2V.getNeighbours().iterator();
while(dg2VNeighbourhood.hasNext())
{
DensityGrid dg2VN = dg2VNeighbourhood.next();
if(this.grids.containsKey(dg2VN) && !this.visited.containsKey(dg2VN))
toAdd.put(dg2VN, this.grids.get(dg2VN));
}
}
if(!toAdd.isEmpty())
{
this.visited.putAll(toAdd);
changesMade = true;
}
}while(changesMade);
}
if (this.visited.size() == this.grids.size())
{
//System.out.println("The cluster is still connected. "+this.visited.size()+" of "+this.grids.size()+" reached.");
return true;
}
else
{
//System.out.println("The cluster is no longer connected. "+this.visited.size()+" of "+this.grids.size()+" reached.");
return false;
}
} | [
"public",
"boolean",
"isConnected",
"(",
")",
"{",
"this",
".",
"visited",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"Boolean",
">",
"(",
")",
";",
"Iterator",
"<",
"DensityGrid",
">",
"initIter",
"=",
"this",
".",
"grids",
".",
"keySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"DensityGrid",
"dg",
";",
"if",
"(",
"initIter",
".",
"hasNext",
"(",
")",
")",
"{",
"dg",
"=",
"initIter",
".",
"next",
"(",
")",
";",
"visited",
".",
"put",
"(",
"dg",
",",
"this",
".",
"grids",
".",
"get",
"(",
"dg",
")",
")",
";",
"boolean",
"changesMade",
";",
"do",
"{",
"changesMade",
"=",
"false",
";",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"Boolean",
">",
">",
"visIter",
"=",
"this",
".",
"visited",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"HashMap",
"<",
"DensityGrid",
",",
"Boolean",
">",
"toAdd",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"Boolean",
">",
"(",
")",
";",
"while",
"(",
"visIter",
".",
"hasNext",
"(",
")",
"&&",
"toAdd",
".",
"isEmpty",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"Boolean",
">",
"toVisit",
"=",
"visIter",
".",
"next",
"(",
")",
";",
"DensityGrid",
"dg2V",
"=",
"toVisit",
".",
"getKey",
"(",
")",
";",
"Iterator",
"<",
"DensityGrid",
">",
"dg2VNeighbourhood",
"=",
"dg2V",
".",
"getNeighbours",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"dg2VNeighbourhood",
".",
"hasNext",
"(",
")",
")",
"{",
"DensityGrid",
"dg2VN",
"=",
"dg2VNeighbourhood",
".",
"next",
"(",
")",
";",
"if",
"(",
"this",
".",
"grids",
".",
"containsKey",
"(",
"dg2VN",
")",
"&&",
"!",
"this",
".",
"visited",
".",
"containsKey",
"(",
"dg2VN",
")",
")",
"toAdd",
".",
"put",
"(",
"dg2VN",
",",
"this",
".",
"grids",
".",
"get",
"(",
"dg2VN",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"toAdd",
".",
"isEmpty",
"(",
")",
")",
"{",
"this",
".",
"visited",
".",
"putAll",
"(",
"toAdd",
")",
";",
"changesMade",
"=",
"true",
";",
"}",
"}",
"while",
"(",
"changesMade",
")",
";",
"}",
"if",
"(",
"this",
".",
"visited",
".",
"size",
"(",
")",
"==",
"this",
".",
"grids",
".",
"size",
"(",
")",
")",
"{",
"//System.out.println(\"The cluster is still connected. \"+this.visited.size()+\" of \"+this.grids.size()+\" reached.\");",
"return",
"true",
";",
"}",
"else",
"{",
"//System.out.println(\"The cluster is no longer connected. \"+this.visited.size()+\" of \"+this.grids.size()+\" reached.\");",
"return",
"false",
";",
"}",
"}"
] | Tests a grid cluster for connectedness according to Definition 3.4, Grid Group, from
Chen and Tu 2007.
Selects one density grid in the grid cluster as a starting point and iterates repeatedly
through its neighbours until no more density grids in the grid cluster can be visited.
@return TRUE if the cluster represent one single grid group; FALSE otherwise. | [
"Tests",
"a",
"grid",
"cluster",
"for",
"connectedness",
"according",
"to",
"Definition",
"3",
".",
"4",
"Grid",
"Group",
"from",
"Chen",
"and",
"Tu",
"2007",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/GridCluster.java#L228-L282 |
28,946 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/GridCluster.java | GridCluster.getInclusionProbability | @Override
public double getInclusionProbability(Instance instance) {
Iterator<Map.Entry<DensityGrid, Boolean>> gridIter = grids.entrySet().iterator();
while(gridIter.hasNext())
{
Map.Entry<DensityGrid, Boolean> grid = gridIter.next();
DensityGrid dg = grid.getKey();
if(dg.getInclusionProbability(instance) == 1.0)
return 1.0;
}
return 0.0;
} | java | @Override
public double getInclusionProbability(Instance instance) {
Iterator<Map.Entry<DensityGrid, Boolean>> gridIter = grids.entrySet().iterator();
while(gridIter.hasNext())
{
Map.Entry<DensityGrid, Boolean> grid = gridIter.next();
DensityGrid dg = grid.getKey();
if(dg.getInclusionProbability(instance) == 1.0)
return 1.0;
}
return 0.0;
} | [
"@",
"Override",
"public",
"double",
"getInclusionProbability",
"(",
"Instance",
"instance",
")",
"{",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"Boolean",
">",
">",
"gridIter",
"=",
"grids",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"gridIter",
".",
"hasNext",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"Boolean",
">",
"grid",
"=",
"gridIter",
".",
"next",
"(",
")",
";",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"if",
"(",
"dg",
".",
"getInclusionProbability",
"(",
"instance",
")",
"==",
"1.0",
")",
"return",
"1.0",
";",
"}",
"return",
"0.0",
";",
"}"
] | Iterates through the DensityGrids in the cluster and calculates the inclusion probability for each.
@return 1.0 if instance matches any of the density grids; 0.0 otherwise. | [
"Iterates",
"through",
"the",
"DensityGrids",
"in",
"the",
"cluster",
"and",
"calculates",
"the",
"inclusion",
"probability",
"for",
"each",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/GridCluster.java#L289-L302 |
28,947 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.add | public void add(int numPoints, double[] sumPoints, double sumSquaredPoints) {
assert (this.sumPoints.length == sumPoints.length);
this.numPoints += numPoints;
super.setWeight(this.numPoints);
for (int i = 0; i < this.sumPoints.length; i++) {
this.sumPoints[i] += sumPoints[i];
}
this.sumSquaredLength += sumSquaredPoints;
} | java | public void add(int numPoints, double[] sumPoints, double sumSquaredPoints) {
assert (this.sumPoints.length == sumPoints.length);
this.numPoints += numPoints;
super.setWeight(this.numPoints);
for (int i = 0; i < this.sumPoints.length; i++) {
this.sumPoints[i] += sumPoints[i];
}
this.sumSquaredLength += sumSquaredPoints;
} | [
"public",
"void",
"add",
"(",
"int",
"numPoints",
",",
"double",
"[",
"]",
"sumPoints",
",",
"double",
"sumSquaredPoints",
")",
"{",
"assert",
"(",
"this",
".",
"sumPoints",
".",
"length",
"==",
"sumPoints",
".",
"length",
")",
";",
"this",
".",
"numPoints",
"+=",
"numPoints",
";",
"super",
".",
"setWeight",
"(",
"this",
".",
"numPoints",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"sumPoints",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"sumPoints",
"[",
"i",
"]",
"+=",
"sumPoints",
"[",
"i",
"]",
";",
"}",
"this",
".",
"sumSquaredLength",
"+=",
"sumSquaredPoints",
";",
"}"
] | Adds a point to the ClusteringFeature.
@param numPoints
the number of points to add
@param sumPoints
the sum of points to add
@param sumSquaredPoints
the sum of the squared lengths to add | [
"Adds",
"a",
"point",
"to",
"the",
"ClusteringFeature",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L95-L103 |
28,948 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.merge | public void merge(ClusteringFeature x) {
assert (this.sumPoints.length == x.sumPoints.length);
this.numPoints += x.numPoints;
super.setWeight(this.numPoints);
for (int i = 0; i < this.sumPoints.length; i++) {
this.sumPoints[i] += x.sumPoints[i];
}
this.sumSquaredLength += x.sumSquaredLength;
} | java | public void merge(ClusteringFeature x) {
assert (this.sumPoints.length == x.sumPoints.length);
this.numPoints += x.numPoints;
super.setWeight(this.numPoints);
for (int i = 0; i < this.sumPoints.length; i++) {
this.sumPoints[i] += x.sumPoints[i];
}
this.sumSquaredLength += x.sumSquaredLength;
} | [
"public",
"void",
"merge",
"(",
"ClusteringFeature",
"x",
")",
"{",
"assert",
"(",
"this",
".",
"sumPoints",
".",
"length",
"==",
"x",
".",
"sumPoints",
".",
"length",
")",
";",
"this",
".",
"numPoints",
"+=",
"x",
".",
"numPoints",
";",
"super",
".",
"setWeight",
"(",
"this",
".",
"numPoints",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"sumPoints",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"sumPoints",
"[",
"i",
"]",
"+=",
"x",
".",
"sumPoints",
"[",
"i",
"]",
";",
"}",
"this",
".",
"sumSquaredLength",
"+=",
"x",
".",
"sumSquaredLength",
";",
"}"
] | Merges the ClusteringFeature with an other ClusteringFeature.
@param x
the ClusteringFeature to merge with | [
"Merges",
"the",
"ClusteringFeature",
"with",
"an",
"other",
"ClusteringFeature",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L111-L119 |
28,949 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.toCluster | public Cluster toCluster() {
double[] output = new double[this.sumPoints.length];
System.arraycopy(this.sumPoints, 0, output, 0, this.sumPoints.length);
for (int i = 0; i < output.length; i++) {
output[i] /= this.numPoints;
}
return new SphereCluster(output, getThreshold(), this.numPoints);
} | java | public Cluster toCluster() {
double[] output = new double[this.sumPoints.length];
System.arraycopy(this.sumPoints, 0, output, 0, this.sumPoints.length);
for (int i = 0; i < output.length; i++) {
output[i] /= this.numPoints;
}
return new SphereCluster(output, getThreshold(), this.numPoints);
} | [
"public",
"Cluster",
"toCluster",
"(",
")",
"{",
"double",
"[",
"]",
"output",
"=",
"new",
"double",
"[",
"this",
".",
"sumPoints",
".",
"length",
"]",
";",
"System",
".",
"arraycopy",
"(",
"this",
".",
"sumPoints",
",",
"0",
",",
"output",
",",
"0",
",",
"this",
".",
"sumPoints",
".",
"length",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"output",
".",
"length",
";",
"i",
"++",
")",
"{",
"output",
"[",
"i",
"]",
"/=",
"this",
".",
"numPoints",
";",
"}",
"return",
"new",
"SphereCluster",
"(",
"output",
",",
"getThreshold",
"(",
")",
",",
"this",
".",
"numPoints",
")",
";",
"}"
] | Creates a Cluster of the ClusteringFeature.
@return a Cluster | [
"Creates",
"a",
"Cluster",
"of",
"the",
"ClusteringFeature",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L126-L133 |
28,950 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.toClusterCenter | public double[] toClusterCenter() {
double[] output = new double[this.sumPoints.length + 1];
System.arraycopy(this.sumPoints, 0, output, 1, this.sumPoints.length);
output[0] = this.numPoints;
for (int i = 1; i < output.length; i++) {
output[i] /= this.numPoints;
}
return output;
} | java | public double[] toClusterCenter() {
double[] output = new double[this.sumPoints.length + 1];
System.arraycopy(this.sumPoints, 0, output, 1, this.sumPoints.length);
output[0] = this.numPoints;
for (int i = 1; i < output.length; i++) {
output[i] /= this.numPoints;
}
return output;
} | [
"public",
"double",
"[",
"]",
"toClusterCenter",
"(",
")",
"{",
"double",
"[",
"]",
"output",
"=",
"new",
"double",
"[",
"this",
".",
"sumPoints",
".",
"length",
"+",
"1",
"]",
";",
"System",
".",
"arraycopy",
"(",
"this",
".",
"sumPoints",
",",
"0",
",",
"output",
",",
"1",
",",
"this",
".",
"sumPoints",
".",
"length",
")",
";",
"output",
"[",
"0",
"]",
"=",
"this",
".",
"numPoints",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"output",
".",
"length",
";",
"i",
"++",
")",
"{",
"output",
"[",
"i",
"]",
"/=",
"this",
".",
"numPoints",
";",
"}",
"return",
"output",
";",
"}"
] | Creates the cluster center of the ClusteringFeature.
@return the cluster center | [
"Creates",
"the",
"cluster",
"center",
"of",
"the",
"ClusteringFeature",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L140-L148 |
28,951 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.printClusterCenter | public void printClusterCenter(Writer stream) throws IOException {
stream.write(String.valueOf(this.numPoints));
for (int j = 0; j < this.sumPoints.length; j++) {
stream.write(' ');
stream.write(String.valueOf(this.sumPoints[j] / this.numPoints));
}
stream.write(System.getProperty("line.separator"));
} | java | public void printClusterCenter(Writer stream) throws IOException {
stream.write(String.valueOf(this.numPoints));
for (int j = 0; j < this.sumPoints.length; j++) {
stream.write(' ');
stream.write(String.valueOf(this.sumPoints[j] / this.numPoints));
}
stream.write(System.getProperty("line.separator"));
} | [
"public",
"void",
"printClusterCenter",
"(",
"Writer",
"stream",
")",
"throws",
"IOException",
"{",
"stream",
".",
"write",
"(",
"String",
".",
"valueOf",
"(",
"this",
".",
"numPoints",
")",
")",
";",
"for",
"(",
"int",
"j",
"=",
"0",
";",
"j",
"<",
"this",
".",
"sumPoints",
".",
"length",
";",
"j",
"++",
")",
"{",
"stream",
".",
"write",
"(",
"'",
"'",
")",
";",
"stream",
".",
"write",
"(",
"String",
".",
"valueOf",
"(",
"this",
".",
"sumPoints",
"[",
"j",
"]",
"/",
"this",
".",
"numPoints",
")",
")",
";",
"}",
"stream",
".",
"write",
"(",
"System",
".",
"getProperty",
"(",
"\"line.separator\"",
")",
")",
";",
"}"
] | Writes the cluster center to a given stream.
@param stream
the stream
@throws IOException
If an I/O error occurs | [
"Writes",
"the",
"cluster",
"center",
"to",
"a",
"given",
"stream",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L158-L165 |
28,952 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.calcKMeansCosts | public double calcKMeansCosts(double[] center) {
assert (this.sumPoints.length == center.length);
return this.sumSquaredLength - 2
* Metric.dotProduct(this.sumPoints, center) + this.numPoints
* Metric.dotProduct(center);
} | java | public double calcKMeansCosts(double[] center) {
assert (this.sumPoints.length == center.length);
return this.sumSquaredLength - 2
* Metric.dotProduct(this.sumPoints, center) + this.numPoints
* Metric.dotProduct(center);
} | [
"public",
"double",
"calcKMeansCosts",
"(",
"double",
"[",
"]",
"center",
")",
"{",
"assert",
"(",
"this",
".",
"sumPoints",
".",
"length",
"==",
"center",
".",
"length",
")",
";",
"return",
"this",
".",
"sumSquaredLength",
"-",
"2",
"*",
"Metric",
".",
"dotProduct",
"(",
"this",
".",
"sumPoints",
",",
"center",
")",
"+",
"this",
".",
"numPoints",
"*",
"Metric",
".",
"dotProduct",
"(",
"center",
")",
";",
"}"
] | Calculates the k-means costs of the ClusteringFeature too a center.
@param center
the center too calculate the costs
@return the costs | [
"Calculates",
"the",
"k",
"-",
"means",
"costs",
"of",
"the",
"ClusteringFeature",
"too",
"a",
"center",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L262-L267 |
28,953 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.calcKMeansCosts | public double calcKMeansCosts(double[] center, double[] point) {
assert (this.sumPoints.length == center.length &&
this.sumPoints.length == point.length);
return (this.sumSquaredLength + Metric.distanceSquared(point)) - 2
* Metric.dotProductWithAddition(this.sumPoints, point, center)
+ (this.numPoints + 1) * Metric.dotProduct(center);
} | java | public double calcKMeansCosts(double[] center, double[] point) {
assert (this.sumPoints.length == center.length &&
this.sumPoints.length == point.length);
return (this.sumSquaredLength + Metric.distanceSquared(point)) - 2
* Metric.dotProductWithAddition(this.sumPoints, point, center)
+ (this.numPoints + 1) * Metric.dotProduct(center);
} | [
"public",
"double",
"calcKMeansCosts",
"(",
"double",
"[",
"]",
"center",
",",
"double",
"[",
"]",
"point",
")",
"{",
"assert",
"(",
"this",
".",
"sumPoints",
".",
"length",
"==",
"center",
".",
"length",
"&&",
"this",
".",
"sumPoints",
".",
"length",
"==",
"point",
".",
"length",
")",
";",
"return",
"(",
"this",
".",
"sumSquaredLength",
"+",
"Metric",
".",
"distanceSquared",
"(",
"point",
")",
")",
"-",
"2",
"*",
"Metric",
".",
"dotProductWithAddition",
"(",
"this",
".",
"sumPoints",
",",
"point",
",",
"center",
")",
"+",
"(",
"this",
".",
"numPoints",
"+",
"1",
")",
"*",
"Metric",
".",
"dotProduct",
"(",
"center",
")",
";",
"}"
] | Calculates the k-means costs of the ClusteringFeature and a point too a
center.
@param center
the center too calculate the costs
@param point
the point too calculate the costs
@return the costs | [
"Calculates",
"the",
"k",
"-",
"means",
"costs",
"of",
"the",
"ClusteringFeature",
"and",
"a",
"point",
"too",
"a",
"center",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L279-L285 |
28,954 | Waikato/moa | moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java | ClusteringFeature.calcKMeansCosts | public double calcKMeansCosts(double[] center, ClusteringFeature points) {
assert (this.sumPoints.length == center.length &&
this.sumPoints.length == points.sumPoints.length);
return (this.sumSquaredLength + points.sumSquaredLength)
- 2 * Metric.dotProductWithAddition(this.sumPoints,
points.sumPoints, center)
+ (this.numPoints + points.numPoints)
* Metric.dotProduct(center);
} | java | public double calcKMeansCosts(double[] center, ClusteringFeature points) {
assert (this.sumPoints.length == center.length &&
this.sumPoints.length == points.sumPoints.length);
return (this.sumSquaredLength + points.sumSquaredLength)
- 2 * Metric.dotProductWithAddition(this.sumPoints,
points.sumPoints, center)
+ (this.numPoints + points.numPoints)
* Metric.dotProduct(center);
} | [
"public",
"double",
"calcKMeansCosts",
"(",
"double",
"[",
"]",
"center",
",",
"ClusteringFeature",
"points",
")",
"{",
"assert",
"(",
"this",
".",
"sumPoints",
".",
"length",
"==",
"center",
".",
"length",
"&&",
"this",
".",
"sumPoints",
".",
"length",
"==",
"points",
".",
"sumPoints",
".",
"length",
")",
";",
"return",
"(",
"this",
".",
"sumSquaredLength",
"+",
"points",
".",
"sumSquaredLength",
")",
"-",
"2",
"*",
"Metric",
".",
"dotProductWithAddition",
"(",
"this",
".",
"sumPoints",
",",
"points",
".",
"sumPoints",
",",
"center",
")",
"+",
"(",
"this",
".",
"numPoints",
"+",
"points",
".",
"numPoints",
")",
"*",
"Metric",
".",
"dotProduct",
"(",
"center",
")",
";",
"}"
] | Calculates the k-means costs of the ClusteringFeature and another
ClusteringFeature too a center.
@param center
the center too calculate the costs
@param points
the points too calculate the costs
@return the costs | [
"Calculates",
"the",
"k",
"-",
"means",
"costs",
"of",
"the",
"ClusteringFeature",
"and",
"another",
"ClusteringFeature",
"too",
"a",
"center",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/kmeanspm/ClusteringFeature.java#L297-L305 |
28,955 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/OnlineAccuracyUpdatedEnsemble.java | OnlineAccuracyUpdatedEnsemble.computeWeight | protected double computeWeight(int i, Instance example) {
int d = this.windowSize;
int t = this.processedInstances - this.ensemble[i].birthday;
double e_it = 0;
double mse_it = 0;
double voteSum = 0;
try{
double[] votes = this.ensemble[i].classifier.getVotesForInstance(example);
for (double element : votes) {
voteSum += element;
}
if (voteSum > 0) {
double f_it = 1 - (votes[(int) example.classValue()] / voteSum);
e_it = f_it * f_it;
} else {
e_it = 1;
}
} catch (Exception e) {
e_it = 1;
}
if(t > d)
{
mse_it = this.ensemble[i].mse_it + e_it/(double)d - this.ensemble[i].squareErrors[t % d]/(double)d;
}
else
{
mse_it = this.ensemble[i].mse_it*(t-1)/t + e_it/(double)t;
}
this.ensemble[i].squareErrors[t % d] = e_it;
this.ensemble[i].mse_it = mse_it;
if(linearOption.isSet())
{
return java.lang.Math.max(mse_r - mse_it, Double.MIN_VALUE);
}
else
{
return 1.0 / (this.mse_r + mse_it + Double.MIN_VALUE);
}
} | java | protected double computeWeight(int i, Instance example) {
int d = this.windowSize;
int t = this.processedInstances - this.ensemble[i].birthday;
double e_it = 0;
double mse_it = 0;
double voteSum = 0;
try{
double[] votes = this.ensemble[i].classifier.getVotesForInstance(example);
for (double element : votes) {
voteSum += element;
}
if (voteSum > 0) {
double f_it = 1 - (votes[(int) example.classValue()] / voteSum);
e_it = f_it * f_it;
} else {
e_it = 1;
}
} catch (Exception e) {
e_it = 1;
}
if(t > d)
{
mse_it = this.ensemble[i].mse_it + e_it/(double)d - this.ensemble[i].squareErrors[t % d]/(double)d;
}
else
{
mse_it = this.ensemble[i].mse_it*(t-1)/t + e_it/(double)t;
}
this.ensemble[i].squareErrors[t % d] = e_it;
this.ensemble[i].mse_it = mse_it;
if(linearOption.isSet())
{
return java.lang.Math.max(mse_r - mse_it, Double.MIN_VALUE);
}
else
{
return 1.0 / (this.mse_r + mse_it + Double.MIN_VALUE);
}
} | [
"protected",
"double",
"computeWeight",
"(",
"int",
"i",
",",
"Instance",
"example",
")",
"{",
"int",
"d",
"=",
"this",
".",
"windowSize",
";",
"int",
"t",
"=",
"this",
".",
"processedInstances",
"-",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"birthday",
";",
"double",
"e_it",
"=",
"0",
";",
"double",
"mse_it",
"=",
"0",
";",
"double",
"voteSum",
"=",
"0",
";",
"try",
"{",
"double",
"[",
"]",
"votes",
"=",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"classifier",
".",
"getVotesForInstance",
"(",
"example",
")",
";",
"for",
"(",
"double",
"element",
":",
"votes",
")",
"{",
"voteSum",
"+=",
"element",
";",
"}",
"if",
"(",
"voteSum",
">",
"0",
")",
"{",
"double",
"f_it",
"=",
"1",
"-",
"(",
"votes",
"[",
"(",
"int",
")",
"example",
".",
"classValue",
"(",
")",
"]",
"/",
"voteSum",
")",
";",
"e_it",
"=",
"f_it",
"*",
"f_it",
";",
"}",
"else",
"{",
"e_it",
"=",
"1",
";",
"}",
"}",
"catch",
"(",
"Exception",
"e",
")",
"{",
"e_it",
"=",
"1",
";",
"}",
"if",
"(",
"t",
">",
"d",
")",
"{",
"mse_it",
"=",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"mse_it",
"+",
"e_it",
"/",
"(",
"double",
")",
"d",
"-",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"squareErrors",
"[",
"t",
"%",
"d",
"]",
"/",
"(",
"double",
")",
"d",
";",
"}",
"else",
"{",
"mse_it",
"=",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"mse_it",
"*",
"(",
"t",
"-",
"1",
")",
"/",
"t",
"+",
"e_it",
"/",
"(",
"double",
")",
"t",
";",
"}",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"squareErrors",
"[",
"t",
"%",
"d",
"]",
"=",
"e_it",
";",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"mse_it",
"=",
"mse_it",
";",
"if",
"(",
"linearOption",
".",
"isSet",
"(",
")",
")",
"{",
"return",
"java",
".",
"lang",
".",
"Math",
".",
"max",
"(",
"mse_r",
"-",
"mse_it",
",",
"Double",
".",
"MIN_VALUE",
")",
";",
"}",
"else",
"{",
"return",
"1.0",
"/",
"(",
"this",
".",
"mse_r",
"+",
"mse_it",
"+",
"Double",
".",
"MIN_VALUE",
")",
";",
"}",
"}"
] | Computes the weight of a learner before training a given example.
@param i the identifier (in terms of array learners)
of the classifier for which the weight is supposed to be computed
@param example the newest example
@return the computed weight. | [
"Computes",
"the",
"weight",
"of",
"a",
"learner",
"before",
"training",
"a",
"given",
"example",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/OnlineAccuracyUpdatedEnsemble.java#L300-L346 |
28,956 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/OnlineAccuracyUpdatedEnsemble.java | OnlineAccuracyUpdatedEnsemble.getPoorestClassifierIndex | private int getPoorestClassifierIndex() {
int minIndex = 0;
for (int i = 1; i < this.weights.length; i++) {
if(this.weights[i][0] < this.weights[minIndex][0]){
minIndex = i;
}
}
return minIndex;
} | java | private int getPoorestClassifierIndex() {
int minIndex = 0;
for (int i = 1; i < this.weights.length; i++) {
if(this.weights[i][0] < this.weights[minIndex][0]){
minIndex = i;
}
}
return minIndex;
} | [
"private",
"int",
"getPoorestClassifierIndex",
"(",
")",
"{",
"int",
"minIndex",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"1",
";",
"i",
"<",
"this",
".",
"weights",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"this",
".",
"weights",
"[",
"i",
"]",
"[",
"0",
"]",
"<",
"this",
".",
"weights",
"[",
"minIndex",
"]",
"[",
"0",
"]",
")",
"{",
"minIndex",
"=",
"i",
";",
"}",
"}",
"return",
"minIndex",
";",
"}"
] | Finds the index of the classifier with the smallest weight.
@return | [
"Finds",
"the",
"index",
"of",
"the",
"classifier",
"with",
"the",
"smallest",
"weight",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/OnlineAccuracyUpdatedEnsemble.java#L406-L416 |
28,957 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java | InstanceImpl.classIndex | @Override
public int classIndex() {
int classIndex = instanceHeader.classIndex();
// return ? classIndex : 0;
if(classIndex == Integer.MAX_VALUE)
if(this.instanceHeader.instanceInformation.range!=null)
classIndex=instanceHeader.instanceInformation.range.getStart();
else
classIndex=0;
return classIndex;
} | java | @Override
public int classIndex() {
int classIndex = instanceHeader.classIndex();
// return ? classIndex : 0;
if(classIndex == Integer.MAX_VALUE)
if(this.instanceHeader.instanceInformation.range!=null)
classIndex=instanceHeader.instanceInformation.range.getStart();
else
classIndex=0;
return classIndex;
} | [
"@",
"Override",
"public",
"int",
"classIndex",
"(",
")",
"{",
"int",
"classIndex",
"=",
"instanceHeader",
".",
"classIndex",
"(",
")",
";",
"// return ? classIndex : 0;",
"if",
"(",
"classIndex",
"==",
"Integer",
".",
"MAX_VALUE",
")",
"if",
"(",
"this",
".",
"instanceHeader",
".",
"instanceInformation",
".",
"range",
"!=",
"null",
")",
"classIndex",
"=",
"instanceHeader",
".",
"instanceInformation",
".",
"range",
".",
"getStart",
"(",
")",
";",
"else",
"classIndex",
"=",
"0",
";",
"return",
"classIndex",
";",
"}"
] | Class index.
@return the int | [
"Class",
"index",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java#L287-L297 |
28,958 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java | InstanceImpl.setDataset | @Override
public void setDataset(Instances dataset) {
if(dataset instanceof InstancesHeader) {
this.instanceHeader = (InstancesHeader) dataset;
}else {
this.instanceHeader = new InstancesHeader(dataset);
}
} | java | @Override
public void setDataset(Instances dataset) {
if(dataset instanceof InstancesHeader) {
this.instanceHeader = (InstancesHeader) dataset;
}else {
this.instanceHeader = new InstancesHeader(dataset);
}
} | [
"@",
"Override",
"public",
"void",
"setDataset",
"(",
"Instances",
"dataset",
")",
"{",
"if",
"(",
"dataset",
"instanceof",
"InstancesHeader",
")",
"{",
"this",
".",
"instanceHeader",
"=",
"(",
"InstancesHeader",
")",
"dataset",
";",
"}",
"else",
"{",
"this",
".",
"instanceHeader",
"=",
"new",
"InstancesHeader",
"(",
"dataset",
")",
";",
"}",
"}"
] | Sets the dataset.
@param dataset the new dataset | [
"Sets",
"the",
"dataset",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java#L365-L372 |
28,959 | Waikato/moa | moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java | InstanceImpl.addSparseValues | @Override
public void addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes) {
this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); //???
} | java | @Override
public void addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes) {
this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); //???
} | [
"@",
"Override",
"public",
"void",
"addSparseValues",
"(",
"int",
"[",
"]",
"indexValues",
",",
"double",
"[",
"]",
"attributeValues",
",",
"int",
"numberAttributes",
")",
"{",
"this",
".",
"instanceData",
"=",
"new",
"SparseInstanceData",
"(",
"attributeValues",
",",
"indexValues",
",",
"numberAttributes",
")",
";",
"//???",
"}"
] | Adds the sparse values.
@param indexValues the index values
@param attributeValues the attribute values
@param numberAttributes the number attributes | [
"Adds",
"the",
"sparse",
"values",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/com/yahoo/labs/samoa/instances/InstanceImpl.java#L381-L384 |
28,960 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/DACC.java | DACC.initVariables | protected void initVariables(){
int ensembleSize = (int)this.memberCountOption.getValue();
this.ensemble = new Classifier[ensembleSize];
this.ensembleAges = new double[ensembleSize];
this.ensembleWindows = new int[ensembleSize][(int)this.evaluationSizeOption.getValue()];
} | java | protected void initVariables(){
int ensembleSize = (int)this.memberCountOption.getValue();
this.ensemble = new Classifier[ensembleSize];
this.ensembleAges = new double[ensembleSize];
this.ensembleWindows = new int[ensembleSize][(int)this.evaluationSizeOption.getValue()];
} | [
"protected",
"void",
"initVariables",
"(",
")",
"{",
"int",
"ensembleSize",
"=",
"(",
"int",
")",
"this",
".",
"memberCountOption",
".",
"getValue",
"(",
")",
";",
"this",
".",
"ensemble",
"=",
"new",
"Classifier",
"[",
"ensembleSize",
"]",
";",
"this",
".",
"ensembleAges",
"=",
"new",
"double",
"[",
"ensembleSize",
"]",
";",
"this",
".",
"ensembleWindows",
"=",
"new",
"int",
"[",
"ensembleSize",
"]",
"[",
"(",
"int",
")",
"this",
".",
"evaluationSizeOption",
".",
"getValue",
"(",
")",
"]",
";",
"}"
] | Initializes the method variables | [
"Initializes",
"the",
"method",
"variables"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/DACC.java#L109-L114 |
28,961 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/DACC.java | DACC.trainAndClassify | protected void trainAndClassify(Instance inst){
nbInstances++;
boolean mature = true;
boolean unmature = true;
for (int i = 0; i < getNbActiveClassifiers(); i++) {
// check if all adaptive learners are mature
if (this.ensembleAges[i] < this.maturityOption.getValue() && i<getNbAdaptiveClassifiers())
mature = false;
// check if all adaptive learners are not mature
if (this.ensembleAges[i] >= this.maturityOption.getValue() && i<getNbAdaptiveClassifiers())
unmature = false;
if (this.nbInstances >= this.ensembleWeights[i].index + 1){
// train adaptive learners
if (i < getNbAdaptiveClassifiers())
this.ensemble[i].trainOnInstance(inst);
int val = this.ensemble[i].correctlyClassifies(inst)?1:0;
double sum = updateEvaluationWindow(i, val);
this.ensembleWeights[i].val = sum;
this.ensembleAges[i] = this.ensembleAges[i]+1;
}
}
// if all adaptive learners are not mature --> set weights to one
if (unmature)
for (int i = 0; i < getNbAdaptiveClassifiers(); i++)
this.ensembleWeights[i].val=1;
// if all adaptive learners are mature --> delete one learner
if (mature){
Pair[] learners = getHalf(false);
if (learners.length > 0){
double rand = classifierRandom.nextInt(learners.length);
discardModel(learners[(int)rand].index);
}
}
} | java | protected void trainAndClassify(Instance inst){
nbInstances++;
boolean mature = true;
boolean unmature = true;
for (int i = 0; i < getNbActiveClassifiers(); i++) {
// check if all adaptive learners are mature
if (this.ensembleAges[i] < this.maturityOption.getValue() && i<getNbAdaptiveClassifiers())
mature = false;
// check if all adaptive learners are not mature
if (this.ensembleAges[i] >= this.maturityOption.getValue() && i<getNbAdaptiveClassifiers())
unmature = false;
if (this.nbInstances >= this.ensembleWeights[i].index + 1){
// train adaptive learners
if (i < getNbAdaptiveClassifiers())
this.ensemble[i].trainOnInstance(inst);
int val = this.ensemble[i].correctlyClassifies(inst)?1:0;
double sum = updateEvaluationWindow(i, val);
this.ensembleWeights[i].val = sum;
this.ensembleAges[i] = this.ensembleAges[i]+1;
}
}
// if all adaptive learners are not mature --> set weights to one
if (unmature)
for (int i = 0; i < getNbAdaptiveClassifiers(); i++)
this.ensembleWeights[i].val=1;
// if all adaptive learners are mature --> delete one learner
if (mature){
Pair[] learners = getHalf(false);
if (learners.length > 0){
double rand = classifierRandom.nextInt(learners.length);
discardModel(learners[(int)rand].index);
}
}
} | [
"protected",
"void",
"trainAndClassify",
"(",
"Instance",
"inst",
")",
"{",
"nbInstances",
"++",
";",
"boolean",
"mature",
"=",
"true",
";",
"boolean",
"unmature",
"=",
"true",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"getNbActiveClassifiers",
"(",
")",
";",
"i",
"++",
")",
"{",
"// check if all adaptive learners are mature",
"if",
"(",
"this",
".",
"ensembleAges",
"[",
"i",
"]",
"<",
"this",
".",
"maturityOption",
".",
"getValue",
"(",
")",
"&&",
"i",
"<",
"getNbAdaptiveClassifiers",
"(",
")",
")",
"mature",
"=",
"false",
";",
"// check if all adaptive learners are not mature ",
"if",
"(",
"this",
".",
"ensembleAges",
"[",
"i",
"]",
">=",
"this",
".",
"maturityOption",
".",
"getValue",
"(",
")",
"&&",
"i",
"<",
"getNbAdaptiveClassifiers",
"(",
")",
")",
"unmature",
"=",
"false",
";",
"if",
"(",
"this",
".",
"nbInstances",
">=",
"this",
".",
"ensembleWeights",
"[",
"i",
"]",
".",
"index",
"+",
"1",
")",
"{",
"// train adaptive learners",
"if",
"(",
"i",
"<",
"getNbAdaptiveClassifiers",
"(",
")",
")",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"trainOnInstance",
"(",
"inst",
")",
";",
"int",
"val",
"=",
"this",
".",
"ensemble",
"[",
"i",
"]",
".",
"correctlyClassifies",
"(",
"inst",
")",
"?",
"1",
":",
"0",
";",
"double",
"sum",
"=",
"updateEvaluationWindow",
"(",
"i",
",",
"val",
")",
";",
"this",
".",
"ensembleWeights",
"[",
"i",
"]",
".",
"val",
"=",
"sum",
";",
"this",
".",
"ensembleAges",
"[",
"i",
"]",
"=",
"this",
".",
"ensembleAges",
"[",
"i",
"]",
"+",
"1",
";",
"}",
"}",
"// if all adaptive learners are not mature --> set weights to one ",
"if",
"(",
"unmature",
")",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"getNbAdaptiveClassifiers",
"(",
")",
";",
"i",
"++",
")",
"this",
".",
"ensembleWeights",
"[",
"i",
"]",
".",
"val",
"=",
"1",
";",
"// if all adaptive learners are mature --> delete one learner",
"if",
"(",
"mature",
")",
"{",
"Pair",
"[",
"]",
"learners",
"=",
"getHalf",
"(",
"false",
")",
";",
"if",
"(",
"learners",
".",
"length",
">",
"0",
")",
"{",
"double",
"rand",
"=",
"classifierRandom",
".",
"nextInt",
"(",
"learners",
".",
"length",
")",
";",
"discardModel",
"(",
"learners",
"[",
"(",
"int",
")",
"rand",
"]",
".",
"index",
")",
";",
"}",
"}",
"}"
] | Receives a training instance from the stream and
updates the adaptive classifiers accordingly
@param inst the instance from the stream | [
"Receives",
"a",
"training",
"instance",
"from",
"the",
"stream",
"and",
"updates",
"the",
"adaptive",
"classifiers",
"accordingly"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/DACC.java#L178-L225 |
28,962 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/DACC.java | DACC.discardModel | public void discardModel(int index) {
this.ensemble[index].resetLearning();
this.ensembleWeights[index].val = 0;
this.ensembleAges[index] = 0;
this.ensembleWindows[index]=new int[(int)this.evaluationSizeOption.getValue()];
} | java | public void discardModel(int index) {
this.ensemble[index].resetLearning();
this.ensembleWeights[index].val = 0;
this.ensembleAges[index] = 0;
this.ensembleWindows[index]=new int[(int)this.evaluationSizeOption.getValue()];
} | [
"public",
"void",
"discardModel",
"(",
"int",
"index",
")",
"{",
"this",
".",
"ensemble",
"[",
"index",
"]",
".",
"resetLearning",
"(",
")",
";",
"this",
".",
"ensembleWeights",
"[",
"index",
"]",
".",
"val",
"=",
"0",
";",
"this",
".",
"ensembleAges",
"[",
"index",
"]",
"=",
"0",
";",
"this",
".",
"ensembleWindows",
"[",
"index",
"]",
"=",
"new",
"int",
"[",
"(",
"int",
")",
"this",
".",
"evaluationSizeOption",
".",
"getValue",
"(",
")",
"]",
";",
"}"
] | Resets a classifier in the ensemble
@param index the index of the classifier in the ensemble | [
"Resets",
"a",
"classifier",
"in",
"the",
"ensemble"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/DACC.java#L231-L236 |
28,963 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/DACC.java | DACC.updateEvaluationWindow | protected double updateEvaluationWindow(int index,int val){
int[] newEnsembleWindows = new int[this.ensembleWindows[index].length];
int wsize = (int)Math.min(this.evaluationSizeOption.getValue(),this.ensembleAges[index]+1);
int sum = 0;
for (int i = 0; i < wsize-1 ; i++){
newEnsembleWindows[i+1] = this.ensembleWindows[index][i];
sum = sum + this.ensembleWindows[index][i];
}
newEnsembleWindows[0] = val;
this.ensembleWindows[index] = newEnsembleWindows;
if (this.ensembleAges[index] >= this.maturityOption.getValue())
return (sum + val) * 1.0/wsize;
else
return 0;
} | java | protected double updateEvaluationWindow(int index,int val){
int[] newEnsembleWindows = new int[this.ensembleWindows[index].length];
int wsize = (int)Math.min(this.evaluationSizeOption.getValue(),this.ensembleAges[index]+1);
int sum = 0;
for (int i = 0; i < wsize-1 ; i++){
newEnsembleWindows[i+1] = this.ensembleWindows[index][i];
sum = sum + this.ensembleWindows[index][i];
}
newEnsembleWindows[0] = val;
this.ensembleWindows[index] = newEnsembleWindows;
if (this.ensembleAges[index] >= this.maturityOption.getValue())
return (sum + val) * 1.0/wsize;
else
return 0;
} | [
"protected",
"double",
"updateEvaluationWindow",
"(",
"int",
"index",
",",
"int",
"val",
")",
"{",
"int",
"[",
"]",
"newEnsembleWindows",
"=",
"new",
"int",
"[",
"this",
".",
"ensembleWindows",
"[",
"index",
"]",
".",
"length",
"]",
";",
"int",
"wsize",
"=",
"(",
"int",
")",
"Math",
".",
"min",
"(",
"this",
".",
"evaluationSizeOption",
".",
"getValue",
"(",
")",
",",
"this",
".",
"ensembleAges",
"[",
"index",
"]",
"+",
"1",
")",
";",
"int",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"wsize",
"-",
"1",
";",
"i",
"++",
")",
"{",
"newEnsembleWindows",
"[",
"i",
"+",
"1",
"]",
"=",
"this",
".",
"ensembleWindows",
"[",
"index",
"]",
"[",
"i",
"]",
";",
"sum",
"=",
"sum",
"+",
"this",
".",
"ensembleWindows",
"[",
"index",
"]",
"[",
"i",
"]",
";",
"}",
"newEnsembleWindows",
"[",
"0",
"]",
"=",
"val",
";",
"this",
".",
"ensembleWindows",
"[",
"index",
"]",
"=",
"newEnsembleWindows",
";",
"if",
"(",
"this",
".",
"ensembleAges",
"[",
"index",
"]",
">=",
"this",
".",
"maturityOption",
".",
"getValue",
"(",
")",
")",
"return",
"(",
"sum",
"+",
"val",
")",
"*",
"1.0",
"/",
"wsize",
";",
"else",
"return",
"0",
";",
"}"
] | Updates the evaluation window of a classifier and returns the
updated weight value.
@param index the index of the classifier in the ensemble
@param val the last evaluation record of the classifier
@return the updated weight value of the classifier | [
"Updates",
"the",
"evaluation",
"window",
"of",
"a",
"classifier",
"and",
"returns",
"the",
"updated",
"weight",
"value",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/DACC.java#L245-L265 |
28,964 | Waikato/moa | moa/src/main/java/moa/classifiers/meta/DACC.java | DACC.getMAXIndexes | protected ArrayList<Integer> getMAXIndexes(){
ArrayList<Integer> maxWIndex=new ArrayList<Integer>();
Pair[] newEnsembleWeights = new Pair[getNbActiveClassifiers()];
System.arraycopy(ensembleWeights, 0, newEnsembleWeights, 0, newEnsembleWeights.length);
Arrays.sort(newEnsembleWeights);
double maxWVal = newEnsembleWeights[newEnsembleWeights.length-1].val;
for (int i = newEnsembleWeights.length-1 ; i>=0 ; i--){
if (newEnsembleWeights[i].val!=maxWVal)
break;
else
maxWIndex.add(newEnsembleWeights[i].index);
}
return maxWIndex;
} | java | protected ArrayList<Integer> getMAXIndexes(){
ArrayList<Integer> maxWIndex=new ArrayList<Integer>();
Pair[] newEnsembleWeights = new Pair[getNbActiveClassifiers()];
System.arraycopy(ensembleWeights, 0, newEnsembleWeights, 0, newEnsembleWeights.length);
Arrays.sort(newEnsembleWeights);
double maxWVal = newEnsembleWeights[newEnsembleWeights.length-1].val;
for (int i = newEnsembleWeights.length-1 ; i>=0 ; i--){
if (newEnsembleWeights[i].val!=maxWVal)
break;
else
maxWIndex.add(newEnsembleWeights[i].index);
}
return maxWIndex;
} | [
"protected",
"ArrayList",
"<",
"Integer",
">",
"getMAXIndexes",
"(",
")",
"{",
"ArrayList",
"<",
"Integer",
">",
"maxWIndex",
"=",
"new",
"ArrayList",
"<",
"Integer",
">",
"(",
")",
";",
"Pair",
"[",
"]",
"newEnsembleWeights",
"=",
"new",
"Pair",
"[",
"getNbActiveClassifiers",
"(",
")",
"]",
";",
"System",
".",
"arraycopy",
"(",
"ensembleWeights",
",",
"0",
",",
"newEnsembleWeights",
",",
"0",
",",
"newEnsembleWeights",
".",
"length",
")",
";",
"Arrays",
".",
"sort",
"(",
"newEnsembleWeights",
")",
";",
"double",
"maxWVal",
"=",
"newEnsembleWeights",
"[",
"newEnsembleWeights",
".",
"length",
"-",
"1",
"]",
".",
"val",
";",
"for",
"(",
"int",
"i",
"=",
"newEnsembleWeights",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"{",
"if",
"(",
"newEnsembleWeights",
"[",
"i",
"]",
".",
"val",
"!=",
"maxWVal",
")",
"break",
";",
"else",
"maxWIndex",
".",
"add",
"(",
"newEnsembleWeights",
"[",
"i",
"]",
".",
"index",
")",
";",
"}",
"return",
"maxWIndex",
";",
"}"
] | Returns the classifiers that vote for the final prediction
when the MAX combination function is selected
@return the classifiers with the highest weight value | [
"Returns",
"the",
"classifiers",
"that",
"vote",
"for",
"the",
"final",
"prediction",
"when",
"the",
"MAX",
"combination",
"function",
"is",
"selected"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/meta/DACC.java#L299-L317 |
28,965 | Waikato/moa | moa/src/main/java/moa/gui/experimentertab/ImageChart.java | ImageChart.exportIMG | public void exportIMG(String path, String type) throws IOException {
switch (type) {
case "JPG":
try {
ChartUtilities.saveChartAsJPEG(new File(path + File.separator + name + ".jpg"), chart, width, height);
} catch (IOException e) {
}
break;
case "PNG":
try {
ChartUtilities.saveChartAsPNG(new File(path + File.separator + name + ".png"), chart, width, height);
} catch (IOException e) {
}
break;
case "SVG":
String svg = generateSVG(width, height);
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(new File(path + File.separator + name + ".svg")));
writer.write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
writer.write(svg + "\n");
writer.flush();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
break;
}
} | java | public void exportIMG(String path, String type) throws IOException {
switch (type) {
case "JPG":
try {
ChartUtilities.saveChartAsJPEG(new File(path + File.separator + name + ".jpg"), chart, width, height);
} catch (IOException e) {
}
break;
case "PNG":
try {
ChartUtilities.saveChartAsPNG(new File(path + File.separator + name + ".png"), chart, width, height);
} catch (IOException e) {
}
break;
case "SVG":
String svg = generateSVG(width, height);
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(new File(path + File.separator + name + ".svg")));
writer.write("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
writer.write(svg + "\n");
writer.flush();
} finally {
try {
if (writer != null) {
writer.close();
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
break;
}
} | [
"public",
"void",
"exportIMG",
"(",
"String",
"path",
",",
"String",
"type",
")",
"throws",
"IOException",
"{",
"switch",
"(",
"type",
")",
"{",
"case",
"\"JPG\"",
":",
"try",
"{",
"ChartUtilities",
".",
"saveChartAsJPEG",
"(",
"new",
"File",
"(",
"path",
"+",
"File",
".",
"separator",
"+",
"name",
"+",
"\".jpg\"",
")",
",",
"chart",
",",
"width",
",",
"height",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"break",
";",
"case",
"\"PNG\"",
":",
"try",
"{",
"ChartUtilities",
".",
"saveChartAsPNG",
"(",
"new",
"File",
"(",
"path",
"+",
"File",
".",
"separator",
"+",
"name",
"+",
"\".png\"",
")",
",",
"chart",
",",
"width",
",",
"height",
")",
";",
"}",
"catch",
"(",
"IOException",
"e",
")",
"{",
"}",
"break",
";",
"case",
"\"SVG\"",
":",
"String",
"svg",
"=",
"generateSVG",
"(",
"width",
",",
"height",
")",
";",
"BufferedWriter",
"writer",
"=",
"null",
";",
"try",
"{",
"writer",
"=",
"new",
"BufferedWriter",
"(",
"new",
"FileWriter",
"(",
"new",
"File",
"(",
"path",
"+",
"File",
".",
"separator",
"+",
"name",
"+",
"\".svg\"",
")",
")",
")",
";",
"writer",
".",
"write",
"(",
"\"<!DOCTYPE svg PUBLIC \\\"-//W3C//DTD SVG 1.1//EN\\\" \\\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\\\">\\n\"",
")",
";",
"writer",
".",
"write",
"(",
"svg",
"+",
"\"\\n\"",
")",
";",
"writer",
".",
"flush",
"(",
")",
";",
"}",
"finally",
"{",
"try",
"{",
"if",
"(",
"writer",
"!=",
"null",
")",
"{",
"writer",
".",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"IOException",
"ex",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"ex",
")",
";",
"}",
"}",
"break",
";",
"}",
"}"
] | Export the image to formats JPG, PNG, SVG and EPS.
@param path
@param type
@throws IOException | [
"Export",
"the",
"image",
"to",
"formats",
"JPG",
"PNG",
"SVG",
"and",
"EPS",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/experimentertab/ImageChart.java#L169-L207 |
28,966 | Waikato/moa | moa/src/main/java/moa/gui/active/MeasureOverview.java | MeasureOverview.setActionListener | public void setActionListener(ActionListener listener) {
for (int i = 0; i < this.radioButtons.length; i++) {
this.radioButtons[i].addActionListener(listener);
}
} | java | public void setActionListener(ActionListener listener) {
for (int i = 0; i < this.radioButtons.length; i++) {
this.radioButtons[i].addActionListener(listener);
}
} | [
"public",
"void",
"setActionListener",
"(",
"ActionListener",
"listener",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"radioButtons",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"radioButtons",
"[",
"i",
"]",
".",
"addActionListener",
"(",
"listener",
")",
";",
"}",
"}"
] | Sets the ActionListener for the radio buttons.
@param listener ActionListener assigned to the radio buttons | [
"Sets",
"the",
"ActionListener",
"for",
"the",
"radio",
"buttons",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/MeasureOverview.java#L203-L207 |
28,967 | Waikato/moa | moa/src/main/java/moa/gui/active/MeasureOverview.java | MeasureOverview.update | public void update(MeasureCollection[] measures, String variedParamName, double[] variedParamValues) {
this.measures = measures;
this.variedParamName = variedParamName;
this.variedParamValues = variedParamValues;
update();
updateParamBox();
} | java | public void update(MeasureCollection[] measures, String variedParamName, double[] variedParamValues) {
this.measures = measures;
this.variedParamName = variedParamName;
this.variedParamValues = variedParamValues;
update();
updateParamBox();
} | [
"public",
"void",
"update",
"(",
"MeasureCollection",
"[",
"]",
"measures",
",",
"String",
"variedParamName",
",",
"double",
"[",
"]",
"variedParamValues",
")",
"{",
"this",
".",
"measures",
"=",
"measures",
";",
"this",
".",
"variedParamName",
"=",
"variedParamName",
";",
"this",
".",
"variedParamValues",
"=",
"variedParamValues",
";",
"update",
"(",
")",
";",
"updateParamBox",
"(",
")",
";",
"}"
] | Updates the measure overview by assigning new measure collections and
varied parameter properties. If no measures are currently to display,
reset the display to hyphens. Otherwise display the last measured and
mean values.
Updates the parameter combo box if needed.
@param measures new MeasureCollection[]
@param variedParamName new varied parameter name
@param variedParamValues new varied parameter values | [
"Updates",
"the",
"measure",
"overview",
"by",
"assigning",
"new",
"measure",
"collections",
"and",
"varied",
"parameter",
"properties",
".",
"If",
"no",
"measures",
"are",
"currently",
"to",
"display",
"reset",
"the",
"display",
"to",
"hyphens",
".",
"Otherwise",
"display",
"the",
"last",
"measured",
"and",
"mean",
"values",
".",
"Updates",
"the",
"parameter",
"combo",
"box",
"if",
"needed",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/MeasureOverview.java#L219-L225 |
28,968 | Waikato/moa | moa/src/main/java/moa/gui/active/MeasureOverview.java | MeasureOverview.update | public void update() {
if (this.measures == null || this.measures.length == 0) {
// no measures to show -> empty entries
for (int i = 0; i < this.currentValues.length; i++) {
this.currentValues[i].setText("-");
this.meanValues[i].setText("-");
}
return;
}
DecimalFormat d = new DecimalFormat("0.00");
MeasureCollection mc;
if (this.measures.length > this.measureCollectionSelected) {
mc = this.measures[this.measureCollectionSelected];
}
else {
mc = this.measures[0];
}
for (int i = 0; i < this.currentValues.length; i++) {
// set current value
if(Double.isNaN(mc.getLastValue(i))) {
this.currentValues[i].setText("-");
} else {
this.currentValues[i].setText(d.format(mc.getLastValue(i)));
}
// set mean value
if(Double.isNaN(mc.getMean(i))) {
this.meanValues[i].setText("-");
} else {
this.meanValues[i].setText(d.format(mc.getMean(i)));
}
}
} | java | public void update() {
if (this.measures == null || this.measures.length == 0) {
// no measures to show -> empty entries
for (int i = 0; i < this.currentValues.length; i++) {
this.currentValues[i].setText("-");
this.meanValues[i].setText("-");
}
return;
}
DecimalFormat d = new DecimalFormat("0.00");
MeasureCollection mc;
if (this.measures.length > this.measureCollectionSelected) {
mc = this.measures[this.measureCollectionSelected];
}
else {
mc = this.measures[0];
}
for (int i = 0; i < this.currentValues.length; i++) {
// set current value
if(Double.isNaN(mc.getLastValue(i))) {
this.currentValues[i].setText("-");
} else {
this.currentValues[i].setText(d.format(mc.getLastValue(i)));
}
// set mean value
if(Double.isNaN(mc.getMean(i))) {
this.meanValues[i].setText("-");
} else {
this.meanValues[i].setText(d.format(mc.getMean(i)));
}
}
} | [
"public",
"void",
"update",
"(",
")",
"{",
"if",
"(",
"this",
".",
"measures",
"==",
"null",
"||",
"this",
".",
"measures",
".",
"length",
"==",
"0",
")",
"{",
"// no measures to show -> empty entries",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"currentValues",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"currentValues",
"[",
"i",
"]",
".",
"setText",
"(",
"\"-\"",
")",
";",
"this",
".",
"meanValues",
"[",
"i",
"]",
".",
"setText",
"(",
"\"-\"",
")",
";",
"}",
"return",
";",
"}",
"DecimalFormat",
"d",
"=",
"new",
"DecimalFormat",
"(",
"\"0.00\"",
")",
";",
"MeasureCollection",
"mc",
";",
"if",
"(",
"this",
".",
"measures",
".",
"length",
">",
"this",
".",
"measureCollectionSelected",
")",
"{",
"mc",
"=",
"this",
".",
"measures",
"[",
"this",
".",
"measureCollectionSelected",
"]",
";",
"}",
"else",
"{",
"mc",
"=",
"this",
".",
"measures",
"[",
"0",
"]",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"currentValues",
".",
"length",
";",
"i",
"++",
")",
"{",
"// set current value",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"mc",
".",
"getLastValue",
"(",
"i",
")",
")",
")",
"{",
"this",
".",
"currentValues",
"[",
"i",
"]",
".",
"setText",
"(",
"\"-\"",
")",
";",
"}",
"else",
"{",
"this",
".",
"currentValues",
"[",
"i",
"]",
".",
"setText",
"(",
"d",
".",
"format",
"(",
"mc",
".",
"getLastValue",
"(",
"i",
")",
")",
")",
";",
"}",
"// set mean value",
"if",
"(",
"Double",
".",
"isNaN",
"(",
"mc",
".",
"getMean",
"(",
"i",
")",
")",
")",
"{",
"this",
".",
"meanValues",
"[",
"i",
"]",
".",
"setText",
"(",
"\"-\"",
")",
";",
"}",
"else",
"{",
"this",
".",
"meanValues",
"[",
"i",
"]",
".",
"setText",
"(",
"d",
".",
"format",
"(",
"mc",
".",
"getMean",
"(",
"i",
")",
")",
")",
";",
"}",
"}",
"}"
] | Updates the measure overview. If no measures are currently to display,
reset the display to hyphens. Otherwise display the last measured and
mean values. | [
"Updates",
"the",
"measure",
"overview",
".",
"If",
"no",
"measures",
"are",
"currently",
"to",
"display",
"reset",
"the",
"display",
"to",
"hyphens",
".",
"Otherwise",
"display",
"the",
"last",
"measured",
"and",
"mean",
"values",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/MeasureOverview.java#L232-L267 |
28,969 | Waikato/moa | moa/src/main/java/moa/gui/active/MeasureOverview.java | MeasureOverview.updateParamBox | private void updateParamBox() {
if (this.variedParamValues == null || this.variedParamValues.length == 0) {
// no varied parameter -> set to empty box
this.paramBox.removeAllItems();
this.paramBox.setEnabled(false);
} else if (this.paramBox.getItemCount() != this.variedParamValues.length) {
// varied parameter changed -> set the paramBox new
this.paramBox.removeAllItems();
for (int i = 0; i < variedParamValues.length; i++) {
this.paramBox.addItem(String.format("%s: %s", this.variedParamName, this.variedParamValues[i]));
}
this.paramBox.setEnabled(true);
}
} | java | private void updateParamBox() {
if (this.variedParamValues == null || this.variedParamValues.length == 0) {
// no varied parameter -> set to empty box
this.paramBox.removeAllItems();
this.paramBox.setEnabled(false);
} else if (this.paramBox.getItemCount() != this.variedParamValues.length) {
// varied parameter changed -> set the paramBox new
this.paramBox.removeAllItems();
for (int i = 0; i < variedParamValues.length; i++) {
this.paramBox.addItem(String.format("%s: %s", this.variedParamName, this.variedParamValues[i]));
}
this.paramBox.setEnabled(true);
}
} | [
"private",
"void",
"updateParamBox",
"(",
")",
"{",
"if",
"(",
"this",
".",
"variedParamValues",
"==",
"null",
"||",
"this",
".",
"variedParamValues",
".",
"length",
"==",
"0",
")",
"{",
"// no varied parameter -> set to empty box",
"this",
".",
"paramBox",
".",
"removeAllItems",
"(",
")",
";",
"this",
".",
"paramBox",
".",
"setEnabled",
"(",
"false",
")",
";",
"}",
"else",
"if",
"(",
"this",
".",
"paramBox",
".",
"getItemCount",
"(",
")",
"!=",
"this",
".",
"variedParamValues",
".",
"length",
")",
"{",
"// varied parameter changed -> set the paramBox new",
"this",
".",
"paramBox",
".",
"removeAllItems",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"variedParamValues",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"paramBox",
".",
"addItem",
"(",
"String",
".",
"format",
"(",
"\"%s: %s\"",
",",
"this",
".",
"variedParamName",
",",
"this",
".",
"variedParamValues",
"[",
"i",
"]",
")",
")",
";",
"}",
"this",
".",
"paramBox",
".",
"setEnabled",
"(",
"true",
")",
";",
"}",
"}"
] | Updates the parameter combo box. If there is no varied parameter, empty
and disable the box. Otherwise display the available parameters. | [
"Updates",
"the",
"parameter",
"combo",
"box",
".",
"If",
"there",
"is",
"no",
"varied",
"parameter",
"empty",
"and",
"disable",
"the",
"box",
".",
"Otherwise",
"display",
"the",
"available",
"parameters",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/active/MeasureOverview.java#L273-L286 |
28,970 | Waikato/moa | moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java | AbstractAMRules.getModelMeasurementsImpl | @Override
protected Measurement[] getModelMeasurementsImpl() {
return new Measurement[]{
new Measurement("anomaly detections", this.numAnomaliesDetected),
new Measurement("change detections", this.numChangesDetected),
new Measurement("rules (number)", this.ruleSet.size()+1)};
} | java | @Override
protected Measurement[] getModelMeasurementsImpl() {
return new Measurement[]{
new Measurement("anomaly detections", this.numAnomaliesDetected),
new Measurement("change detections", this.numChangesDetected),
new Measurement("rules (number)", this.ruleSet.size()+1)};
} | [
"@",
"Override",
"protected",
"Measurement",
"[",
"]",
"getModelMeasurementsImpl",
"(",
")",
"{",
"return",
"new",
"Measurement",
"[",
"]",
"{",
"new",
"Measurement",
"(",
"\"anomaly detections\"",
",",
"this",
".",
"numAnomaliesDetected",
")",
",",
"new",
"Measurement",
"(",
"\"change detections\"",
",",
"this",
".",
"numChangesDetected",
")",
",",
"new",
"Measurement",
"(",
"\"rules (number)\"",
",",
"this",
".",
"ruleSet",
".",
"size",
"(",
")",
"+",
"1",
")",
"}",
";",
"}"
] | print GUI evaluate model | [
"print",
"GUI",
"evaluate",
"model"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java#L294-L300 |
28,971 | Waikato/moa | moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java | AbstractAMRules.getModelDescription | @Override
public void getModelDescription(StringBuilder out, int indent) {
indent=0;
if(!this.unorderedRulesOption.isSet()){
StringUtils.appendIndented(out, indent, "Method Ordered");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Method Unordered");
StringUtils.appendNewline(out);
}
if(this.DriftDetectionOption.isSet()){
StringUtils.appendIndented(out, indent, "Change Detection OFF");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Change Detection ON");
StringUtils.appendNewline(out);
}
if(this.noAnomalyDetectionOption.isSet()){
StringUtils.appendIndented(out, indent, "Anomaly Detection OFF");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Anomaly Detection ON");
StringUtils.appendNewline(out);
}
StringUtils.appendIndented(out, indent, "Number of Rules: " + (this.ruleSet.size()+1));
StringUtils.appendNewline(out);
} | java | @Override
public void getModelDescription(StringBuilder out, int indent) {
indent=0;
if(!this.unorderedRulesOption.isSet()){
StringUtils.appendIndented(out, indent, "Method Ordered");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Method Unordered");
StringUtils.appendNewline(out);
}
if(this.DriftDetectionOption.isSet()){
StringUtils.appendIndented(out, indent, "Change Detection OFF");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Change Detection ON");
StringUtils.appendNewline(out);
}
if(this.noAnomalyDetectionOption.isSet()){
StringUtils.appendIndented(out, indent, "Anomaly Detection OFF");
StringUtils.appendNewline(out);
}else{
StringUtils.appendIndented(out, indent, "Anomaly Detection ON");
StringUtils.appendNewline(out);
}
StringUtils.appendIndented(out, indent, "Number of Rules: " + (this.ruleSet.size()+1));
StringUtils.appendNewline(out);
} | [
"@",
"Override",
"public",
"void",
"getModelDescription",
"(",
"StringBuilder",
"out",
",",
"int",
"indent",
")",
"{",
"indent",
"=",
"0",
";",
"if",
"(",
"!",
"this",
".",
"unorderedRulesOption",
".",
"isSet",
"(",
")",
")",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Method Ordered\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"else",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Method Unordered\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"if",
"(",
"this",
".",
"DriftDetectionOption",
".",
"isSet",
"(",
")",
")",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Change Detection OFF\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"else",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Change Detection ON\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"if",
"(",
"this",
".",
"noAnomalyDetectionOption",
".",
"isSet",
"(",
")",
")",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Anomaly Detection OFF\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"else",
"{",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Anomaly Detection ON\"",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}",
"StringUtils",
".",
"appendIndented",
"(",
"out",
",",
"indent",
",",
"\"Number of Rules: \"",
"+",
"(",
"this",
".",
"ruleSet",
".",
"size",
"(",
")",
"+",
"1",
")",
")",
";",
"StringUtils",
".",
"appendNewline",
"(",
"out",
")",
";",
"}"
] | print GUI learn model | [
"print",
"GUI",
"learn",
"model"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java#L305-L331 |
28,972 | Waikato/moa | moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java | AbstractAMRules.debug | protected void debug(String string, int level) {
if (VerbosityOption.getValue()>=level){
System.out.println(string);
}
} | java | protected void debug(String string, int level) {
if (VerbosityOption.getValue()>=level){
System.out.println(string);
}
} | [
"protected",
"void",
"debug",
"(",
"String",
"string",
",",
"int",
"level",
")",
"{",
"if",
"(",
"VerbosityOption",
".",
"getValue",
"(",
")",
">=",
"level",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"string",
")",
";",
"}",
"}"
] | Print to console
@param string | [
"Print",
"to",
"console"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java#L337-L341 |
28,973 | Waikato/moa | moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java | AbstractAMRules.getVotes | public Vote getVotes(Instance instance) {
ErrorWeightedVote errorWeightedVote=newErrorWeightedVote();
//DoubleVector combinedVote = new DoubleVector();
debug("Test",3);
int numberOfRulesCovering = 0;
VerboseToConsole(instance); // Verbose to console Dataset name.
for (Rule rule : ruleSet) {
if (rule.isCovering(instance) == true){
numberOfRulesCovering++;
//DoubleVector vote = new DoubleVector(rule.getPrediction(instance));
double [] vote=rule.getPrediction(instance);
double error= rule.getCurrentError();
debug("Rule No"+ rule.getRuleNumberID() + " Vote: " + Arrays.toString(vote) + " Error: " + error + " Y: " + instance.classValue(),3); //predictionValueForThisRule);
errorWeightedVote.addVote(vote,error);
//combinedVote.addValues(vote);
if (!this.unorderedRulesOption.isSet()) { // Ordered Rules Option.
break; // Only one rule cover the instance.
}
}
}
if (numberOfRulesCovering == 0) {
//combinedVote = new DoubleVector(defaultRule.getPrediction(instance));
double [] vote=defaultRule.getPrediction(instance);
double error= defaultRule.getCurrentError();
errorWeightedVote.addVote(vote,error);
debug("Default Rule Vote " + Arrays.toString(vote) + " Error " + error + " Y: " + instance.classValue(),3);
}
double[] weightedVote=errorWeightedVote.computeWeightedVote();
double weightedError=errorWeightedVote.getWeightedError();
debug("Weighted Rule - Vote: " + Arrays.toString(weightedVote) + " Weighted Error: " + weightedError + " Y:" + instance.classValue(),3);
return new Vote(weightedVote, weightedError);
} | java | public Vote getVotes(Instance instance) {
ErrorWeightedVote errorWeightedVote=newErrorWeightedVote();
//DoubleVector combinedVote = new DoubleVector();
debug("Test",3);
int numberOfRulesCovering = 0;
VerboseToConsole(instance); // Verbose to console Dataset name.
for (Rule rule : ruleSet) {
if (rule.isCovering(instance) == true){
numberOfRulesCovering++;
//DoubleVector vote = new DoubleVector(rule.getPrediction(instance));
double [] vote=rule.getPrediction(instance);
double error= rule.getCurrentError();
debug("Rule No"+ rule.getRuleNumberID() + " Vote: " + Arrays.toString(vote) + " Error: " + error + " Y: " + instance.classValue(),3); //predictionValueForThisRule);
errorWeightedVote.addVote(vote,error);
//combinedVote.addValues(vote);
if (!this.unorderedRulesOption.isSet()) { // Ordered Rules Option.
break; // Only one rule cover the instance.
}
}
}
if (numberOfRulesCovering == 0) {
//combinedVote = new DoubleVector(defaultRule.getPrediction(instance));
double [] vote=defaultRule.getPrediction(instance);
double error= defaultRule.getCurrentError();
errorWeightedVote.addVote(vote,error);
debug("Default Rule Vote " + Arrays.toString(vote) + " Error " + error + " Y: " + instance.classValue(),3);
}
double[] weightedVote=errorWeightedVote.computeWeightedVote();
double weightedError=errorWeightedVote.getWeightedError();
debug("Weighted Rule - Vote: " + Arrays.toString(weightedVote) + " Weighted Error: " + weightedError + " Y:" + instance.classValue(),3);
return new Vote(weightedVote, weightedError);
} | [
"public",
"Vote",
"getVotes",
"(",
"Instance",
"instance",
")",
"{",
"ErrorWeightedVote",
"errorWeightedVote",
"=",
"newErrorWeightedVote",
"(",
")",
";",
"//DoubleVector combinedVote = new DoubleVector();",
"debug",
"(",
"\"Test\"",
",",
"3",
")",
";",
"int",
"numberOfRulesCovering",
"=",
"0",
";",
"VerboseToConsole",
"(",
"instance",
")",
";",
"// Verbose to console Dataset name.",
"for",
"(",
"Rule",
"rule",
":",
"ruleSet",
")",
"{",
"if",
"(",
"rule",
".",
"isCovering",
"(",
"instance",
")",
"==",
"true",
")",
"{",
"numberOfRulesCovering",
"++",
";",
"//DoubleVector vote = new DoubleVector(rule.getPrediction(instance));",
"double",
"[",
"]",
"vote",
"=",
"rule",
".",
"getPrediction",
"(",
"instance",
")",
";",
"double",
"error",
"=",
"rule",
".",
"getCurrentError",
"(",
")",
";",
"debug",
"(",
"\"Rule No\"",
"+",
"rule",
".",
"getRuleNumberID",
"(",
")",
"+",
"\" Vote: \"",
"+",
"Arrays",
".",
"toString",
"(",
"vote",
")",
"+",
"\" Error: \"",
"+",
"error",
"+",
"\" Y: \"",
"+",
"instance",
".",
"classValue",
"(",
")",
",",
"3",
")",
";",
"//predictionValueForThisRule);",
"errorWeightedVote",
".",
"addVote",
"(",
"vote",
",",
"error",
")",
";",
"//combinedVote.addValues(vote);",
"if",
"(",
"!",
"this",
".",
"unorderedRulesOption",
".",
"isSet",
"(",
")",
")",
"{",
"// Ordered Rules Option.",
"break",
";",
"// Only one rule cover the instance.",
"}",
"}",
"}",
"if",
"(",
"numberOfRulesCovering",
"==",
"0",
")",
"{",
"//combinedVote = new DoubleVector(defaultRule.getPrediction(instance));",
"double",
"[",
"]",
"vote",
"=",
"defaultRule",
".",
"getPrediction",
"(",
"instance",
")",
";",
"double",
"error",
"=",
"defaultRule",
".",
"getCurrentError",
"(",
")",
";",
"errorWeightedVote",
".",
"addVote",
"(",
"vote",
",",
"error",
")",
";",
"debug",
"(",
"\"Default Rule Vote \"",
"+",
"Arrays",
".",
"toString",
"(",
"vote",
")",
"+",
"\" Error \"",
"+",
"error",
"+",
"\" Y: \"",
"+",
"instance",
".",
"classValue",
"(",
")",
",",
"3",
")",
";",
"}",
"double",
"[",
"]",
"weightedVote",
"=",
"errorWeightedVote",
".",
"computeWeightedVote",
"(",
")",
";",
"double",
"weightedError",
"=",
"errorWeightedVote",
".",
"getWeightedError",
"(",
")",
";",
"debug",
"(",
"\"Weighted Rule - Vote: \"",
"+",
"Arrays",
".",
"toString",
"(",
"weightedVote",
")",
"+",
"\" Weighted Error: \"",
"+",
"weightedError",
"+",
"\" Y:\"",
"+",
"instance",
".",
"classValue",
"(",
")",
",",
"3",
")",
";",
"return",
"new",
"Vote",
"(",
"weightedVote",
",",
"weightedError",
")",
";",
"}"
] | getVotes extension of the instance method getVotesForInstance
in moa.classifier.java
returns the prediction of the instance.
Called in WeightedRandomRules | [
"getVotes",
"extension",
"of",
"the",
"instance",
"method",
"getVotesForInstance",
"in",
"moa",
".",
"classifier",
".",
"java",
"returns",
"the",
"prediction",
"of",
"the",
"instance",
".",
"Called",
"in",
"WeightedRandomRules"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/rules/AbstractAMRules.java#L403-L438 |
28,974 | Waikato/moa | moa/src/main/java/moa/core/SizeOf.java | SizeOf.isPresent | protected static synchronized boolean isPresent() {
if (m_Present == null) {
try {
SizeOfAgent.fullSizeOf(new Integer(1));
m_Present = true;
} catch (Throwable t) {
m_Present = false;
}
}
return m_Present;
} | java | protected static synchronized boolean isPresent() {
if (m_Present == null) {
try {
SizeOfAgent.fullSizeOf(new Integer(1));
m_Present = true;
} catch (Throwable t) {
m_Present = false;
}
}
return m_Present;
} | [
"protected",
"static",
"synchronized",
"boolean",
"isPresent",
"(",
")",
"{",
"if",
"(",
"m_Present",
"==",
"null",
")",
"{",
"try",
"{",
"SizeOfAgent",
".",
"fullSizeOf",
"(",
"new",
"Integer",
"(",
"1",
")",
")",
";",
"m_Present",
"=",
"true",
";",
"}",
"catch",
"(",
"Throwable",
"t",
")",
"{",
"m_Present",
"=",
"false",
";",
"}",
"}",
"return",
"m_Present",
";",
"}"
] | Checks whteher the agent is present.
@return true if the agent is present, false otherwise | [
"Checks",
"whteher",
"the",
"agent",
"is",
"present",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/core/SizeOf.java#L41-L52 |
28,975 | Waikato/moa | moa/src/main/java/moa/tasks/Plot.java | Plot.createScript | private String createScript(File resultFile) {
String newLine = System.getProperty("line.separator");
int sourceFileIdx = 0;
// terminal options;
String script = "set term "
+ terminalOptions(Terminal.valueOf(outputTypeOption
.getChosenLabel())) + newLine;
script += "set output '" + resultFile.getAbsolutePath() + "'" + newLine;
script += "set datafile separator ','" + newLine;
script += "set grid" + newLine;
script += "set style line 1 pt 8" + newLine;
script += "set style line 2 lt rgb '#00C000'" + newLine;
script += "set style line 5 lt rgb '#FFD800'" + newLine;
script += "set style line 6 lt rgb '#4E0000'" + newLine;
script += "set format x '%.0s %c" + getAxisUnit(xUnitOption.getValue())
+ "'" + newLine;
script += "set format y '%.0s %c" + getAxisUnit(yUnitOption.getValue())
+ "'" + newLine;
script += "set ylabel '" + yTitleOption.getValue() + "'" + newLine;
script += "set xlabel '" + xTitleOption.getValue() + "'" + newLine;
if (!legendTypeOption.getChosenLabel().equals(LegendType.NONE)) {
script += "set key "
+ legendTypeOption.getChosenLabel().toLowerCase().replace(
'_', ' ')
+ " "
+ legendLocationOption.getChosenLabel().toLowerCase()
.replace('_', ' ') + newLine;
}
// additional commands
script += additionalSetOption.getValue();
// plot command
script += "plot " + additionalPlotOption.getValue() + " ";
// plot for each input file
for (int i = 0; i < inputFilesOption.getList().length; i++) {
if (sourceFileIdx > 0) {
script += ", ";
}
sourceFileIdx++;
script += "'" + ((StringOption) inputFilesOption
.getList()[i]).getValue() + "' using "
+ xColumnOption.getValue() + ":" + yColumnOption.getValue();
if (smoothOption.isSet()) {
script += ":(1.0) smooth bezier";
}
script += " with " + plotStyleOption.getChosenLabel().toLowerCase()
+ " ls " + sourceFileIdx + " lw "
+ lineWidthOption.getValue();
if (plotStyleOption.getChosenLabel().equals(
PlotStyle.LINESPOINTS.toString())
&& pointIntervalOption.getValue() > 0) {
script += " pointinterval " + pointIntervalOption.getValue();
}
script += " title '" + ((StringOption) fileAliasesOption
.getList()[i]).getValue() + "'";
}
script += newLine;
return script;
} | java | private String createScript(File resultFile) {
String newLine = System.getProperty("line.separator");
int sourceFileIdx = 0;
// terminal options;
String script = "set term "
+ terminalOptions(Terminal.valueOf(outputTypeOption
.getChosenLabel())) + newLine;
script += "set output '" + resultFile.getAbsolutePath() + "'" + newLine;
script += "set datafile separator ','" + newLine;
script += "set grid" + newLine;
script += "set style line 1 pt 8" + newLine;
script += "set style line 2 lt rgb '#00C000'" + newLine;
script += "set style line 5 lt rgb '#FFD800'" + newLine;
script += "set style line 6 lt rgb '#4E0000'" + newLine;
script += "set format x '%.0s %c" + getAxisUnit(xUnitOption.getValue())
+ "'" + newLine;
script += "set format y '%.0s %c" + getAxisUnit(yUnitOption.getValue())
+ "'" + newLine;
script += "set ylabel '" + yTitleOption.getValue() + "'" + newLine;
script += "set xlabel '" + xTitleOption.getValue() + "'" + newLine;
if (!legendTypeOption.getChosenLabel().equals(LegendType.NONE)) {
script += "set key "
+ legendTypeOption.getChosenLabel().toLowerCase().replace(
'_', ' ')
+ " "
+ legendLocationOption.getChosenLabel().toLowerCase()
.replace('_', ' ') + newLine;
}
// additional commands
script += additionalSetOption.getValue();
// plot command
script += "plot " + additionalPlotOption.getValue() + " ";
// plot for each input file
for (int i = 0; i < inputFilesOption.getList().length; i++) {
if (sourceFileIdx > 0) {
script += ", ";
}
sourceFileIdx++;
script += "'" + ((StringOption) inputFilesOption
.getList()[i]).getValue() + "' using "
+ xColumnOption.getValue() + ":" + yColumnOption.getValue();
if (smoothOption.isSet()) {
script += ":(1.0) smooth bezier";
}
script += " with " + plotStyleOption.getChosenLabel().toLowerCase()
+ " ls " + sourceFileIdx + " lw "
+ lineWidthOption.getValue();
if (plotStyleOption.getChosenLabel().equals(
PlotStyle.LINESPOINTS.toString())
&& pointIntervalOption.getValue() > 0) {
script += " pointinterval " + pointIntervalOption.getValue();
}
script += " title '" + ((StringOption) fileAliasesOption
.getList()[i]).getValue() + "'";
}
script += newLine;
return script;
} | [
"private",
"String",
"createScript",
"(",
"File",
"resultFile",
")",
"{",
"String",
"newLine",
"=",
"System",
".",
"getProperty",
"(",
"\"line.separator\"",
")",
";",
"int",
"sourceFileIdx",
"=",
"0",
";",
"// terminal options;",
"String",
"script",
"=",
"\"set term \"",
"+",
"terminalOptions",
"(",
"Terminal",
".",
"valueOf",
"(",
"outputTypeOption",
".",
"getChosenLabel",
"(",
")",
")",
")",
"+",
"newLine",
";",
"script",
"+=",
"\"set output '\"",
"+",
"resultFile",
".",
"getAbsolutePath",
"(",
")",
"+",
"\"'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set datafile separator ','\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set grid\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set style line 1 pt 8\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set style line 2 lt rgb '#00C000'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set style line 5 lt rgb '#FFD800'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set style line 6 lt rgb '#4E0000'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set format x '%.0s %c\"",
"+",
"getAxisUnit",
"(",
"xUnitOption",
".",
"getValue",
"(",
")",
")",
"+",
"\"'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set format y '%.0s %c\"",
"+",
"getAxisUnit",
"(",
"yUnitOption",
".",
"getValue",
"(",
")",
")",
"+",
"\"'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set ylabel '\"",
"+",
"yTitleOption",
".",
"getValue",
"(",
")",
"+",
"\"'\"",
"+",
"newLine",
";",
"script",
"+=",
"\"set xlabel '\"",
"+",
"xTitleOption",
".",
"getValue",
"(",
")",
"+",
"\"'\"",
"+",
"newLine",
";",
"if",
"(",
"!",
"legendTypeOption",
".",
"getChosenLabel",
"(",
")",
".",
"equals",
"(",
"LegendType",
".",
"NONE",
")",
")",
"{",
"script",
"+=",
"\"set key \"",
"+",
"legendTypeOption",
".",
"getChosenLabel",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
"+",
"\" \"",
"+",
"legendLocationOption",
".",
"getChosenLabel",
"(",
")",
".",
"toLowerCase",
"(",
")",
".",
"replace",
"(",
"'",
"'",
",",
"'",
"'",
")",
"+",
"newLine",
";",
"}",
"// additional commands",
"script",
"+=",
"additionalSetOption",
".",
"getValue",
"(",
")",
";",
"// plot command",
"script",
"+=",
"\"plot \"",
"+",
"additionalPlotOption",
".",
"getValue",
"(",
")",
"+",
"\" \"",
";",
"// plot for each input file",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"inputFilesOption",
".",
"getList",
"(",
")",
".",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"sourceFileIdx",
">",
"0",
")",
"{",
"script",
"+=",
"\", \"",
";",
"}",
"sourceFileIdx",
"++",
";",
"script",
"+=",
"\"'\"",
"+",
"(",
"(",
"StringOption",
")",
"inputFilesOption",
".",
"getList",
"(",
")",
"[",
"i",
"]",
")",
".",
"getValue",
"(",
")",
"+",
"\"' using \"",
"+",
"xColumnOption",
".",
"getValue",
"(",
")",
"+",
"\":\"",
"+",
"yColumnOption",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"smoothOption",
".",
"isSet",
"(",
")",
")",
"{",
"script",
"+=",
"\":(1.0) smooth bezier\"",
";",
"}",
"script",
"+=",
"\" with \"",
"+",
"plotStyleOption",
".",
"getChosenLabel",
"(",
")",
".",
"toLowerCase",
"(",
")",
"+",
"\" ls \"",
"+",
"sourceFileIdx",
"+",
"\" lw \"",
"+",
"lineWidthOption",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"plotStyleOption",
".",
"getChosenLabel",
"(",
")",
".",
"equals",
"(",
"PlotStyle",
".",
"LINESPOINTS",
".",
"toString",
"(",
")",
")",
"&&",
"pointIntervalOption",
".",
"getValue",
"(",
")",
">",
"0",
")",
"{",
"script",
"+=",
"\" pointinterval \"",
"+",
"pointIntervalOption",
".",
"getValue",
"(",
")",
";",
"}",
"script",
"+=",
"\" title '\"",
"+",
"(",
"(",
"StringOption",
")",
"fileAliasesOption",
".",
"getList",
"(",
")",
"[",
"i",
"]",
")",
".",
"getValue",
"(",
")",
"+",
"\"'\"",
";",
"}",
"script",
"+=",
"newLine",
";",
"return",
"script",
";",
"}"
] | Creates the content of the gnuplot script.
@param resultFile path of the plot output file
@return gnuplot script | [
"Creates",
"the",
"content",
"of",
"the",
"gnuplot",
"script",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/tasks/Plot.java#L486-L550 |
28,976 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.calculateGTPointQualities | private void calculateGTPointQualities(){
for (int p = 0; p < numPoints; p++) {
CMMPoint cmdp = cmmpoints.get(p);
if(!cmdp.isNoise()){
cmdp.connectivity = getConnectionValue(cmdp, cmdp.workclass());
cmdp.p.setMeasureValue("Connectivity", cmdp.connectivity);
}
}
} | java | private void calculateGTPointQualities(){
for (int p = 0; p < numPoints; p++) {
CMMPoint cmdp = cmmpoints.get(p);
if(!cmdp.isNoise()){
cmdp.connectivity = getConnectionValue(cmdp, cmdp.workclass());
cmdp.p.setMeasureValue("Connectivity", cmdp.connectivity);
}
}
} | [
"private",
"void",
"calculateGTPointQualities",
"(",
")",
"{",
"for",
"(",
"int",
"p",
"=",
"0",
";",
"p",
"<",
"numPoints",
";",
"p",
"++",
")",
"{",
"CMMPoint",
"cmdp",
"=",
"cmmpoints",
".",
"get",
"(",
"p",
")",
";",
"if",
"(",
"!",
"cmdp",
".",
"isNoise",
"(",
")",
")",
"{",
"cmdp",
".",
"connectivity",
"=",
"getConnectionValue",
"(",
"cmdp",
",",
"cmdp",
".",
"workclass",
"(",
")",
")",
";",
"cmdp",
".",
"p",
".",
"setMeasureValue",
"(",
"\"Connectivity\"",
",",
"cmdp",
".",
"connectivity",
")",
";",
"}",
"}",
"}"
] | calculate initial connectivities | [
"calculate",
"initial",
"connectivities"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L625-L633 |
28,977 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.calculateGTClusterConnections | private void calculateGTClusterConnections(){
for (int c0 = 0; c0 < gt0Clusters.size(); c0++) {
for (int c1 = 0; c1 < gt0Clusters.size(); c1++) {
gt0Clusters.get(c0).calculateClusterConnection(c1, true);
}
}
boolean changedConnection = true;
while(changedConnection){
if(debug){
System.out.println("Cluster Connection");
for (int c = 0; c < gt0Clusters.size(); c++) {
System.out.print("C"+gt0Clusters.get(c).label+" --> ");
for (int c1 = 0; c1 < gt0Clusters.get(c).connections.size(); c1++) {
System.out.print(" C"+gt0Clusters.get(c1).label+": "+gt0Clusters.get(c).connections.get(c1));
}
System.out.println("");
}
System.out.println("");
}
double max = 0;
int maxIndexI = -1;
int maxIndexJ = -1;
changedConnection = false;
for (int c0 = 0; c0 < gt0Clusters.size(); c0++) {
for (int c1 = c0+1; c1 < gt0Clusters.size(); c1++) {
if(c0==c1) continue;
double min =Math.min(gt0Clusters.get(c0).connections.get(c1), gt0Clusters.get(c1).connections.get(c0));
if(min > max){
max = min;
maxIndexI = c0;
maxIndexJ = c1;
}
}
}
if(maxIndexI!=-1 && max > tauConnection){
gt0Clusters.get(maxIndexI).mergeCluster(maxIndexJ);
if(debug)
System.out.println("Merging "+maxIndexI+" and "+maxIndexJ+" because of connection "+max);
changedConnection = true;
}
}
numGT0Classes = gt0Clusters.size();
} | java | private void calculateGTClusterConnections(){
for (int c0 = 0; c0 < gt0Clusters.size(); c0++) {
for (int c1 = 0; c1 < gt0Clusters.size(); c1++) {
gt0Clusters.get(c0).calculateClusterConnection(c1, true);
}
}
boolean changedConnection = true;
while(changedConnection){
if(debug){
System.out.println("Cluster Connection");
for (int c = 0; c < gt0Clusters.size(); c++) {
System.out.print("C"+gt0Clusters.get(c).label+" --> ");
for (int c1 = 0; c1 < gt0Clusters.get(c).connections.size(); c1++) {
System.out.print(" C"+gt0Clusters.get(c1).label+": "+gt0Clusters.get(c).connections.get(c1));
}
System.out.println("");
}
System.out.println("");
}
double max = 0;
int maxIndexI = -1;
int maxIndexJ = -1;
changedConnection = false;
for (int c0 = 0; c0 < gt0Clusters.size(); c0++) {
for (int c1 = c0+1; c1 < gt0Clusters.size(); c1++) {
if(c0==c1) continue;
double min =Math.min(gt0Clusters.get(c0).connections.get(c1), gt0Clusters.get(c1).connections.get(c0));
if(min > max){
max = min;
maxIndexI = c0;
maxIndexJ = c1;
}
}
}
if(maxIndexI!=-1 && max > tauConnection){
gt0Clusters.get(maxIndexI).mergeCluster(maxIndexJ);
if(debug)
System.out.println("Merging "+maxIndexI+" and "+maxIndexJ+" because of connection "+max);
changedConnection = true;
}
}
numGT0Classes = gt0Clusters.size();
} | [
"private",
"void",
"calculateGTClusterConnections",
"(",
")",
"{",
"for",
"(",
"int",
"c0",
"=",
"0",
";",
"c0",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c0",
"++",
")",
"{",
"for",
"(",
"int",
"c1",
"=",
"0",
";",
"c1",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c1",
"++",
")",
"{",
"gt0Clusters",
".",
"get",
"(",
"c0",
")",
".",
"calculateClusterConnection",
"(",
"c1",
",",
"true",
")",
";",
"}",
"}",
"boolean",
"changedConnection",
"=",
"true",
";",
"while",
"(",
"changedConnection",
")",
"{",
"if",
"(",
"debug",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Cluster Connection\"",
")",
";",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c",
"++",
")",
"{",
"System",
".",
"out",
".",
"print",
"(",
"\"C\"",
"+",
"gt0Clusters",
".",
"get",
"(",
"c",
")",
".",
"label",
"+",
"\" --> \"",
")",
";",
"for",
"(",
"int",
"c1",
"=",
"0",
";",
"c1",
"<",
"gt0Clusters",
".",
"get",
"(",
"c",
")",
".",
"connections",
".",
"size",
"(",
")",
";",
"c1",
"++",
")",
"{",
"System",
".",
"out",
".",
"print",
"(",
"\" C\"",
"+",
"gt0Clusters",
".",
"get",
"(",
"c1",
")",
".",
"label",
"+",
"\": \"",
"+",
"gt0Clusters",
".",
"get",
"(",
"c",
")",
".",
"connections",
".",
"get",
"(",
"c1",
")",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"\"\"",
")",
";",
"}",
"System",
".",
"out",
".",
"println",
"(",
"\"\"",
")",
";",
"}",
"double",
"max",
"=",
"0",
";",
"int",
"maxIndexI",
"=",
"-",
"1",
";",
"int",
"maxIndexJ",
"=",
"-",
"1",
";",
"changedConnection",
"=",
"false",
";",
"for",
"(",
"int",
"c0",
"=",
"0",
";",
"c0",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c0",
"++",
")",
"{",
"for",
"(",
"int",
"c1",
"=",
"c0",
"+",
"1",
";",
"c1",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c1",
"++",
")",
"{",
"if",
"(",
"c0",
"==",
"c1",
")",
"continue",
";",
"double",
"min",
"=",
"Math",
".",
"min",
"(",
"gt0Clusters",
".",
"get",
"(",
"c0",
")",
".",
"connections",
".",
"get",
"(",
"c1",
")",
",",
"gt0Clusters",
".",
"get",
"(",
"c1",
")",
".",
"connections",
".",
"get",
"(",
"c0",
")",
")",
";",
"if",
"(",
"min",
">",
"max",
")",
"{",
"max",
"=",
"min",
";",
"maxIndexI",
"=",
"c0",
";",
"maxIndexJ",
"=",
"c1",
";",
"}",
"}",
"}",
"if",
"(",
"maxIndexI",
"!=",
"-",
"1",
"&&",
"max",
">",
"tauConnection",
")",
"{",
"gt0Clusters",
".",
"get",
"(",
"maxIndexI",
")",
".",
"mergeCluster",
"(",
"maxIndexJ",
")",
";",
"if",
"(",
"debug",
")",
"System",
".",
"out",
".",
"println",
"(",
"\"Merging \"",
"+",
"maxIndexI",
"+",
"\" and \"",
"+",
"maxIndexJ",
"+",
"\" because of connection \"",
"+",
"max",
")",
";",
"changedConnection",
"=",
"true",
";",
"}",
"}",
"numGT0Classes",
"=",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"}"
] | Calculate connections between clusters and merge clusters accordingly as
long as connections exceed threshold | [
"Calculate",
"connections",
"between",
"clusters",
"and",
"merge",
"clusters",
"accordingly",
"as",
"long",
"as",
"connections",
"exceed",
"threshold"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L641-L687 |
28,978 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.getNoiseSeparability | public double getNoiseSeparability(){
if(noise.isEmpty())
return 1;
double connectivity = 0;
for(int p : noise){
CMMPoint npoint = cmmpoints.get(p);
double maxConnection = 0;
//TODO: some kind of pruning possible. what about weighting?
for (int c = 0; c < gt0Clusters.size(); c++) {
double connection = getConnectionValue(npoint, c);
if(connection > maxConnection)
maxConnection = connection;
}
connectivity+=maxConnection;
npoint.p.setMeasureValue("MaxConnection", maxConnection);
}
return 1-(connectivity / noise.size());
} | java | public double getNoiseSeparability(){
if(noise.isEmpty())
return 1;
double connectivity = 0;
for(int p : noise){
CMMPoint npoint = cmmpoints.get(p);
double maxConnection = 0;
//TODO: some kind of pruning possible. what about weighting?
for (int c = 0; c < gt0Clusters.size(); c++) {
double connection = getConnectionValue(npoint, c);
if(connection > maxConnection)
maxConnection = connection;
}
connectivity+=maxConnection;
npoint.p.setMeasureValue("MaxConnection", maxConnection);
}
return 1-(connectivity / noise.size());
} | [
"public",
"double",
"getNoiseSeparability",
"(",
")",
"{",
"if",
"(",
"noise",
".",
"isEmpty",
"(",
")",
")",
"return",
"1",
";",
"double",
"connectivity",
"=",
"0",
";",
"for",
"(",
"int",
"p",
":",
"noise",
")",
"{",
"CMMPoint",
"npoint",
"=",
"cmmpoints",
".",
"get",
"(",
"p",
")",
";",
"double",
"maxConnection",
"=",
"0",
";",
"//TODO: some kind of pruning possible. what about weighting?",
"for",
"(",
"int",
"c",
"=",
"0",
";",
"c",
"<",
"gt0Clusters",
".",
"size",
"(",
")",
";",
"c",
"++",
")",
"{",
"double",
"connection",
"=",
"getConnectionValue",
"(",
"npoint",
",",
"c",
")",
";",
"if",
"(",
"connection",
">",
"maxConnection",
")",
"maxConnection",
"=",
"connection",
";",
"}",
"connectivity",
"+=",
"maxConnection",
";",
"npoint",
".",
"p",
".",
"setMeasureValue",
"(",
"\"MaxConnection\"",
",",
"maxConnection",
")",
";",
"}",
"return",
"1",
"-",
"(",
"connectivity",
"/",
"noise",
".",
"size",
"(",
")",
")",
";",
"}"
] | Calculates how well noise is separable from the given clusters
Small values indicate bad separability, values close to 1 indicate good separability
@return index of noise separability | [
"Calculates",
"how",
"well",
"noise",
"is",
"separable",
"from",
"the",
"given",
"clusters",
"Small",
"values",
"indicate",
"bad",
"separability",
"values",
"close",
"to",
"1",
"indicate",
"good",
"separability"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L717-L737 |
28,979 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.getModelQuality | public double getModelQuality(){
for(int p = 0; p < numPoints; p++){
CMMPoint cmdp = cmmpoints.get(p);
for(int hc = 0; hc < numGTClusters;hc++){
if(gtClustering.get(hc).getGroundTruth() != cmdp.trueClass){
if(gtClustering.get(hc).getInclusionProbability(cmdp) >= 1){
if(!cmdp.isNoise())
pointErrorByModel++;
else
noiseErrorByModel++;
break;
}
}
}
}
if(debug)
System.out.println("Error by model: noise "+noiseErrorByModel+" point "+pointErrorByModel);
return 1-((pointErrorByModel + noiseErrorByModel)/(double) numPoints);
} | java | public double getModelQuality(){
for(int p = 0; p < numPoints; p++){
CMMPoint cmdp = cmmpoints.get(p);
for(int hc = 0; hc < numGTClusters;hc++){
if(gtClustering.get(hc).getGroundTruth() != cmdp.trueClass){
if(gtClustering.get(hc).getInclusionProbability(cmdp) >= 1){
if(!cmdp.isNoise())
pointErrorByModel++;
else
noiseErrorByModel++;
break;
}
}
}
}
if(debug)
System.out.println("Error by model: noise "+noiseErrorByModel+" point "+pointErrorByModel);
return 1-((pointErrorByModel + noiseErrorByModel)/(double) numPoints);
} | [
"public",
"double",
"getModelQuality",
"(",
")",
"{",
"for",
"(",
"int",
"p",
"=",
"0",
";",
"p",
"<",
"numPoints",
";",
"p",
"++",
")",
"{",
"CMMPoint",
"cmdp",
"=",
"cmmpoints",
".",
"get",
"(",
"p",
")",
";",
"for",
"(",
"int",
"hc",
"=",
"0",
";",
"hc",
"<",
"numGTClusters",
";",
"hc",
"++",
")",
"{",
"if",
"(",
"gtClustering",
".",
"get",
"(",
"hc",
")",
".",
"getGroundTruth",
"(",
")",
"!=",
"cmdp",
".",
"trueClass",
")",
"{",
"if",
"(",
"gtClustering",
".",
"get",
"(",
"hc",
")",
".",
"getInclusionProbability",
"(",
"cmdp",
")",
">=",
"1",
")",
"{",
"if",
"(",
"!",
"cmdp",
".",
"isNoise",
"(",
")",
")",
"pointErrorByModel",
"++",
";",
"else",
"noiseErrorByModel",
"++",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"debug",
")",
"System",
".",
"out",
".",
"println",
"(",
"\"Error by model: noise \"",
"+",
"noiseErrorByModel",
"+",
"\" point \"",
"+",
"pointErrorByModel",
")",
";",
"return",
"1",
"-",
"(",
"(",
"pointErrorByModel",
"+",
"noiseErrorByModel",
")",
"/",
"(",
"double",
")",
"numPoints",
")",
";",
"}"
] | Calculates the relative number of errors being caused by the underlying cluster model
@return quality of the model | [
"Calculates",
"the",
"relative",
"number",
"of",
"errors",
"being",
"caused",
"by",
"the",
"underlying",
"cluster",
"model"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L744-L763 |
28,980 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.distance | private double distance(Instance inst1, double[] inst2){
double distance = 0.0;
for (int i = 0; i < numDims; i++) {
double d = inst1.value(i) - inst2[i];
distance += d * d;
}
return Math.sqrt(distance);
} | java | private double distance(Instance inst1, double[] inst2){
double distance = 0.0;
for (int i = 0; i < numDims; i++) {
double d = inst1.value(i) - inst2[i];
distance += d * d;
}
return Math.sqrt(distance);
} | [
"private",
"double",
"distance",
"(",
"Instance",
"inst1",
",",
"double",
"[",
"]",
"inst2",
")",
"{",
"double",
"distance",
"=",
"0.0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numDims",
";",
"i",
"++",
")",
"{",
"double",
"d",
"=",
"inst1",
".",
"value",
"(",
"i",
")",
"-",
"inst2",
"[",
"i",
"]",
";",
"distance",
"+=",
"d",
"*",
"d",
";",
"}",
"return",
"Math",
".",
"sqrt",
"(",
"distance",
")",
";",
"}"
] | Calculates Euclidian distance
@param inst1 point as an instance
@param inst2 point as double array
@return euclidian distance | [
"Calculates",
"Euclidian",
"distance"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L810-L817 |
28,981 | Waikato/moa | moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java | CMM_GTAnalysis.getParameterString | public String getParameterString(){
String para = "";
para+="k="+knnNeighbourhood+";";
if(useExpConnectivity){
para+="lambdaConnX="+lambdaConnX+";";
para+="lambdaConn="+lamdaConn+";";
para+="lambdaConnRef="+lambdaConnRefXValue+";";
}
para+="m="+clusterConnectionMaxPoints+";";
para+="tauConn="+tauConnection+";";
return para;
} | java | public String getParameterString(){
String para = "";
para+="k="+knnNeighbourhood+";";
if(useExpConnectivity){
para+="lambdaConnX="+lambdaConnX+";";
para+="lambdaConn="+lamdaConn+";";
para+="lambdaConnRef="+lambdaConnRefXValue+";";
}
para+="m="+clusterConnectionMaxPoints+";";
para+="tauConn="+tauConnection+";";
return para;
} | [
"public",
"String",
"getParameterString",
"(",
")",
"{",
"String",
"para",
"=",
"\"\"",
";",
"para",
"+=",
"\"k=\"",
"+",
"knnNeighbourhood",
"+",
"\";\"",
";",
"if",
"(",
"useExpConnectivity",
")",
"{",
"para",
"+=",
"\"lambdaConnX=\"",
"+",
"lambdaConnX",
"+",
"\";\"",
";",
"para",
"+=",
"\"lambdaConn=\"",
"+",
"lamdaConn",
"+",
"\";\"",
";",
"para",
"+=",
"\"lambdaConnRef=\"",
"+",
"lambdaConnRefXValue",
"+",
"\";\"",
";",
"}",
"para",
"+=",
"\"m=\"",
"+",
"clusterConnectionMaxPoints",
"+",
"\";\"",
";",
"para",
"+=",
"\"tauConn=\"",
"+",
"tauConnection",
"+",
"\";\"",
";",
"return",
"para",
";",
"}"
] | String with main CMM parameters
@return main CMM parameter | [
"String",
"with",
"main",
"CMM",
"parameters"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/evaluation/CMM_GTAnalysis.java#L823-L835 |
28,982 | Waikato/moa | moa/src/main/java/moa/gui/colorGenerator/HSVColorGenerator.java | HSVColorGenerator.generateColors | @Override
public Color[] generateColors(int numColors) {
Color[] colors = new Color[numColors];
// fix the seed to always get the same colors for the same numColors parameter and ranges for hue, saturation and brightness
Random rand = new Random(0);
for(int i = 0; i < numColors; ++i)
{
float hueRatio = i/(float)numColors;
float saturationRatio = rand.nextFloat();
float brightnessRatio = rand.nextFloat();
float hue = lerp(hueMin, hueMax, hueRatio);
float saturation = lerp(saturationMin, saturationMax, saturationRatio);
float brightness = lerp(brightnessMin, brightnessMax, brightnessRatio);
colors[i] = Color.getHSBColor(hue, saturation, brightness);
}
return colors;
} | java | @Override
public Color[] generateColors(int numColors) {
Color[] colors = new Color[numColors];
// fix the seed to always get the same colors for the same numColors parameter and ranges for hue, saturation and brightness
Random rand = new Random(0);
for(int i = 0; i < numColors; ++i)
{
float hueRatio = i/(float)numColors;
float saturationRatio = rand.nextFloat();
float brightnessRatio = rand.nextFloat();
float hue = lerp(hueMin, hueMax, hueRatio);
float saturation = lerp(saturationMin, saturationMax, saturationRatio);
float brightness = lerp(brightnessMin, brightnessMax, brightnessRatio);
colors[i] = Color.getHSBColor(hue, saturation, brightness);
}
return colors;
} | [
"@",
"Override",
"public",
"Color",
"[",
"]",
"generateColors",
"(",
"int",
"numColors",
")",
"{",
"Color",
"[",
"]",
"colors",
"=",
"new",
"Color",
"[",
"numColors",
"]",
";",
"// fix the seed to always get the same colors for the same numColors parameter and ranges for hue, saturation and brightness",
"Random",
"rand",
"=",
"new",
"Random",
"(",
"0",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"numColors",
";",
"++",
"i",
")",
"{",
"float",
"hueRatio",
"=",
"i",
"/",
"(",
"float",
")",
"numColors",
";",
"float",
"saturationRatio",
"=",
"rand",
".",
"nextFloat",
"(",
")",
";",
"float",
"brightnessRatio",
"=",
"rand",
".",
"nextFloat",
"(",
")",
";",
"float",
"hue",
"=",
"lerp",
"(",
"hueMin",
",",
"hueMax",
",",
"hueRatio",
")",
";",
"float",
"saturation",
"=",
"lerp",
"(",
"saturationMin",
",",
"saturationMax",
",",
"saturationRatio",
")",
";",
"float",
"brightness",
"=",
"lerp",
"(",
"brightnessMin",
",",
"brightnessMax",
",",
"brightnessRatio",
")",
";",
"colors",
"[",
"i",
"]",
"=",
"Color",
".",
"getHSBColor",
"(",
"hue",
",",
"saturation",
",",
"brightness",
")",
";",
"}",
"return",
"colors",
";",
"}"
] | Generate numColors unique colors which should be easily distinguishable.
@param numColors the number of colors to generate
@return an array of unique colors | [
"Generate",
"numColors",
"unique",
"colors",
"which",
"should",
"be",
"easily",
"distinguishable",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/gui/colorGenerator/HSVColorGenerator.java#L67-L84 |
28,983 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java | HSTreeNode.updateMass | public void updateMass(Instance inst, boolean referenceWindow)
{
if(referenceWindow)
r++;
else
l++;
if(internalNode)
{
if(inst.value(this.splitAttribute) > this.splitValue)
right.updateMass(inst, referenceWindow);
else
left.updateMass(inst, referenceWindow);
}
} | java | public void updateMass(Instance inst, boolean referenceWindow)
{
if(referenceWindow)
r++;
else
l++;
if(internalNode)
{
if(inst.value(this.splitAttribute) > this.splitValue)
right.updateMass(inst, referenceWindow);
else
left.updateMass(inst, referenceWindow);
}
} | [
"public",
"void",
"updateMass",
"(",
"Instance",
"inst",
",",
"boolean",
"referenceWindow",
")",
"{",
"if",
"(",
"referenceWindow",
")",
"r",
"++",
";",
"else",
"l",
"++",
";",
"if",
"(",
"internalNode",
")",
"{",
"if",
"(",
"inst",
".",
"value",
"(",
"this",
".",
"splitAttribute",
")",
">",
"this",
".",
"splitValue",
")",
"right",
".",
"updateMass",
"(",
"inst",
",",
"referenceWindow",
")",
";",
"else",
"left",
".",
"updateMass",
"(",
"inst",
",",
"referenceWindow",
")",
";",
"}",
"}"
] | Update the mass profile of this node.
@param inst the instance being passed through the HSTree.
@param referenceWindow if the HSTree is in the initial reference window: <b>true</b>, else: <b>false</b> | [
"Update",
"the",
"mass",
"profile",
"of",
"this",
"node",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java#L120-L134 |
28,984 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java | HSTreeNode.score | public double score(Instance inst, int sizeLimit)
{
double anomalyScore = 0.0;
if(this.internalNode && this.r > sizeLimit)
{
if(inst.value(this.splitAttribute) > this.splitValue)
anomalyScore = right.score(inst, sizeLimit);
else
anomalyScore = left.score(inst, sizeLimit);
}
else
{
anomalyScore = this.r * Math.pow(2.0, this.depth);
}
return anomalyScore;
} | java | public double score(Instance inst, int sizeLimit)
{
double anomalyScore = 0.0;
if(this.internalNode && this.r > sizeLimit)
{
if(inst.value(this.splitAttribute) > this.splitValue)
anomalyScore = right.score(inst, sizeLimit);
else
anomalyScore = left.score(inst, sizeLimit);
}
else
{
anomalyScore = this.r * Math.pow(2.0, this.depth);
}
return anomalyScore;
} | [
"public",
"double",
"score",
"(",
"Instance",
"inst",
",",
"int",
"sizeLimit",
")",
"{",
"double",
"anomalyScore",
"=",
"0.0",
";",
"if",
"(",
"this",
".",
"internalNode",
"&&",
"this",
".",
"r",
">",
"sizeLimit",
")",
"{",
"if",
"(",
"inst",
".",
"value",
"(",
"this",
".",
"splitAttribute",
")",
">",
"this",
".",
"splitValue",
")",
"anomalyScore",
"=",
"right",
".",
"score",
"(",
"inst",
",",
"sizeLimit",
")",
";",
"else",
"anomalyScore",
"=",
"left",
".",
"score",
"(",
"inst",
",",
"sizeLimit",
")",
";",
"}",
"else",
"{",
"anomalyScore",
"=",
"this",
".",
"r",
"*",
"Math",
".",
"pow",
"(",
"2.0",
",",
"this",
".",
"depth",
")",
";",
"}",
"return",
"anomalyScore",
";",
"}"
] | If this node is a leaf node or it has a mass profile of less than sizeLimit, this returns the anomaly score for the argument instance.
Otherwise this node determines which of its subordinate nodes the argument instance belongs to and asks it provide the anomaly score.
@param inst the instance being passed through the tree
@param sizeLimit the minimum mass profile for a node to calculate the argument instance's anomaly score
@return the argument instance's anomaly score (r * 2^depth) | [
"If",
"this",
"node",
"is",
"a",
"leaf",
"node",
"or",
"it",
"has",
"a",
"mass",
"profile",
"of",
"less",
"than",
"sizeLimit",
"this",
"returns",
"the",
"anomaly",
"score",
"for",
"the",
"argument",
"instance",
".",
"Otherwise",
"this",
"node",
"determines",
"which",
"of",
"its",
"subordinate",
"nodes",
"the",
"argument",
"instance",
"belongs",
"to",
"and",
"asks",
"it",
"provide",
"the",
"anomaly",
"score",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java#L161-L178 |
28,985 | Waikato/moa | moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java | HSTreeNode.printNode | protected void printNode()
{
System.out.println(this.depth+", "+this.splitAttribute+", "+this.splitValue+", "+this.r);
if(this.internalNode)
{
this.right.printNode();
this.left.printNode();
}
} | java | protected void printNode()
{
System.out.println(this.depth+", "+this.splitAttribute+", "+this.splitValue+", "+this.r);
if(this.internalNode)
{
this.right.printNode();
this.left.printNode();
}
} | [
"protected",
"void",
"printNode",
"(",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"this",
".",
"depth",
"+",
"\", \"",
"+",
"this",
".",
"splitAttribute",
"+",
"\", \"",
"+",
"this",
".",
"splitValue",
"+",
"\", \"",
"+",
"this",
".",
"r",
")",
";",
"if",
"(",
"this",
".",
"internalNode",
")",
"{",
"this",
".",
"right",
".",
"printNode",
"(",
")",
";",
"this",
".",
"left",
".",
"printNode",
"(",
")",
";",
"}",
"}"
] | Prints this node to string and, if it is an internal node, prints its children nodes as well.
Useful for debugging the entire tree structure. | [
"Prints",
"this",
"node",
"to",
"string",
"and",
"if",
"it",
"is",
"an",
"internal",
"node",
"prints",
"its",
"children",
"nodes",
"as",
"well",
".",
"Useful",
"for",
"debugging",
"the",
"entire",
"tree",
"structure",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/classifiers/oneclass/HSTreeNode.java#L184-L193 |
28,986 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.initialClustering | private void initialClustering() {
//System.out.println("INITIAL CLUSTERING CALLED");
//printDStreamState();
// 1. Update the density of all grids in grid_list
updateGridListDensity();
//printGridList();
// 2. Assign each dense grid to a distinct cluster
// and
// 3. Label all other grids as NO_CLASS
Iterator<Map.Entry<DensityGrid, CharacteristicVector>> glIter = this.grid_list.entrySet().iterator();
HashMap<DensityGrid, CharacteristicVector> newGL = new HashMap<DensityGrid, CharacteristicVector>();
while(glIter.hasNext())
{
Map.Entry<DensityGrid, CharacteristicVector> grid = glIter.next();
DensityGrid dg = grid.getKey();
CharacteristicVector cvOfG = grid.getValue();
//System.out.print(dg.toString());
if(cvOfG.getAttribute() == DENSE)
{
int gridClass = this.cluster_list.size();
cvOfG.setLabel(gridClass);
GridCluster gc = new GridCluster ((CFCluster)dg, new ArrayList<CFCluster>(), gridClass);
gc.addGrid(dg);
this.cluster_list.add(gc);
//System.out.print(" was dense (class "+gridClass+")");
}
else
cvOfG.setLabel(NO_CLASS);
//System.out.println();
newGL.put(dg, cvOfG);
}
this.grid_list = newGL;
//printGridClusters();
// 4. Make changes to grid labels by doing:
// a. For each cluster c
// b. For each outside grid g of c
// c. For each neighbouring grid h of g
// d. If h belongs to c', label c and c' with
// the label of the largest cluster
// e. Else if h is transitional, assign it to c
// f. While changes can be made
boolean changesMade;
do{
changesMade = adjustLabels();
}while(changesMade); // while changes are being made
//printGridList();
//printGridClusters();
} | java | private void initialClustering() {
//System.out.println("INITIAL CLUSTERING CALLED");
//printDStreamState();
// 1. Update the density of all grids in grid_list
updateGridListDensity();
//printGridList();
// 2. Assign each dense grid to a distinct cluster
// and
// 3. Label all other grids as NO_CLASS
Iterator<Map.Entry<DensityGrid, CharacteristicVector>> glIter = this.grid_list.entrySet().iterator();
HashMap<DensityGrid, CharacteristicVector> newGL = new HashMap<DensityGrid, CharacteristicVector>();
while(glIter.hasNext())
{
Map.Entry<DensityGrid, CharacteristicVector> grid = glIter.next();
DensityGrid dg = grid.getKey();
CharacteristicVector cvOfG = grid.getValue();
//System.out.print(dg.toString());
if(cvOfG.getAttribute() == DENSE)
{
int gridClass = this.cluster_list.size();
cvOfG.setLabel(gridClass);
GridCluster gc = new GridCluster ((CFCluster)dg, new ArrayList<CFCluster>(), gridClass);
gc.addGrid(dg);
this.cluster_list.add(gc);
//System.out.print(" was dense (class "+gridClass+")");
}
else
cvOfG.setLabel(NO_CLASS);
//System.out.println();
newGL.put(dg, cvOfG);
}
this.grid_list = newGL;
//printGridClusters();
// 4. Make changes to grid labels by doing:
// a. For each cluster c
// b. For each outside grid g of c
// c. For each neighbouring grid h of g
// d. If h belongs to c', label c and c' with
// the label of the largest cluster
// e. Else if h is transitional, assign it to c
// f. While changes can be made
boolean changesMade;
do{
changesMade = adjustLabels();
}while(changesMade); // while changes are being made
//printGridList();
//printGridClusters();
} | [
"private",
"void",
"initialClustering",
"(",
")",
"{",
"//System.out.println(\"INITIAL CLUSTERING CALLED\");",
"//printDStreamState();",
"// 1. Update the density of all grids in grid_list",
"updateGridListDensity",
"(",
")",
";",
"//printGridList();",
"// 2. Assign each dense grid to a distinct cluster",
"// and",
"// 3. Label all other grids as NO_CLASS\t",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
">",
"glIter",
"=",
"this",
".",
"grid_list",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"newGL",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"(",
")",
";",
"while",
"(",
"glIter",
".",
"hasNext",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"grid",
"=",
"glIter",
".",
"next",
"(",
")",
";",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cvOfG",
"=",
"grid",
".",
"getValue",
"(",
")",
";",
"//System.out.print(dg.toString());",
"if",
"(",
"cvOfG",
".",
"getAttribute",
"(",
")",
"==",
"DENSE",
")",
"{",
"int",
"gridClass",
"=",
"this",
".",
"cluster_list",
".",
"size",
"(",
")",
";",
"cvOfG",
".",
"setLabel",
"(",
"gridClass",
")",
";",
"GridCluster",
"gc",
"=",
"new",
"GridCluster",
"(",
"(",
"CFCluster",
")",
"dg",
",",
"new",
"ArrayList",
"<",
"CFCluster",
">",
"(",
")",
",",
"gridClass",
")",
";",
"gc",
".",
"addGrid",
"(",
"dg",
")",
";",
"this",
".",
"cluster_list",
".",
"add",
"(",
"gc",
")",
";",
"//System.out.print(\" was dense (class \"+gridClass+\")\");",
"}",
"else",
"cvOfG",
".",
"setLabel",
"(",
"NO_CLASS",
")",
";",
"//System.out.println();",
"newGL",
".",
"put",
"(",
"dg",
",",
"cvOfG",
")",
";",
"}",
"this",
".",
"grid_list",
"=",
"newGL",
";",
"//printGridClusters();",
"// 4. Make changes to grid labels by doing:",
"// a. For each cluster c",
"// b. For each outside grid g of c",
"// c. For each neighbouring grid h of g",
"// d. If h belongs to c', label c and c' with ",
"// the label of the largest cluster",
"// e. Else if h is transitional, assign it to c",
"// f. While changes can be made",
"boolean",
"changesMade",
";",
"do",
"{",
"changesMade",
"=",
"adjustLabels",
"(",
")",
";",
"}",
"while",
"(",
"changesMade",
")",
";",
"// while changes are being made",
"//printGridList();",
"//printGridClusters();",
"}"
] | Implements the procedure given in Figure 3 of Chen and Tu 2007 | [
"Implements",
"the",
"procedure",
"given",
"in",
"Figure",
"3",
"of",
"Chen",
"and",
"Tu",
"2007"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L405-L462 |
28,987 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.adjustForSparseGrid | private HashMap<DensityGrid, CharacteristicVector> adjustForSparseGrid(DensityGrid dg, CharacteristicVector cv, int dgClass)
{
HashMap<DensityGrid, CharacteristicVector> glNew = new HashMap<DensityGrid, CharacteristicVector>();
//System.out.print("Density grid "+dg.toString()+" is adjusted as a sparse grid at time "+this.getCurrTime()+". ");
if (dgClass != NO_CLASS)
{
//System.out.println("It is removed from cluster "+dgClass+".");
GridCluster gc = this.cluster_list.get(dgClass);
gc.removeGrid(dg);
cv.setLabel(NO_CLASS);
glNew.put(dg, cv);
this.cluster_list.set(dgClass, gc);
if(gc.getWeight() > 0.0 && !gc.isConnected())
glNew.putAll(recluster(gc));
}
//else
//System.out.println("It was not clustered ("+dgClass+").");
return glNew;
} | java | private HashMap<DensityGrid, CharacteristicVector> adjustForSparseGrid(DensityGrid dg, CharacteristicVector cv, int dgClass)
{
HashMap<DensityGrid, CharacteristicVector> glNew = new HashMap<DensityGrid, CharacteristicVector>();
//System.out.print("Density grid "+dg.toString()+" is adjusted as a sparse grid at time "+this.getCurrTime()+". ");
if (dgClass != NO_CLASS)
{
//System.out.println("It is removed from cluster "+dgClass+".");
GridCluster gc = this.cluster_list.get(dgClass);
gc.removeGrid(dg);
cv.setLabel(NO_CLASS);
glNew.put(dg, cv);
this.cluster_list.set(dgClass, gc);
if(gc.getWeight() > 0.0 && !gc.isConnected())
glNew.putAll(recluster(gc));
}
//else
//System.out.println("It was not clustered ("+dgClass+").");
return glNew;
} | [
"private",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"adjustForSparseGrid",
"(",
"DensityGrid",
"dg",
",",
"CharacteristicVector",
"cv",
",",
"int",
"dgClass",
")",
"{",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"glNew",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"(",
")",
";",
"//System.out.print(\"Density grid \"+dg.toString()+\" is adjusted as a sparse grid at time \"+this.getCurrTime()+\". \");",
"if",
"(",
"dgClass",
"!=",
"NO_CLASS",
")",
"{",
"//System.out.println(\"It is removed from cluster \"+dgClass+\".\");",
"GridCluster",
"gc",
"=",
"this",
".",
"cluster_list",
".",
"get",
"(",
"dgClass",
")",
";",
"gc",
".",
"removeGrid",
"(",
"dg",
")",
";",
"cv",
".",
"setLabel",
"(",
"NO_CLASS",
")",
";",
"glNew",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"this",
".",
"cluster_list",
".",
"set",
"(",
"dgClass",
",",
"gc",
")",
";",
"if",
"(",
"gc",
".",
"getWeight",
"(",
")",
">",
"0.0",
"&&",
"!",
"gc",
".",
"isConnected",
"(",
")",
")",
"glNew",
".",
"putAll",
"(",
"recluster",
"(",
"gc",
")",
")",
";",
"}",
"//else",
"//System.out.println(\"It was not clustered (\"+dgClass+\").\");",
"return",
"glNew",
";",
"}"
] | Adjusts the clustering of a sparse density grid. Implements lines 5 and 6 from Figure 4 of Chen and Tu 2007.
@param dg the sparse density grid being adjusted
@param cv the characteristic vector of dg
@param dgClass the cluster to which dg belonged
@return a HashMap<DensityGrid, CharacteristicVector> containing density grids for update after this iteration | [
"Adjusts",
"the",
"clustering",
"of",
"a",
"sparse",
"density",
"grid",
".",
"Implements",
"lines",
"5",
"and",
"6",
"from",
"Figure",
"4",
"of",
"Chen",
"and",
"Tu",
"2007",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L641-L661 |
28,988 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.adjustForTransitionalGrid | private HashMap<DensityGrid, CharacteristicVector> adjustForTransitionalGrid(DensityGrid dg, CharacteristicVector cv, int dgClass)
{
//System.out.print("Density grid "+dg.toString()+" is adjusted as a transitional grid at time "+this.getCurrTime()+". ");
// Among all neighbours of dg, find the grid h whose cluster ch has the largest size
// and satisfies that dg would be an outside grid if added to it
GridCluster ch; // The cluster, ch, of h
double hChosenSize = 0.0; // The size of ch, the largest cluster
DensityGrid dgH; // The neighbour of dg being considered
int hClass = NO_CLASS; // The class label of h
int hChosenClass = NO_CLASS; // The class label of ch
Iterator<DensityGrid> dgNeighbourhood = dg.getNeighbours().iterator();
HashMap<DensityGrid, CharacteristicVector> glNew = new HashMap<DensityGrid, CharacteristicVector>();
while (dgNeighbourhood.hasNext())
{
dgH = dgNeighbourhood.next();
if (this.grid_list.containsKey(dgH))
{
hClass = this.grid_list.get(dgH).getLabel();
if (hClass != NO_CLASS)
{
ch = this.cluster_list.get(hClass);
if ((ch.getWeight() > hChosenSize) && !ch.isInside(dg, dg))
{
hChosenSize = ch.getWeight();
hChosenClass = hClass;
}
}
}
}
//System.out.println(" Chosen neighbour is from cluster "+hChosenClass+", dgClass is "+dgClass+".");
if (hChosenClass != NO_CLASS && hChosenClass != dgClass)
{
ch = this.cluster_list.get(hChosenClass);
ch.addGrid(dg);
this.cluster_list.set(hChosenClass, ch);
if(dgClass != NO_CLASS)
{
GridCluster c = this.cluster_list.get(dgClass);
c.removeGrid(dg);
this.cluster_list.set(dgClass, c);
}
cv.setLabel(hChosenClass);
glNew.put(dg, cv);
}
return glNew;
} | java | private HashMap<DensityGrid, CharacteristicVector> adjustForTransitionalGrid(DensityGrid dg, CharacteristicVector cv, int dgClass)
{
//System.out.print("Density grid "+dg.toString()+" is adjusted as a transitional grid at time "+this.getCurrTime()+". ");
// Among all neighbours of dg, find the grid h whose cluster ch has the largest size
// and satisfies that dg would be an outside grid if added to it
GridCluster ch; // The cluster, ch, of h
double hChosenSize = 0.0; // The size of ch, the largest cluster
DensityGrid dgH; // The neighbour of dg being considered
int hClass = NO_CLASS; // The class label of h
int hChosenClass = NO_CLASS; // The class label of ch
Iterator<DensityGrid> dgNeighbourhood = dg.getNeighbours().iterator();
HashMap<DensityGrid, CharacteristicVector> glNew = new HashMap<DensityGrid, CharacteristicVector>();
while (dgNeighbourhood.hasNext())
{
dgH = dgNeighbourhood.next();
if (this.grid_list.containsKey(dgH))
{
hClass = this.grid_list.get(dgH).getLabel();
if (hClass != NO_CLASS)
{
ch = this.cluster_list.get(hClass);
if ((ch.getWeight() > hChosenSize) && !ch.isInside(dg, dg))
{
hChosenSize = ch.getWeight();
hChosenClass = hClass;
}
}
}
}
//System.out.println(" Chosen neighbour is from cluster "+hChosenClass+", dgClass is "+dgClass+".");
if (hChosenClass != NO_CLASS && hChosenClass != dgClass)
{
ch = this.cluster_list.get(hChosenClass);
ch.addGrid(dg);
this.cluster_list.set(hChosenClass, ch);
if(dgClass != NO_CLASS)
{
GridCluster c = this.cluster_list.get(dgClass);
c.removeGrid(dg);
this.cluster_list.set(dgClass, c);
}
cv.setLabel(hChosenClass);
glNew.put(dg, cv);
}
return glNew;
} | [
"private",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"adjustForTransitionalGrid",
"(",
"DensityGrid",
"dg",
",",
"CharacteristicVector",
"cv",
",",
"int",
"dgClass",
")",
"{",
"//System.out.print(\"Density grid \"+dg.toString()+\" is adjusted as a transitional grid at time \"+this.getCurrTime()+\". \");",
"// Among all neighbours of dg, find the grid h whose cluster ch has the largest size",
"// and satisfies that dg would be an outside grid if added to it",
"GridCluster",
"ch",
";",
"// The cluster, ch, of h",
"double",
"hChosenSize",
"=",
"0.0",
";",
"// The size of ch, the largest cluster",
"DensityGrid",
"dgH",
";",
"// The neighbour of dg being considered",
"int",
"hClass",
"=",
"NO_CLASS",
";",
"// The class label of h",
"int",
"hChosenClass",
"=",
"NO_CLASS",
";",
"// The class label of ch",
"Iterator",
"<",
"DensityGrid",
">",
"dgNeighbourhood",
"=",
"dg",
".",
"getNeighbours",
"(",
")",
".",
"iterator",
"(",
")",
";",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"glNew",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"(",
")",
";",
"while",
"(",
"dgNeighbourhood",
".",
"hasNext",
"(",
")",
")",
"{",
"dgH",
"=",
"dgNeighbourhood",
".",
"next",
"(",
")",
";",
"if",
"(",
"this",
".",
"grid_list",
".",
"containsKey",
"(",
"dgH",
")",
")",
"{",
"hClass",
"=",
"this",
".",
"grid_list",
".",
"get",
"(",
"dgH",
")",
".",
"getLabel",
"(",
")",
";",
"if",
"(",
"hClass",
"!=",
"NO_CLASS",
")",
"{",
"ch",
"=",
"this",
".",
"cluster_list",
".",
"get",
"(",
"hClass",
")",
";",
"if",
"(",
"(",
"ch",
".",
"getWeight",
"(",
")",
">",
"hChosenSize",
")",
"&&",
"!",
"ch",
".",
"isInside",
"(",
"dg",
",",
"dg",
")",
")",
"{",
"hChosenSize",
"=",
"ch",
".",
"getWeight",
"(",
")",
";",
"hChosenClass",
"=",
"hClass",
";",
"}",
"}",
"}",
"}",
"//System.out.println(\" Chosen neighbour is from cluster \"+hChosenClass+\", dgClass is \"+dgClass+\".\");",
"if",
"(",
"hChosenClass",
"!=",
"NO_CLASS",
"&&",
"hChosenClass",
"!=",
"dgClass",
")",
"{",
"ch",
"=",
"this",
".",
"cluster_list",
".",
"get",
"(",
"hChosenClass",
")",
";",
"ch",
".",
"addGrid",
"(",
"dg",
")",
";",
"this",
".",
"cluster_list",
".",
"set",
"(",
"hChosenClass",
",",
"ch",
")",
";",
"if",
"(",
"dgClass",
"!=",
"NO_CLASS",
")",
"{",
"GridCluster",
"c",
"=",
"this",
".",
"cluster_list",
".",
"get",
"(",
"dgClass",
")",
";",
"c",
".",
"removeGrid",
"(",
"dg",
")",
";",
"this",
".",
"cluster_list",
".",
"set",
"(",
"dgClass",
",",
"c",
")",
";",
"}",
"cv",
".",
"setLabel",
"(",
"hChosenClass",
")",
";",
"glNew",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"}",
"return",
"glNew",
";",
"}"
] | Adjusts the clustering of a transitional density grid. Implements lines 20 and 21 from Figure 4 of Chen and Tu 2007.
@param dg the dense density grid being adjusted
@param cv the characteristic vector of dg
@param dgClass the cluster to which dg belonged
@return a HashMap<DensityGrid, CharacteristicVector> containing density grids for update after this iteration | [
"Adjusts",
"the",
"clustering",
"of",
"a",
"transitional",
"density",
"grid",
".",
"Implements",
"lines",
"20",
"and",
"21",
"from",
"Figure",
"4",
"of",
"Chen",
"and",
"Tu",
"2007",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L981-L1035 |
28,989 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.cleanClusters | private void cleanClusters()
{
//System.out.println("Clean Clusters");
Iterator<GridCluster> clusIter = this.cluster_list.iterator();
ArrayList<GridCluster> toRem = new ArrayList<GridCluster>();
// Check to see if there are any empty clusters
while(clusIter.hasNext())
{
GridCluster c = clusIter.next();
if(c.getWeight() == 0)
toRem.add(c);
}
// Remove empty clusters
if (!toRem.isEmpty())
{
clusIter = toRem.iterator();
while(clusIter.hasNext())
{
this.cluster_list.remove(clusIter.next());
}
}
// Adjust remaining clusters as necessary
clusIter = this.cluster_list.iterator();
while(clusIter.hasNext())
{
GridCluster c = clusIter.next();
int index = this.cluster_list.indexOf(c);
c.setClusterLabel(index);
this.cluster_list.set(index, c);
Iterator<Map.Entry<DensityGrid, Boolean>> gridsOfClus = c.getGrids().entrySet().iterator();
while(gridsOfClus.hasNext())
{
DensityGrid dg = gridsOfClus.next().getKey();
CharacteristicVector cv = this.grid_list.get(dg);
if(cv == null)
{
System.out.println("Warning, cv is null for "+dg.toString()+" from cluster "+index+".");
printGridList();
printGridClusters();
}
//System.out.println("Cluster "+index+": "+dg.toString()+" is here.");
cv.setLabel(index);
this.grid_list.put(dg, cv);
}
}
} | java | private void cleanClusters()
{
//System.out.println("Clean Clusters");
Iterator<GridCluster> clusIter = this.cluster_list.iterator();
ArrayList<GridCluster> toRem = new ArrayList<GridCluster>();
// Check to see if there are any empty clusters
while(clusIter.hasNext())
{
GridCluster c = clusIter.next();
if(c.getWeight() == 0)
toRem.add(c);
}
// Remove empty clusters
if (!toRem.isEmpty())
{
clusIter = toRem.iterator();
while(clusIter.hasNext())
{
this.cluster_list.remove(clusIter.next());
}
}
// Adjust remaining clusters as necessary
clusIter = this.cluster_list.iterator();
while(clusIter.hasNext())
{
GridCluster c = clusIter.next();
int index = this.cluster_list.indexOf(c);
c.setClusterLabel(index);
this.cluster_list.set(index, c);
Iterator<Map.Entry<DensityGrid, Boolean>> gridsOfClus = c.getGrids().entrySet().iterator();
while(gridsOfClus.hasNext())
{
DensityGrid dg = gridsOfClus.next().getKey();
CharacteristicVector cv = this.grid_list.get(dg);
if(cv == null)
{
System.out.println("Warning, cv is null for "+dg.toString()+" from cluster "+index+".");
printGridList();
printGridClusters();
}
//System.out.println("Cluster "+index+": "+dg.toString()+" is here.");
cv.setLabel(index);
this.grid_list.put(dg, cv);
}
}
} | [
"private",
"void",
"cleanClusters",
"(",
")",
"{",
"//System.out.println(\"Clean Clusters\");",
"Iterator",
"<",
"GridCluster",
">",
"clusIter",
"=",
"this",
".",
"cluster_list",
".",
"iterator",
"(",
")",
";",
"ArrayList",
"<",
"GridCluster",
">",
"toRem",
"=",
"new",
"ArrayList",
"<",
"GridCluster",
">",
"(",
")",
";",
"// Check to see if there are any empty clusters",
"while",
"(",
"clusIter",
".",
"hasNext",
"(",
")",
")",
"{",
"GridCluster",
"c",
"=",
"clusIter",
".",
"next",
"(",
")",
";",
"if",
"(",
"c",
".",
"getWeight",
"(",
")",
"==",
"0",
")",
"toRem",
".",
"add",
"(",
"c",
")",
";",
"}",
"// Remove empty clusters",
"if",
"(",
"!",
"toRem",
".",
"isEmpty",
"(",
")",
")",
"{",
"clusIter",
"=",
"toRem",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"clusIter",
".",
"hasNext",
"(",
")",
")",
"{",
"this",
".",
"cluster_list",
".",
"remove",
"(",
"clusIter",
".",
"next",
"(",
")",
")",
";",
"}",
"}",
"// Adjust remaining clusters as necessary",
"clusIter",
"=",
"this",
".",
"cluster_list",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"clusIter",
".",
"hasNext",
"(",
")",
")",
"{",
"GridCluster",
"c",
"=",
"clusIter",
".",
"next",
"(",
")",
";",
"int",
"index",
"=",
"this",
".",
"cluster_list",
".",
"indexOf",
"(",
"c",
")",
";",
"c",
".",
"setClusterLabel",
"(",
"index",
")",
";",
"this",
".",
"cluster_list",
".",
"set",
"(",
"index",
",",
"c",
")",
";",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"Boolean",
">",
">",
"gridsOfClus",
"=",
"c",
".",
"getGrids",
"(",
")",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"gridsOfClus",
".",
"hasNext",
"(",
")",
")",
"{",
"DensityGrid",
"dg",
"=",
"gridsOfClus",
".",
"next",
"(",
")",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cv",
"=",
"this",
".",
"grid_list",
".",
"get",
"(",
"dg",
")",
";",
"if",
"(",
"cv",
"==",
"null",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Warning, cv is null for \"",
"+",
"dg",
".",
"toString",
"(",
")",
"+",
"\" from cluster \"",
"+",
"index",
"+",
"\".\"",
")",
";",
"printGridList",
"(",
")",
";",
"printGridClusters",
"(",
")",
";",
"}",
"//System.out.println(\"Cluster \"+index+\": \"+dg.toString()+\" is here.\");",
"cv",
".",
"setLabel",
"(",
"index",
")",
";",
"this",
".",
"grid_list",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"}",
"}",
"}"
] | Iterates through cluster_list to ensure that all empty clusters have been removed and
that all cluster IDs match the cluster's index in cluster_list. | [
"Iterates",
"through",
"cluster_list",
"to",
"ensure",
"that",
"all",
"empty",
"clusters",
"have",
"been",
"removed",
"and",
"that",
"all",
"cluster",
"IDs",
"match",
"the",
"cluster",
"s",
"index",
"in",
"cluster_list",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1041-L1095 |
28,990 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.removeSporadic | private void removeSporadic() {
//System.out.println("REMOVE SPORADIC CALLED");
// 1. For each grid g in grid_list
// a. If g is sporadic
// i. If currTime - tg > gap, delete g from grid_list
// ii. Else if (S1 && S2), mark as sporadic
// iii. Else, mark as normal
// b. Else
// i. If (S1 && S2), mark as sporadic
// For each grid g in grid_list
Iterator<Map.Entry<DensityGrid, CharacteristicVector>> glIter = this.grid_list.entrySet().iterator();
HashMap<DensityGrid, CharacteristicVector> newGL = new HashMap<DensityGrid, CharacteristicVector>();
ArrayList<DensityGrid> remGL = new ArrayList<DensityGrid>();
while(glIter.hasNext())
{
Map.Entry<DensityGrid, CharacteristicVector> grid = glIter.next();
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
// If g is sporadic
if (cv.isSporadic())
{
// If currTime - tg > gap, delete g from grid_list
if ((this.getCurrTime() - cv.getUpdateTime()) >= gap)
{
int dgClass = cv.getLabel();
if (dgClass != -1)
this.cluster_list.get(dgClass).removeGrid(dg);
remGL.add(dg);
//System.out.println("Removed "+dg.toString()+" from cluster "+dgClass);
}
// Else if (S1 && S2), mark as sporadic - Else mark as normal
else
{
cv.setSporadic(checkIfSporadic(cv));
//System.out.println("within gap" + dg.toString() + " sporadicity assessed "+cv.isSporadic());
newGL.put(dg, cv);
}
}
// Else if (S1 && S2), mark as sporadic
else
{
cv.setSporadic(checkIfSporadic(cv));
//System.out.println(dg.toString() + " sporadicity assessed "+cv.isSporadic());
newGL.put(dg, cv);
}
}
this.grid_list.putAll(newGL);
//System.out.println(" - Removed "+remGL.size()+" grids from grid_list.");
Iterator<DensityGrid> remIter = remGL.iterator();
while(remIter.hasNext())
{
DensityGrid sporadicDG = remIter.next();
//System.out.println("Removing sporadic grid "+sporadicDG.toString()+" at time "+this.getCurrTime()+".");
this.deleted_grids.put(sporadicDG, new Integer(this.getCurrTime()));
this.grid_list.remove(sporadicDG);
}
} | java | private void removeSporadic() {
//System.out.println("REMOVE SPORADIC CALLED");
// 1. For each grid g in grid_list
// a. If g is sporadic
// i. If currTime - tg > gap, delete g from grid_list
// ii. Else if (S1 && S2), mark as sporadic
// iii. Else, mark as normal
// b. Else
// i. If (S1 && S2), mark as sporadic
// For each grid g in grid_list
Iterator<Map.Entry<DensityGrid, CharacteristicVector>> glIter = this.grid_list.entrySet().iterator();
HashMap<DensityGrid, CharacteristicVector> newGL = new HashMap<DensityGrid, CharacteristicVector>();
ArrayList<DensityGrid> remGL = new ArrayList<DensityGrid>();
while(glIter.hasNext())
{
Map.Entry<DensityGrid, CharacteristicVector> grid = glIter.next();
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
// If g is sporadic
if (cv.isSporadic())
{
// If currTime - tg > gap, delete g from grid_list
if ((this.getCurrTime() - cv.getUpdateTime()) >= gap)
{
int dgClass = cv.getLabel();
if (dgClass != -1)
this.cluster_list.get(dgClass).removeGrid(dg);
remGL.add(dg);
//System.out.println("Removed "+dg.toString()+" from cluster "+dgClass);
}
// Else if (S1 && S2), mark as sporadic - Else mark as normal
else
{
cv.setSporadic(checkIfSporadic(cv));
//System.out.println("within gap" + dg.toString() + " sporadicity assessed "+cv.isSporadic());
newGL.put(dg, cv);
}
}
// Else if (S1 && S2), mark as sporadic
else
{
cv.setSporadic(checkIfSporadic(cv));
//System.out.println(dg.toString() + " sporadicity assessed "+cv.isSporadic());
newGL.put(dg, cv);
}
}
this.grid_list.putAll(newGL);
//System.out.println(" - Removed "+remGL.size()+" grids from grid_list.");
Iterator<DensityGrid> remIter = remGL.iterator();
while(remIter.hasNext())
{
DensityGrid sporadicDG = remIter.next();
//System.out.println("Removing sporadic grid "+sporadicDG.toString()+" at time "+this.getCurrTime()+".");
this.deleted_grids.put(sporadicDG, new Integer(this.getCurrTime()));
this.grid_list.remove(sporadicDG);
}
} | [
"private",
"void",
"removeSporadic",
"(",
")",
"{",
"//System.out.println(\"REMOVE SPORADIC CALLED\");",
"// 1. For each grid g in grid_list",
"// a. If g is sporadic",
"// i. If currTime - tg > gap, delete g from grid_list",
"// ii. Else if (S1 && S2), mark as sporadic",
"// iii. Else, mark as normal",
"// b. Else",
"// i. If (S1 && S2), mark as sporadic",
"// For each grid g in grid_list",
"Iterator",
"<",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
">",
"glIter",
"=",
"this",
".",
"grid_list",
".",
"entrySet",
"(",
")",
".",
"iterator",
"(",
")",
";",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"newGL",
"=",
"new",
"HashMap",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"(",
")",
";",
"ArrayList",
"<",
"DensityGrid",
">",
"remGL",
"=",
"new",
"ArrayList",
"<",
"DensityGrid",
">",
"(",
")",
";",
"while",
"(",
"glIter",
".",
"hasNext",
"(",
")",
")",
"{",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"grid",
"=",
"glIter",
".",
"next",
"(",
")",
";",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cv",
"=",
"grid",
".",
"getValue",
"(",
")",
";",
"// If g is sporadic",
"if",
"(",
"cv",
".",
"isSporadic",
"(",
")",
")",
"{",
"// If currTime - tg > gap, delete g from grid_list",
"if",
"(",
"(",
"this",
".",
"getCurrTime",
"(",
")",
"-",
"cv",
".",
"getUpdateTime",
"(",
")",
")",
">=",
"gap",
")",
"{",
"int",
"dgClass",
"=",
"cv",
".",
"getLabel",
"(",
")",
";",
"if",
"(",
"dgClass",
"!=",
"-",
"1",
")",
"this",
".",
"cluster_list",
".",
"get",
"(",
"dgClass",
")",
".",
"removeGrid",
"(",
"dg",
")",
";",
"remGL",
".",
"add",
"(",
"dg",
")",
";",
"//System.out.println(\"Removed \"+dg.toString()+\" from cluster \"+dgClass);",
"}",
"// Else if (S1 && S2), mark as sporadic - Else mark as normal",
"else",
"{",
"cv",
".",
"setSporadic",
"(",
"checkIfSporadic",
"(",
"cv",
")",
")",
";",
"//System.out.println(\"within gap\" + dg.toString() + \" sporadicity assessed \"+cv.isSporadic());",
"newGL",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"}",
"}",
"// Else if (S1 && S2), mark as sporadic",
"else",
"{",
"cv",
".",
"setSporadic",
"(",
"checkIfSporadic",
"(",
"cv",
")",
")",
";",
"//System.out.println(dg.toString() + \" sporadicity assessed \"+cv.isSporadic());",
"newGL",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"}",
"}",
"this",
".",
"grid_list",
".",
"putAll",
"(",
"newGL",
")",
";",
"//System.out.println(\" - Removed \"+remGL.size()+\" grids from grid_list.\");",
"Iterator",
"<",
"DensityGrid",
">",
"remIter",
"=",
"remGL",
".",
"iterator",
"(",
")",
";",
"while",
"(",
"remIter",
".",
"hasNext",
"(",
")",
")",
"{",
"DensityGrid",
"sporadicDG",
"=",
"remIter",
".",
"next",
"(",
")",
";",
"//System.out.println(\"Removing sporadic grid \"+sporadicDG.toString()+\" at time \"+this.getCurrTime()+\".\");",
"this",
".",
"deleted_grids",
".",
"put",
"(",
"sporadicDG",
",",
"new",
"Integer",
"(",
"this",
".",
"getCurrTime",
"(",
")",
")",
")",
";",
"this",
".",
"grid_list",
".",
"remove",
"(",
"sporadicDG",
")",
";",
"}",
"}"
] | Implements the procedure described in section 4.2 of Chen and Tu 2007 | [
"Implements",
"the",
"procedure",
"described",
"in",
"section",
"4",
".",
"2",
"of",
"Chen",
"and",
"Tu",
"2007"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1149-L1215 |
28,991 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.checkIfSporadic | private boolean checkIfSporadic(CharacteristicVector cv)
{
// Check S1
if(cv.getCurrGridDensity(this.getCurrTime(), this.getDecayFactor()) < densityThresholdFunction(cv.getDensityTimeStamp(), this.cl, this.getDecayFactor(), this.N))
{
// Check S2
if(cv.getRemoveTime() == -1 || this.getCurrTime() >= ((1 + this.beta)*cv.getRemoveTime()))
return true;
}
return false;
} | java | private boolean checkIfSporadic(CharacteristicVector cv)
{
// Check S1
if(cv.getCurrGridDensity(this.getCurrTime(), this.getDecayFactor()) < densityThresholdFunction(cv.getDensityTimeStamp(), this.cl, this.getDecayFactor(), this.N))
{
// Check S2
if(cv.getRemoveTime() == -1 || this.getCurrTime() >= ((1 + this.beta)*cv.getRemoveTime()))
return true;
}
return false;
} | [
"private",
"boolean",
"checkIfSporadic",
"(",
"CharacteristicVector",
"cv",
")",
"{",
"// Check S1",
"if",
"(",
"cv",
".",
"getCurrGridDensity",
"(",
"this",
".",
"getCurrTime",
"(",
")",
",",
"this",
".",
"getDecayFactor",
"(",
")",
")",
"<",
"densityThresholdFunction",
"(",
"cv",
".",
"getDensityTimeStamp",
"(",
")",
",",
"this",
".",
"cl",
",",
"this",
".",
"getDecayFactor",
"(",
")",
",",
"this",
".",
"N",
")",
")",
"{",
"// Check S2",
"if",
"(",
"cv",
".",
"getRemoveTime",
"(",
")",
"==",
"-",
"1",
"||",
"this",
".",
"getCurrTime",
"(",
")",
">=",
"(",
"(",
"1",
"+",
"this",
".",
"beta",
")",
"*",
"cv",
".",
"getRemoveTime",
"(",
")",
")",
")",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines whether a sparse density grid is sporadic using rules S1 and S2 of Chen and Tu 2007
@param cv - the CharacteristicVector of the density grid being assessed for sporadicity | [
"Determines",
"whether",
"a",
"sparse",
"density",
"grid",
"is",
"sporadic",
"using",
"rules",
"S1",
"and",
"S2",
"of",
"Chen",
"and",
"Tu",
"2007"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1222-L1233 |
28,992 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.densityThresholdFunction | private double densityThresholdFunction(int tg, double cl, double decayFactor, int N)
{
return (cl * (1.0 - Math.pow(decayFactor, (this.getCurrTime()-tg+1.0))))/(N * (1.0 - decayFactor));
} | java | private double densityThresholdFunction(int tg, double cl, double decayFactor, int N)
{
return (cl * (1.0 - Math.pow(decayFactor, (this.getCurrTime()-tg+1.0))))/(N * (1.0 - decayFactor));
} | [
"private",
"double",
"densityThresholdFunction",
"(",
"int",
"tg",
",",
"double",
"cl",
",",
"double",
"decayFactor",
",",
"int",
"N",
")",
"{",
"return",
"(",
"cl",
"*",
"(",
"1.0",
"-",
"Math",
".",
"pow",
"(",
"decayFactor",
",",
"(",
"this",
".",
"getCurrTime",
"(",
")",
"-",
"tg",
"+",
"1.0",
")",
")",
")",
")",
"/",
"(",
"N",
"*",
"(",
"1.0",
"-",
"decayFactor",
")",
")",
";",
"}"
] | Implements the function pi given in Definition 4.1 of Chen and Tu 2007
@param tg - the update time in the density grid's characteristic vector
@param cl - user defined parameter which controls the threshold for sparse grids
@param decayFactor - user defined parameter which is represented as lambda in Chen and Tu 2007
@param N - the number of density grids, defined after eq 2 in Chen and Tu 2007 | [
"Implements",
"the",
"function",
"pi",
"given",
"in",
"Definition",
"4",
".",
"1",
"of",
"Chen",
"and",
"Tu",
"2007"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1243-L1246 |
28,993 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.mergeClusters | private void mergeClusters (int smallClus, int bigClus)
{
//System.out.println("Merge clusters "+smallClus+" and "+bigClus+".");
// Iterate through the density grids in grid_list to find those which are in highClass
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
// Assign density grids in smallClus to bigClus
if(cv.getLabel() == smallClus)
{
cv.setLabel(bigClus);
this.grid_list.put(dg, cv);
}
}
//System.out.println("Density grids assigned to cluster "+bigClus+".");
// Merge the GridCluster objects representing each cluster
GridCluster bGC = this.cluster_list.get(bigClus);
bGC.absorbCluster(this.cluster_list.get(smallClus));
this.cluster_list.set(bigClus, bGC);
this.cluster_list.remove(smallClus);
//System.out.println("Cluster "+smallClus+" removed from list.");
cleanClusters();
} | java | private void mergeClusters (int smallClus, int bigClus)
{
//System.out.println("Merge clusters "+smallClus+" and "+bigClus+".");
// Iterate through the density grids in grid_list to find those which are in highClass
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
// Assign density grids in smallClus to bigClus
if(cv.getLabel() == smallClus)
{
cv.setLabel(bigClus);
this.grid_list.put(dg, cv);
}
}
//System.out.println("Density grids assigned to cluster "+bigClus+".");
// Merge the GridCluster objects representing each cluster
GridCluster bGC = this.cluster_list.get(bigClus);
bGC.absorbCluster(this.cluster_list.get(smallClus));
this.cluster_list.set(bigClus, bGC);
this.cluster_list.remove(smallClus);
//System.out.println("Cluster "+smallClus+" removed from list.");
cleanClusters();
} | [
"private",
"void",
"mergeClusters",
"(",
"int",
"smallClus",
",",
"int",
"bigClus",
")",
"{",
"//System.out.println(\"Merge clusters \"+smallClus+\" and \"+bigClus+\".\");",
"// Iterate through the density grids in grid_list to find those which are in highClass",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"grid",
":",
"grid_list",
".",
"entrySet",
"(",
")",
")",
"{",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cv",
"=",
"grid",
".",
"getValue",
"(",
")",
";",
"// Assign density grids in smallClus to bigClus",
"if",
"(",
"cv",
".",
"getLabel",
"(",
")",
"==",
"smallClus",
")",
"{",
"cv",
".",
"setLabel",
"(",
"bigClus",
")",
";",
"this",
".",
"grid_list",
".",
"put",
"(",
"dg",
",",
"cv",
")",
";",
"}",
"}",
"//System.out.println(\"Density grids assigned to cluster \"+bigClus+\".\");",
"// Merge the GridCluster objects representing each cluster",
"GridCluster",
"bGC",
"=",
"this",
".",
"cluster_list",
".",
"get",
"(",
"bigClus",
")",
";",
"bGC",
".",
"absorbCluster",
"(",
"this",
".",
"cluster_list",
".",
"get",
"(",
"smallClus",
")",
")",
";",
"this",
".",
"cluster_list",
".",
"set",
"(",
"bigClus",
",",
"bGC",
")",
";",
"this",
".",
"cluster_list",
".",
"remove",
"(",
"smallClus",
")",
";",
"//System.out.println(\"Cluster \"+smallClus+\" removed from list.\");",
"cleanClusters",
"(",
")",
";",
"}"
] | Reassign all grids belonging in the small cluster to the big cluster
Merge the GridCluster objects representing each cluster
@param smallClus - the index of the smaller cluster
@param bigClus - the index of the bigger cluster | [
"Reassign",
"all",
"grids",
"belonging",
"in",
"the",
"small",
"cluster",
"to",
"the",
"big",
"cluster",
"Merge",
"the",
"GridCluster",
"objects",
"representing",
"each",
"cluster"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1255-L1280 |
28,994 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.updateGridListDensity | private void updateGridListDensity()
{
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cvOfG = grid.getValue();
dg.setVisited(false);
cvOfG.updateGridDensity(this.getCurrTime(), this.getDecayFactor(), this.getDL(), this.getDM());
this.grid_list.put(dg, cvOfG);
}
} | java | private void updateGridListDensity()
{
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cvOfG = grid.getValue();
dg.setVisited(false);
cvOfG.updateGridDensity(this.getCurrTime(), this.getDecayFactor(), this.getDL(), this.getDM());
this.grid_list.put(dg, cvOfG);
}
} | [
"private",
"void",
"updateGridListDensity",
"(",
")",
"{",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"grid",
":",
"grid_list",
".",
"entrySet",
"(",
")",
")",
"{",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cvOfG",
"=",
"grid",
".",
"getValue",
"(",
")",
";",
"dg",
".",
"setVisited",
"(",
"false",
")",
";",
"cvOfG",
".",
"updateGridDensity",
"(",
"this",
".",
"getCurrTime",
"(",
")",
",",
"this",
".",
"getDecayFactor",
"(",
")",
",",
"this",
".",
"getDL",
"(",
")",
",",
"this",
".",
"getDM",
"(",
")",
")",
";",
"this",
".",
"grid_list",
".",
"put",
"(",
"dg",
",",
"cvOfG",
")",
";",
"}",
"}"
] | Iterates through grid_list and updates the density for each density grid therein.
Also marks each density grid as unvisited for this call to adjustClustering. | [
"Iterates",
"through",
"grid_list",
"and",
"updates",
"the",
"density",
"for",
"each",
"density",
"grid",
"therein",
".",
"Also",
"marks",
"each",
"density",
"grid",
"as",
"unvisited",
"for",
"this",
"call",
"to",
"adjustClustering",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1286-L1298 |
28,995 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.printGridList | public void printGridList()
{
System.out.println("Grid List. Size "+this.grid_list.size()+".");
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
if (cv.getAttribute() != SPARSE)
{
double dtf = densityThresholdFunction(cv.getUpdateTime(), this.cl, this.getDecayFactor(), this.N);
System.out.println(dg.toString()+" "+cv.toString()+" // Density Threshold Function = "+dtf);
}
}
} | java | public void printGridList()
{
System.out.println("Grid List. Size "+this.grid_list.size()+".");
for (Map.Entry<DensityGrid, CharacteristicVector> grid : grid_list.entrySet())
{
DensityGrid dg = grid.getKey();
CharacteristicVector cv = grid.getValue();
if (cv.getAttribute() != SPARSE)
{
double dtf = densityThresholdFunction(cv.getUpdateTime(), this.cl, this.getDecayFactor(), this.N);
System.out.println(dg.toString()+" "+cv.toString()+" // Density Threshold Function = "+dtf);
}
}
} | [
"public",
"void",
"printGridList",
"(",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"Grid List. Size \"",
"+",
"this",
".",
"grid_list",
".",
"size",
"(",
")",
"+",
"\".\"",
")",
";",
"for",
"(",
"Map",
".",
"Entry",
"<",
"DensityGrid",
",",
"CharacteristicVector",
">",
"grid",
":",
"grid_list",
".",
"entrySet",
"(",
")",
")",
"{",
"DensityGrid",
"dg",
"=",
"grid",
".",
"getKey",
"(",
")",
";",
"CharacteristicVector",
"cv",
"=",
"grid",
".",
"getValue",
"(",
")",
";",
"if",
"(",
"cv",
".",
"getAttribute",
"(",
")",
"!=",
"SPARSE",
")",
"{",
"double",
"dtf",
"=",
"densityThresholdFunction",
"(",
"cv",
".",
"getUpdateTime",
"(",
")",
",",
"this",
".",
"cl",
",",
"this",
".",
"getDecayFactor",
"(",
")",
",",
"this",
".",
"N",
")",
";",
"System",
".",
"out",
".",
"println",
"(",
"dg",
".",
"toString",
"(",
")",
"+",
"\" \"",
"+",
"cv",
".",
"toString",
"(",
")",
"+",
"\" // Density Threshold Function = \"",
"+",
"dtf",
")",
";",
"}",
"}",
"}"
] | Iterates through grid_list and prints out each density grid therein as a string.
@see moa.clusterers.dstream.Dstream.grid_list
@see moa.clusterers.dstream.DensityGrid.toString | [
"Iterates",
"through",
"grid_list",
"and",
"prints",
"out",
"each",
"density",
"grid",
"therein",
"as",
"a",
"string",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1379-L1393 |
28,996 | Waikato/moa | moa/src/main/java/moa/clusterers/dstream/Dstream.java | Dstream.printGridClusters | public void printGridClusters()
{
System.out.println("List of Clusters. Total "+this.cluster_list.size()+".");
for(GridCluster gc : this.cluster_list)
{
System.out.println(gc.getClusterLabel()+": "+gc.getWeight()+" {"+gc.toString()+"}");
}
} | java | public void printGridClusters()
{
System.out.println("List of Clusters. Total "+this.cluster_list.size()+".");
for(GridCluster gc : this.cluster_list)
{
System.out.println(gc.getClusterLabel()+": "+gc.getWeight()+" {"+gc.toString()+"}");
}
} | [
"public",
"void",
"printGridClusters",
"(",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"\"List of Clusters. Total \"",
"+",
"this",
".",
"cluster_list",
".",
"size",
"(",
")",
"+",
"\".\"",
")",
";",
"for",
"(",
"GridCluster",
"gc",
":",
"this",
".",
"cluster_list",
")",
"{",
"System",
".",
"out",
".",
"println",
"(",
"gc",
".",
"getClusterLabel",
"(",
")",
"+",
"\": \"",
"+",
"gc",
".",
"getWeight",
"(",
")",
"+",
"\" {\"",
"+",
"gc",
".",
"toString",
"(",
")",
"+",
"\"}\"",
")",
";",
"}",
"}"
] | Iterates through cluster_list and prints out each grid cluster therein as a string.
@see moa.clusterers.dstream.Dstream.cluster_list
@see moa.clusterers.dstream.GridCluster.toString | [
"Iterates",
"through",
"cluster_list",
"and",
"prints",
"out",
"each",
"grid",
"cluster",
"therein",
"as",
"a",
"string",
"."
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/dstream/Dstream.java#L1401-L1408 |
28,997 | Waikato/moa | moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java | DataSet.addObject | public void addObject(DataSet dataSet) throws Exception {
DataObject[] dataObjects = dataSet.getDataObjectArray();
for (int i = 0; i < dataObjects.length; i++) {
this.addObject(dataObjects[i]);
}
} | java | public void addObject(DataSet dataSet) throws Exception {
DataObject[] dataObjects = dataSet.getDataObjectArray();
for (int i = 0; i < dataObjects.length; i++) {
this.addObject(dataObjects[i]);
}
} | [
"public",
"void",
"addObject",
"(",
"DataSet",
"dataSet",
")",
"throws",
"Exception",
"{",
"DataObject",
"[",
"]",
"dataObjects",
"=",
"dataSet",
".",
"getDataObjectArray",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"dataObjects",
".",
"length",
";",
"i",
"++",
")",
"{",
"this",
".",
"addObject",
"(",
"dataObjects",
"[",
"i",
"]",
")",
";",
"}",
"}"
] | Adds all objects in the given data set
@see addObject(DataObject newData)
@param dataSet
@throws InconsistentDimensionException | [
"Adds",
"all",
"objects",
"in",
"the",
"given",
"data",
"set"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java#L95-L100 |
28,998 | Waikato/moa | moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java | DataSet.getNrOfClasses | public int getNrOfClasses() {
HashMap<Integer, Integer> classes = new HashMap<Integer, Integer>();
for (DataObject currentObject : dataList) {
if (!classes.containsKey(currentObject.getClassLabel()))
classes.put(currentObject.getClassLabel(), 1);
}
return classes.size();
} | java | public int getNrOfClasses() {
HashMap<Integer, Integer> classes = new HashMap<Integer, Integer>();
for (DataObject currentObject : dataList) {
if (!classes.containsKey(currentObject.getClassLabel()))
classes.put(currentObject.getClassLabel(), 1);
}
return classes.size();
} | [
"public",
"int",
"getNrOfClasses",
"(",
")",
"{",
"HashMap",
"<",
"Integer",
",",
"Integer",
">",
"classes",
"=",
"new",
"HashMap",
"<",
"Integer",
",",
"Integer",
">",
"(",
")",
";",
"for",
"(",
"DataObject",
"currentObject",
":",
"dataList",
")",
"{",
"if",
"(",
"!",
"classes",
".",
"containsKey",
"(",
"currentObject",
".",
"getClassLabel",
"(",
")",
")",
")",
"classes",
".",
"put",
"(",
"currentObject",
".",
"getClassLabel",
"(",
")",
",",
"1",
")",
";",
"}",
"return",
"classes",
".",
"size",
"(",
")",
";",
"}"
] | Counts the number of classes that are present in the data set.
!!! It does not check whether all classes are contained !!!
@return the number of distinct class labels | [
"Counts",
"the",
"number",
"of",
"classes",
"that",
"are",
"present",
"in",
"the",
"data",
"set",
".",
"!!!",
"It",
"does",
"not",
"check",
"whether",
"all",
"classes",
"are",
"contained",
"!!!"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java#L136-L145 |
28,999 | Waikato/moa | moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java | DataSet.getDataSetsPerClass | public DataSet[] getDataSetsPerClass() throws Exception {
DataSet[] dataSetsPerClass = new DataSet[this.getNrOfClasses()];
// create a new data set for each class
for (int i = 0; i < dataSetsPerClass.length; i++) {
dataSetsPerClass[i] = new DataSet(this.nrOfDimensions);
}
// fill the data sets
for(DataObject currentObject : dataList) {
dataSetsPerClass[currentObject.getClassLabel()].addObject(currentObject);
}
return dataSetsPerClass;
} | java | public DataSet[] getDataSetsPerClass() throws Exception {
DataSet[] dataSetsPerClass = new DataSet[this.getNrOfClasses()];
// create a new data set for each class
for (int i = 0; i < dataSetsPerClass.length; i++) {
dataSetsPerClass[i] = new DataSet(this.nrOfDimensions);
}
// fill the data sets
for(DataObject currentObject : dataList) {
dataSetsPerClass[currentObject.getClassLabel()].addObject(currentObject);
}
return dataSetsPerClass;
} | [
"public",
"DataSet",
"[",
"]",
"getDataSetsPerClass",
"(",
")",
"throws",
"Exception",
"{",
"DataSet",
"[",
"]",
"dataSetsPerClass",
"=",
"new",
"DataSet",
"[",
"this",
".",
"getNrOfClasses",
"(",
")",
"]",
";",
"// create a new data set for each class",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"dataSetsPerClass",
".",
"length",
";",
"i",
"++",
")",
"{",
"dataSetsPerClass",
"[",
"i",
"]",
"=",
"new",
"DataSet",
"(",
"this",
".",
"nrOfDimensions",
")",
";",
"}",
"// fill the data sets",
"for",
"(",
"DataObject",
"currentObject",
":",
"dataList",
")",
"{",
"dataSetsPerClass",
"[",
"currentObject",
".",
"getClassLabel",
"(",
")",
"]",
".",
"addObject",
"(",
"currentObject",
")",
";",
"}",
"return",
"dataSetsPerClass",
";",
"}"
] | Separates the objects in this data set according to their class label
@return an array of DataSets, one for each class | [
"Separates",
"the",
"objects",
"in",
"this",
"data",
"set",
"according",
"to",
"their",
"class",
"label"
] | 395982e5100bfe75a3a4d26115462ce2cc74cbb0 | https://github.com/Waikato/moa/blob/395982e5100bfe75a3a4d26115462ce2cc74cbb0/moa/src/main/java/moa/clusterers/outliers/AnyOut/util/DataSet.java#L183-L196 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.