function [ result_1] = SVM_ensembler( result_vector_1,result_vector_2,train_data_matrix,test_data_vector,label_vector ,ith_test_object,number_of_train_imgs_per_class)
%
% basic two result svm ensembler
% written by Sudarshan.b
% http://sudarshan1994.weebly.com/
% --------What it does---------------------------------------------------
% The code tries to ensemble results from two different learning models run on the same test data
% The learning models can be based on any learning algorithm.
% But it works well on learners that exploit subspace property in data
% The ensembling of these two learning models is to be done by SVM
% It is important to note that here SVM is not the classifier but an ensembler
% --------INPUTS---------------------------------------------------------
% result_vector_1                   -the results from the learning model-1
% result_vector_2                   -the results from the learning model-2
% result_vector_1 & result_vector_2 -both have numbers as labels 
% train_data_matrix                 -training matrix on which the two learning models worked on
% test_data_vector                  -testing vector coressponds to the feature vector of the test object.
% NOTE- each test object can be represented by a vector.
% when there are several test objects then these vectors are concatenated to form the test matrix.
% hence the term test data matrix is used.
% ith_test_object                   -
% label_vector                      -labels involving different training objects is given here 
% number_of_train_imgs_per_class    -number of training images per class 
% This method assumes that each class is trained with the same number of samples
%--------Outputs----------------------------------------------------------
% result                            -ensembled result
--------------------------------------------------------------------------
%   Detailed explanation goes here
[nr,nc]=size(train_data_matrix);
%initialisation
 train_matrix_of_ith_iteration=[];
 %from line 29 to 47 we code is written to obtain the trainnig images
 %coressponding to the classes predicted by learners 1 & 2
 %we also obtain the required labels for the trainning samples 
        if(result_vector_1(ith_test_object)==result_vector_2(ith_test_object))%it is checked if the results produced by both the learners are the same
            result_1=result_vector_1(ith_test_object)
        else
            if(result_vector_1(ith_test_object)==0)%some learners like the sparse representation learners have self validation ability due to which they can output 0, which means the test object does not belong to any of teh classes the algorithm has been trained with
                train_matrix_of_class_1=[];
                result_1=result_vector_2(ith_test_object)
            else
                train_imgs_of_a_class_1=[(((result_vector_1(ith_test_object)-1)*number_of_train_imgs_per_class)+1):(result_vector_1(ith_test_object)*number_of_train_imgs_per_class)] % based on the result given by learner-1 the training images coressponding to that class is loaded into train_imgs_of_a_class_1 
                [train_matrix_of_class_1,required_label_vector_1]=get_required_feature_matrix(train_data_matrix,label_vector,train_imgs_of_a_class_1); % the coressponding feaure vectors to the training images loaded is obtained from teh train data matrix
            end
            %the same operations done on result 1 is now done for result to obtain the the correct training sample that correspond to the class predicted by learner 2      
            if(result_vector_2(ith_test_object)==0)
                train_matrix_of_class_2=[];
                result_1=result_vector_1(ith_test_object)
            else
                train_imgs_of_a_class_2=[(((result_vector_2(ith_test_object)-1)*number_of_train_imgs_per_class)+1):(result_vector_2(ith_test_object)*number_of_train_imgs_per_class)];
                [train_matrix_of_class_2,required_label_vector_2]=get_required_feature_matrix(train_data_matrix,label_vector,train_imgs_of_a_class_2)
            end       
            %now that we have training sample for the classes predicted by both the learners
            %we train a svm model with these training samples
            if((result_vector_1(ith_test_object)>0)&&(result_vector_2(ith_test_object)>0))
                required_label_vector=[required_label_vector_1,required_label_vector_2];
                train_matrix_of_ith_iteration=[ train_matrix_of_class_1,train_matrix_of_class_2]
                %required_rows=[1:nr];
                train_matrix_with_required_rows=train_matrix_of_ith_iteration %get_required_rows(train_matrix_of_ith_iteration,required_rows);
                %test_data_vector_for_ith_image=get_required_feature_matrix(test_data_vector,label_vector,ith_test_object);
                test_data_vector_for_ith_image_with_required_rows=test_data_vector%test_data_vector_for_ith_image%get_required_rows(test_data_vector_for_ith_image,required_rows);
                %size(train_matrix_with_required_rows);
                %size(test_data_vector_for_ith_image_with_required_rows);
                result_1=two_variable_svm_classifier(train_matrix_with_required_rows,test_data_vector_for_ith_image_with_required_rows,required_label_vector)
            end
           %}
        end
    end
