LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
moment_housematrix.m
1function T = moment_housematrix(edge, n)
2% T = moment_housematrix(edge, n)
3%
4% Conversion matrix of one edge of the house of moments.
5%
6% The edge is returned as a linear map on the moment subspace {m_0 = 1}. Four
7% edges (the Lah pair and the shifted-binomial pair) pin their zeroth output to
8% 1 rather than propagating element 0, so as maps of the whole space they are
9% affine. Here the offset is folded into column 0, which is empty for those
10% edges, making every edge a genuine matrix. On a moment vector, whose element
11% 0 is 1 by definition, the two agree. This is also what makes those edges
12% usable dimension by dimension in the joint conversions.
13%
14% Input:
15% edge: one of 'factorial_from_raw', 'raw_from_factorial',
16% 'upfactorial_from_raw', 'raw_from_upfactorial',
17% 'binomial_from_factorial', 'factorial_from_binomial',
18% 'negbinomial_from_upfactorial', 'upfactorial_from_negbinomial',
19% 'factorial_from_upfactorial', 'upfactorial_from_factorial',
20% 'negbinomial_from_binomial', 'binomial_from_negbinomial',
21% 'binomial_from_tail', 'tail_from_binomial'
22% n: maximum order of the mode (n >= 0)
23%
24% Output:
25% T: (n+1)x(n+1) conversion matrix
26%
27% Example:
28% T = moment_housematrix('factorial_from_raw', 4);
29%
30% Reference:
31% A. Heindl and A. van de Liefvoort. Moment conversions for discrete
32% distributions. PMCCS, 2003.
33
34if ~isscalar(n) || n < 0 || n ~= round(n)
35 line_error(mfilename,'The maximum order n must be a nonnegative integer.');
36end
37switch edge
38 case 'factorial_from_raw'
39 T = moment_stirling1(n);
40 case 'raw_from_factorial'
41 T = moment_stirling2(n);
42 case 'upfactorial_from_raw'
43 T = moment_stirlingcycle(n);
44 case 'raw_from_upfactorial'
45 S = moment_stirling2(n);
46 T = zeros(n+1,n+1);
47 for i = 0:n
48 for j = 0:i
49 T(i+1,j+1) = (-1)^(i-j) * S(i+1,j+1);
50 end
51 end
52 case {'binomial_from_factorial','negbinomial_from_upfactorial'}
53 T = diag(1 ./ factorial(0:n));
54 case {'factorial_from_binomial','upfactorial_from_negbinomial'}
55 T = diag(factorial(0:n));
56 case {'factorial_from_upfactorial','upfactorial_from_factorial'}
57 L = moment_lah(n);
58 T = zeros(n+1,n+1);
59 T(1,1) = 1;
60 for i = 1:n
61 for k = 1:i
62 if strcmp(edge,'upfactorial_from_factorial')
63 T(i+1,k+1) = L(i+1,k+1);
64 else
65 T(i+1,k+1) = (-1)^(i-k) * L(i+1,k+1);
66 end
67 end
68 end
69 case {'negbinomial_from_binomial','binomial_from_negbinomial'}
70 T = zeros(n+1,n+1);
71 T(1,1) = 1;
72 for i = 1:n
73 for k = 1:i
74 c = nchoosek(i-1,k-1);
75 if strcmp(edge,'negbinomial_from_binomial')
76 T(i+1,k+1) = c;
77 else
78 T(i+1,k+1) = (-1)^(i-k) * c;
79 end
80 end
81 end
82 case {'binomial_from_tail','tail_from_binomial'}
83 T = zeros(n+1,n+1);
84 T(1,1) = 1;
85 for i = 1:n
86 for k = i:n
87 c = nchoosek(k-1,i-1);
88 if strcmp(edge,'binomial_from_tail')
89 T(i+1,k+1) = c;
90 else
91 T(i+1,k+1) = (-1)^(k-i) * c;
92 end
93 end
94 end
95 otherwise
96 line_error(mfilename,sprintf('Unknown edge %s.',edge));
97end
98end