weka.filters.Filter.input()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(125)

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

Filter.input介绍

[英]Input an instance for filtering. Ordinarily the instance is processed and made available for output immediately. Some filters require all instances be read before producing output, in which case output instances should be collected after calling batchFinished(). If the input marks the start of a new batch, the output queue is cleared. This default implementation assumes all instance conversion will occur when batchFinished() is called.
[中]输入一个实例进行筛选。通常情况下,会立即处理实例并使其可用于输出。某些筛选器要求在生成输出之前读取所有实例,在这种情况下,应在调用batchFinished()后收集输出实例。如果输入标志着新批处理的开始,则输出队列将被清除。此默认实现假定调用batchFinished()时将发生所有实例转换。

代码示例

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

@Override
public boolean input(Instance inst) throws Exception {
 return m_delegate.input(inst);
}

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

/**
 * Apply the filters (if any) for this map task to the supplied instance
 *
 * @param original the instance in the original space
 * @return a filtered instance
 * @throws Exception if a problem occurs
 */
public Instance applyFilters(Instance original) throws Exception {
 Instance result = original;
 if (m_finalFullPreprocess != null) {
  ((Filter) m_finalFullPreprocess).input(result);
  result = ((Filter) m_finalFullPreprocess).output();
 }
 return result;
}

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

/**
 * Update the distance function (if necessary) for the newly added instance.
 * 
 * @param ins the instance to add
 */
public void update(Instance ins) {
 try {
  m_Remove.input(ins);
  m_Filter.input(m_Remove.output());
  m_Distance.update(m_Filter.output());
 } catch (Exception e) {
  e.printStackTrace();
 }
}

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

/**
 * Classifies a given instance after filtering.
 * 
 * @param instance the instance to be classified
 * @return the class distribution for the given instance
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_Filter.numPendingOutput() > 0) {
  throw new Exception("Filter output queue not empty!");
 }
 if (!m_Filter.input(instance)) {
  throw new Exception(
   "Filter didn't make the test instance immediately available!");
 }
 m_Filter.batchFinished();
 Instance newInstance = m_Filter.output();
 return m_Clusterer.distributionForInstance(newInstance);
}

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

/**
 * Update the distance function (if necessary) for the newly added instance.
 * 
 * @param ins the instance to add
 */
public void update(Instance ins) {
 try {
  m_Remove.input(ins);
  m_Filter.input(m_Remove.output());
  m_Distance.update(m_Filter.output());
 } catch (Exception e) {
  e.printStackTrace();
 }
}

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

/**
 * Classifies a given instance after filtering.
 * 
 * @param instance the instance to be classified
 * @return the class distribution for the given instance
 * @throws Exception if instance could not be classified successfully
 */
@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_Filter.numPendingOutput() > 0) {
  throw new Exception("Filter output queue not empty!");
 }
 if (!m_Filter.input(instance)) {
  throw new Exception(
   "Filter didn't make the test instance immediately available!");
 }
 m_Filter.batchFinished();
 Instance newInstance = m_Filter.output();
 return m_Clusterer.distributionForInstance(newInstance);
}

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

@Override
public double[] distributionForInstance(Instance inst) throws Exception {
 if (!getPreConstructedFilter().input(inst)) {
  throw new Exception("Filter did not make instance available immediately!");
 }
 getPreConstructedFilter().batchFinished();
 Instance testI = getPreConstructedFilter().output();
 return getClassifier().distributionForInstance(testI);
}

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

/**
  * Updates the instance info in the underlying search method, once the
  * instance has been filtered.
  * 
  * @param ins The instance to add the information of.
  */
 @Override
 public void addInstanceInfo(Instance ins) {
  if (m_Instances != null)
   try {
    getFilter().input(ins);
    m_AddID.input(getFilter().output());
    m_ModifiedSearchMethod.addInstanceInfo(m_AddID.output());
   } catch (Exception ex) {
    ex.printStackTrace();
   }
 }
}

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

/**
  * Updates the instance info in the underlying search method, once the
  * instance has been filtered.
  * 
  * @param ins The instance to add the information of.
  */
 @Override
 public void addInstanceInfo(Instance ins) {
  if (m_Instances != null)
   try {
    getFilter().input(ins);
    m_AddID.input(getFilter().output());
    m_ModifiedSearchMethod.addInstanceInfo(m_AddID.output());
   } catch (Exception ex) {
    ex.printStackTrace();
   }
 }
}

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

/**
 * Updates ranges based on the given instance, once it has been filtered.
 * 
 * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance)
 */
@Override
public void update(Instance ins) throws Exception {
 getFilter().input(ins);
 m_AddID.input(getFilter().output());
 m_ModifiedSearchMethod.update(m_AddID.output());
}

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

/**
 * Updates ranges based on the given instance, once it has been filtered.
 * 
 * @see weka.core.neighboursearch.NearestNeighbourSearch#update(weka.core.Instance)
 */
