|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjml.sequence.CRF
public class CRF
A Java implementation for the basic Conditional Random Field (CRF).
Field Summary | |
---|---|
(package private) int |
d
Number of parameters or number of features |
(package private) int |
D
Number of data sequences for training. |
(package private) double |
epsilon
Convergence precision. |
(package private) org.apache.commons.math.linear.RealMatrix[][][] |
Fs
A 3D RealMatrix array, where F[k][i][j] is the sparse
feature matrix for the j-th feature of the k-th observation sequence
at position i, i.e., f_{j}^{{\bf x}_k, i}. |
(package private) int |
maxIter
Maximal number of iterations. |
(package private) int |
numStates
Number of states in the state space. |
(package private) double |
sigma
Regularization parameter |
(package private) int |
startIdx
Index for the start state in the state space. |
(package private) org.apache.commons.math.linear.RealMatrix |
W
d x 1 parameter vector. |
(package private) int[][] |
Ys
A 2D integer array, where Ys[k][i] is the label index for the label of the k-th training data sequence at position i in the label space. |
Constructor Summary | |
---|---|
CRF()
Constructor for a CRF instance. |
|
CRF(double epsilon)
Constructor for a CRF instance. |
|
CRF(int d)
Constructor for a CRF instance. |
|
CRF(int d,
double epsilon)
Constructor for a CRF instance. |
Method Summary | |
---|---|
org.apache.commons.math.linear.RealMatrix |
backwardRecursion4Viterbi(org.apache.commons.math.linear.RealMatrix[] Ms)
Alternative backward recursion with scaling for the Viterbi algorithm. |
org.apache.commons.math.linear.RealMatrix |
computeFeatureVector(org.apache.commons.math.linear.RealMatrix[][] Fs,
int[] Ys)
Compute global feature vector for a data sequences Fs with label Ys. |
double |
computeObjectiveFunctionValue(boolean calcGrad,
org.apache.commons.math.linear.RealMatrix Grad,
org.apache.commons.math.linear.RealMatrix W)
Compute the objective function value (the mean log-likelihood on training data for CRFs). |
org.apache.commons.math.linear.RealMatrix[] |
computeTransitionMatrix(org.apache.commons.math.linear.RealMatrix[][] Fs)
Compute transition matrix set, i.e., {M^{\bf x}_i}, i = 1, 2, ..., n_x |
void |
feedData(org.apache.commons.math.linear.RealMatrix[][][] Fs)
Feed data sequences for training. |
void |
feedLabels(int[][] Ys)
Feed labels for training data sequences. |
static java.lang.Object[] |
generateDataSequences(int D,
int n_min,
int n_max,
int d,
int N,
double sparseness)
Generate random data sequences to train a CRF model. |
void |
loadModel(java.lang.String filePath)
Load the model from a file. |
static void |
main(java.lang.String[] args)
|
int[] |
predict(org.apache.commons.math.linear.RealMatrix[][] Fs)
Predict the single best label sequence given the features for an observation sequence by Viterbi algorithm. |
int[] |
predict2(org.apache.commons.math.linear.RealMatrix[][] Fs)
Predict the single best label sequence given the features for an observation sequence by Viterbi algorithm without normalization. |
void |
saveModel(java.lang.String filePath)
Save the model to a file. |
void |
train()
Estimate parameters for the basic CRF by a maximum conditional log-likelihood estimation principle. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
org.apache.commons.math.linear.RealMatrix[][][] Fs
RealMatrix
array, where F[k][i][j] is the sparse
feature matrix for the j-th feature of the k-th observation sequence
at position i, i.e., f_{j}^{{\bf x}_k, i}.
int D
int d
int numStates
int startIdx
int[][] Ys
org.apache.commons.math.linear.RealMatrix W
double epsilon
double sigma
int maxIter
Constructor Detail |
---|
public CRF()
public CRF(double epsilon)
epsilon
- convergence precisionpublic CRF(int d)
d
- number of feature functionspublic CRF(int d, double epsilon)
d
- number of feature functionsepsilon
- convergence precisionMethod Detail |
---|
public static void main(java.lang.String[] args)
args
- public void feedData(org.apache.commons.math.linear.RealMatrix[][][] Fs)
Fs
- a 3D RealMatrix
array, where F[k][i][j] is the sparse
feature matrix for the j-th feature of the k-th observation sequence
at position i, i.e., f_{j}^{{\bf x}_k, i}public void feedLabels(int[][] Ys)
Ys
- a 2D integer array, where Ys[k][i] is the label index for the label
of the k-th training data sequence at position i in the label spacepublic static java.lang.Object[] generateDataSequences(int D, int n_min, int n_max, int d, int N, double sparseness)
D
- number of data sequences to be generatedn_min
- minimal length for the randomly generated data sequencesn_max
- maximal length for the randomly generated data sequencesd
- number of feature functionsN
- number of statessparseness
- sparseness for the feature matrices
public void train()
public double computeObjectiveFunctionValue(boolean calcGrad, org.apache.commons.math.linear.RealMatrix Grad, org.apache.commons.math.linear.RealMatrix W)
calcGrad
- if gradient requiredGrad
- gradient to be assigned in place if requiredW
- model parameters
public int[] predict2(org.apache.commons.math.linear.RealMatrix[][] Fs)
Fs
- a 2D RealMatrix
array, where F[i][j] is the sparse
feature matrix for the j-th feature of the observation sequence
at position i, i.e., f_{j}^{{\bf x}, i}
public int[] predict(org.apache.commons.math.linear.RealMatrix[][] Fs)
Fs
- a 2D RealMatrix
array, where F[i][j] is the sparse
feature matrix for the j-th feature of the observation sequence
at position i, i.e., f_{j}^{{\bf x}, i}
public org.apache.commons.math.linear.RealMatrix[] computeTransitionMatrix(org.apache.commons.math.linear.RealMatrix[][] Fs)
Fs
- A 2D RealMatrix
array, where F[i][j] is the sparse
feature matrix for the j-th feature of the observation sequence
at position i, i.e., f_{j}^{{\bf x}, i}
public org.apache.commons.math.linear.RealMatrix computeFeatureVector(org.apache.commons.math.linear.RealMatrix[][] Fs, int[] Ys)
Fs
- a 2D RealMatrix
array, where F[i][j] is the sparse
feature matrix for the j-th feature of the observation sequence
at position i, i.e., f_{j}^{{\bf x}, i}Ys
- a 1D integer array, where Ys[i] is the label index in the label
space for the label at position i for the data sequence
public org.apache.commons.math.linear.RealMatrix backwardRecursion4Viterbi(org.apache.commons.math.linear.RealMatrix[] Ms)
Ms
- a set of transition matrices, i.e.,
{M^{\bf x}_i}, i = 1, 2, ..., n_x
public void saveModel(java.lang.String filePath)
filePath
- file path to save the modelpublic void loadModel(java.lang.String filePath)
filePath
- file Path to load the model from
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |