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

📄 yagga2.java

📁 一个很好的LIBSVM的JAVA源码。对于要研究和改进SVM算法的学者。可以参考。来自数据挖掘工具YALE工具包。
💻 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.IOObject;
import edu.udo.cs.yale.operator.parameter.*;
import edu.udo.cs.yale.operator.features.*;
import edu.udo.cs.yale.generator.*;
import edu.udo.cs.yale.tools.LogService;
import edu.udo.cs.yale.example.ExampleSet;

import java.util.List;
import java.util.LinkedList;

/** Like AGA improves the simple GGA approach, YAGGA2 enhances the YAGGA algorithm.
 * 
 *  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>.
 *
 *  @version $Id: YAGGA2.java,v 2.11 2004/09/14 08:39:05 ingomierswa Exp $
 */
public class YAGGA2 extends YAGGA {

    public IOObject[] apply() throws OperatorException {
	if (getParameterAsBoolean("restrictive_selection"))
	    FeatureGenerator.setSelectionMode(FeatureGenerator.SELECTION_MODE_RESTRICTIVE);
	else
	    FeatureGenerator.setSelectionMode(FeatureGenerator.SELECTION_MODE_ALL);
	return super.apply();
    }

    protected PopulationOperator getMutationPopulationOperator() throws OperatorException {
	GeneratingMutation mutation = (GeneratingMutation)super.getMutationPopulationOperator();
	mutation.setMaxConstructionDepth(getParameterAsInt("max_construction_depth"));
	mutation.setUnusedFunctions(getParameterAsString("unused_functions").split(" "));
	return mutation;
    }

    public List getGenerators() {
	List generators = super.getGenerators();
	if (getParameterAsBoolean("use_square_roots")) { generators.add(new SquareRootGenerator()); }
	if (getParameterAsBoolean("use_power_functions")) { generators.add(new PowerGenerator()); }

	if (getParameterAsBoolean("use_sin")) 
	    generators.add(new TrigonometricFunctionGenerator(TrigonometricFunctionGenerator.SINUS));
	if (getParameterAsBoolean("use_cos")) 
	    generators.add(new TrigonometricFunctionGenerator(TrigonometricFunctionGenerator.COSINUS));
	if (getParameterAsBoolean("use_tan")) 
	    generators.add(new TrigonometricFunctionGenerator(TrigonometricFunctionGenerator.TANGENS));
	if (getParameterAsBoolean("use_atan")) 
	    generators.add(new TrigonometricFunctionGenerator(TrigonometricFunctionGenerator.ARC_TANGENS));

	if (getParameterAsBoolean("use_exp")) 
	    generators.add(new ExponentialFunctionGenerator(ExponentialFunctionGenerator.EXP));
	if (getParameterAsBoolean("use_log")) 
	    generators.add(new ExponentialFunctionGenerator(ExponentialFunctionGenerator.LOG));

	if (getParameterAsBoolean("use_absolute_values")) generators.add(new AbsoluteValueGenerator());
	if (getParameterAsBoolean("use_min")) generators.add(new MinMaxGenerator(MinMaxGenerator.MIN));
	if (getParameterAsBoolean("use_max")) generators.add(new MinMaxGenerator(MinMaxGenerator.MAX));

	if (getParameterAsBoolean("use_floor_ceil_functions")) {
	    generators.add(new FloorCeilGenerator(FloorCeilGenerator.FLOOR));
	    generators.add(new FloorCeilGenerator(FloorCeilGenerator.CEIL));
	    generators.add(new FloorCeilGenerator(FloorCeilGenerator.ROUND));
	}
	return generators;
    }

    protected List getPreProcessingPopulationOperators() {
	List popOps = super.getPreProcessingPopulationOperators();
	if (getParameterAsBoolean("remove_useless")) popOps.add(new RemoveUselessAttributes());
	if (getParameterAsBoolean("remove_equivalent")) 
	    popOps.add(new EquivalentAttributeRemoval(getParameterAsInt("equivalency_samples"),
						      getParameterAsDouble("equivalency_epsilon")));
	return popOps;
    }

    public List getParameterTypes() {
	List types = super.getParameterTypes();
	types.add(new ParameterTypeBoolean("use_square_roots", "Generate square root values.", false));
	types.add(new ParameterTypeBoolean("use_power_functions", "Generate the power of one attribute and another.", 
					   false));
	types.add(new ParameterTypeBoolean("use_sin", "Generate sinus.", false));
	types.add(new ParameterTypeBoolean("use_cos", "Generate cosinus.", false));
	types.add(new ParameterTypeBoolean("use_tan", "Generate tangens.", false));
	types.add(new ParameterTypeBoolean("use_atan", "Generate arc tangens.", false));
	types.add(new ParameterTypeBoolean("use_exp", "Generate exponential functions.", false));
	types.add(new ParameterTypeBoolean("use_log", "Generate logarithmic functions.", false));
	types.add(new ParameterTypeBoolean("use_absolute_values", "Generate absolute values.", false));
	types.add(new ParameterTypeBoolean("use_min", "Generate minimum values.", false));
	types.add(new ParameterTypeBoolean("use_max", "Generate maximum values.", false));
	types.add(new ParameterTypeBoolean("use_floor_ceil_functions", "Generate floor, ceil, and rounded values.", 
					   false));
	types.add(new ParameterTypeBoolean("restrictive_selection", "Use restrictive generator selection (faster).", 
					   true));
	types.add(new ParameterTypeBoolean("remove_useless", "Remove useless attributes.", true));
	types.add(new ParameterTypeBoolean("remove_equivalent", "Remove equivalent attributes.", true));
	types.add(new ParameterTypeInt("equivalency_samples", "Check this number of samples to prove equivalency.", 
				       1, Integer.MAX_VALUE, 5));
	types.add(new ParameterTypeDouble("equivalency_epsilon", 
					  "Consider two attributes equivalent if their difference is not bigger than epsilon.", 
					  0.0d, Double.POSITIVE_INFINITY, 0.05d));
	types.add(new ParameterTypeInt("max_construction_depth", 
				       "The maximum depth for the argument attributes used for attribute construction (-a: allow all depths).", 
				       -1, Integer.MAX_VALUE, -1));
	types.add(new ParameterTypeString("unused_functions", 
					  "Space separated list of functions which are not allowed in arguments for attribute construction."));
	return types;
    }
}

⌨️ 快捷键说明

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