function PROCEDURE_CalculateDetectorOutputsForAppearanceAndContext
%function PROCEDURE_CalculateDetectorOutputsForAppearanceAndContext
%
%intent:  apply modelst ot training data to get appearance and context results.  These results will be used
%  to show that context can be used to assist in detection.

ons{1} = 'car';
ons{2} = 'pedestrian';
ons{3} = 'bicycle';
ons{4} = 'sidewalk';
ons{5} = 'store';

AppearanceDataFilename = GetAppearanceDataFilename;
AppearanceModelFilename = GetAppearanceModelFilename;

tic
%for i = 1:4
for i = 1:3
   fprintf('obj = %s\n', ons{i});
   load(AppearanceDataFilename{i});%-->X,y,N,ExtractedLocations,resolution,HelpTextInfo
   load(AppearanceModelFilename{i});%-->CVstats, Model, pTrain, traindatafilename, HelpTextInfo
   [Appearance.yempl.(ons{i}),Appearance.yemp.(ons{i})] = CLSosusvmC(X,Model);
   Appearance.pTrain.(ons{i}) = pTrain;
   Appearance.pTest.(ons{i}) = setdiff(1:length(y), pTrain);
   Appearance.ytrue.(ons{i}) = y;   
   toc
end
save('AppearanceYemp5','Appearance');

ContextDataFilename = GetContextDataFilename;
ContextModelFilename = GetContextModelFilename;
tic
LearnedFields{1} = 'BTRS_POS';
LearnedFields{2} = 'ColTex_Pos';
LearnedFields{3} = 'ALL';
LearnedFields{4} = 'JustPosition';
TrueFields{1} = 'ColTex';
TrueFields{2} = 'BTRS';
for i = 1:3
   fprintf('obj = %s\n', ons{i});
   load(ContextDataFilename{i}.learned);%-->X,HelpTextInfo
   load(ContextModelFilename{i}.learned);%-->Model, N, CVstats
   X = Normalize_Mtx_Apply(X,N);
   for j = 1:4
      field = LearnedFields{j};
      fprintf('  field = %s\n', field);
      FS = FeatureSelection_1600Template(field);
      Xsub = X(find(FS),:);
      [Context.yempl.(ons{i}).(field),Context.yemp.(ons{i}).(field)] = CLSosusvmC(Xsub,Model.(field));
      toc
   end
   load(ContextDataFilename{i}.true);%-->X,HelpTextInfo
   load(ContextModelFilename{i}.true);%-->Model, N, CVstats
   X(1:1200,:) = Normalize_Mtx_Apply(X(1:1200,:),N);
   for j = 1:2
      field = TrueFields{j};
      fprintf('  field = TRUE_%s\n', field);
      FS = FeatureSelection_1600Template(field);
      Xsub = X(find(FS),:);
      [Context.yempl.(ons{i}).(['TRUE_',field]),Context.yemp.(ons{i}).(['TRUE_',field])] = CLSosusvmC(Xsub,Model.(field));
      toc   
   end   
end
save('ContextYemp5','Context');

function C = GetContextModelFilename
C{1}.learned = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_LearnedSemantic04_1200_car.mat';
C{1}.true = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_TrueSemantic_1200_car.mat';
C{2}.learned = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_LearnedSemantic04_1200_pedestrian.mat';
C{2}.true = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_TrueSemantic_1200_pedestrian.mat';
C{3}.learned = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_LearnedSemantic04_1200_bicycle.mat';
C{3}.true = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_TrueSemantic_1200_bicycle.mat';
C{4}.learned = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_LearnedSemantic04_1200_sidewalk.mat';
C{4}.true = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_TrueSemantic_1200_sidewalk.mat';
C{5}.learned = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_LearnedSemantic04_1200_store.mat';
C{5}.true = '/cbcl/scratch01/bileschi/EzContext/ContextDetector/ContextModel_TrueSemantic_1200_store.mat';


function C = GetContextDataFilename
C{1}.learned = 'ContextFeatsAtApprLocs5_car.mat';
C{1}.true = 'ContextFeatsAtApprLocs5_TrueMask_car.mat';
C{2}.learned = 'ContextFeatsAtApprLocs5_pedestrian.mat';
C{2}.true = 'ContextFeatsAtApprLocs5_TrueMask_pedestrian.mat';
C{3}.learned = 'ContextFeatsAtApprLocs5_bicycle.mat';
C{3}.true = 'ContextFeatsAtApprLocs5_TrueMask_bicycle.mat';
C{4}.learned = 'ContextFeatsAtApprLocs5_sidewalk.mat';
C{4}.true = 'ContextFeatsAtApprLocs5_TrueMask_sidewalk.mat';
C{5}.learned = 'ContextFeatsAtApprLocs5_store.mat';
C{5}.true = 'ContextFeatsAtApprLocs5_TrueMask_store.mat';

function A = GetAppearanceDataFilename;
A{1} = 'SobelAppearanceTrainData5_car.mat';
A{2} = 'SobelAppearanceTrainData5_pedestrian.mat';
A{3} = 'SobelAppearanceTrainData5_bicycle.mat';
A{4} = 'SobelAppearanceTrainData5_sidewalk.mat';
A{5} = 'SobelAppearanceTrainData5_store.mat';

function A = GetAppearanceModelFilename;
A{1} = 'ApprModel_N_CVstats5_car.mat';
A{2} = 'ApprModel_N_CVstats5_pedestrian.mat';
A{3} = 'ApprModel_N_CVstats5_bicycle.mat';
A{4} = 'ApprModel_N_CVstats5_sidewalk.mat';
A{5} = 'ApprModel_N_CVstats5_store.mat';


