Darwin
1.10(beta)
|
The matlab project implements mex
interfaces to various components of the Darwin library. A number of Matlab scripts (in src/scripts
) also facilitate interoperating with Darwin from Matlab. The Matlab routines are:
mexAnalyseClassifier
: analyse the performance of a classifier mexDarwinTest
: test Darwin libraries from Matlab mexEvalClassifier
: run a previously trained classifier on some new data mexFactorGraphInference
: perform graphical model inference mexImageCRF
: perform CRF-based pixel labeling on an image mexKMeans
: run (weighted) k-means on a given dataset mexLearnClassifier
: learn a classifier from training data mexLoadSuperpixels
: loads superpixels from a previously saved drwnSuperpixelContainer object mexMaxFlow
: find the maximum flow through a weighted directed graph mexQPSolver
: solve a quadratic program using Darwin's QP solver mexSaveSuperpixels
: saves superpixels to a drwnSuperpixelContainer object mexLoadPatchMatchGraph
: load a drwnPatchMatchGraph object (see PatchMatchGraph Project)drwnCombineImages
: combines multiple images into a single big image drwnLoadDataset
: loads a drwnDataset object drwnSaveDataset
: saves a drwnDataset objectThe remainder of this document describes how to compile the mex
interfaces and provides some example uses. Pre-compiled mex
files can be downloaded from Code Downloads. Additional examples can be found in the projects/matlab/examples
directory.
external
directory, e.g., "make drwnprojs"
projects/matlab
directory and execute buildLinux
sudo
) privileges."mex -setup"
) projects\matlab
directory buildWindows
external
directory, e.g., "make drwnprojs"
projects/matlab
directory and execute buildMacOSX
The full suite of Darwin classifiers can be trained and evaluated from Matlab. The following example shows how to train a multi-class logistic classifier (drwnMultiClassLogistic) and then evaluate it (on the training set!).
The classifier is stored as an XML string and can be saved for later use. Sometimes it is useful to weight the training examples differently, e.g., so that every class contributes the same mass to the classifier. The following code snippet shows an example:
Sometimes it helps to normalize features to have zero mean and unit variance before training classifiers. You can do this automatically using the 'whiten'
option. The normalization parameters are stored with the classifier and will be applied automatically when invoking the the mexEvaluateClassifier
function.
If instead of learning a multi-class logistic classifier (drwnMultiClassLogistic) you want to learn a decision tree classifier (drwnDecisionTree) you can simply change the 'method'
option. The 'set'
option allows you to configure the internal parameters of the decision tree as the following code snippet shows:
In order to perform inference in a graphical model we need to define the universe of variables and a factor graph over which inference will be performed. The universe is defined by a vector specifying the cardinality of each variable. For example,
Defines a universe over three random variables, say, A, B, and C. The first random variable, A, is ternary, while the remaining two are binary.
Next we need to define a factor graph, which is a structure array that specifies the set of variables in each factor and the value of the factor for every possible assignment to it's variables. The following provides an example factor graph with two (random) factors defined over variables (A, B) and (B, C), respectively.
This defines the energy function . Darwin will try to minimize this energy function during inference.
We can now run inference (energy minimization) over the factor graph. For example, to run max-product inference and display the resulting MAP assignment we have
Suppose that we wish to implement a Markov chain over variables to
where we want the labels in the chain to be monotonically non-decreasing. The following code shows how this can be achieved.
The mexMaxFlow
function provides code for computing the minimum-cut in a directed weighted graph (see Max-flow/Min-cut).
The following example shows how to find the value of the minimum cut on a simple graph from Matlab.
The mexKMeans
function provides and interface to Darwin's fast k-means code. An example usage is given below.