covartech / PRT

Pattern Recognition Toolbox for MATLAB
http://covartech.github.io/
MIT License
145 stars 70 forks source link

No appropriate method, property, or field nFeatures for class prtDataSetTimeSeries #34

Closed StevenLOL closed 9 years ago

StevenLOL commented 9 years ago

HI,

I try the prtDataSetTimeSeries, then setup a HMM and start to train a model,

training = prtDataSetTimeSeries; training = training.setX(features); % ... training = training.setY(classes); training.classNames = uniqueLabels;

And found that error occurs in prtDataSetInMem.m , says

No appropriate method, property, or field nFeatures for class prtDataSetTimeSeries.

            if self.nFeatures > 0 % No data?
                self.data = self.data(indices,:);
            end

Indeed I found the self.summarize.nFeatures in this file could give some value, so is there a bug ?

In master branch, UBUNTU 14.04 , matlab2014 and matlab2012

kennethmorton commented 9 years ago

Sorry about this. Definitely a bug. I just pushed a fix. Keep in mind that the timeseries and HMM stuff is in beta. No guarantees. To validate the bug fix try this test script.

Thanks and good luck, Kenny

prtPath( 'alpha', 'beta' ); % make sure prtDataSetTimeSeries is on path

% Generate two HMMs for drawing data
% The second one has a flipped transition matrix.
A = [.9 .1 0; 0 .9 .1; .1 0 .9];
gaussians = repmat(prtRvMvn('sigma',eye(2)),3,1);
gaussians(1).mu = [-2 -2];
gaussians(2).mu = [2 -2];
gaussians(3).mu = [2 2];

sourceHmm1 = prtRvHmm('pi',[1 1 1]/3,...
    'transitionMatrix',A,...
    'components',gaussians);

sourceHmm2 = prtRvHmm('pi',[1 1 1]/3,...
    'transitionMatrix',flipud(A),...
    'components',gaussians);

% Draw data from these HMMs
nTimeSeriesPerClass = 50;
nSamplesPerTimeSeries = 100;

x = cat(1,sourceHmm1.draw(ones(1,nTimeSeriesPerClass)*nSamplesPerTimeSeries),sourceHmm2.draw(ones(1,nTimeSeriesPerClass)*nSamplesPerTimeSeries));
y = prtUtilY(nTimeSeriesPerClass,nTimeSeriesPerClass);

% Place into to a dataSetTimeSeries
ds = prtDataSetTimeSeries(x,y);
ds.classNames = {'Class A','Class flipud(A)'};

% Train a MAP classifier that uses HMMs to model each class
class = train(prtClassMap('rvs',prtRvHmm('components',repmat(prtRvMvn,3,1))),ds);

% Evaluate the classifier (Note: No cross-validation is performed here!!!
out = run(class,ds); % Note: out is a prtDataSetClass
prtScoreRoc(out)

% Plot the learned HMM parameters
figure
subplot(2,4,1)
class.rvs(1).components(1).plotPdf([-5 5 -5 5])
title('Class 1 Component 1 pdf')
subplot(2,4,2)
class.rvs(1).components(2).plotPdf([-5 5 -5 5])
title('Class 1 Component 2 pdf')
subplot(2,4,3)
class.rvs(1).components(3).plotPdf([-5 5 -5 5])
title('Class 1 Component 3 pdf')
subplot(2,4,4)
prtUtilPlotMatrixTable(class.rvs(1).transitionMatrix);
title('Class 1 Transition Matrix')

subplot(2,4,5)
class.rvs(2).components(1).plotPdf([-5 5 -5 5])
title('Class 2 Component 1 pdf')
subplot(2,4,6)
class.rvs(2).components(2).plotPdf([-5 5 -5 5])
title('Class 2 Component 2 pdf')
subplot(2,4,7)
class.rvs(2).components(3).plotPdf([-5 5 -5 5])
title('Class 2 Component 3 pdf')
subplot(2,4,8)
prtUtilPlotMatrixTable(class.rvs(2).transitionMatrix);
title('Class 2 Transition Matrix')
StevenLOL commented 9 years ago

Test script reports no problem. Thank you for the quick response.