org.bigml.mimir.forest.CategoricalNode Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mimir Show documentation
Show all versions of mimir Show documentation
Java/Clojure Prediction Code for BigML
package org.bigml.mimir.forest;
import org.bigml.mimir.utils.fields.FieldCollection;
import com.fasterxml.jackson.databind.JsonNode;
public class CategoricalNode extends ShapNode {
public double categoryIndex;
public CategoricalNode(JsonNode n, FieldCollection fields, double[] obj) {
super(n, fields, obj);
JsonNode[] children = getOrderedChildren(n);
setMissing(children[0], children[1]);
String field = getField(children[0]);
JsonNode value = getPredicateValue(children[0]).get(0);
if (value.isNull())
this.categoryIndex = fields.indexForValue(field, null);
else
this.categoryIndex = fields.indexForValue(field, value.asText());
}
@Override
public JsonNode[] getOrderedChildren(JsonNode aNode) {
JsonNode[] children = super.getOrderedChildren(aNode);
if (getPredicateValue(children[0]).size() > 1) {
assert getPredicateValue(children[1]).size() == 1;
JsonNode temp = children[0];
children[0] = children[1];
children[1] = temp;
}
else assert getPredicateValue(children[0]).size() == 1;
return children;
}
@Override
public int nextIndex(double[] instance) {
double value = instance[this.splitIndex];
if (Double.isNaN(value) || value == -1) return -1;
else if ((int)value == this.categoryIndex) return 0;
else return 1;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy