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

📄 yagga.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.features.ga;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.generator.*;import edu.udo.cs.yale.operator.features.*;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.AttributeSelectionExampleSet;import java.util.ArrayList;import java.util.List;import java.util.LinkedList;/** YAGGA is an acronym for Yet Another Generating Genetic Algorithm.  *  Its approach to generating new attributes differs from the original one.  *  The (generating) mutation can do one of the following things with  *  different probabilities: *  <ul> *    <li>Probability {@yale.math p/4}: Add a newly generated attribute to the feature vector</li> *    <li>Probability {@yale.math p/4}: Add a randomly chosen original attribute to the feature vector</li> *    <li>Probability {@yale.math p/2}: Remove a randomly chosen attribute from the feature vector</li> *  </ul> *  Thus it is guaranteed that the length of the feature vector can both *  grow and shrink. On average it will keep its original length, unless *  longer or shorter individuals prove to have a better fitness. * *  @yale.xmlclass YAGGA *  @author ingo, simon *  @version $Id: YAGGA.java,v 2.4 2003/07/09 15:19:58 fischer Exp $ */public class YAGGA extends GeneticAlgorithm {    /** Returns the generating crossover <tt>PopulationOperator</tt>.     */    PopulationOperator getCrossoverPopulationOperator() {	double pCrossover = getParameterAsDouble("p_crossover");	int crossoverType = getParameterAsInt("crossover_type");	return new UnbalancedCrossover(crossoverType, pCrossover, false);    }    /** Returns the generating mutation <tt>PopulationOperator</tt>.     */    PopulationOperator getMutationPopulationOperator() throws OperatorException {	double pMutation = getParameterAsDouble("p_mutation");		// creates the generators	ArrayList generators = new ArrayList();		if (getParameterAsBoolean("reciprocal_value")) {	    FeatureGenerator g =  new ReciprocalValueGenerator(true);	    generators.add(g);	}	if (getParameterAsBoolean("function_characteristica")) {	    FeatureGenerator g =  new FunctionCharacteristicaGenerator();	    generators.add(g);	}	if (getParameterAsBoolean("use_plus")) {	    FeatureGenerator g =  new BasicArithmeticOperationGenerator(0, true);	    generators.add(g);	}	if (getParameterAsBoolean("use_diff")) {	    FeatureGenerator g =  new BasicArithmeticOperationGenerator(1, true);	    generators.add(g);	}	if (getParameterAsBoolean("use_mult")) {	    FeatureGenerator g =  new BasicArithmeticOperationGenerator(2, true);	    generators.add(g);	}	if (getParameterAsBoolean("use_div")) {	    FeatureGenerator g =  new BasicArithmeticOperationGenerator(3, true);	    generators.add(g);	}	if (generators.size()==0) {	    LogService.logMessage("No FeatureGenerators specified for " + getName() + ".", LogService.WARNING);	} 	// adds generation to the PreEval - List. 	ExampleSet eSet = (ExampleSet)getInput(ExampleSet.class, false);	List attributes = new LinkedList();	for (int i = 0; i < eSet.getNumberOfAttributes(); i++) {	    attributes.add(eSet.getAttribute(i));	} 	// adds generation to the PreEval - List. 	return new GeneratingMutation(attributes, pMutation, generators);    }        /** Creates a initial population.     */    public Population createInitialPopulation(AttributeSelectionExampleSet es) {	Population pop1 = super.createInitialPopulation(es);	Population pop2 = new Population();	for (int i = 0; i < pop1.getNumberOfIndividuals(); i++) {	    pop2.add(new AttributeSelectionExampleSet(pop1.get(i).createExampleSet()));	}	return pop2;    }    public List getParameterTypes() {	List types = super.getParameterTypes();	types.add(new ParameterTypeInt("max_number_of_new_attributes", "Max number of attributes to generate for an individual.", 0, Integer.MAX_VALUE, 1));	types.add(new ParameterTypeDouble("p_generate", "Probability for an individual to be selected for generation.", 0, 1, 0.1));	types.add(new ParameterTypeBoolean("reciprocal_value", "Generate reciprocal values.", true));	types.add(new ParameterTypeBoolean("function_characteristica", "Generate function characteristica (for C9).", false));	types.add(new ParameterTypeBoolean("use_plus", "Generate sums.", true));	types.add(new ParameterTypeBoolean("use_diff", "Generate differences.", true));	types.add(new ParameterTypeBoolean("use_mult", "Generate products.", true));	types.add(new ParameterTypeBoolean("use_div", "Generate quotients.", true));	return types;    }}

⌨️ 快捷键说明

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