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 CRFbased pixel labeling on an image mexKMeans
: run (weighted) kmeans 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. Precompiled 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 multiclass 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 multiclass 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 maxproduct 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 nondecreasing. The following code shows how this can be achieved.
The mexMaxFlow
function provides code for computing the minimumcut in a directed weighted graph (see Maxflow/Mincut).
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 kmeans code. An example usage is given below.