aima.core.learning.inductive.ConstantDecisonTree Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of aima-core Show documentation
Show all versions of aima-core Show documentation
AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.
package aima.core.learning.inductive;
import aima.core.learning.framework.Example;
import aima.core.util.Util;
/**
* @author Ravi Mohan
*
*/
public class ConstantDecisonTree extends DecisionTree {
// represents leaf nodes like "Yes" or "No"
private String value;
public ConstantDecisonTree(String value) {
this.value = value;
}
@Override
public void addLeaf(String attributeValue, String decision) {
throw new RuntimeException("cannot add Leaf to ConstantDecisonTree");
}
@Override
public void addNode(String attributeValue, DecisionTree tree) {
throw new RuntimeException("cannot add Node to ConstantDecisonTree");
}
@Override
public Object predict(Example e) {
return value;
}
@Override
public String toString() {
return "DECISION -> " + value;
}
@Override
public String toString(int depth, StringBuffer buf) {
buf.append(Util.ntimes("\t", depth + 1));
buf.append("DECISION -> " + value + "\n");
return buf.toString();
}
}