@Override
public void update(Instance ins) throws Exception {
 getFilter().input(ins);
 m_AddID.input(getFilter().output());
 m_ModifiedSearchMethod.update(m_AddID.output());
}

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

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_canopies == null || m_canopies.size() == 0) {
  throw new Exception("No canopies available to cluster with!");
 }
 double[] d = new double[numberOfClusters()];
 if (m_missingValuesReplacer != null) {
  m_missingValuesReplacer.input(instance);
  instance = m_missingValuesReplacer.output();
 }
 for (int i = 0; i < m_canopies.numInstances(); i++) {
  double distance = m_distanceFunction.distance(instance,
   m_canopies.instance(i));
  d[i] = 1.0 / (1.0 + distance);
 }
 Utils.normalize(d);
 return d;
}

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

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
 if (m_canopies == null || m_canopies.size() == 0) {
  throw new Exception("No canopies available to cluster with!");
 }
 double[] d = new double[numberOfClusters()];
 if (m_missingValuesReplacer != null) {
  m_missingValuesReplacer.input(instance);
  instance = m_missingValuesReplacer.output();
 }
 for (int i = 0; i < m_canopies.numInstances(); i++) {
  double distance = m_distanceFunction.distance(instance,
   m_canopies.instance(i));
  d[i] = 1.0 / (1.0 + distance);
 }
 Utils.normalize(d);
 return d;
}

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

/**
 * processes the given instance (may change the provided instance) and returns
 * the modified version.
 * 
 * @param instance the instance to process
 * @return the modified data
 * @throws Exception in case the processing goes wrong
 */
@Override
protected Instance process(Instance instance) throws Exception {
 Instance result;
 int i;
 result = (Instance) instance.copy();
 for (i = 0; i < getFilters().length; i++) {
  if (getFilter(i).input(result)) {
   result = getFilter(i).output();
  } else {
   // if a filter says nothing to collect then terminate
   result = null;
   break;
  }
 }
 return result;
}

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

@Override
public void updateClassifier(Instance instance) throws Exception {
 if (getPreConstructedFilter().numPendingOutput() > 0) {
  throw new Exception("Filter output queue not empty!");
 }
 if (!getPreConstructedFilter().input(instance)) {
  // throw new Exception(
  // "Can only use PreconstructedFilters that will produce an output "
  // + "Instance immediately when given an input Instance.");
  // only allow a filter to consume an instance and not buffer anything
  if (getPreConstructedFilter().numPendingOutput() > 0) {
   throw new Exception("Filter output queue not empty!");
  }
  // nothing to train on if filter does not make instance available
  return;
 }
 getPreConstructedFilter().batchFinished();
 Instance filtered = getPreConstructedFilter().output();
 ((UpdateableClassifier) getClassifier()).updateClassifier(filtered);
}

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

/**
 * Apply the filters (if any) setup for this map task to the supplied
 * instances
 *
 * @param toApplyTo the instances to filer
 * @return a filtered set of instances
 * @throws Exception if a problem occurs
 */
public Instances applyFilters(Instances toApplyTo) throws Exception {
 Instances result = toApplyTo;
 if (m_finalFullPreprocess != null) {
  result =
   new Instances(((Filter) m_finalFullPreprocess).getOutputFormat(), 0);
  for (int i = 0; i < toApplyTo.numInstances(); i++) {
   ((Filter) m_finalFullPreprocess).input(toApplyTo.instance(i));
   Instance processed = ((Filter) m_finalFullPreprocess).output();
   result.add(processed);
  }
 }
 return result;
}

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

/**
 * Filters an instance.
 */
protected Instance filterInstance(Instance inst) throws Exception {
 if (!m_checksTurnedOff) {
  m_Missing.input(inst);
  m_Missing.batchFinished();
  inst = m_Missing.output();
 }
 if (m_NominalToBinary != null) {
  m_NominalToBinary.input(inst);
  m_NominalToBinary.batchFinished();
  inst = m_NominalToBinary.output();
 }
 if (m_Filter != null) {
  m_Filter.input(inst);
  m_Filter.batchFinished();
  inst = m_Filter.output();
 }
 return inst;
}

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

/**
 * Returns the nearest neighbour for the given instance based on distance
 * measured in the filtered space.
 * 
 * @param target the instance for which to find the nearest neighbour
 * @return the nearest neighbour
 * 
 * @see weka.core.neighboursearch.NearestNeighbourSearch#nearestNeighbour(weka.core.Instance)
 */
@Override
public Instance nearestNeighbour(Instance target) throws Exception {
 getFilter().input(target);
 m_AddID.input(getFilter().output());
 return getInstances().instance(
  (int) m_ModifiedSearchMethod.nearestNeighbour(m_AddID.output()).value(
   m_IndexOfID) - 1);
}

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

/**
 * Filters an instance.
 */
protected Instance filterInstance(Instance inst) throws Exception {
 if (!m_checksTurnedOff) {
  m_Missing.input(inst);
  m_Missing.batchFinished();
  inst = m_Missing.output();
 }
 if (m_NominalToBinary != null) {
  m_NominalToBinary.input(inst);
  m_NominalToBinary.batchFinished();
  inst = m_NominalToBinary.output();
 }
 if (m_Filter != null) {
  m_Filter.input(inst);
  m_Filter.batchFinished();
  inst = m_Filter.output();
 }
 return inst;
}

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

/**
 * Returns the nearest neighbour for the given instance based on distance
 * measured in the filtered space.
 * 
 * @param target the instance for which to find the nearest neighbour
 * @return the nearest neighbour
 * 
 * @see weka.core.neighboursearch.NearestNeighbourSearch#nearestNeighbour(weka.core.Instance)
 */
@Override
public Instance nearestNeighbour(Instance target) throws Exception {
 getFilter().input(target);
 m_AddID.input(getFilter().output());
 return getInstances().instance(
  (int) m_ModifiedSearchMethod.nearestNeighbour(m_AddID.output()).value(
   m_IndexOfID) - 1);
}

相关文章