Skip to content
This repository has been archived by the owner on Aug 24, 2021. It is now read-only.

Commit

Permalink
fixed a bug when batchSize < valid samples
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcfee committed Dec 3, 2012
1 parent 7335971 commit f113e3b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mlr_demo.m
Expand Up @@ -19,7 +19,7 @@ function mlr_demo()


% Optimize W for AUC
C = 1e2;
C = 1e-2;
display(sprintf('Training with C=%.2e, Delta=mAP', C));
[W, Xi, Diagnostics] = mlr_train(Xtrain, Ytrain, C, 'map');
% [W, Xi, Diagnostics] = mlr_train_primal(Xtrain, Ytrain, C, 'map');
Expand Down
15 changes: 11 additions & 4 deletions mlr_test.m
Expand Up @@ -37,7 +37,7 @@
Perf.dimensionality = mlr_test_dimension(W, nTrain, nKernel);
test_k = min(test_k, nTrain);

if nargin > 4
if nargin > 5
% Knock out the points with no labels
if ~iscell(Ytest)
Ibad = find(isnan(Ytrain));
Expand All @@ -48,8 +48,15 @@
[D, I] = mlr_test_distance(W, Xtrain, Xtest);
else
% Leave-one-out validation
Xtest = Xtrain;
Ytest = Ytrain;

if nargin > 4
% In this case, Xtest is a subset of training indices to test on
testRange = Xtest;
else
testRange = 1:nTrain;
end
Xtest = Xtrain(:,testRange,:);
Ytest = Ytrain(testRange);

% compute self-distance
[D, I] = mlr_test_distance(W, Xtrain, Xtest);
Expand All @@ -69,7 +76,7 @@
% We only compute KNN error if Y are labels
[Perf.KNN, Perf.KNNk] = mlr_test_knn(Labels, Ytest, test_k);
else
if nargin > 4
if nargin > 5
Agree = zeros(nTrain, nTest);
else
Agree = zeros(nTrain-1, nTest);
Expand Down
9 changes: 8 additions & 1 deletion mlr_train.m
Expand Up @@ -263,6 +263,7 @@
batchSize = varargin{5};
end
end

% Algorithm
%
% Working <- []
Expand Down Expand Up @@ -328,6 +329,10 @@
error('MLR:LABELS', 'Incorrect format for Y.');
end

%%
% If we don't have enough data to make the batch, cut the batch
batchSize = min([batchSize, length(SAMPLES)]);


Diagnostics = struct( 'loss', Loss, ... % Which loss are we optimizing?
'feature', Feature, ... % Which ranking feature is used?
Expand Down Expand Up @@ -367,7 +372,9 @@
dbprint(1, 'STOCHASTIC OPTIMIZATION: Batch size is %d/%d', batchSize, n);
end

while 1
MAXITER = 200;
% while 1
while Diagnostics.num_calls_solver < MAXITER
dbprint(1, 'Round %03d', Diagnostics.num_calls_solver);
% Generate a constraint set
Termination = 0;
Expand Down
4 changes: 4 additions & 0 deletions mlr_train_primal.m
Expand Up @@ -290,6 +290,10 @@
error('MLR:LABELS', 'Incorrect format for Y.');
end

%%
% If we don't have enough data to make the batch, cut the batch
batchSize = min([batchSize, length(SAMPLES)]);


Diagnostics = struct( 'loss', Loss, ... % Which loss are we optimizing?
'feature', Feature, ... % Which ranking feature is used?
Expand Down
1 change: 1 addition & 0 deletions util/mlr_admm.m
Expand Up @@ -162,6 +162,7 @@
% 2) solve the QP
%
alpha = qplcprog(H, b, ones(1, m), C, [], [], 0, []);
% alpha = qplcprog(H, b, [], [], ones(1, m), C, 0, []);

%%%
% 3) update the Psi clock
Expand Down

0 comments on commit f113e3b

Please sign in to comment.