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

📄 matlabica.java

📁 wekaUT是 university texas austin 开发的基于weka的半指导学习(semi supervised learning)的分类器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* *    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. *//* *    MatlabICA.java *    Copyright (C) 2002 Sugato Basu and Mikhail Bilenko  * */package weka.attributeSelection;import  java.io.*;import  java.util.*;import  weka.core.*;import  weka.filters.unsupervised.attribute.ReplaceMissingValues;import  weka.filters.unsupervised.attribute.Normalize;import  weka.filters.unsupervised.attribute.NominalToBinary;import  weka.filters.unsupervised.attribute.Remove;import  weka.filters.Filter;/** * Class for performing independent components analysis/transformation. <p> * * Valid options are:<p> * -D <br> * Don't normalize the input data. <p> * * -T <br> * Transform through the IC space and back to the original space. <p> *  * -N <br> num * Number of independant components * * -A <br> approach * ICA Approach * * -F <br> function * ICA function * * @author Sugato Basu * @author Mikhail Bilenko * @version $Revision: 1.2 $ */public class MatlabICA extends AttributeEvaluator   implements AttributeTransformer, OptionHandler {    /** The data to transform analyse/transform */  private Instances m_trainInstances;  /** Keep a copy for the class attribute (if set) */  private Instances m_trainCopy;  /** The header for the transformed data format */  private Instances m_transformedFormat;  /** The header for data transformed back to the original space */  private Instances m_originalSpaceFormat;  /** Data has a class set */  private boolean m_hasClass;  /** Class index */  private int m_classIndex;  /** Number of attributes */  private int m_numAttribs;  /** Number of instances */  private int m_numInstances;  /** Name of the Matlab program file that computes ICA */  protected String m_ICAMFile = new String("/var/local/MatlabICA.m");  /** Will hold the mixing matrix */  protected double [][] m_mixingMatrix;  /** Will hold the inverse of the mixing matrix */  protected double [][] m_inverseMixingMatrix;  /** Will hold the independent components */  protected double [][] m_independentComponents;  /** A timestamp suffix for matching vectors with attributes */  String m_timestamp = null;  /** Name of the file where attribute names will be stored */  String m_icaAttributeFilename = null;  /** Name of the file where attribute names will be stored */  String m_icaAttributeFilenameBase = new String("/var/local/ICAattributes");    /** Name of the file where dataMatrix will be stored */  public String m_dataFilename = new String("/var/local/ICAdataMatrix.txt");    /** Name of the file where mixingMatrix will be stored */  public String m_mixingMatrixFilename = null;  public String m_mixingMatrixFilenameBase = new String("/var/local/ICAmixingMatrix");  /** Name of the file where inverseMixingMatrix will be stored */  public String m_inverseMixingMatrixFilename = new String("/var/local/ICAinverseMixingMatrix.txt");  /** Name of the file where independentComponents will be stored */  public String m_independentComponentsFilename = null;  public String m_independentComponentsFilenameBase = new String("/var/local/ICAindependentComponents");      /** Filters for original data */  private ReplaceMissingValues m_replaceMissingFilter;  private Normalize m_normalizeFilter;  private Remove m_attributeFilter;    /** The number of attributes in the ic transformed data */  private int m_outputNumAtts = -1;    /** normalize the input data? */  private boolean m_normalize = true;  /** transform the data through the ic space and back to the original      space ? */  private boolean m_transBackToOriginal = false;  /** The attribute evaluator to use */  private ASEvaluation m_eval = new weka.attributeSelection.ChiSquaredAttributeEval();  /** load eigenvalues of covariance matrix from file? */  protected boolean m_loadEigenValuesFromFile = false;  /** set m_loadEigenValuesFromFile */  public void setLoadEigenValuesFromFile(boolean choice) {    m_loadEigenValuesFromFile = choice;  }    /** get m_loadEigenValuesFromFile */  public boolean getLoadEigenValuesFromFile () {    return m_loadEigenValuesFromFile;  }  /** load eigenvectors of covariance matrix from file? */  protected boolean m_loadEigenVectorsFromFile = false;  /** set m_loadEigenVectorsFromFile */  public void setLoadEigenVectorsFromFile(boolean choice) {    m_loadEigenVectorsFromFile = choice;  }    /** get m_loadEigenVectorsFromFile */  public boolean getLoadEigenVectorsFromFile () {    return m_loadEigenVectorsFromFile;  }  /** number of Independent Components */  protected int m_NumIndependentComponents = 2;  /** set number of Independent Components */  public void setNumIndependentComponents(int n) {    m_NumIndependentComponents = n;    System.out.println("Number of ICA components: " + n);  }  /** get number of Independent Components */  public int getNumIndependentComponents() {    return m_NumIndependentComponents;  }  /* Define possible ICA approaches */  public static final int APPROACH_SYMM = 0;  public static final int APPROACH_DEFL = 1;  public static final Tag[] TAGS_APPROACH = {    new Tag(APPROACH_SYMM, "symm"),    new Tag(APPROACH_DEFL, "defl")  };  protected int m_ICAapproach = APPROACH_SYMM;  /** get ICA approach */  public SelectedTag getICAapproach ()  {    return new SelectedTag(m_ICAapproach, TAGS_APPROACH);  }  /** set ICA approach */  public void setICAapproach (SelectedTag approach)  {    if (approach.getTags() == TAGS_APPROACH) {      System.out.println("Approach: " + approach.getSelectedTag().getReadable());      m_ICAapproach = approach.getSelectedTag().getID();    }  }  /* Define possible ICA functions */  public static final int FUNCTION_TANH = 0;  public static final int FUNCTION_GAUSS = 1;  public static final int FUNCTION_POW3 = 2;  public static final int FUNCTION_SKEW = 3;  public static final Tag[] TAGS_FUNCTION = {    new Tag(FUNCTION_TANH, "tanh"),    new Tag(FUNCTION_GAUSS, "gauss"),    new Tag(FUNCTION_POW3, "pow3"),    new Tag(FUNCTION_SKEW, "skew")  };  protected int m_ICAfunction = FUNCTION_TANH;  /** get ICA function */  public SelectedTag getICAfunction ()  {    return new SelectedTag(m_ICAfunction, TAGS_FUNCTION);  }  /** set ICA function */  public void setICAfunction (SelectedTag function)  {    if (function.getTags() == TAGS_FUNCTION) {      System.out.println("Function: " + function.getSelectedTag().getReadable());      m_ICAfunction = function.getSelectedTag().getID();    }  }  /**   * Returns a string describing this attribute transformer   * @return a description of the evaluator suitable for   * displaying in the explorer/experimenter gui   */  public String globalInfo() {    return "Performs a independent components analysis and transformation of "      +"the data. Use in conjunction with a Ranker search. Dimensionality "      +"reduction is accomplished by choosing enough eigenvectors to "      +"account for some percentage of the variance in the original data---"      +"default 0.95 (95%). Attribute noise can be filtered by transforming "      +"to the IC space, eliminating some of the worst eigenvectors, and "      +"then transforming back to the original space.";  }  /**   * Returns an enumeration describing the available options. <p>   *   * @return an enumeration of all the available options.   **/  public Enumeration listOptions () {    Vector newVector = new Vector(3);    newVector.addElement(new Option("\tDon't normalize input data." 				    , "D", 0, "-D"));        newVector.addElement(new Option("\tTransform through the IC space and "				    +"\n\tback to the original space."				    , "O", 0, "-O"));    newVector.addElement(new Option("\tNumber of independant components." 				    , "N", 1, "-N"));    newVector.addElement(new Option("\tICA approach." 				    , "A", 1, "-A"));    newVector.addElement(new Option("\tICA function." 				    , "F", 1, "-F"));    return  newVector.elements();  }  /**   * Parses a given list of options.   *   * Valid options are:<p>   * -D <br>   * Don't normalize the input data. <p>   *   * -T <br>   * Transform through the IC space and back to the original space. <p>   *   * -N <br> num   * Number of independant components   *   * -A <br> approach   * ICA Approach   *   * -F <br> function   * ICA function   *   * @param options the list of options as an array of strings   * @exception Exception if an option is not supported   */  public void setOptions (String[] options)    throws Exception  {    resetOptions();    String optionString;    setNormalize(!Utils.getFlag('D', options));    setTransformBackToOriginal(Utils.getFlag('O', options));    optionString = Utils.getOption('F', options);    if (optionString.length() != 0) {      setICAfunction(new SelectedTag(Integer.parseInt(optionString), TAGS_FUNCTION));    }    optionString = Utils.getOption('A', options);    if (optionString.length() != 0) {      setICAapproach(new SelectedTag(Integer.parseInt(optionString), TAGS_APPROACH));    }    optionString = Utils.getOption('N', options);    if (optionString.length() != 0) {      setNumIndependentComponents(Integer.parseInt(optionString));    }  }  /**   * Reset to defaults   */  private void resetOptions() {    m_normalize = false;    m_transBackToOriginal = false;    m_ICAfunction = 0;    m_ICAapproach = 0;    m_eval = new weka.attributeSelection.ChiSquaredAttributeEval();    m_NumIndependentComponents = 2;  }  /**   * Sets the attribute evaluator   *   * @param evaluator the evaluator with all options set.   */  public void setEvaluator(ASEvaluation evaluator) {    m_eval = evaluator;  }  /**   * Gets the attribute evaluator used   *   * @return the attribute evaluator   */

⌨️ 快捷键说明

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