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

📄 featuregenerationoperator.java

📁 著名的开源仿真软件yale
💻 JAVA
字号:
/* *  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.operator;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.generator.GenerationException;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.tools.ParameterService;import edu.udo.cs.yale.tools.Ontology;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.example.AttributeParser;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.generator.*;import java.io.File;import java.io.FileReader;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.ListIterator;/** This operator generates new user specified features. *  The new features are specified by their function names (prefix notation) and their  *  arguments using the names of existing features.<br/> *  Legal function names include +, -, *, and / for the four basic arithemtic funcions. *  Example: <code>+(a1, *(a2, a3))</code> will calculate the sum of the attribute  *  <code>a1</code> and the product of the attributes <code>a2</code> and <code>a3</code>. *  <br/> *  Features are generated in the following order *  <ol> *    <li>Features specified by the parameter list "functions" are generated</li> *    <li>Features specified by the file referenced by the parameter "filename" are generated</li> *    <li>If "keep_all" is false, all of the old attributes are removed now</li> *    <li>If "reciprocal_value" or "normalization" is true, all reciprocal values are generated or  *        normalized, respectively.</li> *  </ol> * *  @yale.xmlclass FeatureGeneration *  @see edu.udo.cs.yale.generator.FeatureGenerator *  @author simon, ingo *  @version $Id: FeatureGenerationOperator.java,v 2.10 2003/07/19 12:30:54 mierswa Exp $ */public class FeatureGenerationOperator extends Operator {    private static final Class[] INPUT_CLASSES  = { ExampleSet.class };    private static final Class[] OUTPUT_CLASSES = { ExampleSet.class };    public Class[] getInputClasses() { return INPUT_CLASSES; }    public Class[] getOutputClasses() { return OUTPUT_CLASSES; }    public IOObject[] apply() throws OperatorException {	ExampleSet exampleSet = (ExampleSet)((ExampleSet)getInput().getInput(ExampleSet.class)).clone();	boolean keepAll = getParameterAsBoolean("keep_all");	String filename = getParameterAsString("filename");	try {	    AttributeParser parser = new AttributeParser(exampleSet.getExampleTable());	    	    if (filename != null) {		parser.parseAll(new FileReader(filename));	    }	    	    Iterator j = getParameterList("functions").iterator();	    while (j.hasNext()) {		Object[] nameFunctionPair = (Object[])j.next();		Attribute attribute = parser.parse((String)nameFunctionPair[1]);		attribute.setName((String)nameFunctionPair[0]);	    }	    //if (!keepAll) { exampleSet.removeAllAttributes(); }	    parser.generateAll(exampleSet);  	} catch (java.io.IOException e) {  	    throw new UserError(this, e, 302, new Object[] {filename, e.getMessage()});  	}	// --------------------------------------------------------------------------------	ArrayList generators = new ArrayList();	if (getParameterAsBoolean("reciprocal_value")) {	    for (int i = 0; i < exampleSet.getNumberOfAttributes(); i++) {		FeatureGenerator g =  new ReciprocalValueGenerator(true);		g.setArguments(new Attribute[] { exampleSet.getAttribute(i) });		generators.add(g);	    }	}	if (getParameterAsBoolean("function_characteristica")) {	    for (int i = 0; i < exampleSet.getNumberOfAttributes(); i++) {		if (Ontology.ATTRIBUTE_BLOCK_TYPE.isA(exampleSet.getAttribute(i).getBlockType(), 						      Ontology.VALUE_SERIES_START)) {		    FeatureGenerator g =  new FunctionCharacteristicaGenerator();		    g.setArguments(new Attribute[] {exampleSet.getAttribute(i)});		    generators.add(g);		}	    }	}	if (getParameterAsBoolean("normalization")) {	    for (int i = 0; i < exampleSet.getNumberOfAttributes(); i++) {		FeatureGenerator g =  new NormalizationGenerator();		g.setArguments(new Attribute[] { exampleSet.getAttribute(i) });		generators.add(g);	    }	}	if (generators.size() > 0) {	    try {		List attributes = FeatureGenerator.generateAll(exampleSet.getExampleTable(),							       generators);		if (!keepAll) { exampleSet.removeAllAttributes(); }		exampleSet.addAllAttributes(attributes);	    } catch (GenerationException e) {		throw new UserError(this, e, 108, e.getMessage());	    }	}	return new IOObject[] { exampleSet };    }    public List getParameterTypes() {	List types = super.getParameterTypes();	types.add(new ParameterTypeFile("filename", "Create the attributes listed in this file (written by an AttributeSetWriter).", true));	types.add(new ParameterTypeList("functions", "List of functions to generate.", 					new ParameterTypeString("function", "Function and arguments to use for generation.")));	types.add(new ParameterTypeBoolean("reciprocal_value", "If set to true, all reciprocal values are calculated.", false));	types.add(new ParameterTypeBoolean("function_characteristica", "If set to true, function characteristica are calculated.", false));	types.add(new ParameterTypeBoolean("normalization", "If set to true, all values will be normalized by their range.", false));	types.add(new ParameterTypeBoolean("keep_all", "If set to true, all the original attributes are kept, otherwise they are removed from the example set.", false));	return types;    }}

⌨️ 快捷键说明

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