Skip to content

Instantly share code, notes, and snippets.

@zhangce
Created November 1, 2016 03:28
Show Gist options
  • Save zhangce/28a355aafaf82a8c1024c1bfee7d9b22 to your computer and use it in GitHub Desktop.
Save zhangce/28a355aafaf82a8c1024c1bfee7d9b22 to your computer and use it in GitHub Desktop.
function m = SVMq(X, y, m, lr, num_range)
n_examples = size(X, 1);
n_features = size(X, 2);
num_ranges = {};
for j=1:n_features
num_ranges{j} = num_range;
end
X1 = quantize_minmaxfull(X, num_ranges);
n_fetchfull = 0;
for i=1:n_examples
label = y(i);
dot = X1(i, :) * m'; % Quantized Version
weight = abs(1-dot* label);
prob = weight/(weight + 1);
if rand() < prob % Importance Sampling --
% Give those near boundary a
% smaller probability to be
% choosen
upper = dot + sum(m(find(m>0)))/num_range;
lower = dot + sum(m(find(m<0)))/num_range;
if (1-upper*label) * (1-lower*label) < 0
% If we are not sure about
% whether quantization is
% safe
n_fetchfull = n_fetchfull + 1;
dot = X(i, :) * m';
% Fetch original data
end
if 1 - dot * label > 0
m = m + lr * label * X1(i, :) / prob;
end
end
end
n_fetchfull
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment