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

📄 defaultlearner.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.learner;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.BatchedExampleSet;import edu.udo.cs.yale.example.ExampleReader;import edu.udo.cs.yale.example.SkipNANExampleReader;import edu.udo.cs.yale.operator.Operator;import edu.udo.cs.yale.operator.UserError;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.operator.FatalException;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.operator.learner.Learner;import edu.udo.cs.yale.operator.learner.Model;import edu.udo.cs.yale.operator.performance.PerformanceVector;import edu.udo.cs.yale.operator.performance.EstimatedPerformance;import edu.udo.cs.yale.tools.ParameterService;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.TempFileService;import edu.udo.cs.yale.tools.Tools;import edu.udo.cs.yale.tools.OutputStreamMultiplier;import edu.udo.cs.yale.tools.Ontology;import java.util.List;import java.util.LinkedList;import java.util.StringTokenizer;import java.util.ArrayList;import java.util.Arrays;import java.io.*;/** This learner creates a model, that will simply predict a default value for all examples, *  i.e. the average or median of the true labels or a fixed specified value. *  This learner can be used to compare the results of &quot;real&quot; learning schemes with *  guessing. * *  @yale.xmlclass DefaultLearner *  @yale.index DefaultLearner *  @author  Stefan R黳ing *  @version $Id: DefaultLearner.java,v 2.4 2003/08/14 10:24:57 fischer Exp $ *  @see     edu.udo.cs.yale.operator.learner.DefaultModel *  @see     edu.udo.cs.yale.example.ExampleSet *  @yale.todo H鋟figste Klasse f黵 Klassifikation zuf黦en, in Datei speichern, imports aufr鋟men (kopiert von MySVMLearner */public class  DefaultLearner  extends Learner {    /** Kernel parameters of the mySVM. */    private static final String[]  METHODS = { "median","average","constant" };    public Model  learn(ExampleSet exampleSet)  throws OperatorException {	double value = 0.0;	String param = getParameterAsString("method");	int labelIndex = exampleSet.getLabel().getIndex();	if(param.equals("median")){	    double[] labels = new double[exampleSet.getSize()];	    ExampleReader  r = new SkipNANExampleReader(exampleSet.getExampleReader());	    int  numberOfExamples = 0;	    while (r.hasNext()) {		// ---- read next example ----		Example  example = (Example)r.next();		labels[numberOfExamples] = example.getLabel();		numberOfExamples++;	    };	    java.util.Arrays.sort(labels,0,numberOfExamples-1);	    value = labels[numberOfExamples/2];	}	else if(param.equals("average")){	    ExampleReader  r = new SkipNANExampleReader(exampleSet.getExampleReader());	    int  numberOfExamples = 0;	    while (r.hasNext()) {		// ---- read next example ----		Example  example = (Example)r.next();		numberOfExamples++;		value += example.getLabel();	    };	    value /= (double)numberOfExamples;	}	else if(param.equals("constant")){	    try{		value = getParameterAsDouble("value");	    }	    catch(Exception e){		LogService.logMessage("No constant set.",LogService.ERROR);	    };	}	else{	    LogService.logMessage("No method set.",LogService.ERROR);	};	LogService.logMessage("Default value is "+value,LogService.TASK);	return new DefaultModel(value);    }    /** sepcifies the parameters of the <tt>MySVMLearner</tt>, their types,      *  their default values, and descriptions of them.     */    public List getParameterTypes() {	List types = super.getParameterTypes();	types.add(new ParameterTypeStringCategory("method", "The method to compute the default.",						  METHODS));	types.add(new ParameterTypeDouble("constant", "Value returned when method = \"constant\".", Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY,0.0));	return types;    }}

⌨️ 快捷键说明

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