Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
J. Almazan committed Mar 3, 2014
2 parents 4f0f155 + e26e392 commit 3252048
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 20 deletions.
7 changes: 4 additions & 3 deletions evaluate.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@
end

% Embed the test attributes representation (attRepreTe_emb)
mat = emb.rndmat(1:emb.M,:);
tmp = mat*data.attReprTe;
matx = emb.rndmatx(1:emb.M,:);
tmp = matx*data.attReprTe;
attReprTe_emb = 1/sqrt(emb.M) * [ cos(tmp); sin(tmp)];
attReprTe_emb = bsxfun(@minus, attReprTe_emb, emb.matts);
attReprTe_emb = emb.Wx(:,1:emb.K)' * attReprTe_emb;
attReprTe_emb = (bsxfun(@rdivide, attReprTe_emb, sqrt(sum(attReprTe_emb.*attReprTe_emb))));

% Embed the dictionary
phocs = single(lexicon.phocs);
tmp = mat*phocs;
maty = emb.rndmaty(1:emb.M,:);
tmp = maty*phocs;
phocs_cca = 1/sqrt(emb.M) * [ cos(tmp); sin(tmp)];
phocs_cca=bsxfun(@minus, phocs_cca, emb.mphocs);
phocs_cca = emb.Wy(:,1:emb.K)' * phocs_cca;
Expand Down
4 changes: 2 additions & 2 deletions prepare_opts.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
rng('default');

% Select the dataset
opts.dataset = 'ICDAR11';
opts.dataset = 'SVT';

opts.path_datasets = 'datasets';
opts.pathDataset = sprintf('%s/%s/',opts.path_datasets,opts.dataset);
Expand Down Expand Up @@ -54,7 +54,7 @@
% Options embedding
opts.RemoveStopWords = 0;
opts.TestFV = 0;
opts.TestDirect = 1;
opts.TestDirect = 0;

opts.TestPlatts = 0;
opts.Platts.verbose = 1;
Expand Down
7 changes: 4 additions & 3 deletions util/evaluateKCCA.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
disp('*************** KCSR **************');
disp('**************************************');

mat = embedding.rndmat(1:embedding.M,:);
matx = embedding.rndmatx(1:embedding.M,:);
maty = embedding.rndmaty(1:embedding.M,:);

tmp = mat*DATA.attReprTe;
tmp = matx*DATA.attReprTe;
attReprTe_emb = 1/sqrt(embedding.M) * [ cos(tmp); sin(tmp)];
tmp = mat*DATA.phocsTe;
tmp = maty*DATA.phocsTe;
phocsTe_emb = 1/sqrt(embedding.M) * [ cos(tmp); sin(tmp)];

% Mean center
Expand Down
31 changes: 19 additions & 12 deletions util/learnKCCA.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,30 @@
bestG = opts.KCCA.G(end);
bestM = opts.KCCA.M(end);

D = size(DATA.attReprTr,1);
Dx = size(DATA.attReprTr,1);
Dy = size(DATA.phocsTr,1);
for G=opts.KCCA.G
% Create random projections matrix
RandStream.setGlobalStream(RandStream('mt19937ar','seed',0));
rndmat = normrnd(0,1/G, 2500,D);
rndmatx = normrnd(0,1/G, 2500,Dx);
rndmaty = normrnd(0,1/G, 2500,Dy);

for M=opts.KCCA.M
% Cut slice
mat = rndmat(1:M,:);
matx = rndmatx(1:M,:);
maty = rndmaty(1:M,:);

% Project attributes and phocs using the explicit exponential
% embedding. Project train, val, and test.
% train
tmp = mat*DATA.attReprTr;
tmp = matx*DATA.attReprTr;
attReprTr_emb = 1/sqrt(M) * [ cos(tmp); sin(tmp)];
tmp = mat*DATA.phocsTr;
tmp = maty*DATA.phocsTr;
phocsTr_emb = 1/sqrt(M) * [ cos(tmp); sin(tmp)];
% val
tmp = mat*DATA.attReprVa;
tmp = matx*DATA.attReprVa;
attReprVal_emb = 1/sqrt(M) * [ cos(tmp); sin(tmp)];
tmp = mat*DATA.phocsVa;
tmp = maty*DATA.phocsVa;
phocsVal_emb = 1/sqrt(M) * [ cos(tmp); sin(tmp)];

% Mean center
Expand Down Expand Up @@ -106,15 +110,17 @@

% Get random matrix
RandStream.setGlobalStream(RandStream('mt19937ar','seed',0));
rndmat = normrnd(0,1/bestG, 2500,D);
mat = rndmat(1:bestM,:);
rndmatx = normrnd(0,1/bestG, 2500,Dx);
matx = rndmatx(1:bestM,:);
rndmaty = normrnd(0,1/bestG, 2500,Dy);
maty = rndmaty(1:bestM,:);
% Embed train (full) and test
% Project attributes and phocs using the explicit exponential
% embedding. Project train, val, and test.
% train
tmp = mat*DATA.attReprTrFull;
tmp = matx*DATA.attReprTrFull;
attReprTrFull_emb = 1/sqrt(bestM) * [ cos(tmp); sin(tmp)];
tmp = mat*DATA.phocsTrFull;
tmp = maty*DATA.phocsTrFull;
phocsTrFull_emb = 1/sqrt(bestM) * [ cos(tmp); sin(tmp)];

% Mean center
Expand All @@ -133,7 +139,8 @@
embedding.K = bestK;
embedding.M = bestM;
embedding.reg = bestReg;
embedding.rndmat = rndmat;
embedding.rndmatx = rndmatx;
embedding.rndmaty = rndmaty;
embedding.matts = ma;
embedding.mphocs = mh;

Expand Down

0 comments on commit 3252048

Please sign in to comment.