LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
moment_joint_cumulant_from_raw.m
1function kappa = moment_joint_cumulant_from_raw(m)
2% kappa = moment_joint_cumulant_from_raw(m)
3%
4% Converts the joint power (raw) moments of a random vector (N_1,...,N_d) into
5% its joint cumulants, the coefficients of the joint cumulant generating
6% function
7%
8% log E[exp(s_1 N_1 + ... + s_d N_d)] = sum_(a ~= 0) kappa_a prod_j
9% s_j^(a_j) / a_j!
10%
11% They obey the multivariate exponential formula, equivalently the
12% Leonov-Shiryaev partition formula. With j the first dimension in which the
13% multi-index a is nonzero,
14%
15% m_a = sum_(0<b<=a) prod_l nchoosek(a_l-[l=j], b_l-[l=j]) kappa_b m_(a-b)
16%
17% which isolates kappa_a because the b = a term has unit coefficient and
18% m_0 = 1. Unlike every other conversion in the house, this one does not factor
19% into a product of univariate transforms: the cumulant of multi-order (1,1) is
20% the covariance, which mixes the dimensions.
21%
22% Input:
23% m: array of size (n_1+1)x...x(n_d+1) holding the joint power moments, with
24% element 1 equal to 1
25%
26% Output:
27% kappa: array of the same size holding the joint cumulants, element 1 being
28% kappa_0 = 0
29%
30% Example:
31% kappa = moment_joint_cumulant_from_raw(m); % kappa(2,2) is the covariance
32%
33% Reference:
34% V. P. Leonov and A. N. Shiryaev. On a method of calculation of
35% semi-invariants. Theory of Probability and its Applications,
36% 4(3):319-329, 1959.
37
38sz = moment_tensorsize(m);
39d = numel(sz);
40nel = prod(sz);
41stride = cumprod([1, sz(1:end-1)]);
42mv = reshape(m, [], 1);
43kv = zeros(nel,1);
44a = ones(1,d);
45for ia = 1:nel
46 if any(a > 1)
47 j = find(a > 1, 1);
48 acc = 0;
49 b = ones(1,d);
50 for ib = 1:prod(a)
51 if any(b > 1) && ~isequal(b,a) && b(j) > 1
52 c = 1;
53 for l = 1:d
54 alpha = a(l) - 1 - (l == j);
55 beta = b(l) - 1 - (l == j);
56 c = c * nchoosek(alpha, beta);
57 end
58 if c ~= 0
59 acc = acc + c * kv(1 + sum((b-1).*stride)) * mv(1 + sum((a-b).*stride));
60 end
61 end
62 for l = 1:d
63 b(l) = b(l) + 1;
64 if b(l) <= a(l)
65 break
66 end
67 b(l) = 1;
68 end
69 end
70 kv(ia) = mv(ia) - acc;
71 end
72 for l = 1:d
73 a(l) = a(l) + 1;
74 if a(l) <= sz(l)
75 break
76 end
77 a(l) = 1;
78 end
79end
80kappa = reshape(kv, size(m));
81end