Instances dataUnlabeled = new Instances("TestInstances", atts, 0); dataUnlabeled.add(newInst); dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1); double classif = ibk.classifyInstance(dataUnlabeled.firstInstance());
/** * Copies instances from one set to the end of another one. * * @param from the position of the first instance to be copied * @param dest the destination for the instances * @param num the number of instances to be copied */ // @ requires 0 <= from && from <= numInstances() - num; // @ requires 0 <= num; protected void copyInstances(int from, /* @non_null@ */Instances dest, int num) { for (int i = 0; i < num; i++) { dest.add(instance(from + i)); } }
/** * Stack two Instances together row-wise. */ public static final Instances combineInstances(Instances D1, Instances D2) { Instances D = new Instances(D1); for(int i = 0; i < D2.numInstances(); i++) { D.add(D2.instance(i)); } return D; }
/** * Add the supplied instances to the training header * * @param toAdd the instances to add */ public void addToTrainingHeader(Instances toAdd) { for (int i = 0; i < toAdd.numInstances(); i++) { m_trainingHeader.add(toAdd.instance(i)); } }
/** * Returns the set of instances that are not covered by this rule. * * @param data the instances to be checked * @return the instances not covered */ public Instances notCoveredBy(Instances data) { Instances r = new Instances(data, data.numInstances()); Enumeration enu = data.enumerateInstances(); while (enu.hasMoreElements()) { Instance i = (Instance) enu.nextElement(); if (resultRule(i) == -1) { r.add(i); } } r.compactify(); return r; }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
@Override public Instances getDataSet() throws IOException { if (m_sourceFile == null) { throw new IOException("No source has been specified"); } if (getRetrieval() == INCREMENTAL) { throw new IOException("This loader cannot load instances incrementally."); } setRetrieval(BATCH); if (m_structure == null) { getStructure(); } Instances result = new Instances(m_structure); for (String word : vec.getVocab().words()) { double[] values = new double[result.numAttributes()]; for (int i = 0; i < this.vec.getWordVector(word).length; i++) values[i] = this.vec.getWordVector(word)[i]; values[result.numAttributes() - 1] = result.attribute("word_id").addStringValue(word); Instance inst = new DenseInstance(1, values); inst.setDataset(result); result.add(inst); } return result; }
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedMatrix); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(this.size); return newDataSet.instance(0); }
/** * Merge two datasets of Weka instances in place * @param first first (and destination) dataset * @param second second dataset */ public void mergeDataInPlace(Instances first, Instances second) { for(int i=0; i<second.numInstances(); i++) first.add(second.get(i)); }
/** * Stack two Instances together row-wise. */ public static final Instances combineInstances(Instances D1, Instances D2) { Instances D = new Instances(D1); for(int i = 0; i < D2.numInstances(); i++) { D.add(D2.instance(i)); } return D; }
/** * Adds the supplied node as a child of this node. All of the child's * instances are added to this nodes instances * * @param child the child to add */ protected void addChildNode(CNode child) { for (int i = 0; i < child.m_clusterInstances.numInstances(); i++) { Instance temp = child.m_clusterInstances.instance(i); m_clusterInstances.add(temp); updateStats(temp, false); } if (m_children == null) { m_children = new ArrayList<CNode>(); } m_children.add(child); }
/** * Returns the set of instances that are covered by this rule. * * @param data the instances to be checked * @return the instances covered */ public Instances coveredBy(Instances data) { Instances r = new Instances(data, data.numInstances()); Enumeration enu = data.enumerateInstances(); while (enu.hasMoreElements()) { Instance i = (Instance) enu.nextElement(); if (resultRule(i) != -1) { r.add(i); } } r.compactify(); return r; }
/** * 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); }
public void insertInstance(int index, boolean notify) { if (!m_IgnoreChanges) { addUndoPoint(); } double[] vals = new double[m_Data.numAttributes()]; // set any string or relational attribute values to missing // in the new instance, just in case this is the very first // instance in the dataset. for (int i = 0; i < m_Data.numAttributes(); i++) { if (m_Data.attribute(i).isString() || m_Data.attribute(i).isRelationValued()) { vals[i] = Utils.missingValue(); } } Instance toAdd = new DenseInstance(1.0, vals); if (index < 0) { m_Data.add(toAdd); } else { m_Data.add(index, toAdd); } if (notify) { notifyListener(new TableModelEvent(this, m_Data.numInstances() - 1, m_Data.numInstances() - 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); } }
/** * tests the data whether the filter can actually handle it. * * @param instanceInfo the data to test * @throws Exception if the test fails */ @Override protected void testInputFormat(Instances instanceInfo) throws Exception { for (int i = 0; i < getRanges().length; i++) { Instances newi = new Instances(instanceInfo, 0); if (instanceInfo.size() > 0) { newi.add((Instance) instanceInfo.get(0).copy()); } Range range = getRanges()[i]; range.setUpper(instanceInfo.numAttributes() - 1); Instances subset = generateSubset(newi, range); getFilters()[i].setInputFormat(subset); } }
System.out.println("--------------------------"); double[] instanceValue1 = new double[dataRaw.numAttributes()]; dataRaw.add(new DenseInstance(1.0, instanceValue1)); System.out.println("--------------------------"); double[] instanceValue2 = new double[dataRaw.numAttributes()]; dataRaw.add(new DenseInstance(1.0, instanceValue2));
@Override public Instance transformInstance(Instance x) throws Exception{ Instances tmpInst = new Instances(x.dataset()); tmpInst.delete(); tmpInst.add(x); Instances features = this.extractPart(tmpInst, false); Instances pseudoLabels = new Instances(this.compressedMatrix); Instance tmpin = pseudoLabels.instance(0); pseudoLabels.delete(); pseudoLabels.add(tmpin); for ( int i = 0; i< pseudoLabels.classIndex(); i++) { pseudoLabels.instance(0).setMissing(i); } Instances newDataSet = Instances.mergeInstances(pseudoLabels, features); newDataSet.setClassIndex(this.size); return newDataSet.instance(0); }
/** * Merge two datasets of Weka instances in place * @param first first (and destination) dataset * @param second second dataset */ public void mergeDataInPlace(Instances first, Instances second) { for(int i=0; i<second.numInstances(); i++) first.add(second.get(i)); }
/** * Copies instances from one set to the end of another one. * * @param from the position of the first instance to be copied * @param dest the destination for the instances * @param num the number of instances to be copied */ // @ requires 0 <= from && from <= numInstances() - num; // @ requires 0 <= num; protected void copyInstances(int from, /* @non_null@ */Instances dest, int num) { for (int i = 0; i < num; i++) { dest.add(instance(from + i)); } }