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

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

Go to download

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

The newest version!
package aima.core.learning.inductive;

import java.util.Hashtable;

import aima.core.learning.framework.DataSet;
import aima.core.learning.framework.Example;

/**
 * @author Ravi Mohan
 * 
 */
public class DLTest {

	// represents a single test in the Decision List
	private Hashtable attrValues;

	public DLTest() {
		attrValues = new Hashtable();
	}

	public void add(String nta, String ntaValue) {
		attrValues.put(nta, ntaValue);

	}

	public boolean matches(Example e) {
		for (String key : attrValues.keySet()) {
			if (!(attrValues.get(key).equals(e.getAttributeValueAsString(key)))) {
				return false;
			}
		}
		return true;
		// return e.targetValue().equals(targetValue);
	}

	public DataSet matchedExamples(DataSet ds) {
		DataSet matched = ds.emptyDataSet();
		for (Example e : ds.examples) {
			if (matches(e)) {
				matched.add(e);
			}
		}
		return matched;
	}

	public DataSet unmatchedExamples(DataSet ds) {
		DataSet unmatched = ds.emptyDataSet();
		for (Example e : ds.examples) {
			if (!(matches(e))) {
				unmatched.add(e);
			}
		}
		return unmatched;
	}

	@Override
	public String toString() {
		StringBuffer buf = new StringBuffer();
		buf.append("IF  ");
		for (String key : attrValues.keySet()) {
			buf.append(key + " = ");
			buf.append(attrValues.get(key) + " ");
		}
		buf.append(" DECISION ");
		return buf.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy