function model = short_train(cls, n, note)
% Train a model without parts training
%   model = j_train(cls, n, note)
%
%   The model will be a mixture of n star models, each of which
%   has 2 latent orientations.
%
% Arguments
%   cls           Object class to train and evaluate
%   n             Number of aspect ratio clusters to use
%                 (The final model has 2*n components)
%   note          Save a note in the model.note field that describes this model

% At every "checkpoint" in the training process we reset the 
% RNG's seed to a fixed value so that experimental results are 
% reproducible.
seed_rand();

tic

% Default to no note
if nargin < 3
  note = 'no parts fitlers';
end

global VOC_CONFIG_OVERRIDE;
VOC_CONFIG_OVERRIDE = @kitti_voc_config_override;

conf = voc_config();

cachedir = conf.paths.model_dir;

% Load the training data
[pos, neg, impos] = kitti_data(cls, conf.pascal.year);

% keyboard

% for i=1:length(pos)
%     if 
%     
% end

% pos = pos(1:min(conf.training.maxpos,length(pos)));
% impos = impos(1:min(conf.training.maxpos,length(impos)));

% Sample the positives
% pos = pos(randi(length(pos),1,conf.training.maxpos));

% Sample the image positives
% impos = impos(randi(length(impos),1,conf.training.maxpos));

% Split foreground examples into n groups by aspect ratio
spos = split(pos, n);

max_num_examples = conf.training.cache_example_limit;
num_fp           = conf.training.wlssvm_M;
fg_overlap       = conf.training.fg_overlap;

% Select a small, random subset of negative images
% All data mining iterations use this subset, except in a final
% round of data mining where the model is exposed to all negative
% images
num_neg   = length(neg);
neg_perm  = neg(randperm(num_neg));
neg_small = neg_perm(1:min(num_neg, conf.training.num_negatives_small));
neg_large = neg; % use all of the negative images

% Train one asymmetric root filter for each aspect ratio group
% using warped positives and random negatives

try
  disp(['loading cache dir: ' cachedir cls '_lrsplit1'])
  load([cachedir cls '_lrsplit1']);
  disp('done')
catch
  disp('Training one asymmetric root filter')
  seed_rand();
  for i = 1:n
    models{i} = root_model(cls, spos{i}, note);
    % Split the i-th aspect ratio group into two clusters: 
    % left vs. right facing instances
    inds = lrsplit(models{i}, spos{i});
    
    % Train asymmetric root filter on one of these groups
    models{i} = train(models{i}, spos{i}(inds), neg_large, true, true, 1, 1, ...
                      max_num_examples, fg_overlap, 0, false, ...
                      ['lrsplit1_' num2str(i)]);
  end
  disp('save to cache')
  save([cachedir cls '_lrsplit1'], 'models');
end

for i=1:length(models)
    figure
    visualizemodel(models{i})
end

disp('Asymmetric root filters, using warped positives and random negatives')
disp('press any key to continue ...')
pause(0.5)

% Train a mixture of two root filters for each aspect ratio group
% Each pair of root filters are mirror images of each other
% and correspond to two latent orientations choices
% Training uses latent positives and hard negatives
try
  load([cachedir cls '_lrsplit2']);
catch
  seed_rand();
  for i = 1:n
    % Build a mixture of two (mirrored) root filters
    models{i} = lr_root_model(models{i});
    models{i} = train(models{i}, spos{i}, neg_small, false, false, 4, 3, ...
                      max_num_examples, fg_overlap, 0, false, ...
                      ['lrsplit2_' num2str(i)]);
  end
  save([cachedir cls '_lrsplit2'], 'models');
end

close all 

for i=1:length(models)
    figure
    visualizemodel(models{i})
end

disp('Mirror filters using latent positives and hard negatives')
disp('press any key to continue ...')
pause(0.5)


% Train a mixture model composed all of aspect ratio groups and 
% latent orientation choices using latent positives and hard negatives
try 
  load([cachedir cls '_mix']);
catch
  seed_rand();
  % Combine separate mixture models into one mixture model
  model = model_merge(models);
  disp('training with impos')
  model = train(model, impos, neg_small, false, false, 1, 5, ...
                max_num_examples, fg_overlap, num_fp, false, 'mix');
  save([cachedir cls '_mix'], 'model');
end

close all 

visualizemodel(model)

disp('Mixture model using latent positives and hard negatives')
disp('press any key to continue ...')

total_time = toc;
hours = floor(total_time/(60*60));
minutes = floor(total_time/60) - hours*60;
seconds = floor(total_time) - hours*60*60 - minutes*60;

fprintf('Training finished in %d hours %d minutes %d seconds\n',hours,minutes,seconds);
