Skip to content

Instantly share code, notes, and snippets.

@lithtle
Created December 4, 2012 08:59
Show Gist options
  • Save lithtle/4201979 to your computer and use it in GitHub Desktop.
Save lithtle/4201979 to your computer and use it in GitHub Desktop.
ディリクレ分布をプロットして遊ぶ
n = 100;
d = 3;
% alpha = [2 3 6];
% alpha = [0.5 0.5 0.5];
alpha = [1 1 1];
[x y] = meshgrid(linspace(0, 1, n), linspace(0, 1, n));
x = x .* fliplr(tril(ones(length(x)), 1)');
y = y .* fliplr(tril(ones(length(y)), 1)');
z = 1 - x - y;
z = z .* fliplr(tril(ones(length(z)), -1)');
g = @(alpha, d)(gamma(sum(alpha)) / (prod(gamma(alpha))));
v = g(alpha, d) .* x .^ (alpha(1) - 1) .* y .^ (alpha(2) - 1) .* z .^ (alpha(3) - 1);
plot3(x, y, v, 'x', 'LineWidth', 2, 'Color', 'red');
zlim([0 max(max(v))]);
grid on;
title(['alpha = ' num2str(alpha(1)) ', ' num2str(alpha(2)) ', ' num2str(alpha(3))]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment