http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeBinaryTest.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeBinaryTest.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeBinaryTest.java deleted file mode 100644 index e9de3a3..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeBinaryTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.conditionaltests; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.instances.InstancesHeader; -import com.yahoo.labs.samoa.instances.Instance; - -/** - * Nominal binary conditional test for instances to use to split nodes in Hoeffding trees. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class NominalAttributeBinaryTest extends InstanceConditionalBinaryTest { - - private static final long serialVersionUID = 1L; - - protected int attIndex; - - protected int attValue; - - public NominalAttributeBinaryTest(int attIndex, int attValue) { - this.attIndex = attIndex; - this.attValue = attValue; - } - - @Override - public int branchForInstance(Instance inst) { - int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex - : this.attIndex + 1; - return inst.isMissing(instAttIndex) ? -1 : ((int) inst.value(instAttIndex) == this.attValue ? 0 : 1); - } - - @Override - public String describeConditionForBranch(int branch, InstancesHeader context) { - if ((branch == 0) || (branch == 1)) { - return InstancesHeader.getAttributeNameString(context, - this.attIndex) - + (branch == 0 ? " = " : " != ") - + InstancesHeader.getNominalValueString(context, - this.attIndex, this.attValue); - } - throw new IndexOutOfBoundsException(); - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - public int[] getAttsTestDependsOn() { - return new int[] { this.attIndex }; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeMultiwayTest.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeMultiwayTest.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeMultiwayTest.java deleted file mode 100644 index c581936..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NominalAttributeMultiwayTest.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.conditionaltests; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.instances.InstancesHeader; -import com.yahoo.labs.samoa.instances.Instance; - -/** - * Nominal multi way conditional test for instances to use to split nodes in Hoeffding trees. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class NominalAttributeMultiwayTest extends InstanceConditionalTest { - - private static final long serialVersionUID = 1L; - - protected int attIndex; - - public NominalAttributeMultiwayTest(int attIndex) { - this.attIndex = attIndex; - } - - @Override - public int branchForInstance(Instance inst) { - int instAttIndex = this.attIndex; // < inst.classIndex() ? this.attIndex - // : this.attIndex + 1; - return inst.isMissing(instAttIndex) ? -1 : (int) inst.value(instAttIndex); - } - - @Override - public String describeConditionForBranch(int branch, InstancesHeader context) { - return InstancesHeader.getAttributeNameString(context, this.attIndex) - + " = " - + InstancesHeader.getNominalValueString(context, this.attIndex, - branch); - } - - @Override - public int maxBranches() { - return -1; - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - public int[] getAttsTestDependsOn() { - return new int[] { this.attIndex }; - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NumericAttributeBinaryTest.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NumericAttributeBinaryTest.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NumericAttributeBinaryTest.java deleted file mode 100644 index 753b586..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/conditionaltests/NumericAttributeBinaryTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.conditionaltests; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.instances.InstancesHeader; -import com.yahoo.labs.samoa.instances.Instance; - -/** - * Numeric binary conditional test for instances to use to split nodes in Hoeffding trees. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class NumericAttributeBinaryTest extends InstanceConditionalBinaryTest { - - private static final long serialVersionUID = 1L; - - protected int attIndex; - - protected double attValue; - - protected boolean equalsPassesTest; - - public NumericAttributeBinaryTest(int attIndex, double attValue, - boolean equalsPassesTest) { - this.attIndex = attIndex; - this.attValue = attValue; - this.equalsPassesTest = equalsPassesTest; - } - - @Override - public int branchForInstance(Instance inst) { - int instAttIndex = this.attIndex; // < inst.classIndex() ? this.attIndex - // : this.attIndex + 1; - if (inst.isMissing(instAttIndex)) { - return -1; - } - double v = inst.value(instAttIndex); - if (v == this.attValue) { - return this.equalsPassesTest ? 0 : 1; - } - return v < this.attValue ? 0 : 1; - } - - @Override - public String describeConditionForBranch(int branch, InstancesHeader context) { - if ((branch == 0) || (branch == 1)) { - char compareChar = branch == 0 ? '<' : '>'; - int equalsBranch = this.equalsPassesTest ? 0 : 1; - return InstancesHeader.getAttributeNameString(context, - this.attIndex) - + ' ' - + compareChar - + (branch == equalsBranch ? "= " : " ") - + InstancesHeader.getNumericValueString(context, - this.attIndex, this.attValue); - } - throw new IndexOutOfBoundsException(); - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - public int[] getAttsTestDependsOn() { - return new int[] { this.attIndex }; - } - - public double getSplitValue() { - return this.attValue; - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWIN.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWIN.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWIN.java deleted file mode 100644 index bf6d02f..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWIN.java +++ /dev/null @@ -1,590 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.AbstractMOAObject; - -/** - * ADaptive sliding WINdow method. This method is a change detector and estimator. It keeps a variable-length window of - * recently seen items, with the property that the window has the maximal length statistically consistent with the - * hypothesis "there has been no change in the average value inside the window". - * - * - * @author Albert Bifet (abifet at cs dot waikato dot ac dot nz) - * @version $Revision: 7 $ - */ -public class ADWIN extends AbstractMOAObject { - - private class List extends AbstractMOAObject { - - protected int count; - - protected ListItem head; - - protected ListItem tail; - - public List() { - // post: initializes the list to be empty. - clear(); - addToHead(); - } - - /* Interface Store Methods */ - public int size() { - // post: returns the number of elements in the list. - return this.count; - } - - public ListItem head() { - // post: returns the number of elements in the list. - return this.head; - } - - public ListItem tail() { - // post: returns the number of elements in the list. - return this.tail; - } - - public boolean isEmpty() { - // post: returns the true iff store is empty. - return (this.size() == 0); - } - - public void clear() { - // post: clears the list so that it contains no elements. - this.head = null; - this.tail = null; - this.count = 0; - } - - /* Interface List Methods */ - public void addToHead() { - // pre: anObject is non-null - // post: the object is added to the beginning of the list - this.head = new ListItem(this.head, null); - if (this.tail == null) { - this.tail = this.head; - } - this.count++; - } - - public void removeFromHead() { - // pre: list is not empty - // post: removes and returns first object from the list - // ListItem temp; - // temp = this.head; - this.head = this.head.next(); - if (this.head != null) { - this.head.setPrevious(null); - } else { - this.tail = null; - } - this.count--; - } - - public void addToTail() { - // pre: anObject is non-null - // post: the object is added at the end of the list - this.tail = new ListItem(null, this.tail); - if (this.head == null) { - this.head = this.tail; - } - this.count++; - } - - public void removeFromTail() { - // pre: list is not empty - // post: the last object in the list is removed and returned - // ListItem temp; - // temp = this.tail; - this.tail = this.tail.previous(); - if (this.tail == null) { - this.head = null; - } else { - this.tail.setNext(null); - } - this.count--; - // temp=null; - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - } - } - - private class ListItem extends AbstractMOAObject { - protected ListItem next; - - protected ListItem previous; - - protected int bucketSizeRow = 0; - - protected int MAXBUCKETS = ADWIN.MAXBUCKETS; - - protected double bucketTotal[] = new double[MAXBUCKETS + 1]; - - protected double bucketVariance[] = new double[MAXBUCKETS + 1]; - - public ListItem() { - // post: initializes the node to be a tail node - // containing the given value. - this(null, null); - } - - public void clear() { - bucketSizeRow = 0; - for (int k = 0; k <= MAXBUCKETS; k++) { - clearBucket(k); - } - } - - private void clearBucket(int k) { - setTotal(0, k); - setVariance(0, k); - } - - public ListItem(ListItem nextNode, ListItem previousNode) { - // post: initializes the node to contain the given - // object and link to the given next node. - // this.data = element; - this.next = nextNode; - this.previous = previousNode; - if (nextNode != null) { - nextNode.previous = this; - } - if (previousNode != null) { - previousNode.next = this; - } - clear(); - } - - public void insertBucket(double Value, double Variance) { - // insert a Bucket at the end - int k = bucketSizeRow; - bucketSizeRow++; - // Insert new bucket - setTotal(Value, k); - setVariance(Variance, k); - } - - public void RemoveBucket() { - // Removes the first Buvket - compressBucketsRow(1); - } - - public void compressBucketsRow(int NumberItemsDeleted) { - // Delete first elements - for (int k = NumberItemsDeleted; k <= MAXBUCKETS; k++) { - bucketTotal[k - NumberItemsDeleted] = bucketTotal[k]; - bucketVariance[k - NumberItemsDeleted] = bucketVariance[k]; - } - for (int k = 1; k <= NumberItemsDeleted; k++) { - clearBucket(MAXBUCKETS - k + 1); - } - bucketSizeRow -= NumberItemsDeleted; - // BucketNumber-=NumberItemsDeleted; - } - - public ListItem previous() { - // post: returns the previous node. - return this.previous; - } - - public void setPrevious(ListItem previous) { - // post: sets the previous node to be the given node - this.previous = previous; - } - - public ListItem next() { - // post: returns the next node. - return this.next; - } - - public void setNext(ListItem next) { - // post: sets the next node to be the given node - this.next = next; - } - - public double Total(int k) { - // post: returns the element in this node - return bucketTotal[k]; - } - - public double Variance(int k) { - // post: returns the element in this node - return bucketVariance[k]; - } - - public void setTotal(double value, int k) { - // post: sets the element in this node to the given - // object. - bucketTotal[k] = value; - } - - public void setVariance(double value, int k) { - // post: sets the element in this node to the given - // object. - bucketVariance[k] = value; - } - - /* - * public ListItem(Object element, ListItem nextNode){ // post: initializes - * the node to contain the given // object and link to the given next node. - * this.data = element; this.next = nextNode; } public ListItem(Object - * element) { // post: initializes the node to be a tail node // containing - * the given value. this(element, null); } - * - * - * public Object value() { // post: returns the element in this node return - * this.data; } public void setValue(Object anObject) { // post: sets the - * element in this node to the given // object. this.data = anObject; } - */ - - @Override - public void getDescription(StringBuilder sb, int indent) { - } - } - - public static final double DELTA = .002; // .1; - - private static final int mintMinimLongitudWindow = 10; // 10 - - private double mdbldelta = .002; // .1; - - private int mintTime = 0; - - private int mintClock = 32; - - private double mdblWidth = 0; // Mean of Width = mdblWidth/Number of items - // BUCKET - - public static final int MAXBUCKETS = 5; - - private int lastBucketRow = 0; - - private double TOTAL = 0; - - private double VARIANCE = 0; - - private int WIDTH = 0; - - private int BucketNumber = 0; - - private int Detect = 0; - - private int numberDetections = 0; - - private int DetectTwice = 0; - - private boolean blnBucketDeleted = false; - - private int BucketNumberMAX = 0; - - private int mintMinWinLength = 5; - - private List listRowBuckets; - - public boolean getChange() { - return blnBucketDeleted; - } - - public void resetChange() { - blnBucketDeleted = false; - } - - public int getBucketsUsed() { - return BucketNumberMAX; - } - - public int getWidth() { - return WIDTH; - } - - public void setClock(int intClock) { - mintClock = intClock; - } - - public int getClock() { - return mintClock; - } - - public boolean getWarning() { - return false; - } - - public boolean getDetect() { - return (Detect == mintTime); - } - - public int getNumberDetections() { - return numberDetections; - } - - public double getTotal() { - return TOTAL; - } - - public double getEstimation() { - return TOTAL / WIDTH; - } - - public double getVariance() { - return VARIANCE / WIDTH; - } - - public double getWidthT() { - return mdblWidth; - } - - private void initBuckets() { - // Init buckets - listRowBuckets = new List(); - lastBucketRow = 0; - TOTAL = 0; - VARIANCE = 0; - WIDTH = 0; - BucketNumber = 0; - } - - private void insertElement(double Value) { - WIDTH++; - insertElementBucket(0, Value, listRowBuckets.head()); - double incVariance = 0; - if (WIDTH > 1) { - incVariance = (WIDTH - 1) * (Value - TOTAL / (WIDTH - 1)) * (Value - TOTAL / (WIDTH - 1)) / WIDTH; - } - VARIANCE += incVariance; - TOTAL += Value; - compressBuckets(); - } - - private void insertElementBucket(double Variance, double Value, ListItem Node) { - // Insert new bucket - Node.insertBucket(Value, Variance); - BucketNumber++; - if (BucketNumber > BucketNumberMAX) { - BucketNumberMAX = BucketNumber; - } - } - - private int bucketSize(int Row) { - return (int) Math.pow(2, Row); - } - - public int deleteElement() { - // LIST - // Update statistics - ListItem Node; - Node = listRowBuckets.tail(); - int n1 = bucketSize(lastBucketRow); - WIDTH -= n1; - TOTAL -= Node.Total(0); - double u1 = Node.Total(0) / n1; - double incVariance = Node.Variance(0) + n1 * WIDTH * (u1 - TOTAL / WIDTH) * (u1 - TOTAL / WIDTH) / (n1 + WIDTH); - VARIANCE -= incVariance; - - // Delete Bucket - Node.RemoveBucket(); - BucketNumber--; - if (Node.bucketSizeRow == 0) { - listRowBuckets.removeFromTail(); - lastBucketRow--; - } - return n1; - } - - public void compressBuckets() { - // Traverse the list of buckets in increasing order - int n1, n2; - double u2, u1, incVariance; - ListItem cursor; - ListItem nextNode; - cursor = listRowBuckets.head(); - int i = 0; - do { - // Find the number of buckets in a row - int k = cursor.bucketSizeRow; - // If the row is full, merge buckets - if (k == MAXBUCKETS + 1) { - nextNode = cursor.next(); - if (nextNode == null) { - listRowBuckets.addToTail(); - nextNode = cursor.next(); - lastBucketRow++; - } - n1 = bucketSize(i); - n2 = bucketSize(i); - u1 = cursor.Total(0) / n1; - u2 = cursor.Total(1) / n2; - incVariance = n1 * n2 * (u1 - u2) * (u1 - u2) / (n1 + n2); - - nextNode.insertBucket(cursor.Total(0) + cursor.Total(1), cursor.Variance(0) + cursor.Variance(1) + incVariance); - BucketNumber++; - cursor.compressBucketsRow(2); - if (nextNode.bucketSizeRow <= MAXBUCKETS) { - break; - } - } else { - break; - } - cursor = cursor.next(); - i++; - } while (cursor != null); - } - - public boolean setInput(double intEntrada) { - return setInput(intEntrada, mdbldelta); - } - - public boolean setInput(double intEntrada, double delta) { - boolean blnChange = false; - boolean blnExit; - ListItem cursor; - mintTime++; - - // 1,2)Increment window in one element - insertElement(intEntrada); - blnBucketDeleted = false; - // 3)Reduce window - if (mintTime % mintClock == 0 && getWidth() > mintMinimLongitudWindow) { - boolean blnReduceWidth = true; // Diference - - while (blnReduceWidth) // Diference - { - blnReduceWidth = false; // Diference - blnExit = false; - int n0 = 0; - int n1 = WIDTH; - double u0 = 0; - double u1 = getTotal(); - double v0 = 0; - double v1 = VARIANCE; - double n2; - double u2; - - cursor = listRowBuckets.tail(); - int i = lastBucketRow; - do { - for (int k = 0; k <= (cursor.bucketSizeRow - 1); k++) { - n2 = bucketSize(i); - u2 = cursor.Total(k); - if (n0 > 0) { - v0 += cursor.Variance(k) + (double) n0 * n2 * (u0 / n0 - u2 / n2) * (u0 / n0 - u2 / n2) / (n0 + n2); - } - if (n1 > 0) { - v1 -= cursor.Variance(k) + (double) n1 * n2 * (u1 / n1 - u2 / n2) * (u1 / n1 - u2 / n2) / (n1 + n2); - } - - n0 += bucketSize(i); - n1 -= bucketSize(i); - u0 += cursor.Total(k); - u1 -= cursor.Total(k); - - if (i == 0 && k == cursor.bucketSizeRow - 1) { - blnExit = true; - break; - } - double absvalue = (u0 / n0) - (u1 / n1); // n1<WIDTH-mintMinWinLength-1 - if ((n1 > mintMinWinLength + 1 && n0 > mintMinWinLength + 1) && // Diference NEGATIVE if( - blnCutexpression(n0, n1, u0, u1, v0, v1, absvalue, delta)) { - blnBucketDeleted = true; - Detect = mintTime; - - if (Detect == 0) { - Detect = mintTime; - // blnFirst=true; - // blnWarning=true; - } else if (DetectTwice == 0) { - DetectTwice = mintTime; - // blnDetect=true; - } - blnReduceWidth = true; // Diference - blnChange = true; - if (getWidth() > 0) { // Reduce width of the window - // while (n0>0) // Diference NEGATIVE - n0 -= deleteElement(); - blnExit = true; - break; - } - } // End if - }// Next k - cursor = cursor.previous(); - i--; - } while (((!blnExit && cursor != null))); - }// End While // Diference - }// End if - - mdblWidth += getWidth(); - if (blnChange) { - numberDetections++; - } - return blnChange; - } - - private boolean blnCutexpression(int n0, int n1, double u0, double u1, double v0, double v1, double absvalue, - double delta) { - int n = getWidth(); - double dd = Math.log(2 * Math.log(n) / delta); // -- ull perque el ln n va al numerador. - // Formula Gener 2008 - double v = getVariance(); - double m = ((double) 1 / ((n0 - mintMinWinLength + 1))) + ((double) 1 / ((n1 - mintMinWinLength + 1))); - double epsilon = Math.sqrt(2 * m * v * dd) + (double) 2 / 3 * dd * m; - - return (Math.abs(absvalue) > epsilon); - } - - public ADWIN() { - mdbldelta = DELTA; - initBuckets(); - Detect = 0; - numberDetections = 0; - DetectTwice = 0; - - } - - public ADWIN(double d) { - mdbldelta = d; - initBuckets(); - Detect = 0; - numberDetections = 0; - DetectTwice = 0; - } - - public ADWIN(int cl) { - mdbldelta = DELTA; - initBuckets(); - Detect = 0; - numberDetections = 0; - DetectTwice = 0; - mintClock = cl; - } - - public String getEstimatorInfo() { - return "ADWIN;;"; - } - - public void setW(int W0) { - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWINChangeDetector.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWINChangeDetector.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWINChangeDetector.java deleted file mode 100644 index 472fad7..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ADWINChangeDetector.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in ADWIN. ADaptive sliding WINdow is a change detector and estimator. It keeps a - * variable-length window of recently seen items, with the property that the window has the maximal length statistically - * consistent with the hypothesis "there has been no change in the average value inside the window". - * - * - * @author Albert Bifet (abifet at cs dot waikato dot ac dot nz) - * @version $Revision: 7 $ - */ -public class ADWINChangeDetector extends AbstractChangeDetector { - - protected ADWIN adwin; - - public FloatOption deltaAdwinOption = new FloatOption("deltaAdwin", 'a', - "Delta of Adwin change detection", 0.002, 0.0, 1.0); - - @Override - public void input(double inputValue) { - if (this.adwin == null) { - resetLearning(); - } - this.isChangeDetected = adwin.setInput(inputValue); - this.isWarningZone = false; - this.delay = 0.0; - this.estimation = adwin.getEstimation(); - } - - @Override - public void resetLearning() { - adwin = new ADWIN(this.deltaAdwinOption.getValue()); - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/AbstractChangeDetector.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/AbstractChangeDetector.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/AbstractChangeDetector.java deleted file mode 100644 index 5c0a387..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/AbstractChangeDetector.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.options.AbstractOptionHandler; - -/** - * Abstract Change Detector. All change detectors in MOA extend this class. - * - * @author Albert Bifet (abifet at cs dot waikato dot ac dot nz) - * @version $Revision: 7 $ - */ -public abstract class AbstractChangeDetector extends AbstractOptionHandler - implements ChangeDetector { - - /** - * Change was detected - */ - protected boolean isChangeDetected; - - /** - * Warning Zone: after a warning and before a change - */ - protected boolean isWarningZone; - - /** - * Prediction for the next value based in previous seen values - */ - protected double estimation; - - /** - * Delay in detecting change - */ - protected double delay; - - /** - * Resets this change detector. It must be similar to starting a new change detector from scratch. - * - */ - public void resetLearning() { - this.isChangeDetected = false; - this.isWarningZone = false; - this.estimation = 0.0; - this.delay = 0.0; - } - - /** - * Adding a numeric value to the change detector<br> - * <br> - * - * The output of the change detector is modified after the insertion of a new item inside. - * - * @param inputValue - * the number to insert into the change detector - */ - public abstract void input(double inputValue); - - /** - * Gets whether there is change detected. - * - * @return true if there is change - */ - public boolean getChange() { - return this.isChangeDetected; - } - - /** - * Gets whether the change detector is in the warning zone, after a warning alert and before a change alert. - * - * @return true if the change detector is in the warning zone - */ - public boolean getWarningZone() { - return this.isWarningZone; - } - - /** - * Gets the prediction of next values. - * - * @return a prediction of the next value - */ - public double getEstimation() { - return this.estimation; - } - - /** - * Gets the length of the delay in the change detected. - * - * @return he length of the delay in the change detected - */ - public double getDelay() { - return this.delay; - } - - /** - * Gets the output state of the change detection. - * - * @return an array with the number of change detections, number of warnings, delay, and estimation. - */ - public double[] getOutput() { - return new double[] { this.isChangeDetected ? 1 : 0, this.isWarningZone ? 1 : 0, this.delay, this.estimation }; - } - - /** - * Returns a string representation of the model. - * - * @param sb - * the stringbuilder to add the description - * @param indent - * the number of characters to indent - */ - @Override - public abstract void getDescription(StringBuilder sb, int indent); - - /** - * Produces a copy of this change detector method - * - * @return the copy of this change detector method - */ - @Override - public ChangeDetector copy() { - return (ChangeDetector) super.copy(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ChangeDetector.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ChangeDetector.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ChangeDetector.java deleted file mode 100644 index f2d8e2c..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/ChangeDetector.java +++ /dev/null @@ -1,103 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.options.OptionHandler; - -/** - * Change Detector interface to implement methods that detects change. - * - * @author Albert Bifet (abifet at cs dot waikato dot ac dot nz) - * @version $Revision: 7 $ - */ -public interface ChangeDetector extends OptionHandler { - - /** - * Resets this change detector. It must be similar to starting a new change detector from scratch. - * - */ - public void resetLearning(); - - /** - * Adding a numeric value to the change detector<br> - * <br> - * - * The output of the change detector is modified after the insertion of a new item inside. - * - * @param inputValue - * the number to insert into the change detector - */ - public void input(double inputValue); - - /** - * Gets whether there is change detected. - * - * @return true if there is change - */ - public boolean getChange(); - - /** - * Gets whether the change detector is in the warning zone, after a warning alert and before a change alert. - * - * @return true if the change detector is in the warning zone - */ - public boolean getWarningZone(); - - /** - * Gets the prediction of next values. - * - * @return a prediction of the next value - */ - public double getEstimation(); - - /** - * Gets the length of the delay in the change detected. - * - * @return he length of the delay in the change detected - */ - public double getDelay(); - - /** - * Gets the output state of the change detection. - * - * @return an array with the number of change detections, number of warnings, delay, and estimation. - */ - public double[] getOutput(); - - /** - * Returns a string representation of the model. - * - * @param out - * the stringbuilder to add the description - * @param indent - * the number of characters to indent - */ - @Override - public void getDescription(StringBuilder sb, int indent); - - /** - * Produces a copy of this drift detection method - * - * @return the copy of this drift detection method - */ - @Override - public ChangeDetector copy(); -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/CusumDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/CusumDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/CusumDM.java deleted file mode 100644 index e7b7f23..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/CusumDM.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in Cusum - * - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class CusumDM extends AbstractChangeDetector { - - private static final long serialVersionUID = -3518369648142099719L; - - public IntOption minNumInstancesOption = new IntOption( - "minNumInstances", - 'n', - "The minimum number of instances before permitting detecting change.", - 30, 0, Integer.MAX_VALUE); - - public FloatOption deltaOption = new FloatOption("delta", 'd', - "Delta parameter of the Cusum Test", 0.005, 0.0, 1.0); - - public FloatOption lambdaOption = new FloatOption("lambda", 'l', - "Threshold parameter of the Cusum Test", 50, 0.0, Float.MAX_VALUE); - - private int m_n; - - private double sum; - - private double x_mean; - - private double delta; - - private double lambda; - - public CusumDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1; - x_mean = 0.0; - sum = 0.0; - delta = this.deltaOption.getValue(); - lambda = this.lambdaOption.getValue(); - } - - @Override - public void input(double x) { - // It monitors the error rate - if (this.isChangeDetected) { - resetLearning(); - } - - x_mean = x_mean + (x - x_mean) / (double) m_n; - sum = Math.max(0, sum + x - x_mean - this.delta); - m_n++; - - // System.out.print(prediction + " " + m_n + " " + (m_p+m_s) + " "); - this.estimation = x_mean; - this.isChangeDetected = false; - this.isWarningZone = false; - this.delay = 0; - - if (m_n < this.minNumInstancesOption.getValue()) { - return; - } - - if (sum > this.lambda) { - this.isChangeDetected = true; - } - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/DDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/DDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/DDM.java deleted file mode 100644 index c6410fc..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/DDM.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in DDM method of Joao Gama SBIA 2004. - * - * <p> - * João Gama, Pedro Medas, Gladys Castillo, Pedro Pereira Rodrigues: Learning with Drift Detection. SBIA 2004: 286-295 - * </p> - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class DDM extends AbstractChangeDetector { - - private static final long serialVersionUID = -3518369648142099719L; - - // private static final int DDM_MINNUMINST = 30; - public IntOption minNumInstancesOption = new IntOption( - "minNumInstances", - 'n', - "The minimum number of instances before permitting detecting change.", - 30, 0, Integer.MAX_VALUE); - private int m_n; - - private double m_p; - - private double m_s; - - private double m_psmin; - - private double m_pmin; - - private double m_smin; - - public DDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1; - m_p = 1; - m_s = 0; - m_psmin = Double.MAX_VALUE; - m_pmin = Double.MAX_VALUE; - m_smin = Double.MAX_VALUE; - } - - @Override - public void input(double prediction) { - // prediction must be 1 or 0 - // It monitors the error rate - if (this.isChangeDetected) { - resetLearning(); - } - m_p = m_p + (prediction - m_p) / (double) m_n; - m_s = Math.sqrt(m_p * (1 - m_p) / (double) m_n); - - m_n++; - - // System.out.print(prediction + " " + m_n + " " + (m_p+m_s) + " "); - this.estimation = m_p; - this.isChangeDetected = false; - this.isWarningZone = false; - this.delay = 0; - - if (m_n < this.minNumInstancesOption.getValue()) { - return; - } - - if (m_p + m_s <= m_psmin) { - m_pmin = m_p; - m_smin = m_s; - m_psmin = m_p + m_s; - } - - if (m_n > this.minNumInstancesOption.getValue() && m_p + m_s > m_pmin + 3 * m_smin) { - this.isChangeDetected = true; - // resetLearning(); - } else - this.isWarningZone = m_p + m_s > m_pmin + 2 * m_smin; - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EDDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EDDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EDDM.java deleted file mode 100644 index 8db5625..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EDDM.java +++ /dev/null @@ -1,139 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in EDDM method of Manuel Baena et al. - * - * <p> - * Early Drift Detection Method. Manuel Baena-Garcia, Jose Del Campo-Avila, Raúl Fidalgo, Albert Bifet, Ricard Gavalda, - * Rafael Morales-Bueno. In Fourth International Workshop on Knowledge Discovery from Data Streams, 2006. - * </p> - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class EDDM extends AbstractChangeDetector { - - /** - * - */ - private static final long serialVersionUID = 140980267062162000L; - - private static final double FDDM_OUTCONTROL = 0.9; - - private static final double FDDM_WARNING = 0.95; - - private static final double FDDM_MINNUMINSTANCES = 30; - - private double m_numErrors; - - private int m_minNumErrors = 30; - - private int m_n; - - private int m_d; - - private int m_lastd; - - private double m_mean; - - private double m_stdTemp; - - private double m_m2smax; - - public EDDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1; - m_numErrors = 0; - m_d = 0; - m_lastd = 0; - m_mean = 0.0; - m_stdTemp = 0.0; - m_m2smax = 0.0; - this.estimation = 0.0; - } - - @Override - public void input(double prediction) { - // prediction must be 1 or 0 - // It monitors the error rate - // System.out.print(prediction + " " + m_n + " " + probability + " "); - if (this.isChangeDetected) { - resetLearning(); - } - this.isChangeDetected = false; - - m_n++; - if (prediction == 1.0) { - this.isWarningZone = false; - this.delay = 0; - m_numErrors += 1; - m_lastd = m_d; - m_d = m_n - 1; - int distance = m_d - m_lastd; - double oldmean = m_mean; - m_mean = m_mean + ((double) distance - m_mean) / m_numErrors; - this.estimation = m_mean; - m_stdTemp = m_stdTemp + (distance - m_mean) * (distance - oldmean); - double std = Math.sqrt(m_stdTemp / m_numErrors); - double m2s = m_mean + 2 * std; - - if (m2s > m_m2smax) { - if (m_n > FDDM_MINNUMINSTANCES) { - m_m2smax = m2s; - } - // m_lastLevel = DDM_INCONTROL_LEVEL; - // System.out.print(1 + " "); - } else { - double p = m2s / m_m2smax; - // System.out.print(p + " "); - if (m_n > FDDM_MINNUMINSTANCES && m_numErrors > m_minNumErrors - && p < FDDM_OUTCONTROL) { - // System.out.println(m_mean + ",D"); - this.isChangeDetected = true; - // resetLearning(); - } else { - this.isWarningZone = m_n > FDDM_MINNUMINSTANCES - && m_numErrors > m_minNumErrors && p < FDDM_WARNING; - } - } - } - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EWMAChartDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EWMAChartDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EWMAChartDM.java deleted file mode 100644 index 264673c..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/EWMAChartDM.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in EWMA Charts of Ross, Adams, Tasoulis and Hand 2012 - * - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class EWMAChartDM extends AbstractChangeDetector { - - private static final long serialVersionUID = -3518369648142099719L; - - // private static final int DDM_MIN_NUM_INST = 30; - public IntOption minNumInstancesOption = new IntOption( - "minNumInstances", - 'n', - "The minimum number of instances before permitting detecting change.", - 30, 0, Integer.MAX_VALUE); - - public FloatOption lambdaOption = new FloatOption("lambda", 'l', - "Lambda parameter of the EWMA Chart Method", 0.2, 0.0, Float.MAX_VALUE); - - private double m_n; - - private double m_sum; - - private double m_p; - - private double m_s; - - private double lambda; - - private double z_t; - - public EWMAChartDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1.0; - m_sum = 0.0; - m_p = 0.0; - m_s = 0.0; - z_t = 0.0; - lambda = this.lambdaOption.getValue(); - } - - @Override - public void input(double prediction) { - // prediction must be 1 or 0 - // It monitors the error rate - if (this.isChangeDetected) { - resetLearning(); - } - - m_sum += prediction; - - m_p = m_sum / m_n; // m_p + (prediction - m_p) / (double) (m_n+1); - - m_s = Math.sqrt(m_p * (1.0 - m_p) * lambda * (1.0 - Math.pow(1.0 - lambda, 2.0 * m_n)) / (2.0 - lambda)); - - m_n++; - - z_t += lambda * (prediction - z_t); - - double L_t = 3.97 - 6.56 * m_p + 48.73 * Math.pow(m_p, 3) - 330.13 * Math.pow(m_p, 5) + 848.18 * Math.pow(m_p, 7); // %1 FP - this.estimation = m_p; - this.isChangeDetected = false; - this.isWarningZone = false; - this.delay = 0; - - if (m_n < this.minNumInstancesOption.getValue()) { - return; - } - - if (m_n > this.minNumInstancesOption.getValue() && z_t > m_p + L_t * m_s) { - this.isChangeDetected = true; - // resetLearning(); - } else { - this.isWarningZone = z_t > m_p + 0.5 * L_t * m_s; - } - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/GeometricMovingAverageDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/GeometricMovingAverageDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/GeometricMovingAverageDM.java deleted file mode 100644 index 0f05a51..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/GeometricMovingAverageDM.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in Geometric Moving Average Test - * - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class GeometricMovingAverageDM extends AbstractChangeDetector { - - private static final long serialVersionUID = -3518369648142099719L; - - public IntOption minNumInstancesOption = new IntOption( - "minNumInstances", - 'n', - "The minimum number of instances before permitting detecting change.", - 30, 0, Integer.MAX_VALUE); - - public FloatOption lambdaOption = new FloatOption("lambda", 'l', - "Threshold parameter of the Geometric Moving Average Test", 1, 0.0, Float.MAX_VALUE); - - public FloatOption alphaOption = new FloatOption("alpha", 'a', - "Alpha parameter of the Geometric Moving Average Test", .99, 0.0, 1.0); - - private double m_n; - - private double sum; - - private double x_mean; - - private double alpha; - - private double lambda; - - public GeometricMovingAverageDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1.0; - x_mean = 0.0; - sum = 0.0; - alpha = this.alphaOption.getValue(); - lambda = this.lambdaOption.getValue(); - } - - @Override - public void input(double x) { - // It monitors the error rate - if (this.isChangeDetected) { - resetLearning(); - } - - x_mean = x_mean + (x - x_mean) / m_n; - sum = alpha * sum + (1.0 - alpha) * (x - x_mean); - m_n++; - this.estimation = x_mean; - this.isChangeDetected = false; - this.isWarningZone = false; - this.delay = 0; - - if (m_n < this.minNumInstancesOption.getValue()) { - return; - } - - if (sum > this.lambda) { - this.isChangeDetected = true; - } - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/PageHinkleyDM.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/PageHinkleyDM.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/PageHinkleyDM.java deleted file mode 100644 index 4ebf2b8..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/driftdetection/PageHinkleyDM.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.driftdetection; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Drift detection method based in Page Hinkley Test. - * - * - * @author Manuel Baena ([email protected]) - * @version $Revision: 7 $ - */ -public class PageHinkleyDM extends AbstractChangeDetector { - - private static final long serialVersionUID = -3518369648142099719L; - - public IntOption minNumInstancesOption = new IntOption( - "minNumInstances", - 'n', - "The minimum number of instances before permitting detecting change.", - 30, 0, Integer.MAX_VALUE); - - public FloatOption deltaOption = new FloatOption("delta", 'd', - "Delta parameter of the Page Hinkley Test", 0.005, 0.0, 1.0); - - public FloatOption lambdaOption = new FloatOption("lambda", 'l', - "Lambda parameter of the Page Hinkley Test", 50, 0.0, Float.MAX_VALUE); - - public FloatOption alphaOption = new FloatOption("alpha", 'a', - "Alpha parameter of the Page Hinkley Test", 1 - 0.0001, 0.0, 1.0); - - private int m_n; - - private double sum; - - private double x_mean; - - private double alpha; - - private double delta; - - private double lambda; - - public PageHinkleyDM() { - resetLearning(); - } - - @Override - public void resetLearning() { - m_n = 1; - x_mean = 0.0; - sum = 0.0; - delta = this.deltaOption.getValue(); - alpha = this.alphaOption.getValue(); - lambda = this.lambdaOption.getValue(); - } - - @Override - public void input(double x) { - // It monitors the error rate - if (this.isChangeDetected) { - resetLearning(); - } - - x_mean = x_mean + (x - x_mean) / (double) m_n; - sum = this.alpha * sum + (x - x_mean - this.delta); - m_n++; - this.estimation = x_mean; - this.isChangeDetected = false; - this.isWarningZone = false; - this.delay = 0; - - if (m_n < this.minNumInstancesOption.getValue()) { - return; - } - - if (sum > this.lambda) { - this.isChangeDetected = true; - } - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/GiniSplitCriterion.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/GiniSplitCriterion.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/GiniSplitCriterion.java deleted file mode 100644 index 8c230b9..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/GiniSplitCriterion.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.core.Utils; -import com.yahoo.labs.samoa.moa.options.AbstractOptionHandler; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Class for computing splitting criteria using Gini with respect to distributions of class values. The split criterion - * is used as a parameter on decision trees and decision stumps. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class GiniSplitCriterion extends AbstractOptionHandler implements - SplitCriterion { - - private static final long serialVersionUID = 1L; - - @Override - public double getMeritOfSplit(double[] preSplitDist, double[][] postSplitDists) { - double totalWeight = 0.0; - double[] distWeights = new double[postSplitDists.length]; - for (int i = 0; i < postSplitDists.length; i++) { - distWeights[i] = Utils.sum(postSplitDists[i]); - totalWeight += distWeights[i]; - } - double gini = 0.0; - for (int i = 0; i < postSplitDists.length; i++) { - gini += (distWeights[i] / totalWeight) - * computeGini(postSplitDists[i], distWeights[i]); - } - return 1.0 - gini; - } - - @Override - public double getRangeOfMerit(double[] preSplitDist) { - return 1.0; - } - - public static double computeGini(double[] dist, double distSumOfWeights) { - double gini = 1.0; - for (double aDist : dist) { - double relFreq = aDist / distSumOfWeights; - gini -= relFreq * relFreq; - } - return gini; - } - - public static double computeGini(double[] dist) { - return computeGini(dist, Utils.sum(dist)); - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterion.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterion.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterion.java deleted file mode 100644 index 62fc9fa..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterion.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.FloatOption; -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.core.Utils; -import com.yahoo.labs.samoa.moa.options.AbstractOptionHandler; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -/** - * Class for computing splitting criteria using information gain with respect to distributions of class values. The - * split criterion is used as a parameter on decision trees and decision stumps. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class InfoGainSplitCriterion extends AbstractOptionHandler implements - SplitCriterion { - - private static final long serialVersionUID = 1L; - - public FloatOption minBranchFracOption = new FloatOption("minBranchFrac", - 'f', - "Minimum fraction of weight required down at least two branches.", - 0.01, 0.0, 0.5); - - @Override - public double getMeritOfSplit(double[] preSplitDist, - double[][] postSplitDists) { - if (numSubsetsGreaterThanFrac(postSplitDists, this.minBranchFracOption.getValue()) < 2) { - return Double.NEGATIVE_INFINITY; - } - return computeEntropy(preSplitDist) - computeEntropy(postSplitDists); - } - - @Override - public double getRangeOfMerit(double[] preSplitDist) { - int numClasses = preSplitDist.length > 2 ? preSplitDist.length : 2; - return Utils.log2(numClasses); - } - - public static double computeEntropy(double[] dist) { - double entropy = 0.0; - double sum = 0.0; - for (double d : dist) { - if (d > 0.0) { // TODO: how small can d be before log2 overflows? - entropy -= d * Utils.log2(d); - sum += d; - } - } - return sum > 0.0 ? (entropy + sum * Utils.log2(sum)) / sum : 0.0; - } - - public static double computeEntropy(double[][] dists) { - double totalWeight = 0.0; - double[] distWeights = new double[dists.length]; - for (int i = 0; i < dists.length; i++) { - distWeights[i] = Utils.sum(dists[i]); - totalWeight += distWeights[i]; - } - double entropy = 0.0; - for (int i = 0; i < dists.length; i++) { - entropy += distWeights[i] * computeEntropy(dists[i]); - } - return entropy / totalWeight; - } - - public static int numSubsetsGreaterThanFrac(double[][] distributions, double minFrac) { - double totalWeight = 0.0; - double[] distSums = new double[distributions.length]; - for (int i = 0; i < distSums.length; i++) { - for (int j = 0; j < distributions[i].length; j++) { - distSums[i] += distributions[i][j]; - } - totalWeight += distSums[i]; - } - int numGreater = 0; - for (double d : distSums) { - double frac = d / totalWeight; - if (frac > minFrac) { - numGreater++; - } - } - return numGreater; - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterionMultilabel.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterionMultilabel.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterionMultilabel.java deleted file mode 100644 index f60cd72..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/InfoGainSplitCriterionMultilabel.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.core.Utils; - -/** - * Class for computing splitting criteria using information gain with respect to distributions of class values for - * Multilabel data. The split criterion is used as a parameter on decision trees and decision stumps. - * - * @author Richard Kirkby ([email protected]) - * @author Jesse Read ([email protected]) - * @version $Revision: 1 $ - */ -public class InfoGainSplitCriterionMultilabel extends InfoGainSplitCriterion { - - private static final long serialVersionUID = 1L; - - public static double computeEntropy(double[] dist) { - double entropy = 0.0; - double sum = 0.0; - for (double d : dist) { - sum += d; - } - if (sum > 0.0) { - for (double num : dist) { - double d = num / sum; - if (d > 0.0) { // TODO: how small can d be before log2 overflows? - entropy -= d * Utils.log2(d) + (1 - d) * Utils.log2(1 - d); // Extension to Multilabel - } - } - } - return sum > 0.0 ? entropy : 0.0; - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SDRSplitCriterion.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SDRSplitCriterion.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SDRSplitCriterion.java deleted file mode 100644 index 6eba291..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SDRSplitCriterion.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -public class SDRSplitCriterion extends VarianceReductionSplitCriterion { - private static final long serialVersionUID = 1L; - - public static double computeSD(double[] dist) { - int N = (int) dist[0]; - double sum = dist[1]; - double sumSq = dist[2]; - return Math.sqrt((sumSq - ((sum * sum) / N)) / N); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SplitCriterion.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SplitCriterion.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SplitCriterion.java deleted file mode 100644 index 0e0a04e..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/SplitCriterion.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.options.OptionHandler; - -/** - * Interface for computing splitting criteria. with respect to distributions of class values. The split criterion is - * used as a parameter on decision trees and decision stumps. The two split criteria most used are Information Gain and - * Gini. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public interface SplitCriterion extends OptionHandler { - - /** - * Computes the merit of splitting for a given ditribution before the split and after it. - * - * @param preSplitDist - * the class distribution before the split - * @param postSplitDists - * the class distribution after the split - * @return value of the merit of splitting - */ - public double getMeritOfSplit(double[] preSplitDist, - double[][] postSplitDists); - - /** - * Computes the range of splitting merit - * - * @param preSplitDist - * the class distribution before the split - * @return value of the range of splitting merit - */ - public double getRangeOfMerit(double[] preSplitDist); -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/VarianceReductionSplitCriterion.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/VarianceReductionSplitCriterion.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/VarianceReductionSplitCriterion.java deleted file mode 100644 index 33875b4..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/core/splitcriteria/VarianceReductionSplitCriterion.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.core.splitcriteria; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.core.ObjectRepository; -import com.yahoo.labs.samoa.moa.options.AbstractOptionHandler; -import com.yahoo.labs.samoa.moa.tasks.TaskMonitor; - -public class VarianceReductionSplitCriterion extends AbstractOptionHandler implements SplitCriterion { - - private static final long serialVersionUID = 1L; - - /* - * @Override public double getMeritOfSplit(double[] preSplitDist, double[][] - * postSplitDists) { - * - * double N = preSplitDist[0]; double SDR = computeSD(preSplitDist); - * - * // System.out.print("postSplitDists.length"+postSplitDists.length+"\n"); - * for(int i = 0; i < postSplitDists.length; i++) { double Ni = - * postSplitDists[i][0]; SDR -= (Ni/N)*computeSD(postSplitDists[i]); } - * - * return SDR; } - */ - - @Override - public double getMeritOfSplit(double[] preSplitDist, double[][] postSplitDists) { - double SDR = 0.0; - double N = preSplitDist[0]; - int count = 0; - - for (int i1 = 0; i1 < postSplitDists.length; i1++) { - double[] postSplitDist = postSplitDists[i1]; - double Ni = postSplitDist[0]; - if (Ni >= 5.0) { - count = count + 1; - } - } - - if (count == postSplitDists.length) { - SDR = computeSD(preSplitDist); - for (int i = 0; i < postSplitDists.length; i++) - { - double Ni = postSplitDists[i][0]; - SDR -= (Ni / N) * computeSD(postSplitDists[i]); - } - } - return SDR; - } - - @Override - public double getRangeOfMerit(double[] preSplitDist) { - return 1; - } - - public static double computeSD(double[] dist) { - - int N = (int) dist[0]; - double sum = dist[1]; - double sumSq = dist[2]; - // return Math.sqrt((sumSq - ((sum * sum)/N))/N); - return (sumSq - ((sum * sum) / N)) / N; - } - - @Override - public void getDescription(StringBuilder sb, int indent) { - // TODO Auto-generated method stub - } - - @Override - protected void prepareForUseImpl(TaskMonitor monitor, - ObjectRepository repository) { - // TODO Auto-generated method stub - } - -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/functions/MajorityClass.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/functions/MajorityClass.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/functions/MajorityClass.java deleted file mode 100644 index f8cb325..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/functions/MajorityClass.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.functions; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.moa.classifiers.AbstractClassifier; -import com.yahoo.labs.samoa.moa.core.DoubleVector; -import com.yahoo.labs.samoa.moa.core.Measurement; -import com.yahoo.labs.samoa.moa.core.StringUtils; -import com.yahoo.labs.samoa.instances.Instance; - -/** - * Majority class learner. This is the simplest classifier. - * - * @author Richard Kirkby ([email protected]) - * @version $Revision: 7 $ - */ -public class MajorityClass extends AbstractClassifier { - - private static final long serialVersionUID = 1L; - - @Override - public String getPurposeString() { - return "Majority class classifier: always predicts the class that has been observed most frequently the in the training data."; - } - - protected DoubleVector observedClassDistribution; - - @Override - public void resetLearningImpl() { - this.observedClassDistribution = new DoubleVector(); - } - - @Override - public void trainOnInstanceImpl(Instance inst) { - this.observedClassDistribution.addToValue((int) inst.classValue(), inst.weight()); - } - - public double[] getVotesForInstance(Instance i) { - return this.observedClassDistribution.getArrayCopy(); - } - - @Override - protected Measurement[] getModelMeasurementsImpl() { - return null; - } - - @Override - public void getModelDescription(StringBuilder out, int indent) { - StringUtils.appendIndented(out, indent, "Predicted majority "); - out.append(getClassNameString()); - out.append(" = "); - out.append(getClassLabelString(this.observedClassDistribution.maxIndex())); - StringUtils.appendNewline(out); - for (int i = 0; i < this.observedClassDistribution.numValues(); i++) { - StringUtils.appendIndented(out, indent, "Observed weight of "); - out.append(getClassLabelString(i)); - out.append(": "); - out.append(this.observedClassDistribution.getValue(i)); - StringUtils.appendNewline(out); - } - } - - public boolean isRandomizable() { - return false; - } -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/Predicate.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/Predicate.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/Predicate.java deleted file mode 100644 index 995dd05..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/Predicate.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.rules.core; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.yahoo.labs.samoa.instances.Instance; - -/** - * Interface for a predicate (a feature) in rules. - * - */ -public interface Predicate { - - public boolean evaluate(Instance instance); - -} http://git-wip-us.apache.org/repos/asf/incubator-samoa/blob/9b178f63/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/attributeclassobservers/FIMTDDNumericAttributeClassLimitObserver.java ---------------------------------------------------------------------- diff --git a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/attributeclassobservers/FIMTDDNumericAttributeClassLimitObserver.java b/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/attributeclassobservers/FIMTDDNumericAttributeClassLimitObserver.java deleted file mode 100644 index cb47039..0000000 --- a/samoa-api/src/main/java/com/yahoo/labs/samoa/moa/classifiers/rules/core/attributeclassobservers/FIMTDDNumericAttributeClassLimitObserver.java +++ /dev/null @@ -1,120 +0,0 @@ -package com.yahoo.labs.samoa.moa.classifiers.rules.core.attributeclassobservers; - -/* - * #%L - * SAMOA - * %% - * Copyright (C) 2014 - 2015 Apache Software Foundation - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import com.github.javacliparser.IntOption; -import com.yahoo.labs.samoa.moa.classifiers.core.attributeclassobservers.FIMTDDNumericAttributeClassObserver; - -public class FIMTDDNumericAttributeClassLimitObserver extends FIMTDDNumericAttributeClassObserver { - - /** - * - */ - private static final long serialVersionUID = 1L; - protected int maxNodes; - // public IntOption maxNodesOption = new IntOption("maxNodesOption", 'z', - // "Maximum number of nodes", 50, 0, Integer.MAX_VALUE); - - protected int numNodes; - - public int getMaxNodes() { - return this.maxNodes; - } - - public void setMaxNodes(int maxNodes) { - this.maxNodes = maxNodes; - } - - @Override - public void observeAttributeClass(double attVal, double classVal, double weight) { - if (Double.isNaN(attVal)) { // Instance.isMissingValue(attVal) - } else { - if (this.root == null) { - // maxNodes=maxNodesOption.getValue(); - maxNodes = 50; - this.root = new FIMTDDNumericAttributeClassLimitObserver.Node(attVal, classVal, weight); - } else { - this.root.insertValue(attVal, classVal, weight); - } - } - } - - protected class Node extends FIMTDDNumericAttributeClassObserver.Node { - /** - * - */ - private static final long serialVersionUID = -4484141636424708465L; - - public Node(double val, double label, double weight) { - super(val, label, weight); - } - - protected Node root = null; - - /** - * Insert a new value into the tree, updating both the sum of values and sum of squared values arrays - */ - @Override - public void insertValue(double val, double label, double weight) { - - // If the new value equals the value stored in a node, update - // the left (<=) node information - if (val == this.cut_point) - { - this.leftStatistics.addToValue(0, 1); - this.leftStatistics.addToValue(1, label); - this.leftStatistics.addToValue(2, label * label); - } - // If the new value is less than the value in a node, update the - // left distribution and send the value down to the left child node. - // If no left child exists, create one - else if (val <= this.cut_point) { - this.leftStatistics.addToValue(0, 1); - this.leftStatistics.addToValue(1, label); - this.leftStatistics.addToValue(2, label * label); - if (this.left == null) { - if (numNodes < maxNodes) { - this.left = new Node(val, label, weight); - ++numNodes; - } - } else { - this.left.insertValue(val, label, weight); - } - } - // If the new value is greater than the value in a node, update the - // right (>) distribution and send the value down to the right child node. - // If no right child exists, create one - else { // val > cut_point - this.rightStatistics.addToValue(0, 1); - this.rightStatistics.addToValue(1, label); - this.rightStatistics.addToValue(2, label * label); - if (this.right == null) { - if (numNodes < maxNodes) { - this.right = new Node(val, label, weight); - ++numNodes; - } - } else { - this.right.insertValue(val, label, weight); - } - } - } - } -}
