132 const std::function<T(
const std::vector<int>&)>& mu,
134 const std::size_t R = lambda.size();
138 std::vector<std::size_t> act;
139 for (std::size_t r = 0; r < R; ++r)
140 if (lambda[r] > zero) act.push_back(r);
145 if (act.size() > 16) {
146 out.
why =
"too many classes";
151 "pfqn_oi_respt: mu must be a function mu(n) on the per-class count vector.");
156 lambda, std::vector<double>(R, std::numeric_limits<double>::infinity()), mu,
opt);
158 out.
why =
"unstable";
161 for (std::size_t r : act)
162 if (r < mx.
tau.size() && mx.
tau[r] > 1) {
163 out.
why =
"not support-only";
167 const std::size_t Ra = act.size();
169 const auto m = [&](
unsigned long mask) -> T {
170 std::vector<int> n(R, 0);
171 for (std::size_t i = 0; i < Ra; ++i)
172 if (mask & (1UL << i)) n[act[i]] = 1;
175 std::vector<T> mi(Ra, zero);
176 std::vector<double> mid(Ra, 0.0);
177 for (std::size_t i = 0; i < Ra; ++i) {
181 const double tol = 1e-10;
183 std::vector<std::vector<bool> > D(Ra, std::vector<bool>(Ra,
false));
184 for (std::size_t i = 0; i < Ra; ++i) {
186 for (std::size_t j = i + 1; j < Ra; ++j) {
188 const double sc = tol * std::max(1.0, mij);
189 if (std::fabs(mij - mid[i]) <= sc) D[i][j] =
true;
190 if (std::fabs(mij - mid[j]) <= sc) D[j][i] =
true;
191 if (!D[i][j] && !D[j][i] && std::fabs(mij - mid[i] - mid[j]) > sc) {
192 out.
why =
"not nested";
198 for (std::size_t i = 0; i < Ra; ++i)
199 for (std::size_t j = 0; j < Ra; ++j) {
200 if (!D[i][j])
continue;
201 for (std::size_t k = 0; k < Ra; ++k)
202 if (!D[i][k] && D[j][k]) {
203 out.
why =
"not nested";
208 for (
unsigned long mask = 1; mask < (1UL << Ra); ++mask) {
209 std::vector<std::size_t> set, top;
210 for (std::size_t i = 0; i < Ra; ++i)
211 if (mask & (1UL << i)) set.push_back(i);
212 for (std::size_t i : set) {
214 for (std::size_t j : set)
215 if (D[j][i] && !D[i][j]) dom =
true;
216 bool covered =
false;
217 for (std::size_t t : top)
218 if (D[t][i]) covered =
true;
219 if (!dom && !covered) top.push_back(i);
223 for (std::size_t t : top) s += mid[t];
224 if (std::fabs(v - s) > tol * std::max(1.0, v)) {
225 out.
why =
"not a pool";
229 std::vector<T> la(Ra, zero), lamR(Ra, zero);
230 for (std::size_t i = 0; i < Ra; ++i) la[i] = lambda[act[i]];
231 for (std::size_t i = 0; i < Ra; ++i)
232 for (std::size_t j = 0; j < Ra; ++j)
233 if (D[i][j]) lamR[i] += la[j];
234 for (std::size_t i = 0; i < Ra; ++i) {
235 std::vector<T> rates, probs;
236 std::vector<bool> done(Ra,
false);
237 for (std::size_t g = 0; g < Ra; ++g) {
238 const bool strict = D[g][i] && !D[i][g];
239 if (!strict || done[g])
continue;
241 for (std::size_t j = 0; j < Ra; ++j)
242 if (D[g][j] && D[j][g]) {
246 const T muh = T(mi[g] - lamR[g] + lg);
247 rates.push_back(T(muh - lg));
248 probs.push_back(T(lg / muh));
250 rates.push_back(T(mi[i] - lamR[i]));
252 out.
PH[act[i]] = detail::oi_respt_series_ph(rates, probs);