All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aima.core.learning.inductive.ConstantDecisonTree Maven / Gradle / Ivy

Go to download

AIMA-Java Core Algorithms from the book Artificial Intelligence a Modern Approach 3rd Ed.

There is a newer version: 3.0.0
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy