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