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

📄 maxentclassifierfactory.java

📁 Standord Classifier实现了一个基于Java的最大熵分类器。用于模式识别
💻 JAVA
字号:
package edu.stanford.nlp.classify;import java.util.*;import edu.stanford.nlp.util.*;import edu.stanford.nlp.optimization.*;/** @author Dan Klein */public class MaxentClassifierFactory extends AbstractLinearClassifierFactory {  double TOL = 1e-4;  double sigma = 1.0;  boolean verbose = false;  public double[][] trainWeights(int[][] data, int[] labels) {    Minimizer minimizer = new CGMinimizer(!verbose);    DiffFunction objective = new LogConditionalObjectiveFunction(numFeatures(), numClasses(), data, labels, sigma);    double[] weights = minimizer.minimize(objective, TOL, ((HasInitial)objective).initial());    //System.err.println("Final derivative norm2: "+((AbstractCachingDiffFunction)objective).norm2(((AbstractCachingDiffFunction)objective).derivative));    return ((LogConditionalObjectiveFunction)objective).to2D(weights);  }  /** Set the smoothing amount: 1.0 is the default. */  public void setSigma(double sigma) {    this.sigma = sigma;  }  public void setTol(double tol) {    TOL = tol;  }  public void setVerbose(boolean verbose) {    this.verbose = verbose;  }}

⌨️ 快捷键说明

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