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

📄 functioncharacteristicagenerator.java

📁 著名的开源仿真软件yale
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* *  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.generator;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.Ontology;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.DataRow;import edu.udo.cs.yale.example.ExampleTable;import edu.udo.cs.yale.example.Attribute;import java.util.ArrayList;/**  A <tt>FunctionCharacteristicaGenerator</tt> expects a function value series *   as input (attribute value type <tt>Ontology.NUMERICAL</tt> and attribute block *   type <tt>Ontology.VALUE_SERIES</tt>, where the first attribute is of the more *   specific attribute block type <tt>Ontology.VALUE_SERIES_START</tt>). *   <i>The proper attribute input types have to be ensured by the calling class /method, *   or by its source, e.g. the corresponding <tt>AttributeAndExampleSource</tt>-Operator.</i> *   The output consists of six generated attributes, each of attribute value type *   <tt>Ontology.NUMERICAL</tt> and of attribute block type <tt>Ontology.SINGLE_VALUE</tt>: *   <ol> *     <li><b>WP1.x : </b> x-value of the first turning point (of the value series). </li> *     <li><b>WP1.y : </b> y-value of the first turning point (of the value series). </li> *     <li><b>Max.x : </b> x-value of the global maximum (of the value series). </li> *     <li><b>Max.y : </b> y-value of the global maximum (of the value series). </li> *     <li><b>WP2.x : </b> x-value of the second turning point (of the value series). </li> *     <li><b>WP2.y : </b> y-value of the second turning point (of the value series). </li> *   </ol> *   <b>Important Note:</b> <i>This generator has been designed for a special form of *   functions (function value series), i.e. for functions which have one global maximum (Max), *   one turning point left of the maximum (WP1), and one turning point right of the *   maximum (WP2).  This generator will probably not work with other function types.</i> * *   @author simon, ingo *   @version $Id: FunctionCharacteristicaGenerator.java,v 2.3 2003/04/23 13:45:42 fischer Exp $ */public class FunctionCharacteristicaGenerator extends FeatureGenerator {    /** Input attribute value type and block type:  Block type <tt>Ontology.VALUE_SERIES</tt> here means that one     *  or more attributes of the specified attribute value type <tt>Ontology.NUMERICAL</tt> may be used as input     *  for this generator as long as they have the same block number and they will be interpreted as a function     *  value series (e.g. a time series).     */    private static final Attribute[] INPUT_ATTR = { new Attribute(Ontology.NUMERICAL, Ontology.VALUE_SERIES_START) };    // Generator input:  series of numerical function values.    private static final int[] VALUE_TYPES = {Ontology.NUMERICAL};    private static final int[] BLOCK_TYPES = {Ontology.VALUE_SERIES_START};    // Generator output:  six numeric single values (WP1.x, WP1.y, Max.x, Max.y, WP2.x, WP2.y).    private static final int[] RESULT_VALUE_TYPE = { Ontology.NUMERICAL, Ontology.NUMERICAL, Ontology.NUMERICAL,						     Ontology.NUMERICAL, Ontology.NUMERICAL, Ontology.NUMERICAL };    private static final int[] RESULT_BLOCK_TYPE = { Ontology.SINGLE_VALUE, Ontology.SINGLE_VALUE,						     Ontology.SINGLE_VALUE, Ontology.SINGLE_VALUE,						     Ontology.SINGLE_VALUE, Ontology.SINGLE_VALUE };    // Positions (indices) of the new attributes within the array of new attribute values    private static final int  WP1_X = 0;    private static final int  WP1_Y = 1;    private static final int  MAX_X = 2;    private static final int  MAX_Y = 3;    private static final int  WP2_X = 4;    private static final int  WP2_Y = 5;    public static final String[] FUNCTION_NAMES = { "WP1.X", "WP1.Y", "Max.X", "Max.Y", "WP2.X", "WP2.Y" };    /* --------- Private Variables ---------- */    private int          attributeIndexStart,  // attribute index of the first and last attribute (value)		         attributeIndexEnd;    // of function value series (if valueSeriesStart >= 0)    private double[]     y;		       // array with the y-values of the function value series    private int          n;		       // number of y-values of the function value series    /* --------- Public Methods ---------- */    /** creates a <tt>FunctionCharacteristicaGenerator</tt> that has to be initialized with the methods     *  <tt>setArguements(...)</tt> and <tt>setAttributeSet(...)</tt> before its <tt>generate(...)</tt>     *  method may be called.     *  The method <tt>setAttributeSet(...)</tt> is called automatically in <tt>generateAll(...)</tt> of     *  the super class <tt>FeatureGenerator</tt> before this methods calls the <tt>generate(...)</tt>     *  method of each <tt>Generator</tt> in its list.     */    public FunctionCharacteristicaGenerator() {	super();	attributeIndexStart = -1;	attributeIndexEnd   = -2;	y = null;	n = -1;    }    public FeatureGenerator newInstance() {  	return new FunctionCharacteristicaGenerator();    }    /** returns an array with the expected input <tt>Attribute</tt>s (i.e. value types and block types);     *  here: an array with one element of value type <tt>Ontology.NUMERICAL</tt> and block type     *  <tt>Ontology.VALUE_SERIES</tt>.     */    public Attribute[] getInputAttributes() {	return INPUT_ATTR;    }    /** returns a list of the output attributes */    public Attribute[] getOutputAttributes(ExampleTable input) {	Attribute   inputAttribute   = getArgument(0);	Attribute[] outputAttributes = new Attribute[6];	for (int i=0; i<6; i++) {	  outputAttributes[i] = new Attribute(Ontology.NUMERICAL, Ontology.SINGLE_VALUE,					      FUNCTION_NAMES[i], new Attribute[] {inputAttribute}, 					      false,					      input.getNextFreeBlockNr(),					      null);	}	return outputAttributes;    }    public void setFunction(String name) {	for (int i = 0; i < FUNCTION_NAMES.length; i++) {	    if (FUNCTION_NAMES[i].equals(name)) return;	}	LogService.logMessage("Illegal function name '"+name+"' for "+getClass().getName()+".", 			      LogService.ERROR);    }    public String getFunction() {	return "FunctionCharacteristica";    }    /** This method generates the new attributes' values for the given example and returns them in an array.     */    public void generate(DataRow data) throws GenerationException {	double[] functionCharacteristica = new double[6]; // array for WP1.x, WP1.y, Max.x, Max.y, WP2.x, WP2.y							  // (output of the generator)	for (int i = 0; i < functionCharacteristica.length; i++) 	    functionCharacteristica[i] = Double.NaN;	// ----- determine start and end index of the value series within the attribute set -----	// ----- and allocate array for values of the value series (both done only once)    -----        if (y == null) {	    attributeIndexStart = getArgument(0).getIndex();	    attributeIndexEnd   = getExampleTable().getBlockEndIndex(attributeIndexStart);	    n = attributeIndexEnd - attributeIndexStart + 1;    // number of values in the value series	    if (n < 5) {		throw new GenerationException("FunctionCharacteristicaGenerator.generate(Example): "					      +"this generator can only be applied to value series "					      +"with at least five values.");	    }	    y = new double[n];     // array for the values of the value series (input of the generator) 	}	// ----- get the attribute values of the example to be used as input value series -----	for (int x=attributeIndexStart; x <= attributeIndexEnd; x++)	    y[x - attributeIndexStart] = data.get(getExampleTable().getAttribute(x));	// ----- compute global maximum (Max), first turning point (WP1), and second turning point (WP2) -----	// ----- of the value series 'y' and write result into 'functionCharacteristica'                 -----	computeFunctionCharacteristica (y, functionCharacteristica);	// ----- return the resulting, newly generated six x- and y-values -----	for (int i = 0; i < functionCharacteristica.length; i++) {	    if (resultAttributes[i] != null)		data.set(resultAttributes[i], functionCharacteristica[i]);	}    }

⌨️ 快捷键说明

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