clear
if ~exist('experimentNo') experimentNo = 5; end
if ~exist('index') index =2; end
randn('seed', 1e5);
rand('seed', 1e5);
[~, lbls] = lvmLoadData('cmu16Jog');
seq = cumsum(sum(lbls)) - [1:5];
dataSetName = 'cmu16gplvm';

% load test data
Y = lvmLoadData(dataSetName);
Ytests{1} = Y(1:seq(1),:);
for i =2:5
    Ytests{i} = Y(seq(i-1)+1:seq(i),:);
end
save('cmu16gpdmTs','Ytests');
Ytest = Ytests{index};% for one test
% save('cmu16JogTs','Ytest');
dt=0.05;
timeStampsTest = ([0:size(Ytest,1)-1].*dt)';

% load data
dataSetName = 'cmu35gplvm';
load([dataSetName 'Jog']);
origBias = mean(Y);
origScale = 1./sqrt(var(Y));

% load trained model
dataSetName = 'cmu35gplvm';
capName = dataSetName;
capName(1) = upper(capName(1));
fileName=['dem' capName 'Varmgplvm' num2str(experimentNo)];
load(fileName); % From demCmu35gplvmVargplvm1.m
fprintf(1,'# Loaded %s\n',fileName);
% experimentNo = 15;

% Indices associated with left leg.
legInd = [8:14];
% Indices associated with upper body.
bodyInd = [21:50];



if isfield(model, 'dynamics') & ~isempty(model.dynamics)
    fprintf(1,'# Dynamics kernel:');
    kernDisplay(model.dynamics.kern);
    model.dynamics.t_star = timeStampsTest;
    kernName = model.dynamics.kern.comp{1}.type;
else
    kernName = 'static';
end
fprintf(1,'# experimentNo=%d\n',experimentNo);
fprintf(1,'# Reconstruction Iters=%d\n',model.reconstrIters);

model.reconstrIters = 2000; %%%TEMP

experimentNo = experimentNo*10+index;
% legInd=[1:50];
startInd = 1;%fix(size(Ytest,1)/2);
LegErrs = vargplvmTaylorAngleErrors(model, Y, Ytest, startInd, origBias, origScale, legInd, [dataSetName ...
    'Leg'], experimentNo);
LegErrs
BodyErrs = vargplvmTaylorAngleErrors(model, Y, Ytest, startInd, origBias, origScale, bodyInd, [dataSetName ...
    'Body'],  experimentNo);

BodyErrs
fileName=['dem' capName 'Varmgplvm' num2str(experimentNo)];
save([fileName 'results.mat'], 'LegErrs','BodyErrs');


%----





% bodyErrs = vargplvmTaylorAngleErrors(model, Y, Ytest, startInd, origBias, origScale, bodyInd, [dataSetName ...
%     'Body'], experimentNo);
% 
% save(['dem' capName 'ReconstructBody' num2str(experimentNo) '.mat'], 'bodyErrs');
% 
% 
% figPath = ['Results/CMU/' num2str(experimentNo) kernName '/Body/'];
% try
%     saveAllOpenFigures(figPath, [],1)
% catch 
%     %
% end
% 
% %----
% bodyErrs

% bar(model.kern.comp{1}.inputScales)


%end


