% Generic script for training an FCRBM
%
% Version 2.0
%
% By: Omid Alemi
%
% Train a Factored Conditional RBM with real style values 
%

tic

%initialize RAND,RANDN to a different state
rand('state',sum(100*clock))
randn('state',sum(100*clock))



%downsample from 120fps
% for ii=1:length(Motion)
%     Motion{ii}=Motion{ii}(1:downsample:end,:);
%     %remember to downsample labels too
%     Labels{ii}=Labels{ii}(1:downsample:end,:);
% end

MotionData.data =  Motion;
MotionData.skel = skel;
MotionData.FEAT_DIM = [];
MotionData.mean = 0;
MotionData.std = 0;
MotionData.batchdata = [];
MotionData.minibatch = [];
MotionData.batchdataindex = [];
MotionData.dropRate=4;
MotionData.batchsize = 100;


fprintf(1,'Preprocessing data \n');


%Remove the empty or constant dimensions from the data
%MotionData = Prep_InvarRoot(MotionData);
MotionData = preprocess1(MotionData);
MotionData = Prep_RemoveEmpty(MotionData,0);
% MotionData = Prep_AddVelocity(MotionData);
MotionData = Prep_MiniBatch(MotionData,n1);
batchdata = MotionData.batchdata;
minibatch = MotionData.minibatch;

labeldata = [];
for jj=1:length(Labels)
  labeldata = [labeldata; Labels{jj}];
end


numdims = size(batchdata,2); %data (visible) dimension

%%%%%%%%%%%%%%%%%%%%%%%%%

%every xxx epochs, write a snapshot of the model
%will be written to snapshot_path_epxxx.mat
%snapshot_path = 'default' %don't overwrite our models

snapshotevery=100; %write out a snapshot of the weights every xx epochs

nt=n1;
numhid=numhid1;

fprintf(1,'Training Layer 1 FBM, order %d: %d-%d(%d) \n',nt,numdims, ...
  numhid,numfac);
restart=1;      %initialize weights

%train network with only feature-to-factor weights tied
if realfeat==1
    gaussianfbm_sharefeatfac_realfeat
else
    gaussianfbm_sharefeatfac
end

fprintf(1,'Training finished. Run demo_generate to generate data\n');

toc