Mercurial > hg > camir-ismir2012
annotate toolboxes/FullBNT-1.0.7/KPMstats/multipdf.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 p = multipdf(x,theta) |
Daniel@0 | 2 %MULTIPDF Multinomial probability density function. |
Daniel@0 | 3 % p = multipdf(x,theta) returns the probabilities of |
Daniel@0 | 4 % vector x, under the multinomial distribution |
Daniel@0 | 5 % with parameter vector theta. |
Daniel@0 | 6 % |
Daniel@0 | 7 % Author: David Ross |
Daniel@0 | 8 |
Daniel@0 | 9 %-------------------------------------------------------- |
Daniel@0 | 10 % Check the arguments. |
Daniel@0 | 11 %-------------------------------------------------------- |
Daniel@0 | 12 error(nargchk(2,2,nargin)); |
Daniel@0 | 13 |
Daniel@0 | 14 % make sure theta is a vector |
Daniel@0 | 15 if ndims(theta) > 2 | all(size(theta) > 1) |
Daniel@0 | 16 error('theta must be a vector'); |
Daniel@0 | 17 end |
Daniel@0 | 18 |
Daniel@0 | 19 % make sure x is of the appropriate size |
Daniel@0 | 20 if ndims(x) > 2 | any(size(x) ~= size(theta)) |
Daniel@0 | 21 error('columns of X must have same length as theta'); |
Daniel@0 | 22 end |
Daniel@0 | 23 |
Daniel@0 | 24 |
Daniel@0 | 25 %-------------------------------------------------------- |
Daniel@0 | 26 % Main... |
Daniel@0 | 27 %-------------------------------------------------------- |
Daniel@0 | 28 p = prod(theta .^ x); |
Daniel@0 | 29 p = p .* factorial(sum(x)) ./ prod(factorial_v(x)); |
Daniel@0 | 30 |
Daniel@0 | 31 |
Daniel@0 | 32 %-------------------------------------------------------- |
Daniel@0 | 33 % Function factorial_v(x): computes the factorial function |
Daniel@0 | 34 % on each element of x |
Daniel@0 | 35 %-------------------------------------------------------- |
Daniel@0 | 36 function r = factorial_v(x) |
Daniel@0 | 37 |
Daniel@0 | 38 if size(x,2) == 1 |
Daniel@0 | 39 x = x'; |
Daniel@0 | 40 end |
Daniel@0 | 41 |
Daniel@0 | 42 r = []; |
Daniel@0 | 43 for y = x |
Daniel@0 | 44 r = [r factorial(y)]; |
Daniel@0 | 45 end |