public abstract 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.
Modifier and Type | Class and Description |
---|---|
static class |
Maxent.Binomial
Binomial maximum entropy classifier.
|
static class |
Maxent.Multinomial
Multinomial maximum entropy classifier.
|
Constructor and Description |
---|
Maxent(int p,
double L,
double lambda,
smile.util.IntSet labels)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
double |
AIC()
Returns the AIC score.
|
static Maxent.Binomial |
binomial(int p,
int[][] x,
int[] y)
Learn maximum entropy classifier.
|
static Maxent.Binomial |
binomial(int p,
int[][] x,
int[] y,
double lambda,
double tol,
int maxIter)
Learn maximum entropy classifier.
|
static Maxent.Binomial |
binomial(int p,
int[][] x,
int[] y,
java.util.Properties prop)
Learn maximum entropy classifier.
|
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.
|
static Maxent.Multinomial |
multinomial(int p,
int[][] x,
int[] y)
Learn maximum entropy classifier.
|
static Maxent.Multinomial |
multinomial(int p,
int[][] x,
int[] y,
double lambda,
double tol,
int maxIter)
Learn maximum entropy classifier.
|
static Maxent.Multinomial |
multinomial(int p,
int[][] x,
int[] y,
java.util.Properties prop)
Learn maximum entropy classifier.
|
void |
setLearningRate(double rate)
Sets the learning rate of stochastic gradient descent.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
predict
update, update
applyAsDouble, applyAsInt, f, predict, predict
public Maxent(int p, double L, double lambda, smile.util.IntSet labels)
p
- the dimension of input data.L
- the log-likelihood of learned model.lambda
- λ > 0 gives a "regularized" estimate of linear
weights which often has superior generalization performance,
especially when the dimensionality is high.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 static Maxent.Binomial binomial(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.Binomial binomial(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.Binomial binomial(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 static Maxent.Multinomial multinomial(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.Multinomial multinomial(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.Multinomial multinomial(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 setLearningRate(double rate)
rate
- the learning rate.public double getLearningRate()
public double loglikelihood()
public double AIC()