Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/KPMstats/multinomial_sample.m @ 0:cc4b1211e677 tip
initial commit to HG from
Changeset:
646 (e263d8a21543) added further path and more save "camirversion.m"
author | Daniel Wolff |
---|---|
date | Fri, 19 Aug 2016 13:07:06 +0200 |
parents | |
children |
rev | line source |
---|---|
Daniel@0 | 1 function Y = sample_cond_multinomial(X, M) |
Daniel@0 | 2 % SAMPLE_MULTINOMIAL Sample Y(i) ~ M(X(i), :) |
Daniel@0 | 3 % function Y = sample_multinomial(X, M) |
Daniel@0 | 4 % |
Daniel@0 | 5 % X(i) = i'th sample |
Daniel@0 | 6 % M(i,j) = P(Y=j | X=i) = noisy channel model |
Daniel@0 | 7 % |
Daniel@0 | 8 % e.g., if X is a binary image, |
Daniel@0 | 9 % Y = sample_multinomial(softeye(2, 0.9), X) |
Daniel@0 | 10 % will create a noisy version of X, where bits are flipped with probability 0.1 |
Daniel@0 | 11 |
Daniel@0 | 12 if any(X(:)==0) |
Daniel@0 | 13 error('data must only contain positive integers') |
Daniel@0 | 14 end |
Daniel@0 | 15 |
Daniel@0 | 16 Y = zeros(size(X)); |
Daniel@0 | 17 for i=min(X(:)):max(X(:)) |
Daniel@0 | 18 ndx = find(X==i); |
Daniel@0 | 19 Y(ndx) = sample_discrete(M(i,:), length(ndx), 1); |
Daniel@0 | 20 end |
Daniel@0 | 21 |
Daniel@0 | 22 |