📄 methodvalidationchain.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* web: http://yale.cs.uni-dortmund.de/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package edu.udo.cs.yale.operator.validation;
import edu.udo.cs.yale.operator.Operator;
import edu.udo.cs.yale.operator.OperatorChain;
import edu.udo.cs.yale.operator.IOContainer;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.IllegalInputException;
import edu.udo.cs.yale.operator.IODescription;
import edu.udo.cs.yale.operator.IOObject;
import edu.udo.cs.yale.operator.MissingIOObjectException;
import edu.udo.cs.yale.operator.Value;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.example.ExampleSet;
import edu.udo.cs.yale.example.AttributeVector;
import edu.udo.cs.yale.operator.learner.Model;
import edu.udo.cs.yale.operator.performance.*;
import edu.udo.cs.yale.tools.ParameterService;
/** This operator evaluates the performance of algorithms, e.g. feature selection algorithms. The first
* inner operator is the algorithm to be evaluated itself. It must return an example set which is in turn
* used to create a new model using the second inner operator and retrieve a performance vector using
* the third inner operator. This performance vector serves as a performance indicator for the actual algorithm.
*
* @author ingo
* @version $Id: MethodValidationChain.java,v 1.3 2004/09/12 11:09:52 ingomierswa Exp $
*/
public abstract class MethodValidationChain extends OperatorChain {
private static final Class[] OUTPUT_CLASSES = { PerformanceVector.class, AttributeVector.class };
private static final Class[] INPUT_CLASSES = { ExampleSet.class };
private PerformanceCriterion lastPerformance;
private IOContainer learnResult;
private IOContainer methodResult;
public MethodValidationChain() {
addValue(new Value("performance", "The last performance (main criterion).") {
public double getValue() {
if (lastPerformance != null)
return lastPerformance.getValue();
else
return Double.NaN;
}
});
addValue(new Value("variance", "The variance of the last performance (main criterion).") {
public double getValue() {
if (lastPerformance != null)
return lastPerformance.getVariance();
else
return Double.NaN;
}
});
}
/** Returns the maximum number of innner operators. */
public int getMaxNumberOfInnerOperators() { return 3; }
/** Returns the minimum number of innner operators. */
public int getMinNumberOfInnerOperators() { return 3; }
public Class[] getOutputClasses() { return OUTPUT_CLASSES; }
public Class[] getInputClasses() { return INPUT_CLASSES; }
/** Ok if the first inner operator returns a example set, the second returns model and the third a performance vector.
*/
public Class[] checkIO(Class[] input) throws IllegalInputException {
Operator method = getMethod();
Operator learner = getLearner();
Operator evaluator = getEvaluator();
//input = method.getIODescription().getOutputClasses(input);
input = method.checkIO(input);
if (!IODescription.containsClass(ExampleSet.class, input))
throw new IllegalInputException(this, learner, ExampleSet.class);
//input = learner.getIODescription().getOutputClasses(input);
input = learner.checkIO(input);
if (!IODescription.containsClass(Model.class, input))
throw new IllegalInputException(this, learner, Model.class);
// GUT?
Class[] newInput = new Class[input.length+1];
for (int i = 0; i < input.length; i++) {
newInput[i] = input[i];
}
newInput[newInput.length-1] = ExampleSet.class;
input = evaluator.checkIO(newInput);
// ???
//input = evaluator.getIODescription().getOutputClasses(input);
if (!IODescription.containsClass(PerformanceVector.class, input))
throw new IllegalInputException(this, evaluator, PerformanceVector.class);
return new Class[] { PerformanceVector.class, AttributeVector.class };
}
private Operator getMethod() { return getOperator(0); }
private Operator getLearner() { return getOperator(1); }
private Operator getEvaluator() { return getOperator(2); }
/** Can be used by subclasses to set the performance of the example set. */
void setResult(PerformanceCriterion pc) { lastPerformance = pc; }
/** Applies the method.
*/
IOContainer useMethod(ExampleSet methodTrainingSet) throws OperatorException {
methodTrainingSet.recalculateAllAttributeStatistics();
return methodResult = getMethod().apply(getInput().append(new IOObject[] { methodTrainingSet }));
}
/** Applies the learner.
*/
IOContainer learn(ExampleSet trainingSet) throws OperatorException {
if (methodResult == null) {
throw new RuntimeException("Wrong use of MethodEvaluator.evaluate(ExampleSet): No preceding invocation of useMethod(ExampleSet)!");
}
trainingSet.recalculateAllAttributeStatistics();
learnResult = getLearner().apply(getInput().append(new IOObject[] { trainingSet }));
methodResult = null;
return learnResult;
}
/** Applies the applier and evaluator.
*/
IOContainer evaluate(ExampleSet testSet) throws OperatorException {
if (learnResult == null) {
throw new RuntimeException("Wrong use of ValidationChain.evaluate(ExampleSet): No preceding invocation of learn(ExampleSet)!");
}
testSet.recalculateAllAttributeStatistics();
IOContainer result = getEvaluator().apply(learnResult.append(new IOObject[] { testSet }));
learnResult = null;
return result;
}
void setLastPerformance(PerformanceCriterion pc) {
lastPerformance = pc;
}
public abstract int getNumberOfValidationSteps();
public int getNumberOfSteps() {
return getNumberOfValidationSteps() * super.getNumberOfChildrensSteps();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -