亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來(lái)到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? votedperceptron.java

?? MacroWeka擴(kuò)展了著名數(shù)據(jù)挖掘工具weka
?? 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.
 */

/*
 *    VotedPerceptron.java
 *    Copyright (C) 1999 Eibe Frank
 *
 */


package weka.classifiers.functions;

import weka.classifiers.Classifier;
import weka.classifiers.Evaluation;
import weka.filters.unsupervised.attribute.NominalToBinary;
import weka.filters.unsupervised.attribute.ReplaceMissingValues;
import weka.filters.Filter;
import weka.core.*;
import java.util.*;

/**
 * Implements the voted perceptron algorithm by Freund and
 * Schapire. Globally replaces all missing values, and transforms
 * nominal attributes into binary ones. For more information, see<p>
 *
 * Y. Freund and R. E. Schapire (1998). <i> Large margin
 * classification using the perceptron algorithm</i>.  Proc. 11th
 * Annu. Conf. on Comput. Learning Theory, pp. 209-217, ACM Press, New
 * York, NY. <p>
 *
 * Valid options are:<p>
 *
 * -I num <br>
 * The number of iterations to be performed. (default 1)<p>
 *
 * -E num <br>
 * The exponent for the polynomial kernel. (default 1)<p>
 *
 * -S num <br>
 * The seed for the random number generator. (default 1)<p>
 *
 * -M num <br>
 * The maximum number of alterations allowed. (default 10000) <p>
 *
 * @author Eibe Frank (eibe@cs.waikato.ac.nz)
 * @version $Revision: 1.1 $ 
*/
public class VotedPerceptron extends Classifier implements OptionHandler {
  
  /** The maximum number of alterations to the perceptron */
  private int m_MaxK = 10000;

  /** The number of iterations */
  private int m_NumIterations = 1;

  /** The exponent */
  private double m_Exponent = 1.0;

  /** The actual number of alterations */
  private int m_K = 0;

  /** The training instances added to the perceptron */
  private int[] m_Additions = null;

  /** Addition or subtraction? */
  private boolean[] m_IsAddition = null;

  /** The weights for each perceptron */
  private int[] m_Weights = null;
  
  /** The training instances */
  private Instances m_Train = null;

  /** Seed used for shuffling the dataset */
  private int m_Seed = 1;

  /** The filter used to make attributes numeric. */
  private NominalToBinary m_NominalToBinary;

  /** The filter used to get rid of missing values. */
  private ReplaceMissingValues m_ReplaceMissingValues;

  /**
   * Returns a string describing this classifier
   * @return a description of the classifier suitable for
   * displaying in the explorer/experimenter gui
   */
  public String globalInfo() {
    return "Implementation of the voted perceptron algorithm by Freund and "
      +"Schapire. Globally replaces all missing values, and transforms "
      +"nominal attributes into binary ones. For more information, see:\n\n"
      +"Y. Freund and R. E. Schapire (1998). Large margin "
      +"classification using the perceptron algorithm.  Proc. 11th "
      +"Annu. Conf. on Comput. Learning Theory, pp. 209-217, ACM Press, New "
      +"York, NY.";
  }

  /**
   * Returns an enumeration describing the available options.
   *
   * @return an enumeration of all the available options.
   */
  public Enumeration listOptions() {

    Vector newVector = new Vector(4);

    newVector.addElement(new Option("\tThe number of iterations to be performed.\n"
				    + "\t(default 1)",
				    "I", 1, "-I <int>"));
    newVector.addElement(new Option("\tThe exponent for the polynomial kernel.\n"
				    + "\t(default 1)",
				    "E", 1, "-E <double>"));
    newVector.addElement(new Option("\tThe seed for the random number generation.\n"
				    + "\t(default 1)",
				    "S", 1, "-S <int>"));
    newVector.addElement(new Option("\tThe maximum number of alterations allowed.\n"
				    + "\t(default 10000)",
				    "M", 1, "-M <int>"));

    return newVector.elements();
  }

  /**
   * Parses a given list of options. Valid options are:<p>
   *
   * -I num <br>
   * The number of iterations to be performed. (default 1)<p>
   *
   * -E num <br>
   * The exponent for the polynomial kernel. (default 1)<p>
   *
   * -S num <br>
   * The seed for the random number generator. (default 1)<p>
   *
   * -M num <br>
   * The maximum number of alterations allowed. (default 10000) <p>
   *
   * @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 {
    
    String iterationsString = Utils.getOption('I', options);
    if (iterationsString.length() != 0) {
      m_NumIterations = Integer.parseInt(iterationsString);
    } else {
      m_NumIterations = 1;
    }
    String exponentsString = Utils.getOption('E', options);
    if (exponentsString.length() != 0) {
      m_Exponent = (new Double(exponentsString)).doubleValue();
    } else {
      m_Exponent = 1.0;
    }
    String seedString = Utils.getOption('S', options);
    if (seedString.length() != 0) {
      m_Seed = Integer.parseInt(seedString);
    } else {
      m_Seed = 1;
    }
    String alterationsString = Utils.getOption('M', options);
    if (alterationsString.length() != 0) {
      m_MaxK = Integer.parseInt(alterationsString);
    } else {
      m_MaxK = 10000;
    }
  }

  /**
   * Gets the current settings of the classifier.
   *
   * @return an array of strings suitable for passing to setOptions
   */
  public String[] getOptions() {

    String[] options = new String [8];
    int current = 0;

    options[current++] = "-I"; options[current++] = "" + m_NumIterations;
    options[current++] = "-E"; options[current++] = "" + m_Exponent;
    options[current++] = "-S"; options[current++] = "" + m_Seed;
    options[current++] = "-M"; options[current++] = "" + m_MaxK;
    while (current < options.length) {
      options[current++] = "";
    }
    return options;
  }

  /**
   * Builds the ensemble of perceptrons.
   *
   * @exception Exception if something goes wrong during building
   */
  public void buildClassifier(Instances insts) throws Exception {
 
    if (insts.checkForStringAttributes()) {
      throw new UnsupportedAttributeTypeException("Cannot handle string attributes!");
    }
    if (insts.numClasses() > 2) {
      throw new Exception("Can only handle two-class datasets!");
    }
    if (insts.classAttribute().isNumeric()) {
      throw new UnsupportedClassTypeException("Can't handle a numeric class!");
    }

    // Filter data
    m_Train = new Instances(insts);
    m_Train.deleteWithMissingClass();
    m_ReplaceMissingValues = new ReplaceMissingValues();
    m_ReplaceMissingValues.setInputFormat(m_Train);
    m_Train = Filter.useFilter(m_Train, m_ReplaceMissingValues);
    
    m_NominalToBinary = new NominalToBinary();
    m_NominalToBinary.setInputFormat(m_Train);
    m_Train = Filter.useFilter(m_Train, m_NominalToBinary);

    /** Randomize training data */
    m_Train.randomize(new Random(m_Seed));

    /** Make space to store perceptrons */
    m_Additions = new int[m_MaxK + 1];
    m_IsAddition = new boolean[m_MaxK + 1];
    m_Weights = new int[m_MaxK + 1];

    /** Compute perceptrons */
    m_K = 0;
  out:
    for (int it = 0; it < m_NumIterations; it++) {
      for (int i = 0; i < m_Train.numInstances(); i++) {
	Instance inst = m_Train.instance(i);
	if (!inst.classIsMissing()) {
	  int prediction = makePrediction(m_K, inst);
	  int classValue = (int) inst.classValue();
	  if (prediction == classValue) {
	    m_Weights[m_K]++;
	  } else {
	    m_IsAddition[m_K] = (classValue == 1);
	    m_Additions[m_K] = i;
	    m_K++;
	    m_Weights[m_K]++;
	  }
	  if (m_K == m_MaxK) {
	    break out;
	  }
	}
      }
    }
  }

