📄 reciprocalvaluegenerator.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.generator;import edu.udo.cs.yale.tools.Ontology;import edu.udo.cs.yale.tools.LogService;import edu.udo.cs.yale.example.Attribute;import edu.udo.cs.yale.example.ExampleTable;import edu.udo.cs.yale.example.Example;import edu.udo.cs.yale.example.DataRow;/** Creates the reciprocal value of all input attributes. If the generator is bounded, * the values are bounded by the biggest and smallest possible values. * * @author simon, ingo * @version $Id: ReciprocalValueGenerator.java,v 2.3 2003/04/23 13:45:42 fischer Exp $ */ public class ReciprocalValueGenerator extends FeatureGenerator { private static final double UPPER_BOUND = Double.MAX_VALUE; private static final double LOWER_BOUND = Double.MIN_VALUE; public static final String FUNCTION_NAMES[] = {"1/"}; /** Possible input attributes are numerical single values. */ private static final Attribute[] INPUT_ATTR = { new Attribute(Ontology.NUMERICAL, Ontology.SINGLE_VALUE) }; /** Indicates if this generator works with bounded values. */ private boolean bounded = true; public ReciprocalValueGenerator(boolean bounded) { this.bounded = bounded; } public FeatureGenerator newInstance() { return new ReciprocalValueGenerator(bounded); } public Attribute[] getInputAttributes() { return INPUT_ATTR; } public Attribute[] getOutputAttributes(ExampleTable input) { Attribute a = getArgument(0); Attribute ao = new Attribute(Ontology.NUMERICAL, Ontology.SINGLE_VALUE, FUNCTION_NAMES[0], new Attribute[] {a}, false, input.getNextFreeBlockNr(), null); return new Attribute[] { ao }; } public void generate(DataRow data) throws GenerationException { try { Attribute a = getArgument(0); double o = data.get(a); double r = 1 / o; if (bounded) { if (r > UPPER_BOUND) { LogService.logMessage(this.toString() + ": cannot operate on argument " + a + ": result is out of bounds!", LogService.WARNING); r = UPPER_BOUND; } else if (r < LOWER_BOUND) { LogService.logMessage(this.toString() + ": cannot operate on argument " + a + ": result is out of bounds!", LogService.WARNING); r = LOWER_BOUND; } } else { if ((Double.isInfinite(r)) || (Double.isNaN(r))) { throw new GenerationException(this.toString() + ": cannot operate on argument " + a + " (" + o + ") = "+r); } } if (resultAttributes[0] != null) data.set(resultAttributes[0], r); } catch (ArrayIndexOutOfBoundsException ex) { throw new GenerationException("a1:" + getArgument(0)); } } public void setFunction(String name) { for (int i = 0; i < FUNCTION_NAMES.length; i++) { if (FUNCTION_NAMES[i].equals(name)) return; } LogService.logMessage("Illegal function name '"+name+"' for "+getClass().getName()+".", LogService.ERROR); } public String getFunction() { return FUNCTION_NAMES[0]; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -