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

📄 performanceevaluator.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 *  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.performance;

import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.operator.OperatorException;
import edu.udo.cs.yale.operator.*;
import edu.udo.cs.yale.example.*;
import java.io.FileNotFoundException;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.tools.ParameterService;

import java.util.*;

/** A performance evaluator is an operator that expects a test {@link ExampleSet} as
 *  input, whose elements have both true and predicted labels, and delivers as output a
 *  list of performance values according to a list of performance criteria that
 *  it calculates.
 *  <br/>
 *  All of the performance criteria can be switched on using boolean parameters. Their 
 *  values can be queried by a {@link edu.udo.cs.yale.operator.ExperimentLogOperator} using
 *  the same names. The main criterion is used for comparisons
 *  and need to be specified only for experiments where performance vectors are compared, 
 *  e.g. feature selection experiments.
 *  <br/>
 *  Additional user-defined implementations of {@link PerformanceCriterion} can be specified
 *  by using the parameter list <var>additional_performance_criteria</var>. Each key/value pair 
 *  in this list must specify a fully qualified classname (as the key), and the a string parameter 
 *  (as the value) that is passed to the constructor. Please make sure that the class files are in
 *  the classpath (this is the case if the implementations are supplied by a plugin) and that they 
 *  implement a one-argument constructor taking a string parameter.
 *  <br/>
 *  Other implementations than the simple comparator, that only compares the main criterion,
 *  can be specified using the parameter <var>comparator_class</var>. This may for instance
 *  be useful if you want to compare performance vectors according to the weighted sum of the 
 *  individual criteria. In order to implement your own comparator, simply subclass
 *  {@link PerformanceComparator}.
 *
 *  @yale.xmlclass PerformanceEvaluator
 *  @author Simon
 *  @version $Id: PerformanceEvaluator.java,v 2.30 2004/09/14 08:39:06 ingomierswa Exp $
 */
public class PerformanceEvaluator extends Operator {

    /** Names of the performance criteria which can be used in experiment configuration files. */
    private static final String[] CRITERIA_NAMES = {
	"absolute",
	"scaled",
	"squared",
        "relative",
	"prediction_average",
	"mdl"
    };

    /** The proper criteria to the names. */
    private static final Class[] CRITERIA_CLASSES = {
	edu.udo.cs.yale.operator.performance.AbsoluteError.class,
	edu.udo.cs.yale.operator.performance.ScaledError.class,
	edu.udo.cs.yale.operator.performance.SquaredError.class,
        edu.udo.cs.yale.operator.performance.RelativeError.class,
        edu.udo.cs.yale.operator.performance.PredictionAverage.class,
        edu.udo.cs.yale.operator.performance.MDLCriterion.class
    };

    private static String[] allCriteriaNames;
    private static String[] allCriteriaDescriptions;


    /** Perform this initialization when the class is loaded. */
    static {
	int numberOfCriteria    = CRITERIA_NAMES.length + MultiClassificationPerformance.NAME.length + BinaryClassificationPerformance.NAME.length;
	allCriteriaNames        = new String[numberOfCriteria];
	allCriteriaDescriptions = new String[numberOfCriteria];

	System.arraycopy(CRITERIA_NAMES, 0, 
			 allCriteriaNames, 0, 
			 CRITERIA_NAMES.length);
	
	for (int i = 0; i < CRITERIA_CLASSES.length; i++) {
	    allCriteriaDescriptions[i] = "The performance criterion "+CRITERIA_NAMES[i]+" error.";
	    try {
		allCriteriaDescriptions[i] = ((MeasuredPerformance)CRITERIA_CLASSES[i].newInstance()).getDescription();
	    } catch (Throwable t) {
		LogService.logException("Cannot instantiate '"+CRITERIA_CLASSES[i]+"'!", t);
	    }
	}

	System.arraycopy(MultiClassificationPerformance.NAME,
			 0,
			 allCriteriaNames,
			 CRITERIA_NAMES.length,
			 MultiClassificationPerformance.NAME.length);

	System.arraycopy(MultiClassificationPerformance.DESCRIPTION,
			 0,
			 allCriteriaDescriptions,
			 CRITERIA_NAMES.length,
			 MultiClassificationPerformance.DESCRIPTION.length);

	System.arraycopy(BinaryClassificationPerformance.NAME, 
			 0,
			 allCriteriaNames,
			 CRITERIA_NAMES.length + MultiClassificationPerformance.NAME.length,
			 BinaryClassificationPerformance.NAME.length);


	System.arraycopy(BinaryClassificationPerformance.DESCRIPTION, 
			 0,
			 allCriteriaDescriptions,
			 CRITERIA_NAMES.length + MultiClassificationPerformance.NAME.length,
			 BinaryClassificationPerformance.DESCRIPTION.length);
    }


    private static final Class[] INPUT_CLASSES = { ExampleSet.class };
    private static final Class[] OUTPUT_CLASSES = { PerformanceVector.class };

    /** Maps criteria names to classes. */
    private static Map classnameMap;

    public PerformanceEvaluator() {
	for (int i = 0;i < CRITERIA_NAMES.length; i++) {
	    addPerformanceValue(CRITERIA_NAMES[i],
				allCriteriaDescriptions[i]);
	}
	for (int i = 0;i < MultiClassificationPerformance.NAME.length; i++) {
	    addPerformanceValue(MultiClassificationPerformance.NAME[i],
				MultiClassificationPerformance.DESCRIPTION[i]);
	}
	for (int i = 0;i < BinaryClassificationPerformance.NAME.length; i++) {
	    addPerformanceValue(BinaryClassificationPerformance.NAME[i],
				BinaryClassificationPerformance.DESCRIPTION[i]);
	}
    }

    private void addPerformanceValue(final String name, String description) {
	addValue(new Value(name, description) {
		public double getValue() {
		    if (performanceCriteria == null) return Double.NaN;
		    PerformanceCriterion c = (PerformanceCriterion)performanceCriteria.getCriterion(name);
		    if (c != null) {
			return c.getValue();
		    } else {
			return Double.NaN;
		    }
		}
	    });
    }

    static {
	classnameMap = new HashMap();
	for (int i = 0; i < CRITERIA_NAMES.length; i++)
	    classnameMap.put(CRITERIA_NAMES[i], CRITERIA_CLASSES[i]);
    }

    private PerformanceVector performanceCriteria;

    private void initialisePerformanceVector() throws OperatorException {
	//int mainCriterionIndex = getParameterAsInt("main_criterion");

⌨️ 快捷键说明

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