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

org.bigml.mimir.forest.SetNode Maven / Gradle / Ivy

The newest version!
package org.bigml.mimir.forest;

import org.bigml.mimir.utils.fields.CategoricalField;
import org.bigml.mimir.utils.fields.Field;
import org.bigml.mimir.utils.fields.FieldCollection;

import com.fasterxml.jackson.databind.JsonNode;

public class SetNode extends ShapNode {

    public SetNode(JsonNode node, FieldCollection fields, double[] obj) {
        super(node, fields, obj);

        JsonNode[] children = super.getOrderedChildren(node);
        Field f = fields.getField(getField(children[0]));
        CategoricalField field = (CategoricalField)f;

        JsonNode leftValues = getPredicateValue(children[0]);
        JsonNode rightValues = getPredicateValue(children[1]);

        _leftSet = makeBitSet(field, leftValues);
        _rightSet = makeBitSet(field, rightValues);

        leftMissing = checkForNull(leftValues);
        rightMissing = checkForNull(rightValues);
    }

    @Override
    public int nextIndex(double[] instance) {
        double value = instance[this.splitIndex];

        if (Double.isNaN(value) || value == -1) {
            return -1;
        }
        else {
            int catIdx = (int)value;
            if (catIdx == _leftSet.length) {
                if (leftMissing) return 0;
                else if (rightMissing) return 1;
                else return -1;
            }
            else {
                if (_leftSet[catIdx]) return 0;
                else if (_rightSet[catIdx]) return 1;
                else return -1;
            }
        }
    }

    public boolean[] _leftSet;
    public boolean[] _rightSet;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy