public class Maxent extends java.lang.Object implements SoftClassifier<int[]>, OnlineClassifier<int[]>
Basically, maximum entropy classifier is another name of multinomial logistic regression applied to categorical independent variables, which are converted to binary dummy variables. Maximum entropy models are widely used in natural language processing. Here, we provide an implementation which assumes that binary features are stored in a sparse array, of which entries are the indices of nonzero features.
Constructor and Description |
---|
Maxent(double L,
double[] w)
Constructor of binary maximum entropy classifier.
|
Maxent(double L,
double[][] W)
Constructor of multi-class maximum entropy classifier.
|
Maxent(double L,
double[][] W,
smile.util.IntSet labels)
Constructor of multi-class maximum entropy classifier.
|
Maxent(double L,
double[] w,
smile.util.IntSet labels)
Constructor of binary maximum entropy classifier.
|
Modifier and Type | Method and Description |
---|---|
int |
dimension()
Returns the dimension of input space.
|
static Maxent |
fit(int p,
int[][] x,
int[] y)
Learn maximum entropy classifier.
|
static Maxent |
fit(int p,
int[][] x,
int[] y,
double lambda,
double tol,
int maxIter)
Learn maximum entropy classifier.
|
static Maxent |
fit(int p,
int[][] x,
int[] y,
java.util.Properties prop)
Learn maximum entropy classifier.
|
double |
getLearningRate()
Returns the learning rate of stochastic gradient descent.
|
double |
loglikelihood()
Returns the log-likelihood of model.
|
int |
predict(int[] x)
Predicts the class label of an instance.
|
int |
predict(int[] x,
double[] posteriori)
Predicts the class label of an instance and also calculate a posteriori
probabilities.
|
void |
setLearningRate(double rate)
Sets the learning rate of stochastic gradient descent.
|
void |
update(int[] x,
int y)
Online update the classifier with a new training instance.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
update
applyAsDouble, applyAsInt, f, predict
public Maxent(double L, double[] w)
L
- the log-likelihood of learned model.w
- the weights.public Maxent(double L, double[] w, smile.util.IntSet labels)
L
- the log-likelihood of learned model.w
- the weights.labels
- class labelspublic Maxent(double L, double[][] W)
L
- the log-likelihood of learned model.W
- the weights of first k - 1 classes.public Maxent(double L, double[][] W, smile.util.IntSet labels)
L
- the log-likelihood of learned model.W
- the weights of first k - 1 classes.labels
- class labelspublic static Maxent fit(int p, int[][] x, int[] y)
p
- the dimension of feature space.x
- training samples. Each sample is represented by a set of sparse
binary features. The features are stored in an integer array, of which
are the indices of nonzero features.y
- training labels in [0, k), where k is the number of classes.public static Maxent fit(int p, int[][] x, int[] y, java.util.Properties prop)
p
- the dimension of feature space.x
- training samples. Each sample is represented by a set of sparse
binary features. The features are stored in an integer array, of which
are the indices of nonzero features.y
- training labels in [0, k), where k is the number of classes.public static Maxent fit(int p, int[][] x, int[] y, double lambda, double tol, int maxIter)
p
- the dimension of feature space.x
- training samples. Each sample is represented by a set of sparse
binary features. The features are stored in an integer array, of which
are the indices of nonzero features.y
- training labels in [0, k), where k is the number of classes.lambda
- λ > 0 gives a "regularized" estimate of linear
weights which often has superior generalization performance, especially
when the dimensionality is high.tol
- the tolerance for stopping iterations.maxIter
- maximum number of iterations.public int dimension()
public void update(int[] x, int y)
OnlineClassifier
update
in interface OnlineClassifier<int[]>
x
- training instance.y
- training label.public void setLearningRate(double rate)
rate
- the learning rate.public double getLearningRate()
public double loglikelihood()
public int predict(int[] x)
Classifier
predict
in interface Classifier<int[]>
x
- the instance to be classified.public int predict(int[] x, double[] posteriori)
SoftClassifier
predict
in interface SoftClassifier<int[]>
x
- an instance to be classified.posteriori
- the array to store a posteriori probabilities on output.