/** * Gets the index of the attribute in the instance, * given the index of the attribute in the learner. * * @param index the index of the attribute in the learner * @param inst the instance * @return the index in the instance */ protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return index<= inst.classIndex() ? index : index + 1; } }
/** * Gets the index of the attribute in the instance, * given the index of the attribute in the learner. * * @param index the index of the attribute in the learner * @param inst the instance * @return the index in the instance */ protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return inst.classIndex() > index ? index : index + 1; }
/** * Gets the index of the attribute in the instance, * given the index of the attribute in the learner. * * @param index the index of the attribute in the learner * @param inst the instance * @return the index in the instance */ public static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return index<= inst.classIndex() ? index : index + 1; }
/** * Gets the index of the attribute in the instance, * given the index of the attribute in the learner. * * @param index the index of the attribute in the learner * @param inst the instance * @return the index in the instance */ protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return index<= inst.classIndex() ? index : index + 1; }
protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return inst.classIndex() > index ? index : index + 1; }
protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return inst.classIndex() > index ? index : index + 1; }
protected static int modelAttIndexToInstanceAttIndex(int index, Instance inst) { return inst.classIndex() > index ? index : index + 1; }
private static int modelAttIndexToInstanceAttIndex(int index, Instance inst){ return inst.classIndex() > index ? index : index + 1; }
private static int modelAttIndexToInstanceAttIndex(int index, Instance inst){ return inst.classIndex() > index ? index : index + 1; }
@Override public int branchForInstance(Instance inst) { int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex : this.attIndex + 1; return inst.isMissing(instAttIndex) ? -1 : ((int) inst.value(instAttIndex) == this.attValue ? 0 : 1); }
@Override public int branchForInstance(Instance inst) { int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex : this.attIndex + 1; return inst.isMissing(instAttIndex) ? -1 : ((int) inst.value(instAttIndex) == this.attValue ? 0 : 1); }
@Override public int branchForInstance(Instance inst) { int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex : this.attIndex + 1; return inst.isMissing(instAttIndex) ? -1 : ((int) inst.value(instAttIndex) == this.attValue ? 0 : 1); }
@Override public int branchForInstance(Instance inst) { int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex : this.attIndex + 1; if (inst.isMissing(instAttIndex)) { return -1; } double v = inst.value(instAttIndex); int ret = 0; switch (this.operator) { case 0: ret = (v == this.attValue) ? 0 : 1; break; case 1: ret = (v <= this.attValue) ? 0 : 1; break; case 2: ret = (v > this.attValue) ? 0 : 1; } return ret; }
@Override public int branchForInstance(Instance inst) { int instAttIndex = this.attIndex < inst.classIndex() ? this.attIndex : this.attIndex + 1; if (inst.isMissing(instAttIndex)) { return -1; } double v = inst.value(instAttIndex); int ret = 0; switch (this.operator) { case 0: ret = (v == this.attValue) ? 0 : 1; break; case 1: ret = (v <= this.attValue) ? 0 : 1; break; case 2: ret = (v > this.attValue) ? 0 : 1; } return ret; }
/** * Checks if there is any missing value in the given * instance. * @param ins The instance to check missing values in. * @throws Exception If there is a missing value in the * instance. */ protected void checkMissing(Instance ins) throws Exception { for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } }
@Override public Node learnFromInstance(Instance instance) { this.numericAttClassObserver.addValue(instance.value(this.attIndex), (int) instance.value(instance.classIndex()), instance.weight()); this.classValueDist.addToValue((int) instance.value(instance.classIndex()), instance.weight()); this.heuristicMeasureUpdated = false; return this; }
/** * Checks if there is any instance with missing values. Throws an exception if * there is, as KDTree does not handle missing values. * * @param instances the instances to check * @throws Exception if missing values are encountered */ protected void checkMissing(Instances instances) throws Exception { for (int i = 0; i < instances.numInstances(); i++) { Instance ins = instances.instance(i); for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } } }
public double totalSize(Instance instance) { int classIndex = instance.classIndex(); double total = 0.0; for (int i = 0; i < instance.numValues(); i++) { int index = instance.index(i); if (index == classIndex || instance.isMissing(i)) { continue; } double count = instance.valueSparse(i); if (count >= 0) { total += count; } else { //throw new Exception("Numeric attribute value is not >= 0. " + i + " " + index + " " + // instance.valueSparse(i) + " " + " " + instance); } } return total; }
@Override public Node learnFromInstance(Instance inst) { this.instNodeCountSinceVirtual += inst.weight(); this.classValueDist.addToValue((int) inst.value(inst.classIndex()), inst.weight()); this.instNodeCountSinceReal += inst.weight(); this.instSeenSinceLastSplitAttempt += inst.weight(); for (int i = 0; i < inst.numAttributes() - 1; i++) { VirtualNode virtual = this.virtualChildren.get(i); if (virtual != null) { virtual.learnFromInstance(inst); } } if (this.split) { attemptToSplit(inst); } return this; }
@Override public Node learnFromInstance(Instance inst) { double attValue = inst.value(this.attIndex); if (Utils.isMissingValue(attValue)) { } else { int intAttValue = (int) attValue; this.attValueDist.addToValue(intAttValue, inst.weight()); this.classValueDist.addToValue((int) inst.value(inst.classIndex()), inst.weight()); DoubleVector valDist = this.nominalAttClassObserver.get(intAttValue); if (valDist == null) { valDist = new DoubleVector(); this.nominalAttClassObserver.set(intAttValue, valDist); } int classValue = (int) inst.classValue(); valDist.addToValue(classValue, inst.weight()); this.heuristicMeasureUpdated = false; } return this; }