  /**
   * Outputs the distribution for the given output.
   *
   * Pipes output of SVM through sigmoid function.
   * @param inst the instance for which distribution is to be computed
   * @return the distribution
   * @exception Exception if something goes wrong
   */
  public double[] distributionForInstance(Instance inst) throws Exception {

    // Filter instance
    m_ReplaceMissingValues.input(inst);
    m_ReplaceMissingValues.batchFinished();
    inst = m_ReplaceMissingValues.output();

    m_NominalToBinary.input(inst);
    m_NominalToBinary.batchFinished();
    inst = m_NominalToBinary.output();
    
    // Get probabilities
    double output = 0, sumSoFar = 0;
    if (m_K > 0) {
      for (int i = 0; i <= m_K; i++) {
	if (sumSoFar < 0) {
	  output -= m_Weights[i];
	} else {
	  output += m_Weights[i];
	}
	if (m_IsAddition[i]) {
	  sumSoFar += innerProduct(m_Train.instance(m_Additions[i]), inst);
	} else {
	  sumSoFar -= innerProduct(m_Train.instance(m_Additions[i]), inst);
	}
      }
    }
    double[] result = new double[2];
    result[1] = 1 / (1 + Math.exp(-output));
    result[0] = 1 - result[1];

    return result;
  }

  /**
   * Returns textual description of classifier.
   */
  public String toString() {

    return "VotedPerceptron: Number of perceptrons=" + m_K;
  }
 
  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String maxKTipText() {
    return "The maximum number of alterations to the perceptron.";
  }

  /**
   * Get the value of maxK.
   *
   * @return Value of maxK.
   */
  public int getMaxK() {
    
    return m_MaxK;
  }
  
  /**
   * Set the value of maxK.
   *
   * @param v  Value to assign to maxK.
   */
  public void setMaxK(int v) {
    
    m_MaxK = v;
  }
  
  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String numIterationsTipText() {
    return "Number of iterations to be performed.";
  }

  /**
   * Get the value of NumIterations.
   *
   * @return Value of NumIterations.
   */
  public int getNumIterations() {
    
    return m_NumIterations;
  }
  
  /**
   * Set the value of NumIterations.
   *
   * @param v  Value to assign to NumIterations.
   */
  public void setNumIterations(int v) {
    
    m_NumIterations = v;
  }

  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String exponentTipText() {
    return "Exponent for the polynomial kernel.";
  }

  /**
   * Get the value of exponent.
   *
   * @return Value of exponent.
   */
  public double getExponent() {
    
    return m_Exponent;
  }
  
  /**
   * Set the value of exponent.
   *
   * @param v  Value to assign to exponent.
   */
  public void setExponent(double v) {
    
    m_Exponent = v;
  }
  
  /**
   * Returns the tip text for this property
   * @return tip text for this property suitable for
   * displaying in the explorer/experimenter gui
   */
  public String seedTipText() {
    return "Seed for the random number generator.";
  }

  /**
   * Get the value of Seed.
   *
   * @return Value of Seed.
   */
  public int getSeed() {
    
    return m_Seed;
  }
  
  /**
   * Set the value of Seed.
   *
   * @param v  Value to assign to Seed.
   */
  public void setSeed(int v) {
    
    m_Seed = v;
  }

  /** 
   * Computes the inner product of two instances
   */
  private double innerProduct(Instance i1, Instance i2) throws Exception {

    // we can do a fast dot product
    double result = 0;
    int n1 = i1.numValues(); int n2 = i2.numValues();
    int classIndex = m_Train.classIndex();
    for (int p1 = 0, p2 = 0; p1 < n1 && p2 < n2;) {
        int ind1 = i1.index(p1);
        int ind2 = i2.index(p2);
        if (ind1 == ind2) {
            if (ind1 != classIndex) {
                result += i1.valueSparse(p1) *
                          i2.valueSparse(p2);
            }
            p1++; p2++;
        } else if (ind1 > ind2) {
            p2++;
        } else {
            p1++;
        }
    }
    result += 1.0;
    
    if (m_Exponent != 1) {
      return Math.pow(result, m_Exponent);
    } else {
      return result;
    }
  }

