-
大小: 19.06MB文件类型: .rar金币: 1下载: 0 次发布日期: 2023-07-13
- 语言: Matlab
- 标签: LDA、Matlab
资源简介
主题模型(Topic Model)LDA详解及其Matlab代码
代码片段和文件信息
function [ probs_sorted index probs ] = AssociationLDA( WP BETA W1 )
%% Function WriteTopics
%
% works on single samples as well as multiple samples
if iscell( WP )
% we are dealing with multiple Gibbs samples. Need to average
% predictions over these samples. Note that the WP samples do not have
% to contain the same number of topics
NS = length( WP ); % number of samples
NW = size( WP{ 1 } 1 ); % number of words
NW1 = length( W1 ); % number of W1 cues
probs = zeros( NW NW1 );
for s=1:NS
T = size( WP{ s } 2 ); % number of topics
sumt = full( sum( WP{ s } 1 )) + NW * BETA;
beta2 = BETA ./ sumt;
WP2 = WP{ s }; % note WP2 stays sparse
for z=1:T
WP2( : z ) = WP2( : z ) / sumt( z );
end
% take transpose of WP2 for faster processing
WP3 = WP2( W1 : )‘;
% this should also be sparse
crossprods = WP2 * WP2( W1 : )‘;
sum4 = sum( beta2 .* beta2 );
sumbeta = sum( beta2 );
for i=1:NW1
sum1 = crossprods( : i ) ;
sum2 = sum( WP3( : i )‘ .* beta2 );
sum3 = WP2 * beta2‘;
sum5 = sum( WP3( : i )) + sumbeta;
sumt = ( sum1 + sum2 + sum3 + sum4 ) / sum5;
sumt( W1( i )) = 0;
sumt = sumt / sum( sumt );
probs( : i ) = probs( : i ) + sumt;
end
end
probs = probs / NS;
else
% we are dealing with just one Gibbs sample
NW = size( WP 1 ); % number of words
T = size( WP 2 ); % number of topics
NW1 = length( W1 ); % number of W1 cues
sumt = full( sum( WP 1 )) + NW * BETA;
beta2 = BETA ./ sumt;
WP2 = WP; % note WP2 stays sparse
for z=1:T
WP2( : z ) = WP2( : z ) / sumt( z );
end
% take transpose of WP2 for faster processing
WP3 = WP2( W1 : )‘;
% this should also be sparse
crossprods = WP2 * WP2( W1 : )‘;
probs = zeros( NW NW1 );
sum4 = sum( beta2 .* beta2 );
sumbeta = sum( beta2 );
for i=1:NW1
sum1 = crossprods( : i ) ;
sum2 = sum( WP3( : i )‘ .* beta2 );
sum3 = WP2 * beta2‘;
sum5 = sum( WP3( : i )) + sumbeta;
sumt = ( sum1 + sum2 + sum3 + sum4 ) / sum5;
sumt( W1( i )) = 0;
sumt = sumt / sum( sumt );
probs( : i ) = sumt;
end
end
[ probs_sorted index ] = sort( probs 1 ‘descend‘ );
% TEST CODE
% pwz = WP + BETA;
% for i=1:T
% pwz( : i ) = pwz( : i ) / sum( pwz( : i ));
% end
% probs2 = zeros( NW NW1 );
% for i=1:NW1
% w1 = W1( i );
% p = zeros( NW 1 );
% for z=1:T
% p = p + pwz( : z ) * pwz( w1 z ) / sum( pwz( w1 : ));
% end
%
% probs2( : i ) = p;
% end
%
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 18494 2014-12-03 16:32 LDA讲解及matlab程序\LDA实验\Matlab Topic Modeling Toolbox 1.docx
文件 2987 2006-06-18 15:57 LDA讲解及matlab程序\LDA实验\topictoolbox\AssociationLDA.m
文件 2904 2008-05-20 07:51 LDA讲解及matlab程序\LDA实验\topictoolbox\AssociationLDA2.m
文件 2906 2008-06-03 09:04 LDA讲解及matlab程序\LDA实验\topictoolbox\AssociationLDA3.m
文件 1681 2008-06-17 12:10 LDA讲解及matlab程序\LDA实验\topictoolbox\AssociationLDA4.m
文件 1167 2006-06-18 15:45 LDA讲解及matlab程序\LDA实验\topictoolbox\AssociationTFIDF.m
文件 55048 2005-04-03 12:20 LDA讲解及matlab程序\LDA实验\topictoolbox\authordoc_nips.mat
文件 155264 2005-04-03 12:21 LDA讲解及matlab程序\LDA实验\topictoolbox\authors_nips.mat
文件 1830695 2005-09-07 12:12 LDA讲解及matlab程序\LDA实验\topictoolbox\bagofwords_nips.mat
文件 127316 2005-09-07 12:13 LDA讲解及matlab程序\LDA实验\topictoolbox\bagofwords_psychreview.mat
文件 449816 2005-04-03 12:22 LDA讲解及matlab程序\LDA实验\topictoolbox\binaryalphabet.mat
文件 2381 2006-01-06 16:56 LDA讲解及matlab程序\LDA实验\topictoolbox\binarysearchstrings.c
文件 5120 2006-01-06 16:52 LDA讲解及matlab程序\LDA实验\topictoolbox\binarysearchstrings.dll
文件 7312 2006-01-06 16:57 LDA讲解及matlab程序\LDA实验\topictoolbox\binarysearchstrings.mexglx
文件 7680 2011-04-04 08:39 LDA讲解及matlab程序\LDA实验\topictoolbox\binarysearchstrings.mexw64
文件 7054 2006-07-15 14:32 LDA讲解及matlab程序\LDA实验\topictoolbox\cokus.cpp
文件 379 2011-04-04 08:40 LDA讲解及matlab程序\LDA实验\topictoolbox\compilesc
文件 713 2005-09-07 12:18 LDA讲解及matlab程序\LDA实验\topictoolbox\convertimstocounts.m
文件 735 2006-01-06 17:31 LDA讲解及matlab程序\LDA实验\topictoolbox\convertmatfiles.m
文件 834 2005-04-02 11:12 LDA讲解及matlab程序\LDA实验\topictoolbox\createcollage.m
文件 2509 2005-09-06 15:10 LDA讲解及matlab程序\LDA实验\topictoolbox\CreateCollocationTopics.m
文件 11278 2005-09-14 08:51 LDA讲解及matlab程序\LDA实验\topictoolbox\dataformat.m
文件 156 2005-04-01 22:26 LDA讲解及matlab程序\LDA实验\topictoolbox\drchrnd.m
文件 1662 2005-09-07 12:14 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleAT1.m
文件 2794 2005-09-09 09:43 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleAT2.m
文件 4553 2005-09-06 16:59 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleimages1.m
文件 3924 2005-09-07 12:20 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleimages2.m
文件 1755 2014-12-05 17:53 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleLDA1.m
文件 2234 2005-09-07 12:14 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleLDA2.m
文件 1023 2005-09-06 15:30 LDA讲解及matlab程序\LDA实验\topictoolbox\exampleLDA3.m
............此处省略85个文件信息
评论
共有 条评论