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

📄 runvector.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.tools.math;

import edu.udo.cs.yale.tools.ResultService;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.operator.Operator; 
import edu.udo.cs.yale.operator.IOObject; 
import edu.udo.cs.yale.operator.ResultObjectAdapter; 
import edu.udo.cs.yale.example.Attribute;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;

/** Collects the average vectors of a run. The averagables can be averaged by using
 *  <code>average()</code>.  
 *
 *  @version $Id: RunVector.java,v 1.2 2004/08/27 11:57:46 ingomierswa Exp $
 */
public class RunVector extends ResultObjectAdapter {

    /** list of average vectors. */
    private ArrayList vectorList;
    
    public RunVector() {
	vectorList = new ArrayList();
    }
    
    public void addVector(AverageVector av) {
	vectorList.add(av);
    }

    /** Returns the average vector with index i.
     */
    public AverageVector getVector(int index) {
	return (AverageVector)vectorList.get(index);
    }

    /** Returns all average vectors as list.
     */
    public ArrayList getVectorList() {
	return vectorList;
    }

    /** Returns the number of average vectors.
     */
    public int size() {
	return vectorList.size();
    }

    /** Calculates the mean value of the averagables of the average vectors and returns 
     *  a average vector of which contain for each averagable the mean value.
     */
    public AverageVector average() {
	AverageVector output = (AverageVector)getVector(0).clone();
	for (int i = 1; i < size(); i++) {
	    AverageVector av = getVector(i);
	    for (int j = 0; j < av.size(); j++) {
		output.getAveragable(j).buildAverage(av.getAveragable(j));
	    }
	}
	return output;
    }

    public String toString() {
	String result = "RunVector: \n";
	ListIterator i = vectorList.listIterator();
	while (i.hasNext()) 
	    result += (AverageVector)i.next() + "\n";
	return result;
    }


    /** returns a <tt>String</tt> containing a time series of the values of each averagable
     *  and the average of all averagables over all runs.
     */
    public String  toResultString() {
	// Output format:
	//   Time series of performance criterion 'error':   0.1  0.2  0.3  ...
	//   Time series of performance criterion 'recall':  0.1  0.2  0.3  ...
	//   ...
	//   Average of performance criterion 'error':  0.2  (standard deviation:  0.15)
	//   ...

	String result = "";
	AverageVector averageVector = average();   // compute the averages
	
	// ---- print the time series of all performance criteria ----
	for (int averagableIndex = 0; averagableIndex < averageVector.size(); averagableIndex++) {
	    result += "Time series of averagable '"+((this.getVector(0)).getAveragable(averagableIndex)).getName()+"':";
      	    for (int timeIndex = 0; timeIndex < this.size(); timeIndex++) {
		AverageVector currentAveragables = getVector(timeIndex);
		Averagable averagable = currentAveragables.getAveragable(averagableIndex);
		result += "  "+averagable.getValue();
	    }
	    result += "\n";
	}

	// ---- print the overall average (and variance) ----
	for (int i = 0; i < averageVector.size(); i++) {
	    Averagable averagable = averageVector.getAveragable(i);
	    result += "  Average of averagable '"+averagable.getName()+"':  " + averagable.getValue();
	    if (averagable.getVariance() >= 0) { result += "  (" + averagable.getVariance() + ")"; }
	    result += "\n";
	    // Alternativ:  criterion.toResultString()
	}
	result += "\n";
	return result;
    }

}

⌨️ 快捷键说明

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