Vectorization in matlab
Some trick about how to speed up your matlab application is to use vector functionality. Reed more on the official matlab site
09.1.11Working with Cell array (matrix) of structs
After some experiment I have ONE model as the result which is represented as struct:
>>models{1}
ans =
nstates: 3
type: 'mhmm'
nmix: 1
d: 1
cov_type: 'full'
init_type: 'manual'
pi_Prior: [3x1 double]
A_Prior: [3x3 double]
pi: [3x1 double]
A: [3x3 double]
mu: [52.9712 2.1608e+003 5.4774e+004]
Sigma: [1x1x3 double]
mixmat: [3x1 double]
loglike: [1x36 double]
So, after some series of experiments I have cell array (or matrix) of structs and the best way to get some fields of each model is:
nstates = cellfun(@(x) x.nstates, models(:), 'Uniform', 1); % for uniform output
logLikes = cellfun(@(x) x.logLikes, models(:), 'Uniform', 0); % for non-Uniform output, for expl. with %different length logLikes
if we have matrix of cells: models{nRuns, nModels} than we should use repmat at the end
logLikes = cellfun(@(x) x.nstates, models(:), 'Uniform', 0);
logLikes = reshape(logLikes,nRuns,nModels);
Improve speed up for forward-backward algorithm
In the previous post we were talking about repmat function in MEX format. We can reach further improvements if replace forward-backward procedure with C implementation (MEX format). The source code for the forward-backward in C can be found in PMTK which is a collection of Matlab/Octave functions, written by Matt Dunham, Kevin Murphy.
The results see below (with the same initial conditions):

Without MEX fwdbck procudure

forward-backward MEX
| Posted in Matlab, Software | No Comments »

| Posted in Matlab | No Comments »