Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
function logistic_regression(is_train, f_p, f_n)
% train the pairwise model
% Input1: positive features: f_p
% Input2: negative features: f_n
% To Jie: you need to download liblinear to learn the logistic_regression
addpath(genpath('/BS/pedestrian-detection-tracking/work/project/3rd/liblinear-1.94/'));
if is_train == 1 % train
num_positive = size(f_p,1);
num_negative = size(f_n,1);
% normalize the features;
% To jie: f_p is the feature list for the positive examples (e.g. part field evalue of pair of detections from the same person), f_n is the feature list from the negative examples
% To jie: the features have to be normalized to 0~1
[f_normalize, normalize_ratio]= normalize_feature([f_p; f_n]);
f_p = f_normalize(1:num_positive,:);
f_n = f_normalize(1+num_positive:num_positive+num_negative,:);
label = [ones(num_positive,1); zeros(num_negative,1)];
example = sparse(double([f_p;f_n]));
% L2 regularizer and C = 1; one can do cross validation for c
% parameters
regularizer_para = 0;
c_para = 1;
% To jie: call the train function in liblinear to obtain the model
model = train(label, example, ['-s ' num2str(regularizer_para) ' -B ' num2str(1) ' -c ' num2str(c_para) ]);
model_name = 'first_model.mat';
save(model_name , 'model', 'normalize_ratio');
else %test
load('first_model.mat');
f = f_p;
f = normalize_feature(f, normalize_ratio);
f = sparse(double(f));
label = ones(size(f,1),1);
[~, ~, pro_estimate] = predict(label, f, model, '-b 1 -q');
probablity = pro_estimate(:,1);
end
end