Created
September 11, 2012 17:01
-
-
Save michaelchughes/3699842 to your computer and use it in GitHub Desktop.
Script to understand calculation of log probability of the Dirichlet in high dimensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Script to understand calculation of log probability of the Dirichlet | |
% in high dimensions. | |
% Requires: Minka's fastfit toolbox | |
% http://research.microsoft.com/en-us/um/people/minka/software/fastfit/ | |
% For complete problem description, check out | |
% http://stats.stackexchange.com/questions/36111/calculating-log-prob-of-dirichlet-distribution-in-high-dimensions | |
concParam = 0.01; | |
EPS = 1e-15; | |
fprintf( ' [1 0...0] [unif 0..0] [ unif ]\n'); | |
for K= [4 10 50 100 500 1000]; | |
lambda = concParam*ones( 1, K ); | |
% ------------------------------------------ Create 3 possible outcomes | |
X = zeros(3, K); | |
% First, consider a very sharply peaked distribution | |
% only the first dimension has significant mass | |
X(1,:) = [1 eps+zeros(1,K-1)]; | |
% Next, consider a "halfway" uniform distribution, | |
% half the K dims have significant mass, others negligible | |
X(2,1:K/2) = [ones(1,K/2)]; | |
X(2,:) = ( X(2,:)+EPS )./sum( X(2,:) ); | |
% Last, consider a fully uniform distribution | |
X(3,:) = ones(1,K)/K; | |
% ------------------------------------------ Calc log prob of each one | |
logPr = zeros( 1, 3); | |
for aa = 1:3 | |
logPr(aa) = dirichlet_logProb( lambda, X(aa,:) ); | |
end | |
fprintf( 'K=%4d % .2e % .2e % .2e\n', K, logPr); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment