/** * Sets the current instance to be the supplied instance * * @param instance instance to be set as the current instance */ public void setInstance(Instance instance) { assert dataset.equalHeaders(instance.dataset()); this.instance = instance; missingAccessed = false; }
/** * Sets the current instance to be the supplied instance * * @param instance instance to be set as the current instance */ public void setInstance(Instance instance) { assert dataset.equalHeaders(instance.dataset()); this.instance = instance; missingAccessed = false; }
@Override public Table getTable() { return new WekaObviousTable(instance.dataset()); }
@SuppressWarnings("unchecked") @Override public int getRow() { Instances instances = instance.dataset(); Enumeration instEnum = instances.enumerateInstances(); int count = -1; while (instEnum.hasMoreElements()) { count++; if (instance.equals(instEnum.nextElement())) { return count; } } return -1; }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
private void copyStringAttVals(InstanceHolder holder) { for (String attName : m_stringAttIndexes.keySet()) { Attribute att = holder.m_instance.dataset().attribute(attName); String val = holder.m_instance.stringValue(att); if (holder.m_stringVals == null) { holder.m_stringVals = new HashMap<String, String>(); } holder.m_stringVals.put(attName, val); } }
/** * Updates the classifier using the given instance. * * @param instance the instance to include * @throws Exception if instance could not be incorporated * successfully */ public void updateClassifier(Instance instance) throws Exception { if (m_Train.equalHeaders(instance.dataset()) == false) { throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset())); } update(instance); }
@Override public boolean equalHeaders(Instance inst) { return dataset().equalHeaders(inst.dataset()); }
@Override public String branchForInstance(Instance inst) { Attribute att = inst.dataset().attribute(m_splitAttNames.get(0)); if (att == null || inst.isMissing(att)) { // TODO ------------- return null; } if (inst.value(att) <= m_splitPoint) { return "left"; } return "right"; }
private int countTrueLabels(Instance instance) { int numTrueLabels = 0; for (int i = 0; i < numLabels; i++) { int labelIndice = labelIndices[i]; if (instance.dataset().attribute(labelIndice).value((int) instance.value(labelIndice)).equals("1")) { numTrueLabels++; } } return numTrueLabels; }
@Override public String branchForInstance(Instance inst) { Attribute att = inst.dataset().attribute(m_splitAttNames.get(0)); if (att == null || inst.isMissing(att)) { // TODO ------------- return null; } if (inst.value(att) <= m_splitPoint) { return "left"; } return "right"; }
/** * Adds the supplied instance to the training set * * @param instance the instance to add * @throws Exception if instance could not be incorporated successfully */ public void updateClassifier(Instance instance) throws Exception { if (m_Train.equalHeaders(instance.dataset()) == false) throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset())); if ( instance.classIsMissing() ) return; m_Train.add(instance); // update relevant attributes ... update_m_Attributes(); }
@Override public String branchForInstance(Instance inst) { Attribute att = inst.dataset().attribute(m_splitAttNames.get(0)); if (att == null || inst.isMissing(att)) { return null; } return att.value((int) inst.value(att)); }
@Override public double[] distributionForInstance(Instance instance) throws Exception { Instances data = new Instances(instance.dataset()); data.add(instance); return distributionsForInstances(data)[0]; }
@Override public String branchForInstance(Instance inst) { Attribute att = inst.dataset().attribute(m_splitAttNames.get(0)); if (att == null || inst.isMissing(att)) { return null; } return att.value((int) inst.value(att)); }
/** * Creates a new leaf <code>CNode</code> instance. * * @param numAttributes the number of attributes in the data * @param leafInstance the instance to store at this leaf */ public CNode(int numAttributes, Instance leafInstance) { this(numAttributes); if (m_clusterInstances == null) { m_clusterInstances = new Instances(leafInstance.dataset(), 1); } m_clusterInstances.add(leafInstance); updateStats(leafInstance, false); }
/** * Creates a new leaf <code>CNode</code> instance. * * @param numAttributes the number of attributes in the data * @param leafInstance the instance to store at this leaf */ public CNode(int numAttributes, Instance leafInstance) { this(numAttributes); if (m_clusterInstances == null) { m_clusterInstances = new Instances(leafInstance.dataset(), 1); } m_clusterInstances.add(leafInstance); updateStats(leafInstance, false); }
@Override public Instance output() { Instance outInst = m_delegate.output(); if (m_hasStringAtts && outInst != null) { for (int i = 0; i < outInst.dataset().numAttributes(); i++) { if (outInst.dataset().attribute(i).isString() && !outInst.isMissing(i)) { String val = outInst.stringValue(i); outInst.attribute(i).setStringValue(val); outInst.setValue(i, 0); } } } return outInst; }