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