本文整理了Java中weka.filters.Filter.output()
方法的一些代码示例,展示了Filter.output()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Filter.output()
方法的具体详情如下:
包路径:weka.filters.Filter
类名称:Filter
方法名:output
[英]Output an instance after filtering and remove from the output queue.
[中]过滤后输出实例并从输出队列中删除。
代码示例来源: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
/**
* 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: 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: 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);
}
代码示例来源: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: nz.ac.waikato.cms.weka/distributedWekaBase
@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;
}
内容来源于网络,如有侵权,请联系作者删除!