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

📄 batchedvalidationchain.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 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.IOObject;
import edu.udo.cs.yale.operator.UserError;
import edu.udo.cs.yale.operator.Value;
import edu.udo.cs.yale.operator.IOContainer;
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 "batch" 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 1.4 2004/10/07 20:30:59 ingomierswa 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.getAttribute(ExampleSet.BATCH_NAME);
	Attribute testBatchAttribute     = testSet.getAttribute(ExampleSet.BATCH_NAME);
	if (trainingBatchAttribute == null) { throw new UserError(this, 113, ExampleSet.BATCH_NAME); }
	if (testBatchAttribute == null) { throw new UserError(this, 113, ExampleSet.BATCH_NAME); }

	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.getCriterion(i).buildAverage(iterationPerformance.getCriterion(i));
		}		     
	    }

	    inApplyLoop();
	}
	setResult(performanceVector.getMainCriterion());
	return new IOObject[] { performanceVector };
    }


    public List getParameterTypes() {
	List types = super.getParameterTypes();
	ParameterType type = new ParameterTypeInt("first_batch", "Number of the first batch (inclusive).", Integer.MIN_VALUE, Integer.MAX_VALUE);
	type.setExpert(false);
	types.add(type);
	type = new ParameterTypeInt("last_batch", "Number of the last batch (inclusive).", Integer.MIN_VALUE, Integer.MAX_VALUE);
	type.setExpert(false);
	types.add(type);
	return types;
    }
}

⌨️ 快捷键说明

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