  /** 
   * Compute a prediction from a perceptron
   */
  private int makePrediction(int k, Instance inst) throws Exception {

    double result = 0;
    for (int i = 0; i < k; i++) {
      if (m_IsAddition[i]) {
	result += innerProduct(m_Train.instance(m_Additions[i]), inst);
      } else {
	result -= innerProduct(m_Train.instance(m_Additions[i]), inst);
      }
    }
    if (result < 0) {
      return 0;
    } else {
      return 1;
    }
  }

  /**
   * Main method.
   */
  public static void main(String[] argv) {
    
    try {
      System.out.println(Evaluation.evaluateModel(new VotedPerceptron(), argv));
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }
}
    
  

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本一区二区三区四区 | 日韩亚洲欧美中文三级| 日韩一区二区在线观看视频| 精品国产在天天线2019| 亚洲欧洲av一区二区三区久久| 一区二区三区美女| 久久99精品国产.久久久久| 粗大黑人巨茎大战欧美成人| 欧美亚洲另类激情小说| 久久免费午夜影院| 亚洲乱码国产乱码精品精可以看| 日本91福利区| www..com久久爱| 制服视频三区第一页精品| 国产午夜亚洲精品午夜鲁丝片| 一区二区三区四区在线| 黄页网站大全一区二区| 色天使久久综合网天天| 久久久久久日产精品| 亚洲一区二区在线免费看| 久久国产麻豆精品| 欧美系列在线观看| 国产亚洲短视频| 视频精品一区二区| 成人性生交大片免费看视频在线| 欧美高清一级片在线| 国产精品天天看| 老司机免费视频一区二区三区| 色综合天天在线| 久久久久国产精品厨房| 午夜久久久影院| 91亚洲国产成人精品一区二区三 | 日韩中文字幕亚洲一区二区va在线| 国产成人在线网站| 3d动漫精品啪啪| 亚洲欧美一区二区三区久本道91| 久久99国产精品久久99 | 久久国产欧美日韩精品| 欧美色综合网站| 1000精品久久久久久久久| 国产麻豆9l精品三级站| 日韩写真欧美这视频| 亚洲最新视频在线观看| 国产成人av一区二区| 精品国产乱码久久久久久久| 日韩专区在线视频| 欧美日韩在线播放一区| 亚洲精品成人在线| 91在线观看一区二区| 国产亚洲精品福利| 国产一区二区网址| 精品成人一区二区三区四区| 视频在线观看一区二区三区| 欧美无砖专区一中文字| 一区二区三区四区在线播放| 99re66热这里只有精品3直播| 国产精品乱码一区二三区小蝌蚪| 国模无码大尺度一区二区三区| 日韩欧美一区电影| 日本美女一区二区三区视频| 欧美精品一二三| 亚洲一本大道在线| 欧美在线免费视屏| 亚洲激情图片小说视频| 色94色欧美sute亚洲线路一久| 亚洲欧美在线高清| 91日韩一区二区三区| 亚洲欧美乱综合| 欧美在线一二三四区| 亚洲妇熟xx妇色黄| 欧美日韩精品一区二区| 舔着乳尖日韩一区| 91精品国产高清一区二区三区蜜臀| 亚洲国产一区二区三区| 欧美日精品一区视频| 亚洲不卡在线观看| 欧美一级黄色录像| 久久精品国产亚洲一区二区三区| 精品国产91亚洲一区二区三区婷婷 | 久久91精品久久久久久秒播| 欧美大片在线观看一区二区| 久久精品噜噜噜成人av农村| 久久综合久久综合久久| 国产成人免费在线观看不卡| 国产精品色噜噜| 99re成人精品视频| 亚洲无人区一区| 欧美一级一级性生活免费录像| 久久成人综合网| 国产香蕉久久精品综合网| 99久久99久久精品免费看蜜桃| 亚洲狠狠丁香婷婷综合久久久| 欧美日韩色一区| 奇米色一区二区| 国产欧美日韩三区| 91免费在线播放| 午夜精品视频在线观看| 2021国产精品久久精品| 成人av资源网站| 亚洲成av人影院| 久久影视一区二区| 91在线码无精品| 日韩制服丝袜av| 国产欧美日韩三级| 欧美日韩一级大片网址| 久久www免费人成看片高清| 国产精品久久三区| 在线不卡免费欧美| 成人小视频在线| 亚洲mv在线观看| 国产三级一区二区| 欧美在线啊v一区| 国产一区二区福利视频| 有码一区二区三区| www国产精品av| 色婷婷国产精品| 精品一区二区免费| 亚洲免费观看高清| 精品国产免费久久| 色婷婷国产精品综合在线观看| 久久精品99国产精品| 亚洲天堂久久久久久久| 日韩欧美中文字幕制服| 99re热这里只有精品视频| 久久99精品久久久久久国产越南 | 一本大道久久a久久综合| 麻豆国产精品一区二区三区 | 色呦呦国产精品| 精品制服美女久久| 亚洲一级二级在线| 久久精品一区二区| 在线不卡欧美精品一区二区三区| 粉嫩欧美一区二区三区高清影视 | 欧美大胆一级视频| 色综合亚洲欧洲| 国产精品中文字幕欧美| 亚洲一区电影777| 国产精品三级av| 日韩视频在线永久播放| 在线视频欧美精品| 大美女一区二区三区| 美女网站在线免费欧美精品| 亚洲最新视频在线播放| 国产精品久久夜| 久久综合成人精品亚洲另类欧美 | 蜜桃精品视频在线观看| 亚洲综合av网| 国产精品初高中害羞小美女文 | 丁香天五香天堂综合| 奇米777欧美一区二区| 亚洲综合丝袜美腿| 中文字幕一区二区日韩精品绯色| 久久综合九色综合欧美就去吻 | 国产福利精品导航| 久久精品999| 免费成人在线观看| 五月激情丁香一区二区三区| 亚洲黄色片在线观看| 国产精品国产a级| 久久精品视频一区二区三区| 91精品国产品国语在线不卡| 欧美日韩一区视频| 欧美天天综合网| 欧美影院一区二区| 一本高清dvd不卡在线观看 | 亚洲一二三四区| 亚洲人123区| 亚洲女同ⅹxx女同tv| 亚洲欧美一区二区在线观看| 国产精品丝袜久久久久久app| 久久久噜噜噜久久中文字幕色伊伊 | 国产精品国产三级国产三级人妇 | 色综合av在线| 色婷婷精品大在线视频| 一本久久a久久免费精品不卡| 色综合天天综合色综合av| 91在线视频播放地址| 91首页免费视频| 色综合久久中文综合久久牛| 99久久精品国产导航| 99精品久久只有精品| 91一区二区在线| 欧美伊人久久大香线蕉综合69| 色综合久久88色综合天天6 | 日韩电影一区二区三区四区| 日精品一区二区| 久久精品久久精品| 韩日精品视频一区| 丰满放荡岳乱妇91ww| 99精品久久久久久| 欧美亚洲动漫精品| 欧美人与禽zozo性伦| 欧美大片一区二区三区| 国产亚洲欧美日韩俺去了| 国产精品全国免费观看高清 | 欧美系列亚洲系列| 91精品国产高清一区二区三区蜜臀| 日韩亚洲欧美一区| 国产欧美日韩视频在线观看| 中文字幕日韩av资源站|