⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 batchedvalidationchain.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  YALE - Yet Another Learning Environment *  Copyright (C) 2002, 2003 *      Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,  *          Katharina Morik, Oliver Ritthoff *      Artificial Intelligence Unit *      Computer Science Department *      University of Dortmund *      44221 Dortmund,  Germany *  email: yale@ls8.cs.uni-dortmund.de *  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;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.BatchedExampleSet;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.operator.performance.*;import edu.udo.cs.yale.tools.*;import java.util.List;/** This operator chain takes two {@link ExampleSet}s as input the first of which is considered *  to be a training set and the latter of which is considered to be a test set. Both  *  example sets must have equal attributes and must have a special &quot;batch&quot; attribute. *  Then, for each batch, the inner learner and evaluation chain are applied, similar to *  the {@link XValidation}. * * *  @yale.xmlclass BatchValidation *  @version $Id: BatchedValidationChain.java,v 2.5 2003/08/14 10:24:57 fischer Exp $ */public class BatchedValidationChain extends ValidationChain {        private int firstBatch, lastBatch, currentBatch;    private static final Class[] INPUT_CLASSES =  { ExampleSet.class, ExampleSet.class };        public BatchedValidationChain() {	addValue(new Value("batch", "The number of the current batch.") {		public double getValue() {		    return currentBatch;		}	    });    }    public Class[] getInputClasses() { return INPUT_CLASSES; }    public int getNumberOfValidationSteps() {	return lastBatch - firstBatch + 1;    }    public IOObject[] apply() throws OperatorException {	ExampleSet testSet     = (ExampleSet)getInput(ExampleSet.class);	ExampleSet trainingSet = (ExampleSet)getInput(ExampleSet.class);	Attribute trainingBatchAttribute = trainingSet.getSpecialAttribute("batch");	Attribute testBatchAttribute     = testSet.getSpecialAttribute("batch");	if (trainingBatchAttribute == null) { throw new UserError(this, 113, "batch"); }	if (testBatchAttribute == null) { throw new UserError(this, 113, "batch"); }	firstBatch = getParameterAsInt("first_batch");	lastBatch = getParameterAsInt("last_batch");	LogService.logMessage(getName() + ": Starting batch-validation for batches "+firstBatch+" through "+lastBatch+".", 			      LogService.TASK);	PerformanceVector performanceVector = null;	for (currentBatch = firstBatch; currentBatch <= lastBatch; currentBatch++) {	    learn(new BatchedExampleSet(trainingSet, trainingBatchAttribute, currentBatch));	    IOContainer evalOutput = evaluate(new BatchedExampleSet(testSet, testBatchAttribute, currentBatch));	    PerformanceVector iterationPerformance = (PerformanceVector)evalOutput.getInput(PerformanceVector.class);  	    if (performanceVector == null) {		performanceVector = iterationPerformance;	    } else {		for (int i = 0; i  < performanceVector.size(); i++) {		    performanceVector.get(i).buildAverage(iterationPerformance.get(i));		}		     	    }	    setLastPerformance(iterationPerformance.getMainCriterion());	    inApplyLoop();	}	setResult(performanceVector.getMainCriterion());	return new IOObject[] { performanceVector };    }    public List getParameterTypes() {	List types = super.getParameterTypes();	//types.add(new ParameterTypeString("batch_attribute", "Name of the batch attribute.", false));	types.add(new ParameterTypeInt("first_batch", "Number of the first batch (inclusive).", Integer.MIN_VALUE, Integer.MAX_VALUE));	types.add(new ParameterTypeInt("last_batch", "Number of the last batch (inclusive).", Integer.MIN_VALUE, Integer.MAX_VALUE));	return types;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -