% HDP by gibbs sampling, especially for multinomial components, using range
% limiting auxiliary variables
gamma = hdp.gamma;
alpha = hdp.alpha;
eta = hdp.eta;
beta = hdp.beta;
datacc = hdp.datacc;
numgroup = hdp.numgroup;
numclass = hdp.numclass;
numdim = size(eta,1);
% figures out maximum value of datacc.
maxcc = 0;
for jj = 1:numgroup
maxcc = max(maxcc, max(datacc{jj}));
end
% generates range limiting auxiliary variable. The maximum value of datacc
% now has to lie in the range lowlim+1:upplim.
AA = randmult(ones(1,hdp.range+1))-1;
upplim = maxcc + AA;
lowlim = max(0, upplim - hdp.range - 1);
% adds new classes if necessary
classss = cat(2,hdp.classss, zeros(numdim,upplim-numclass));
classnd = cat(2,hdp.classnd, zeros(numgroup,upplim-numclass));
totalnt = cat(2,hdp.totalnt, zeros(1,upplim-numclass));
classnt = cat(2,hdp.classnt, zeros(numgroup,upplim-numclass));
% this is now the number of classes represented.
numclass = max(numclass,upplim);
% sample the multinomial weights only for required classes (1:upplim)
KK = 1:upplim;
beta = [beta(1:end-1) beta(end)*randstick(gamma,hdp.range)];
beta = beta(1,KK);
pi = randdir(classnd(:,KK)+alpha*beta(ones(numgroup,1),KK),2);
theta = randdir(classss(:,KK)+eta(:,ones(1,upplim)),1);
% remove data items from totalnt, classnd and classss. totalnt and classss
% includes information from other groups which we have conditioned on, so
% cannot reset to zero.
totalnt = totalnt - sum(classnt,1);
classnd(:) = 0;
for jj = 1:numgroup
% remove data items from structures
numdata = hdp.numdata(jj);
datass = hdp.datass{jj};
datasc = sparse(datass,datacc{jj},ones(1,numdata),numdim,numclass);
[i,j,sc] = find(datasc(:));
classss(i) = classss(i) - sc;
end
% Now sample for datacc. datacc has probabilities given by the
% responsibilities for each data item, with mixing proportions given
% in pi(jj,:), and class cc being multinomial with weights theta(:,cc),
% subject to the condition that the maximum value of datacc lies in
% lowlim+1:upplim. We can obtain a sample from this using a forward-
% backward type algorithm.
% data structures used for forward-backward type sampling.
uppcc = cell(1,numgroup);
KK = 1:lowlim;
mesg = 1;
for jj = 1:numgroup
numdata = hdp.numdata(jj);
datass = hdp.datass{jj};
% compute probability of choosing classes in range 1:upplim
allweights = theta(datass,:) .* pi(jj*ones(1,numdata),:);
% compute probabilities for each datacc.
% mesg(i) is relative probability of all data items before item i choosing
% classes in range 1:lowlim (relative to range 1:upplim).
% prop is relative probability that at least one item before i chose a
% class in range lowlim+1:upplim.
mesg = cumprod([mesg;sum(allweights(:,KK),2)./sum(allweights,2)]);
prop = 1-mesg(1:numdata);
uppweights = allweights;
uppweights(:,KK) = uppweights(:,KK).*prop(:,ones(1,lowlim));
% sample class associate with each data item for both cases
datacc{jj} = randmult(allweights,2)';
uppcc{jj} = randmult(uppweights,2)';
% pass this onto next group. Basically we string all data items in all
% groups into one sequence.
mesg = mesg(numdata+1);
if (mesg == 0) | (jj==numgroup)
% if the probability is zero that all data items up to now will choose
% class in range 1:lowlim, we can bail out and just sample without the
% lower limit consideration (upper limit still holds).
mm = 0;
for j2 = numgroup:-1:jj+1
numdata = hdp.numdata(j2);
datass = hdp.datass{j2};
% sample data items without worrying about lower limit effect on max value
allweights = theta(datass,:) .* pi(j2*ones(1,numdata),:);
datacc{j2} = randmult(allweights,2)';
mm = max(mm,max(datacc{j2}));
end
if mm <= lowlim
% if all data items after class jj chose class in range 1:lowlim, we
% find the last data item to have chosen a class in range lowlim+1:upplim
% using uppcc (the probability is one that at least one exists). Then
% get samples from uppcc for items after this one, and from datacc from
% those before.
for j2 = jj:-1:1
ii = max(find(uppcc{j2} > lowlim));
if ~isempty(ii)
datacc{j2}(ii:end) = uppcc{j2}(ii:end);
break;
else
datacc{j2} = uppcc{j2};
end
end
end
break
end
end
% update data structures
for jj = 1:numgroup
datasc = sparse(hdp.datass{jj},datacc{jj},ones(1,hdp.numdata(jj)),...
numdim,numclass);
[i,j,sc] = find(datasc(:));
classss(i) = classss(i) + sc;
classnd(jj,:) = sum(datasc,1);
end
% sample number of tables
classnt = randnumtable(alpha*beta(ones(1,numgroup),:),classnd);
totalnt = totalnt + sum(classnt,1);
% remove empty classes
for cc = numclass:-1:1
if totalnt(cc) == 0
numclass = numclass - 1;
classss(:,cc) = [];
classnd(:,cc) = [];
classnt(:,cc) = [];
totalnt(cc) = [];
for jj = 1:numgroup
ii = find(datacc{jj} > cc);
datacc{jj}(ii) = datacc{jj}(ii) - 1;
end
end
end
% update beta weights
weights = totalnt;
weights(1,numclass+1) = gamma;
beta = randdir(weights);
hdp.numclass = numclass;
hdp.classss = classss;
hdp.classnd = classnd;
hdp.classnt = classnt;
hdp.totalnt = totalnt;
hdp.datacc = datacc;
hdp.beta = beta;
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
fd.rar (98个子文件)
fd
npbayes-r1
hdpmix
hdp_init.m 2KB
hdp_predict.m 1KB
hdp_crf.m 4KB
hdp_iterateconparam.m 974B
hdp2lda.m 190B
hdp_posterior.m 987B
hdp_standardize.m 910B
README 6KB
hdpMultinomial_block.m 6KB
hdp_specialize.m 1KB
hdp_beta.m 2KB
hdp_conparam.m 233B
hdp_iterate.m 927B
.htaccess 17B
utilities
plotellipse.m 230B
randdir.m 298B
stirling.m 517B
randconparam.m 515B
imlayout.m 640B
randbeta.m 128B
randmult.m 718B
randcrp.m 392B
randconparam3.m 515B
randconparam2.m 207B
README 3KB
enumclass.m 95B
randconparam1.m 433B
logmeanexp.m 329B
meanlik.m 71B
randnumtable.m 446B
mysubplot.m 297B
randgamma.m 2KB
randstick.m 145B
lda
lda_predict.m 1KB
lda_beta.m 1KB
ldaMultinomial_block.m 988B
lda2hdp.m 424B
lda_crf.m 3KB
lda_init.m 1KB
lda_specialize.m 1KB
lda_posterior.m 851B
lda_iterate.m 927B
README 5KB
lda_iterateconparam.m 1023B
lda_conparam.m 359B
lda_standardize.m 729B
dpmix
dp_predict.m 559B
dp_kmeans.m 2KB
dp_iterateconparam.m 953B
dp_standardize.m 198B
dp_conparam.m 119B
dp_init.m 1KB
dp_samplepred.m 1KB
README 3KB
dp_specialize.m 209B
dp_beta.m 2KB
dp_posterior.m 893B
dp_crp.m 2KB
dp_iterate.m 909B
tests
testrandconparam.m 563B
testbars.m 3KB
testdpmixGaussianWishart.m 3KB
testpredict.m 1KB
README 3KB
COPYRIGHT 651B
distributions
cleardist.m 58B
deldist.m 70B
README 4KB
@GaussianWishart
deldata.m 542B
likelihood.m 53B
GaussianWishart.m 2KB
map.m 362B
private
incmaxeval.m 778B
adddata.m 553B
marglikelihood.m 346B
@Multinomial
sample.m 144B
length.m 47B
deldata.m 730B
subsref.m 112B
likelihood.m 53B
map.m 189B
double.m 47B
private
incmax.m 602B
adddata.m 786B
subsasgn.m 494B
display.m 39B
Multinomial.m 801B
parameters.m 82B
marglikelihood.m 110B
adddist.m 168B
mixtures
ldaMultinomial.m 138B
dpGaussianWishart.m 1KB
estimateGaussianWishart.m 324B
hdpMultinomial.m 226B
initpath.m 235B
datasets
gengaussian.m 351B
README 1KB
genbars.m 943B
共 98 条
- 1
邓凌佳
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- pta题库答案c语言之排序4统计工龄.zip
- pta题库答案c语言之树结构7堆中的路径.zip
- pta题库答案c语言之树结构3TreeTraversalsAgain.zip
- pta题库答案c语言之树结构2ListLeaves.zip
- pta题库答案c语言之树结构1树的同构.zip
- 基于C++实现民航飞行与地图简易管理系统可执行程序+说明+详细注释.zip
- pta题库答案c语言之复杂度1最大子列和问题.zip
- 三维装箱问题(Three-Dimensional Bin Packing Problem,3D-BPP)是一个经典的组合优化问题
- 以下是一些关于Linux线程同步的基本概念和方法.txt
- 以下是一个简化的示例,它使用pygame库来模拟烟花动画的框架.txt
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0