Permalink
Browse files

bugfixes

  • Loading branch information...
1 parent ead0d35 commit b355dee990e5a011d1aceaebfc5e22ef76c804c2 @jacobeisenstein committed Apr 2, 2012
View
BIN 3rd-party/fastfit/di_pochhammer.mexglx
Binary file not shown.
View
BIN 3rd-party/fastfit/pochhammer.mexglx
Binary file not shown.
View
3 HOWTO
@@ -8,4 +8,5 @@ runLDA(5,1,500,'debug',1)
from the command line in matlab. This will run standard LDA first, then SAGE LDA. If you just want to run SAGE LDA, try:
-runLDA(5,1,500,'debug',1,'do-non-sparse',0)
+runLDA(5,1,500,'debug',1,'do-non-sparse',0)
+
View
12 estimate/computeBetaSparseVariational.m
@@ -4,7 +4,7 @@
% newton optimization, variational EM for tau.
[max_its verbose init_eta min_eta max_inv_tau] = ...
process_options(varargin,'max-its',1,...
- 'verbose',false,'init-eta',[],'min-eta',1e-20,...
+ 'verbose',0,'init-eta',[],'min-eta',1e-20,...
'max-inv-tau',1e5);
[W K] = size(ecounts); %eta = zeros(size(ecounts));
@@ -17,15 +17,17 @@
eq_inv_tau = 1./(eta.^2);
end
-if ~verbose, fprintf('.'); end
-
+if verbose==1, fprintf('.'); end
+if sum(ecounts)==0,
+ eta = zeros(W,1);
+else
em_iter = newDeltaIterator(max_its,'debug',verbose,'thresh',1e-4);
-
exp_eq_m = exp(eq_m);
while ~(em_iter.done)
- eta = newtonArmijo(@evalLogNormal,eta,{ecounts,exp_eq_m,eq_inv_tau},'debug',verbose==1,'init-alpha',.1,'max-its',10000);
+ eta = newtonArmijo(@evalLogNormal,eta,{ecounts,exp_eq_m,eq_inv_tau},'debug',verbose>1,'init-alpha',.1,'max-its',10000);
eq_inv_tau = 1./(eta.^2);
eq_inv_tau(eq_inv_tau >= max_inv_tau) = max_inv_tau;
em_iter = updateDeltaIterator(em_iter,eta);
end
end
+end
View
2 runLDA.m
@@ -7,7 +7,7 @@ function runLDA(K,seed,W,varargin)
if strcmp(dataset,'20news')
words = tr_data;
- [tr_words te_words widx] = preprocess(words,'max-words',W,'debug',debug,'num-folds',10);
+ [tr_words te_words widx tr_idx te_idx] = preprocess(words,'max-words',W,'debug',debug,'num-folds',10);
else
[tr_words te_words widx] = preprocess(counts','max-words',W,'holdout',0.1,'debug',debug,'num-folds',50);
vocab = words;
View
6 sparseTAM.m
@@ -85,7 +85,7 @@
%doc_word_score] = tamEStep(x(i,:),eta_sum,alpha,log_p_a,old_sigma);
[theta(i,:) q_a(i,:) new_counts sigma(i,:) score doc_lv_score doc_word_score] = tamEStep(x(i,:),eta_sum(:,:,aspects(i)),alpha,0,old_sigma);
q_a(i,:) = 0; q_a(i,aspects(i)) = 1;
- ecounts(:,:,aspects(i)) = ecounts(:,:,aspects(i)) + full(new_counts(:,:));
+ ecounts(:,:,aspects(i)) = ecounts(:,:,aspects(i)) + full(new_counts);
doc_lv_score = doc_lv_score + digamma(sum(q_a(:,aspects(i)))) - digamma(sum(sum(q_a))); %E[log P(a_i)] - E[log Q(a_i)]
word_score = word_score + doc_word_score;
@@ -126,7 +126,7 @@
end
fprintf(' ');
if topic_aspects, for k = 1:K, for j=1:A,
- assert(sparse);
+ assert(sparse==1);
eq_m = logNormalizeRows(eta_sum(:,k,j)' - eta_ta(:,k,j)');
eta_ta(:,k,j) = computeBetaSparseVariational(ecounts(:,k,j),eq_m','max-its',max_mstep_its);
end; end;
@@ -271,7 +271,7 @@
eta_sum = zeros(W,K,A);
for j = 1:A
for k = 1:K
- eta_sum(:,k,j) = logNormalizeVec(m + eta_a(:,j) + eta_t(:,k) + eta_ta(:,k));
+ eta_sum(:,k,j) = logNormalizeVec(m + eta_a(:,j) + eta_t(:,k) + eta_ta(:,k,j));
end
end
end
View
2 startup.m
@@ -1,4 +1,4 @@
addpath(genpath('3rd-party'));
addpath(genpath('utils'));
addpath(genpath('estimate'));
-addpath(genpath('bounds'));
+addpath(genpath('bounds'));
View
1 tamEStep.m
@@ -1,4 +1,5 @@
function [theta q_a out_counts sigma score lv_score word_score] = tamEStep(x,beta,alpha,a_log_prior,sigma)
+%function [theta q_a out_counts sigma score lv_score word_score] = tamEStep(x,beta,alpha,a_log_prior,sigma)
[W K A] = size(beta);
mydudes = x>0;
myx = x(mydudes);
View
9 utils/bayesian/fitDirichletPrior.m
@@ -1,11 +1,13 @@
-function [ alpha ] = fitDirichletPrior( e_log_theta, alpha )
+function [ alpha ] = fitDirichletPrior( e_log_theta, alpha, varargin )
%function [ alpha ] = fitDirichletPrior( e_log_theta, alpha )
%maximize E[log P(theta | alpha)], for
% theta | alpha ~ Dirichlet(alpha)
if ~exist('alpha','var')
alpha = normalize_vec(sum(exp(e_log_theta)));
end
+[use_exp_hyperprior] = process_options(varargin,'hyper',0);
+
[solution fX] = minimize(log(alpha)',@ll_log_alpha,100,e_log_theta);
alpha = exp(solution)';
@@ -14,9 +16,12 @@
alpha = exp(log_alpha');
l = N * (gammaln(sum(alpha)) - sum(gammaln(alpha))) + (alpha - 1) * sum(e_log_theta)';
g = N * (digamma(sum(alpha)) - digamma(alpha)) + sum(e_log_theta);
+ if use_exp_hyperprior
+ l = l - sum(alpha);
+ g = g - 1;
+ end
g = transpose(-g .* alpha);
l = -l;
end
-
end
View
1 utils/bayesian/kldirichlet.m
@@ -1,4 +1,5 @@
function y = kldirichlet(p,q)
+%function y = kldirichlet(p,q)
sumq = sum(q); sump = sum(p);
y = gammaln(sump) - gammaln(sumq) + sum(gammaln(q)-gammaln(p)) + ...
(p - q) * (digamma(p) - digamma(sump))';
View
1 utils/iterator/newDeltaIterator.m
@@ -1,4 +1,5 @@
function iter = newDeltaIterator(max_its,varargin)
+%function iter = newDeltaIterator(max_its,varargin)
iter.max_its = max_its;
[iter.thresh iter.min_its iter.debug] = process_options(varargin,'thresh',1e-6,'min_its',0,'debug',false);
iter.prev = [];
View
6 utils/newtonArmijo.m
@@ -3,7 +3,7 @@
% do a newton minimization
% func must return the likelihood and the value of the update -H^{-1}g
-[max_its init_alpha thresh debug min_alpha] = process_options(varargin,'max-its',1000,'init-alpha',1,'thresh',1e-8,'debug',0,'min-alpha',1e-15);
+[max_its init_alpha thresh debug min_alpha max_inner_its] = process_options(varargin,'max-its',1000,'init-alpha',1,'thresh',1e-8,'debug',0,'min-alpha',1e-15,'max-inner-its',1000);
x = init;
beta = 1e-4; tau = 0.25;
@@ -14,10 +14,12 @@
%do armijo linear-searchto find step size
new_score = feval(func,x+alpha*step,arguments{:});
- while alpha > min_alpha && (isnan(new_score) || isinf(new_score) || new_score > old_score + beta * gradient' * (alpha * step))
+ inner_its = 0;
+ while inner_its < max_inner_its && alpha > min_alpha && (isnan(new_score) || isinf(new_score) || new_score > old_score + beta * gradient' * (alpha * step))
%if debug, fprintf('alpha: %.2e -> %.2e\n',alpha,alpha*tau); end
alpha = alpha * tau;
new_score = feval(func,x+alpha*step,arguments{:});
+ inner_its = inner_its + 1;
end
if alpha < min_alpha, alpha == 0; end
try %try to take a step, if you can
View
8 utils/randsample.m
@@ -1,8 +1,10 @@
-function y = randsample(n,k)
+function y = randsample(n,k,j)
%function y = randsample(n,k)
%
%sample without replacement k integers from 1:n
-[ig idx] = sort(rand(n,1));
-y = idx(1:k);
+if nargin==2, j = 1; end
+
+[ig idx] = sort(rand(n,j));
+y = idx(1:k,:);
end

0 comments on commit b355dee

Please sign in to comment.