1function [kpcMAP,subMAPs,error]=kpcfit_sub_compose(E1j,SCVj,E3j,G2j,varargin)
2% map_kpcfit_compose make a large MAP out of several small MAP(2) or
5% MAP=map_kpcfit_compose(E1j,SCVj,E3j,G2j) gives a big MAP composed by
6% many small MAP(2) or MAP(1)s with individual E1, SCV, E3, G2.
9% E1j = a vector of the first moment for every
map
10% SCVj = a vector of squared coefficient of variation for every
12% E3j = a vector of the third moment for every
map
13% G2j = a vector of gamma2 for every
map
16% MAP = A
map composed by J maps, each
map(2) has the specified
17% first moment, SCV, third moment, gamma2 in the vectors of E1j,
21% The first
map is a mmpp2 while the other J-1 maps are HMAPs
27 verbose = varargin{1};
30% compute the composed process
32kpcMAP = mmpp2_fit3(E1j(1),(1+SCVj(1))*E1j(1)^2,E3j(1),G2j(1));
33if any(imag(kpcMAP{1})>10^-4,
'all') || any(imag(kpcMAP{2})>10^-4,
'all') || map_isfeasible(kpcMAP) == 0
35 kpcMAP = map_erlang(E1j(1),2);
37 fprintf(1,
'MAP 1 is erlang-2\n');
41 fprintf(1,
'MAP 1 has presumably infeasible E3: %f\n', E3j(1));
43 [kpcMAP,fitErr] = map2_fit(E1j(1),(1+SCVj(1))*E1j(1)^2,-1,G2j(1));
44 if isempty(kpcMAP) || fitErr ~= 0
46 fprintf(1,
'MAP 1 has infeasible G2: %f (err=%d)\n', G2j(1), fitErr);
48 [kpcMAP,fitErr] = map2_fit(E1j(1),(1+SCVj(1))*E1j(1)^2,-1,0);
50 if fitErr ~= 0 || isempty(kpcMAP)
51 %fprintf(
"map2_fit returned: %d\n", fitErr);
63 MAPj=map_feasblock(E1j(j),(1+SCVj(j))*E1j(j)^2,E3j(j),G2j(j));
65 feasible = map_isfeasible(MAPj);
68 fprintf(1,
"Could not check feasibility of MAP-%d", j);
75 fprintf(1,
'MAP %d has low variability\n',j);
77 MAPj = map2_exponential(E1j(j));
80 fprintf(1,
'MAP %d has presumably infeasible E3\n',j);
82 [MAPj,fitErr] = map2_fit(E1j(j),(1+SCVj(j))*E1j(j)^2,-1,G2j(j));
83 if fitErr ~= 0 || isempty(MAPj)
84 [MAPj,fitErr] = map2_fit(E1j(j),(1+SCVj(j))*E1j(j)^2,-1,0);
87 fprintf(1,
'MAP %d has infeasible G2: %f)\n',j, G2j(j));
90 if fitErr ~= 0 || isempty(MAPj)
95 lambda=eig(-inv(MAPj{1}));
96 D0 = diag(-1./(lambda));
97 P = map_embedded(MAPj);
99 D1 = -D0*[p,1-p;p,1-p];
100 MAPj=map_normalize({D0,D1});
105 fprintf(1,
'Replacing MAP %d with an exponential\n', j);
107 subMAPs{j}=map_exponential(E1j(j));
112 kpcMAP= map_kpc(kpcMAP,MAPj);
115 if map_isfeasible(subMAPs{j}) == 0
116 fprintf(1,
'MAP %d is infeasible\n',j);
122kpcMAP=map_normalize(kpcMAP);
125% fprintf(
"MAP %d: ", j);
126% fprintf(
"E1: %f (%f)\n", map_mean(subMAPs{j}), E1j(j));
127% fprintf(
"SCV: %f (%f)\n", map_scv(subMAPs{j}), SCVj(j));
128% fprintf(
"G2: %f (%f)\n", map_gamma(subMAPs{j}), G2j(j));