📄 yagga.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.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 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.
*
* Since this operator does not contain algorithms to extract features from value series, it is restricted
* to example sets with only single attributes. For (automatic) feature extraction from values series the
* value series plugin for Yale written by Ingo Mierswa should be used. It is available at
* <a href="http://yale.cs.uni-dortmund.de">http://yale.cs.uni-dortmund.de</a>.
*
* @yale.xmlclass YAGGA
* @author ingo, simon
* @version $Id: YAGGA.java,v 2.16 2004/08/27 11:57:36 ingomierswa Exp $
*/
public class YAGGA extends AbstractGeneratingGeneticAlgorithm {
/** Since the mutation of YAGGA also creates new attributes this method returns null. */
protected PopulationOperator getGeneratingPopulationOperator() { return null; }
/** Returns the generating mutation <code>PopulationOperator</code>. */
protected PopulationOperator getMutationPopulationOperator() throws OperatorException {
List generators = getGenerators();
if (generators.size()==0) {
LogService.logMessage("No FeatureGenerators specified for " + getName() + ".", LogService.WARNING);
}
ExampleSet eSet = (ExampleSet)getInput(ExampleSet.class, false);
List attributes = new LinkedList();
for (int i = 0; i < eSet.getNumberOfAttributes(); i++) {
attributes.add(eSet.getAttribute(i));
}
double pMutation = getParameterAsDouble("p_mutation");
return new GeneratingMutation(attributes, pMutation, generators);
}
/** Creates a initial population. */
public Population createInitialPopulation(ExampleSet es) {
Population population = super.createInitialPopulation(es);
Population popRemovedDeselected = new Population();
for (int i = 0; i < population.getNumberOfIndividuals(); i++) {
popRemovedDeselected.add(population.get(i).createCleanExampleSet());
}
return popRemovedDeselected;
}
public List getParameterTypes() {
List types = super.getParameterTypes();
ParameterType type = new ParameterTypeDouble("p_mutation",
"Probability for mutation.",
0, 1, 0.5);
type.setExpert(false);
types.add(type);
return types;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -