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

📄 measuredcriteriontest.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.performance.test;

import edu.udo.cs.yale.operator.performance.*;
import edu.udo.cs.yale.example.test.*;
import edu.udo.cs.yale.example.*;
import edu.udo.cs.yale.tools.att.*;
import java.util.*;

/** Tests regression critetia.
 *
 *  @version $Id: MeasuredCriterionTest.java,v 1.9 2004/08/27 11:57:43 ingomierswa Exp $
 */
public class MeasuredCriterionTest extends CriterionTestCase {

    private ExampleSet exampleSet1, exampleSet2;

    private ExampleSet createExampleSet(double[][] labelValues, double[] predictedValues) throws Exception {
	Attribute label = ExampleTestTools.attributeReal();
	label.setIndex(0);
 	List attributeList = new LinkedList();
	attributeList.add(label);
		
	MemoryExampleTable exampleTable
	    = new MemoryExampleTable(attributeList, 
				     ExampleTestTools.createDataRowReader(labelValues));
	AttributeSet attributeSet = new AttributeSet();
	attributeSet.setSpecialAttribute("label", label);
	ExampleSet exampleSet = exampleTable.createExampleSet(attributeSet);
	ExampleTestTools.createPredictedLabel(exampleSet);
	ExampleReader r = exampleSet.getExampleReader();
	for (int i = 0; i < predictedValues.length; i++)
	    r.next().setPredictedLabel(predictedValues[i]);

	return exampleSet;
    }
    
    public void setUp() throws Exception {
	super.setUp();
	exampleSet1 = createExampleSet(new double[][] { {5.0}, {3.0}, {-1.0}, {-4.0}, {0.0}, {2.0}},
				       new double[]   {  6.0,   1.0,   0.0,    -1.0,   3.0,   -2.0} );
	exampleSet2 = createExampleSet(new double[][] { {3.0}, {6.0}, {-1.0} },
				       new double[]   {  1.0,   8.0,   -4.0} );
    }

    public void tearDown() throws Exception {
	exampleSet1 = exampleSet2 = null;
	super.tearDown();
    }

    /** Tests calculation, average, and clone. */
    private void criterionTest(PerformanceCriterion c1, 
			       PerformanceCriterion c2,
			       double expected1, 
			       double expected2, 
			       double expectedOverall) throws Exception {
	PerformanceVector pv1 = new PerformanceVector();
	pv1.addCriterion(c1);
	PerformanceEvaluator.evaluate(null, exampleSet1, pv1, false);
	assertEquals(c1.getName()+" 1",            expected1, c1.getValue(), 0.00000001);
	assertEquals(c1.getName() + " 1 clone", expected1, ((PerformanceCriterion)c1.clone()).getValue(), 0.00000001);

	PerformanceVector pv2 = new PerformanceVector();
	pv2.addCriterion(c2);
	PerformanceEvaluator.evaluate(null, exampleSet2, pv2, false);
	assertEquals(c2.getName()+ " 2",            expected2, c2.getValue(), 0.00000001);
	assertEquals(c2.getName() + " 2 clone", expected2, ((PerformanceCriterion)c2.clone()).getValue(), 0.00000001);

	c1.buildAverage(c2);
	assertEquals(c1.getName() + " average", expectedOverall, c1.getValue(), 0.00000001);
	assertEquals(c1.getName() + " makro average", (expected1+expected2)/2.0, c1.getMakroAverage(), 0.00000001);
    }

    public void testAbsoluteError() throws Exception {
	criterionTest(new AbsoluteError(), new AbsoluteError(), 
		      14.0 / 6.0,
		      7.0  / 3.0,
		      21.0 / 9.0);
    }

    public void testSquaredError() throws Exception {
	criterionTest(new SquaredError(), new SquaredError(), 
		      40.0 / 6.0,
		      17.0 / 3.0,
		      57.0 / 9.0);
    }

    public void testScaledError() throws Exception {
	criterionTest(new ScaledError(), new ScaledError(), 
		      14.0/6.0/9.0,
		      7.0/3.0/7.0,
		      (14.0/9.0 + 7.0/7.0) / 9.0);
    }
}

⌨️ 快捷键说明

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