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

📄 featuregenerator.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.generator;

import edu.udo.cs.yale.example.Example;
import edu.udo.cs.yale.example.ExampleSet;
import edu.udo.cs.yale.example.ExampleTable;
import edu.udo.cs.yale.example.ExampleReader;
import edu.udo.cs.yale.example.Attribute;
import edu.udo.cs.yale.example.DataRow;
import edu.udo.cs.yale.example.DataRowReader;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.tools.RandomGenerator;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;

/** Abstract superclass of all attribute generators.
 *  Implementing classes have to implement the <tt>generate(Example)</tt>, method and specify the
 *  input and output attributes by the appropriate methods so that the using algorithms can use them
 *  correctly.
 *
 *  @author simon, ingo
 *  @version $Id: FeatureGenerator.java,v 2.19 2004/08/27 11:57:32 ingomierswa Exp $
 */
public abstract class FeatureGenerator {

    private static final String[] FUNCTION_NAMES = {
	"+", "-", "*", "/",
	"WP1.X", "WP1.Y", "Max.X", "Max.Y", "WP2.X", "WP2.Y",
	"1/",
	"norm",
	"sin", "cos", "tan", "atan",
	"exp", "log",
	"min", "max",
	"floor", "ceil", "round",
	"sqrt",
	"abs",
	"pow"
    };

    /** The classes which corresponds to FUNCTION_NAMES. */
    private static final Class[] GENERATOR_CLASSES = {
	BasicArithmeticOperationGenerator.class, 
	BasicArithmeticOperationGenerator.class, 
	BasicArithmeticOperationGenerator.class, 
	BasicArithmeticOperationGenerator.class, 

	FunctionCharacteristicaGenerator.class, 
	FunctionCharacteristicaGenerator.class, 
	FunctionCharacteristicaGenerator.class, 
	FunctionCharacteristicaGenerator.class, 
	FunctionCharacteristicaGenerator.class, 
	FunctionCharacteristicaGenerator.class, 

	ReciprocalValueGenerator.class,
	NormalizationGenerator.class,
	
	TrigonometricFunctionGenerator.class,
	TrigonometricFunctionGenerator.class,
	TrigonometricFunctionGenerator.class,
	TrigonometricFunctionGenerator.class,

	ExponentialFunctionGenerator.class,
	ExponentialFunctionGenerator.class,

	MinMaxGenerator.class,
	MinMaxGenerator.class,

	FloorCeilGenerator.class,
	FloorCeilGenerator.class,
	FloorCeilGenerator.class,

	SquareRootGenerator.class,
	AbsoluteValueGenerator.class,
	PowerGenerator.class
    };

    /** Maps function names to generators. */
    private static Map generatorMap;

    static {
	generatorMap = new Hashtable();
	for (int i = 0; i < FUNCTION_NAMES.length; i++) {
	    generatorMap.put(FUNCTION_NAMES[i], GENERATOR_CLASSES[i]);
	}
    }

    /** Indicates a non-restrictive generator selection mode. */
    public static int SELECTION_MODE_ALL         = 0;
    /** Indicates a restrictive generator selection mode. */
    public static int SELECTION_MODE_RESTRICTIVE = 1;

    /** Indicates the selection mode. One of SELECTION_MODE_ALL and SELECTION_MODE_RESTRICTIVE. */
    private static int selectionMode = SELECTION_MODE_ALL;

    /** The attributes of the function(s) calculated by this FeatureGenerator. */
    protected Attribute[] resultAttributes;

    /** The argument attributes on which to operate with respect to the example tables
     *  attribute array. */
    private Attribute[] arguments = null;

    /** The example table to work on. */
    private ExampleTable exampleTable;    
 

    // ------------------------------ The abstract methods ------------------------------

    /** Generates the new attribute values for the example e and returns the new attribute
     *  values as doubles. <tt>e.getAttribute(getArgument(i))</tt> is the correct way to access
     *  argument <i>i</i>.
     *  If the according attribute's type is VALUE_SERIES, the end index can be determined by 
     *  <tt>i_end = getExampleTable().getBlockEndIndex(getArgument(i))</tt>. Thus all values of the series
     *  can be accessed using indices <i>i</i> through <i>i_end</i>. */
    public abstract void generate(DataRow data) throws GenerationException;
 
    /** Returns an array of Attributes where the length is the arity of the generator,
     *  <tt>[i]</tt> is the attribute type of the i-th argument. */
    public abstract Attribute[] getInputAttributes();

    /** Returns the generated attributes types. */
    public abstract Attribute[] getOutputAttributes(ExampleTable input);

    /** Subclasses must implement this method so that a new instance of this generator
     *  class is returned. The arguments and the example table will not be cloned and thus 
     *  be null. This kind of clone is needed as generating algorithms must be able 
     *  to clone generators form their pool without changing the arguments already set
     *  for the others. */
    public abstract FeatureGenerator newInstance();

    /** Sets the function name. This method is only useful if subclasses can generate more
     *  than one function. (like the BasicArithmeticOperationGenerator). */
    public abstract void setFunction(String name);

    /** Sets the function name. This method is only useful if subclasses can generate more
     *  than one function. (like the BasicArithmeticOperationGenerator). */
    public abstract String getFunction();

    /** Returns the number of applicable generations on the given example set. Subclasses must consider if
     *  the generator is self-applicable or commutative. */
    //public abstract int getNumberOfApplicableGenerations(ExampleSet exampleSet, int maxDepth, String[] functions);
 
    /** Returns all compatible input attribute arrays for this generator from the given example set as list. 
     *  Features with a depth greater than maxDepth or which contains one of the given functions should
     *  not be used as input candidates.  Subclasses must consider if the generator is self-applicable 
     *  or commutative. */
    public abstract List getInputCandidates(ExampleSet exampleSet, int maxDepth, String[] functions);

    // --------------------------------------------------------------------------------

    protected boolean checkCompatibility(Attribute attribute, Attribute compatible, int maxDepth, String[] functions) {
	if (attribute.compatible(compatible) && ((maxDepth == -1) || (attribute.getConstructionDepth() <= maxDepth))) {
	    for (int f = 0; f < functions.length; f++) {
		if (attribute.getConstructionDescription().indexOf(functions[f]) != -1)
		    return false;
	    }
	    return true;
	} else {
	    return false;
	}
    }

    protected void setExampleTable(ExampleTable et) { 
	this.exampleTable = et; 
    }

    /** Gets the example table the examples are from. */
    protected ExampleTable getExampleTable() { return exampleTable; }

    /** Sets the arguments (indices) used in future <tt>generate(...)</tt>  calls and has to be called prior
     *  to any <tt>generate(...)</tt> calls.  The caller of this method has to take care that:
     *  <ul>
     *    <li><tt>args.length == getInputAttributes().length</tt>, i.e. that the arity is correct.
     *    <li>The types of the example attributes match the types specified by 
     *        <tt>getInputAttributes()</tt>.
     *    <li>The true attribute indices are used (as used by the example set's example table)
     *  </ul>
     */
    public void setArguments(Attribute[] args) {
	arguments = args;
    }

    /** returns <tt>true</tt>, if the arguments have already been set, and <tt>false</tt> otherwise. */
    public boolean argumentsSet() {
        return (getInputAttributes().length == 0) || (arguments != null);
    }

⌨️ 快捷键说明

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