Conditional Random Field (CRF) Toolbox for Matlab
Written by Kevin Murphy, 2004.
Updated by Mark Schmidt, December 2005.
This toolbox supports inference and learning for CRFs, with the following topologies: chains, 2D lattices, arbitrary graphs. It assumes all potentials are pairwise. Inference is done using belief propagation (my BPMRF2 and BPlattice code). For chains and trees, this is exact, otherwise it is approximate.
See also 1D CRFs in Java
数据挖掘交友
Download
Click here Unziping creates a directory called CRFall, which contains several subdirectories.
This code contains netlab 3.3 bundled in.
Installation
Assuming you unzip it to C:/CRFall...
>> addpath(genpath(′C:/CRFall′))
>> testCRF
This will run various simple 1D and 2D demos. Look at the source code for more details...
Documentation
The code is modelled on netlab.
Represenation
Several kinds of CRF structures are supported:
- crfchain for 1D chains (in CRF1D)
- crf2Ddemo for 2D lattices (in CRF2D)
- crf for general graphs (in CRF)
All models have potentials defined as follows: 数据挖掘工具
- For local evidence for node i in state qi:
phi{i}(qi) = exp[ sum_d w{i}(d,qi) f{i}(d) ]
数据挖掘交友
where f{i}(d) is the d′th element of the feature vector for node i and w{i}(d, qi) is the weight matrix representing the compatibility of feature d to state qi.
- For hidden edge e conecting nodes i and j in states qi, qj:
psi{e}(qi,qj) is a table.
数据挖掘交友
Note that the current implementation does not support data-dependent edge potnetials. Also, the edge potentials take O(K^2) space to represent, although they can be tied.
Inference
Currently we support the following inference engines
- BP (belief propagation), which is exact for chains and trees
- Exact-2D (by converting the 2D lattice to an HMM - this only works for small grids)
- Graph cuts: to be added.
Learning
Currently we support the following max likelihood parameter learning engines
- Various first order gradient methods : see crf2Ddemo for a list. You can extend this by modifying the switch statement in crf2DdemoTrain.
- Pseudo-likelihood: to be added.
The gradient methods use the following pieces:
- crfpack to extract all the parameters from the CRF structure into an initial parameter vector.
- crfunpack to store the final parameter vector inside the CRF structure.
- Some function to compute the gradient such as crfErrAndGrad. The ′net′ crf structure contains the name of the inference engine internally.
- Some gradient based optimizer (eg fminsearch).
Further reading