70 const std::size_t n = D0.
rows();
71 if (n == 0)
throw InputError(
"aoi_dist2ph: empty process");
73 throw InputError(
"aoi_dist2ph: D0 and D1 must be square matrices of the same size");
82 for (std::size_t i = 0; i < n; ++i)
83 for (std::size_t j = 0; j < n; ++j) Q(i, j) = D0(i, j) + D1(i, j);
87 std::vector<T> rowSum(n, zero);
88 for (std::size_t i = 0; i < n; ++i) {
89 for (std::size_t j = 0; j < n; ++j) rowSum[i] += Q(i, j);
90 const T a = rowSum[i] < zero ? T(-rowSum[i]) : rowSum[i];
91 if (a > worst) worst = a;
94 for (std::size_t i = 0; i < n; ++i) Q(i, i) = Q(i, i) - rowSum[i];
99 std::vector<T> Atb(n, one);
100 for (std::size_t i = 0; i < n; ++i)
101 for (std::size_t j = 0; j < n; ++j) {
103 for (std::size_t k = 0; k < n; ++k) s += Q(i, k) * Q(j, k);
106 std::vector<T> theta =
solve(AtA, Atb);
109 for (std::size_t i = 0; i < n; ++i) {
110 if (theta[i] < zero) theta[i] = zero;
113 if (mass == zero)
throw NumericError(
"aoi_dist2ph: the phase process has no stationary law");
114 for (std::size_t i = 0; i < n; ++i) theta[i] = theta[i] / mass;
116 std::vector<T> completion(n, zero);
117 for (std::size_t i = 0; i < n; ++i)
118 for (std::size_t j = 0; j < n; ++j) completion[i] += D1(i, j);
120 out.
alpha.assign(n, zero);
122 for (std::size_t i = 0; i < n; ++i) {
123 out.
alpha[i] = theta[i] * completion[i];
127 for (std::size_t i = 0; i < n; ++i) out.
alpha[i] = out.
alpha[i] / num;
131 for (std::size_t i = 0; i < n; ++i) s += out.
alpha[i];
132 if (s == zero)
throw NumericError(
"aoi_dist2ph: alpha cannot be normalized");
133 for (std::size_t i = 0; i < n; ++i) out.
alpha[i] = out.
alpha[i] / s;
136 for (std::size_t i = 0; i < n; ++i)
137 if (out.
Tmat(i, i) > zero)
138 throw InputError(
"aoi_dist2ph: T has a positive diagonal entry, which is not a "