weka.core.Instances.add()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中weka.core.Instances.add()方法的一些代码示例,展示了Instances.add()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.add()方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:add

Instances.add介绍

[英]Adds one instance at the given position in the list. Shallow copies instance before it is added. Increases the size of the dataset if it is not large enough. Does not check if the instance is compatible with the dataset. Note: String or relational values are not transferred.
[中]在列表中的给定位置添加一个实例。在添加实例之前,浅层复制实例。如果数据集不够大,则增加其大小。不检查实例是否与数据集兼容。注意:不传输字符串或关系值。

代码示例

代码示例来源:origin: stackoverflow.com

Instances dataUnlabeled = new Instances("TestInstances", atts, 0);
dataUnlabeled.add(newInst);
dataUnlabeled.setClassIndex(dataUnlabeled.numAttributes() - 1);        
double classif = ibk.classifyInstance(dataUnlabeled.firstInstance());

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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));
 }
}

代码示例来源:origin: net.sf.meka/meka

/**
 * 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;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

/**
 * 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));
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/simpleEducationalLearningSchemes

/**
 * 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;
}

代码示例来源:origin: Waikato/wekaDeeplearning4j

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 Instances data = new Instances(instance.dataset());
 data.add(instance);
 return distributionsForInstances(data)[0];
}

代码示例来源:origin: Waikato/weka-trunk

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));
 }
}

代码示例来源:origin: Waikato/wekaDeeplearning4j

@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;
}

代码示例来源:origin: Waikato/meka

@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);
}

代码示例来源:origin: sc.fiji/Trainable_Segmentation

/**
 * 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));
}

代码示例来源:origin: Waikato/meka

/**
 * 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;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/simpleEducationalLearningSchemes

/**
 * 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;
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

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));
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * 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);
 }
}

代码示例来源:origin: stackoverflow.com

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));

代码示例来源:origin: net.sf.meka/meka

@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);
}

代码示例来源:origin: fiji/Trainable_Segmentation

/**
 * 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));
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * 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));
 }
}

相关文章

Instances类方法