Permalink
Cannot retrieve contributors at this time
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?
tracking4movie/normalize_feature.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
43 lines (41 sloc)
1.19 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |