jml.classification
Class MaxEnt

java.lang.Object
  extended by jml.classification.Classifier
      extended by jml.classification.MaxEnt
All Implemented Interfaces:
java.io.Serializable

public class MaxEnt
extends Classifier

A Java implementation for the maximum entropy modeling. We aim to maximize the log-likelihood of p(y_n|x_n) for {(x_n, y_n)|n = 1, 2, ..., N}, which can be written as L(X) = sum_n [log P(y_n|x_n)] / N.

Version:
1.0, Feb. 18th, 2013
Author:
Mingjie Qian
See Also:
Serialized Form

Field Summary
private  org.apache.commons.math.linear.RealMatrix[] F
          Feature matrix array.
private static long serialVersionUID
           
 
Fields inherited from class jml.classification.Classifier
epsilon, IDLabelMap, labelIDs, labels, nClass, nExample, nFeature, W, X, Y
 
Constructor Summary
MaxEnt()
           
 
Method Summary
 void feedData(double[][][] data)
          Feed features for this maximum entropy model.
 void feedData(org.apache.commons.math.linear.RealMatrix[] F)
          Feed features for this maximum entropy model.
 void loadModel(java.lang.String filePath)
          Load the model for a classifier.
static void main(java.lang.String[] args)
           
 int[] predict(double[][][] data)
          Predict labels for the test data formated as a 3D double array.
 int[] predict(org.apache.commons.math.linear.RealMatrix[] Ft)
          Predict labels for the test data formated as a 1D RealMatrix array.
 org.apache.commons.math.linear.RealMatrix predictLabelMatrix(double[][][] data)
          Predict the label matrix given test data formated as a 3D double array.
 org.apache.commons.math.linear.RealMatrix predictLabelMatrix(org.apache.commons.math.linear.RealMatrix[] Ft)
          Predict the label matrix given test data formated as a 1D RealMatrix array.
 org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(double[][][] data)
          Predict the label score matrix given test data formated as a 3D double array.
 org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix Ft)
          Predict the label score matrix given test data formated as an original data matrix.
 org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix[] Ft)
          Predict the label score matrix given test data formated as a RealMatrix array.
 void saveModel(java.lang.String filePath)
          Save the model for a classifier.
 void train()
          Train the classifier.
 
Methods inherited from class jml.classification.Classifier
calcNumClass, feedData, feedData, feedLabels, feedLabels, feedLabels, getAccuracy, getIDLabelMap, getLabelIDMap, getProjectionMatrix, getTrainingLabelMatrix, labelIndexArray2LabelMatrix, labelScoreMatrix2LabelIndexArray, predict, predict, predictLabelMatrix, predictLabelMatrix, predictLabelScoreMatrix
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

F

private org.apache.commons.math.linear.RealMatrix[] F
Feature matrix array. F[n] is the feature matrix for the n-th sample, where F[n][i][k] is the i-th feature value on the k-th class for the n-th sample.

Constructor Detail

MaxEnt

public MaxEnt()
Method Detail

main

public static void main(java.lang.String[] args)
Parameters:
args -

feedData

public void feedData(double[][][] data)
Feed features for this maximum entropy model.

Parameters:
data - a 3D double array, where data[n][i][k] is the i-th feature value on the k-th class for the n-th sample

feedData

public void feedData(org.apache.commons.math.linear.RealMatrix[] F)
Feed features for this maximum entropy model.

Parameters:
F - a feature matrix array. F[n] is the feature matrix for the n-th sample, where F[n][i][k] is the i-th feature value on the k-th class for the n-th sample

train

public void train()
Description copied from class: Classifier
Train the classifier.

Specified by:
train in class Classifier

predict

public int[] predict(double[][][] data)
Predict labels for the test data formated as a 3D double array.

Parameters:
data - a 3D double array, where data[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted label array with original integer label code

predict

public int[] predict(org.apache.commons.math.linear.RealMatrix[] Ft)
Predict labels for the test data formated as a 1D RealMatrix array.

Parameters:
Ft - a feature matrix array. F[n] is the feature matrix for the n-th sample, where F[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted label array with original integer label code

loadModel

public void loadModel(java.lang.String filePath)
Description copied from class: Classifier
Load the model for a classifier.

Specified by:
loadModel in class Classifier
Parameters:
filePath - file path to load the model

saveModel

public void saveModel(java.lang.String filePath)
Description copied from class: Classifier
Save the model for a classifier.

Specified by:
saveModel in class Classifier
Parameters:
filePath - file path to save the model

predictLabelScoreMatrix

public org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix Ft)
Description copied from class: Classifier
Predict the label score matrix given test data formated as an original data matrix. Note that if a method of an abstract class is declared as abstract, it is implemented as an interface function in Java. Thus subclass needs to implement this abstract method rather than to override it.

Specified by:
predictLabelScoreMatrix in class Classifier
Parameters:
Ft - test data matrix with each column being a feature vector
Returns:
predicted N x K label score matrix, where N is the number of test samples, and K is the number of classes

predictLabelScoreMatrix

public org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(org.apache.commons.math.linear.RealMatrix[] Ft)
Predict the label score matrix given test data formated as a RealMatrix array.

Parameters:
Ft - a feature matrix array. F[n] is the feature matrix for the n-th sample, where F[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted N x K label score matrix, where N is the number of test examples, and K is the number of classes

predictLabelScoreMatrix

public org.apache.commons.math.linear.RealMatrix predictLabelScoreMatrix(double[][][] data)
Predict the label score matrix given test data formated as a 3D double array.

Parameters:
data - a 3D double array, where data[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted N x K label score matrix, where N is the number of test examples, and K is the number of classes

predictLabelMatrix

public org.apache.commons.math.linear.RealMatrix predictLabelMatrix(org.apache.commons.math.linear.RealMatrix[] Ft)
Predict the label matrix given test data formated as a 1D RealMatrix array.

Parameters:
Ft - a feature matrix array. F[n] is the feature matrix for the n-th sample, where F[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted N x K label matrix, where N is the number of test examples, and K is the number of classes

predictLabelMatrix

public org.apache.commons.math.linear.RealMatrix predictLabelMatrix(double[][][] data)
Predict the label matrix given test data formated as a 3D double array.

Parameters:
data - a 3D double array, where data[n][i][k] is the i-th feature value on the k-th class for the n-th sample
Returns:
predicted N x K label matrix, where N is the number of test examples, and K is the number of classes