Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d2fbe22
Fixed error in derivative
henrygouk Jul 3, 2017
fa123a2
Add ADOB, BOLE and RDDM methods
silasgtcs Aug 29, 2017
300b310
Update BOLE.java
silasgtcs Aug 29, 2017
042d0a2
Update ADOB, BOLE, RDDM and add DDM modifications
silasgtcs Sep 6, 2017
46c7fd4
Add ADOBTest and BOLETest
silasgtcs Sep 11, 2017
12b45f0
Update BOLETest
silasgtcs Sep 11, 2017
710b8c4
Merge remote-tracking branch 'Waikato/master'
Mar 30, 2018
610874e
Update licenses and other code details
silasgtcs Apr 19, 2018
5fe11ef
Merge branch 'adob_bole_rddm' of https://github.com/silasgtcs/moa int…
silasgtcs Apr 19, 2018
4e31577
Update licenses and other code details
silasgtcs Apr 19, 2018
6bd8c8e
Merge pull request #109 from silasgtcs/adob_bole_rddm
abifet Apr 19, 2018
b2fe845
Updates to .ref files for recently added methods to comply with curre…
hmgomes Apr 21, 2018
08b6977
Merge pull request #132 from hmgomes/master
abifet Apr 21, 2018
7b1b4fe
Merge branch 'master' of https://github.com/Waikato/moa
henrygouk Apr 22, 2018
90888b4
Weka 3.9.2 is minimum
fracpete Apr 22, 2018
f8b4d48
isJavaVersionOK now handles version numbers with and without dots; mi…
fracpete Apr 22, 2018
43aee02
Merge branch 'master' of https://github.com/Waikato/moa
henrygouk Apr 22, 2018
2ed12b7
Merge pull request #134 from henrygouk/master
abifet Apr 22, 2018
0d96101
Merge remote-tracking branch 'Waikato/master'
Apr 23, 2018
491288d
Reset of ADWIN change detector
Apr 26, 2018
5f97a6e
Fix adwinchangedetector
Apr 26, 2018
7253825
Merge pull request #135 from jpbarddal/master
abifet Apr 26, 2018
6218fa4
HoeffdingResgressionTree
ahmedbenhassine Jun 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions moa/src/main/java/moa/DoTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,40 @@ public class DoTask {
*/
public static boolean isJavaVersionOK() {
boolean isJavaVersionOK = true;
String version = System.getProperty("java.version");
char major = version.charAt(0);
char minor = version.length() > 1 ? version.charAt(2): '0';
if (major == '1' && minor < '6') {
String versionStr = System.getProperty("java.version");
String[] parts;
double version;
if (versionStr.contains(".")) {
parts = versionStr.split("\\.");
}
else {
parts = new String[]{versionStr};
}
if (parts.length == 1) {
try {
version = Double.parseDouble(parts[0]);
}
catch (Exception e) {
System.err.println("Unparsable Java version: " + versionStr);
return false;
}
}
else {
try {
version = Double.parseDouble(parts[0]) + Double.parseDouble(parts[1]) / 10;
}
catch (Exception e) {
System.err.println("Unparsable Java version: " + versionStr);
return false;
}
}
if (version < 1.8) {
isJavaVersionOK = false;
System.err.println();
System.err.println(Globals.getWorkbenchInfoString());
System.err.println();
System.err.print("JDK 1.6.0 or higher is required to run MOA. ");
System.err.println("JDK version " + version + " found");
System.err.print("Java 8 or higher is required to run MOA. ");
System.err.println("Java version " + versionStr + " found");
}
return isJavaVersionOK;
}
Expand All @@ -82,11 +106,11 @@ public static boolean isJavaVersionOK() {
*/
public static boolean isWekaVersionOK() {
Version version = new Version();
if (version.isOlder("3.7.1")) {
if (version.isOlder("3.9.2")) {
System.err.println();
System.err.println(Globals.getWorkbenchInfoString());
System.err.println();
System.err.print("Weka 3.7.1 or higher is required to run MOA. ");
System.err.print("Weka 3.9.2 or higher is required to run MOA. ");
System.err.println("Weka version " + Version.VERSION + " found");
return false;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
package moa.classifiers.core.attributeclassobservers;

import moa.classifiers.core.AttributeSplitSuggestion;
import moa.classifiers.core.conditionaltests.NominalAttributeMultiwayTest;
import moa.classifiers.core.splitcriteria.SplitCriterion;
import moa.core.DoubleVector;
import moa.core.ObjectRepository;
import moa.options.AbstractOptionHandler;
import moa.tasks.TaskMonitor;
import moa.classifiers.core.conditionaltests.NominalAttributeBinaryTest;

import java.io.Serializable;

public class HoeffdingNominalAttributeClassObserver extends AbstractOptionHandler implements
DiscreteAttributeClassObserver {

private static final long serialVersionUID = 1L;

protected class Node implements Serializable {

private static final long serialVersionUID = 1L;

// The split point to use
public double cut_point;

// statistics
public DoubleVector statistics = new DoubleVector();


// Child node
public HoeffdingNominalAttributeClassObserver.Node child;


public Node(double val, double label) {
this.cut_point = val;
this.statistics.addToValue(0, 1);
this.statistics.addToValue(1, label);
this.statistics.addToValue(2, label * label);
}

/**
* Insert a new value into the tree, updating both the sum of values and
* sum of squared values arrays
*/
public void insertValue(double val, double label) {
//System.out.println(val);
// If the new value equals the value stored in a node, update
// the node information
if (val == this.cut_point) {
this.statistics.addToValue(0, 1);
this.statistics.addToValue(1, label);
this.statistics.addToValue(2, label * label);
} // If the new value is less or greater than the value in a node, send the value down to the child node.
// If no left child exists, create one
else {

if (this.child == null) {
this.child = new HoeffdingNominalAttributeClassObserver.Node(val, label);
numberOfPossibleValues += 1 ;
} else {
this.child.insertValue(val, label);
}

}
}
}

// Root node of the tree structure for this attribute
protected HoeffdingNominalAttributeClassObserver.Node root = null;

// Global variables for use in the FindBestSplit algorithm
double sumOne;
double sumRest;
double sumSqOne;
double sumSqRest;
double countOne;
double countRest;
double sumTotal;
double sumSqTotal;
double count ;
boolean binaryOnly;
int numberOfPossibleValues ;

public void observeAttributeClass(double attVal, int classVal, double weight) {


}

@Override
public double probabilityOfAttributeValueGivenClass(double attVal,
int classVal) {
// TODO: NaiveBayes broken until implemented
return 0.0;
}

@Override
public AttributeSplitSuggestion getBestEvaluatedSplitSuggestion(SplitCriterion criterion, double[] preSplitDist, int attIndex, boolean binaryOnly) {

// Initialise global variables
sumOne = 0;
sumRest = 0;
sumSqOne = 0;
sumSqRest = 0;
countOne = 0;
countRest = 0;
sumTotal = preSplitDist[1];
sumSqTotal = preSplitDist[2];
count = preSplitDist[0];
this.binaryOnly = binaryOnly;
if (binaryOnly) {
return searchForBestBinarySplitOption(this.root, null, criterion, attIndex);
} else {
return searchForBestMultiwaySplitOption(this.root, null, criterion, attIndex);
}
}

/**
* Implementation of the FindBestSplit algorithm
*/
protected AttributeSplitSuggestion searchForBestBinarySplitOption(HoeffdingNominalAttributeClassObserver.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 || countRest == 0.0) {
return currentBestOption;
}

if (currentNode.child != null) {
currentBestOption = searchForBestBinarySplitOption(currentNode.child, currentBestOption, criterion, attIndex);
}

sumOne = currentNode.statistics.getValue(1);
sumRest = sumTotal - sumOne;
sumSqOne = currentNode.statistics.getValue(2);
sumSqRest = sumSqTotal - sumSqOne;
countOne = currentNode.statistics.getValue(0);
countRest = count - countOne;

double[][] postSplitDists = new double[][]{{countOne, sumOne, sumSqOne}, {countRest, sumRest, sumSqRest}};
double[] preSplitDist = new double[]{(count), (sumTotal), (sumSqTotal)};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);

if ((currentBestOption == null) || (merit > currentBestOption.merit)) {
currentBestOption = new AttributeSplitSuggestion(
new NominalAttributeBinaryTest(attIndex,
(int) currentNode.cut_point), postSplitDists, merit);


}

return currentBestOption;

}
protected AttributeSplitSuggestion searchForBestMultiwaySplitOption(HoeffdingNominalAttributeClassObserver.Node currentNode, AttributeSplitSuggestion currentBestOption, SplitCriterion criterion, int attIndex)
{

double[][] postSplitDists = new double[numberOfPossibleValues][3];
for (int i = 0; i < numberOfPossibleValues; i++)
{

if (currentNode == null || countRest == 0.0) {
return currentBestOption;
}
postSplitDists[i][0] = currentNode.statistics.getValue(0);
postSplitDists[i][1] = currentNode.statistics.getValue(1);
postSplitDists[i][2] = currentNode.statistics.getValue(2);
currentNode = currentNode.child ;

}
double[] preSplitDist = new double[]{(count), (sumTotal), (sumSqTotal)};
double merit = criterion.getMeritOfSplit(preSplitDist, postSplitDists);
if ((currentBestOption == null) || (merit > currentBestOption.merit)) {
currentBestOption = new AttributeSplitSuggestion(
new NominalAttributeMultiwayTest(attIndex), postSplitDists, merit);
}



return currentBestOption;

}







public void observeAttributeTarget(double attVal, double classVal) {
if (Double.isNaN(attVal)) { //Instance.isMissingValue(attVal)
} else {
if (this.root == null) {
numberOfPossibleValues= 1 ;
this.root = new HoeffdingNominalAttributeClassObserver.Node(attVal, classVal);
} else {
this.root.insertValue(attVal, classVal);
}
}
}

@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
}
}
Loading