?? regoptimizer.java
字號(hào):
/* * 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., 675 Mass Ave, Cambridge, MA 02139, USA. *//* * RegOptimizer.java * Copyright (C) 2006 University of Waikato, Hamilton, New Zealand * */package weka.classifiers.functions.supportVector;import weka.classifiers.functions.SVMreg;import weka.core.Instance;import weka.core.Instances;import weka.core.Option;import weka.core.OptionHandler;import weka.core.Utils;import java.io.Serializable;import java.util.Enumeration;import java.util.Random;import java.util.Vector;/** * Base class implementation for learning algorithm of SVMreg * <!-- options-start --> * Valid options are: <p/> * * <pre> -L <double> * The epsilon parameter in epsilon-insensitive loss function. * (default 1.0e-3)</pre> * * <pre> -W <double> * The random number seed. * (default 1)</pre> * <!-- options-end --> * * @author Remco Bouckaert (remco@cs.waikato.ac.nz,rrb@xm.co.nz) * @version $Revision: 1.2 $ */public class RegOptimizer implements OptionHandler, Serializable { /** for serialization */ private static final long serialVersionUID = -2198266997254461814L; /** loss type **/ //protected int m_nLossType = EPSILON; /** the loss type: L1 */ //public final static int L1 = 1; /** the loss type: L2 */ //public final static int L2 = 2; /** the loss type: HUBER */ //public final static int HUBER = 3; /** the loss type: EPSILON */ //public final static int EPSILON = 4; /** the loss type */ //public static final Tag[] TAGS_LOSS_TYPE = { // new Tag(L2, "L2"), // new Tag(L1, "L1"), // new Tag(HUBER, "Huber"), // new Tag(EPSILON, "EPSILON"), //}; /** alpha and alpha* arrays containing weights for solving dual problem **/ public double[] m_alpha; public double[] m_alphaStar; /** offset **/ protected double m_b; /** epsilon of epsilon-insensitive cost function **/ protected double m_epsilon = 1e-3; /** capacity parameter, copied from SVMreg **/ protected double m_C = 1.0; /** class values/desired output vector **/ protected double[] m_target; /** points to data set **/ protected Instances m_data; /** the kernel */ protected Kernel m_kernel; /** index of class variable in data set **/ protected int m_classIndex = -1; /** number of instances in data set **/ protected int m_nInstances = -1; /** random number generator **/ protected Random m_random; /** seed for initializing random number generator **/ protected int m_nSeed = 1; /** set of support vectors, that is, vectors with alpha(*)!=0 **/ protected SMOset m_supportVectors; /** number of kernel evaluations, used for printing statistics only **/ protected int m_nEvals = 0; /** number of kernel cache hits, used for printing statistics only **/ protected int m_nCacheHits = -1; /** weights for linear kernel **/ protected double[] m_weights; /** Variables to hold weight vector in sparse form. (To reduce storage requirements.) */ protected double[] m_sparseWeights; protected int[] m_sparseIndices; /** flag to indicate whether the model is built yet **/ protected boolean m_bModelBuilt = false; /** parent SVMreg class **/ protected SVMreg m_SVM = null; /** * the default constructor */ public RegOptimizer() { super(); m_random = new Random(m_nSeed); } /** * Gets an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector result = new Vector(); result.addElement(new Option( "\tThe epsilon parameter in epsilon-insensitive loss function.\n" + "\t(default 1.0e-3)", "L", 1, "-L <double>")); // result.addElement(new Option(// "\tLoss type (L1, L2, Huber, Epsilon insensitive loss)\n",// "L", 1, "-L [L1|L2|HUBER|EPSILON]")); result.addElement(new Option( "\tThe random number seed.\n" + "\t(default 1)", "W", 1, "-W <double>")); return result.elements(); } /** * Parses a given list of options. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -L <double> * The epsilon parameter in epsilon-insensitive loss function. * (default 1.0e-3)</pre> * * <pre> -W <double> * The random number seed. * (default 1)</pre> * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String tmpStr; tmpStr = Utils.getOption('L', options); if (tmpStr.length() != 0) { setEpsilonParameter(Double.parseDouble(tmpStr)); } else { setEpsilonParameter(1.0e-3); } /* tmpStr = Utils.getOption('S', options); if (tmpStr.length() != 0) setLossType(new SelectedTag(tmpStr, TAGS_LOSS_TYPE)); else setLossType(new SelectedTag(EPSILON, TAGS_LOSS_TYPE)); */ tmpStr = Utils.getOption('W', options); if (tmpStr.length() != 0) { setSeed(Integer.parseInt(tmpStr)); } else { setSeed(1); } } /** * Gets the current settings of the classifier. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { Vector result; result = new Vector(); result.add("-L"); result.add("" + getEpsilonParameter()); result.add("-W"); result.add("" + getSeed()); //result.add("-S"; //result.add((new SelectedTag(m_nLossType, TAGS_LOSS_TYPE)).getSelectedTag().getReadable(); return (String[]) result.toArray(new String[result.size()]); } /** * flag to indicate whether the model was built yet * * @return true if the model was built */ public boolean modelBuilt() { return m_bModelBuilt; } /** * sets the parent SVM * * @param value the parent SVM */ public void setSVMReg(SVMreg value) { m_SVM = value; } /** * returns the number of kernel evaluations * * @return the number of kernel evaluations */ public int getKernelEvaluations() { return m_nEvals; } /** * return the number of kernel cache hits * * @return the number of hits */ public int getCacheHits() { return m_nCacheHits; } /** * initializes the algorithm * * @param data the data to work with * @throws Exception if m_SVM is null
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -