📄 directedattributegenerator.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.example.ExampleSet;import edu.udo.cs.yale.tools.RandomGenerator;import edu.udo.cs.yale.generator.*;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.example.Tools;import edu.udo.cs.yale.operator.features.*;import edu.udo.cs.yale.operator.AttributeInformationGain;import java.util.ArrayList;import java.util.LinkedList;import java.util.List;/** In contrast to its superclass this AttributeGenerator selects the arguments for the * generation of new attributes according to their information gain. The probability * is determined similar to the calculation in DirectedMutation. * * @author ingo * @version $Id: DirectedAttributeGenerator.java,v 2.2 2003/04/04 11:59:28 fischer Exp $ */public class DirectedAttributeGenerator extends AttributeGenerator { /** Left margin */ double leftBound; /** Right margin */ double rightBound; /** Constructs a new <tt>DirectedAttributeGenerator</tt>. Parameters for the generation probability, maximal * number of new attribtues and a list of applicable generators. Information gain values are scaled to * the given bounds. */ public DirectedAttributeGenerator(double pGenerate, int numberOfNewAttributes, ArrayList generatorList, double leftBound, double rightBound) { super(pGenerate, numberOfNewAttributes, generatorList); this.leftBound = leftBound; this.rightBound = rightBound; } Attribute[] getArguments(ExampleSet exampleSet, Attribute[] expectedInputAttributes) { Attribute[] arguments = new Attribute[expectedInputAttributes.length]; double smallest = ((Double)exampleSet.getUserData(AttributeInformationGain.SMALLEST_INFORMATION_GAIN_KEY)).doubleValue(); double greatest = 1; double sum = 0; double[] shouldBeUsed = new double[exampleSet.getNumberOfAttributes()]; for (int i = 0 ; i < exampleSet.getNumberOfAttributes(); i++) { double[] informationGain = (double[])exampleSet.getUserData(AttributeInformationGain.SMALLEST_INFORMATION_GAIN_KEY); shouldBeUsed[i] = (((informationGain[i] - smallest) / (greatest - smallest)) * (rightBound - leftBound)) + leftBound; sum += shouldBeUsed[i]; } for (int i = 0 ; i < exampleSet.getNumberOfAttributes(); i++) shouldBeUsed[i] /= sum; for (int j = 0 ; j < expectedInputAttributes.length ; j++){ Attribute attribute = expectedInputAttributes[j]; Attribute[] compatibleAttributes = Tools.getCompatibleAttributes(exampleSet, attribute); double currentProb = RandomGenerator.getGlobalRandomGenerator().nextDouble(); double bound = 0; for (int i = 0; i < compatibleAttributes.length; i++) { bound += shouldBeUsed[i]; if (currentProb < bound) { arguments[j] = compatibleAttributes[i]; break; } } } return arguments; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -