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
executable file 43 lines (41 sloc) 1.19 KB
function [feature, normalize_ratio]= normalize_feature(feature,normalize_ratio)
%
% Ratio = 0
% normalize each dimension of the feature seperately for L2 regularized
% logistic regression.
% Record the parameter of each dimension in the global variable.
% given normalize_ratio
% compute normalized feature according to ratio
%
num_dim = size(feature,2);
% compute and record ratio and normalized feature
if nargin ==1
normalize_ratio = zeros(num_dim,2);
for i = 1 : num_dim
fprintf('normalize for dimention %d. \n', i);
v = feature(:,i);
v_min = min(v);
v_max = max(v);
if v_max - v_min ~=0
v_new = (v - v_min)/(v_max - v_min);
else
v_new = v;
end
% normalized feature
feature(:,i) = v_new;
% normalize ratio
normalize_ratio(i,:) = [v_min v_max];
end
% compute normalized feature
elseif nargin ==2
for i = 1 : num_dim
v_min = normalize_ratio(i,1);
v_max = normalize_ratio(i,2);
if v_max - v_min ~=0
feature(:,i) = (feature(:,i) - v_min)./(v_max - v_min);
else
feature(:,i) = feature(:,i);
end
end
end
end