29 #ifndef KALDI_MATRIX_JAMA_EIG_H_ 30 #define KALDI_MATRIX_JAMA_EIG_H_ 1 51 for (
int i = 0;
i <
n_;
i++)
52 for (
int j = 0;
j <
n_;
j++)
53 (*V_out)(
i,
j) =
V(
i,
j);
58 for (
int i = 0;
i <
n_;
i++)
64 for (
int i = 0;
i <
n_;
i++)
69 inline Real &
H(
int r,
int c) {
return H_[r*
n_ + c]; }
70 inline Real &
V(
int r,
int c) {
return V_[r*
n_ + c]; }
73 inline static void cdiv(Real xr, Real xi, Real yr, Real yi, Real *cdivr, Real *cdivi) {
75 if (std::abs(yr) > std::abs(yi)) {
78 *cdivr = (xr + r*xi)/d;
79 *cdivi = (xi - r*xr)/d;
83 *cdivr = (r*xr + xi)/d;
84 *cdivi = (r*xi - xr)/d;
119 for (
int j = 0;
j <
n_;
j++) {
125 for (
int i = n_-1;
i > 0;
i--) {
131 for (
int k = 0; k <
i; k++) {
132 scale = scale + std::abs(
d_[k]);
136 for (
int j = 0;
j <
i;
j++) {
145 for (
int k = 0; k <
i; k++) {
150 Real g = std::sqrt(h);
157 for (
int j = 0;
j <
i;
j++) {
163 for (
int j = 0;
j <
i;
j++) {
167 for (
int k =
j+1; k <= i-1; k++) {
168 g +=
V(k,
j) *
d_[k];
169 e_[k] +=
V(k,
j) * f;
174 for (
int j = 0;
j <
i;
j++) {
178 Real hh = f / (h + h);
179 for (
int j = 0;
j <
i;
j++) {
182 for (
int j = 0;
j <
i;
j++) {
185 for (
int k =
j; k <= i-1; k++) {
186 V(k,
j) -= (f *
e_[k] + g *
d_[k]);
197 for (
int i = 0;
i < n_-1;
i++) {
198 V(n_-1,
i) =
V(
i,
i);
202 for (
int k = 0; k <=
i; k++) {
203 d_[k] =
V(k,
i+1) / h;
205 for (
int j = 0;
j <=
i;
j++) {
207 for (
int k = 0; k <=
i; k++) {
208 g +=
V(k,
i+1) *
V(k,
j);
210 for (
int k = 0; k <=
i; k++) {
211 V(k,
j) -= g *
d_[k];
215 for (
int k = 0; k <=
i; k++) {
219 for (
int j = 0;
j <
n_;
j++) {
233 for (
int i = 1;
i <
n_;
i++) {
240 Real eps = std::numeric_limits<Real>::epsilon();
241 for (
int l = 0; l <
n_; l++) {
245 tst1 = std::max(tst1, std::abs(
d_[l]) + std::abs(
e_[l]));
248 if (std::abs(
e_[m]) <= eps*tst1) {
265 Real p = (
d_[l+1] - g) / (2.0 *
e_[l]);
266 Real r =
Hypot(p, static_cast<Real>(1.0));
270 d_[l] =
e_[l] / (p + r);
271 d_[l+1] =
e_[l] * (p + r);
274 for (
int i = l+2;
i <
n_;
i++) {
288 for (
int i = m-1;
i >= l;
i--) {
298 p = c * d_[
i] - s * g;
299 d_[i+1] = h + s * (c * g + s * d_[
i]);
303 for (
int k = 0; k <
n_; k++) {
305 V(k, i+1) = s *
V(k, i) + c * h;
306 V(k, i) = c *
V(k, i) - s * h;
309 p = -s * s2 * c3 * el1 *
e_[l] / dl1;
315 }
while (std::abs(
e_[l]) > eps*tst1);
323 for (
int i = 0;
i < n_-1;
i++) {
326 for (
int j =
i+1;
j <
n_;
j++) {
335 for (
int j = 0;
j <
n_;
j++) {
344 template<
typename Real>
355 for (
int m = low+1; m <= high-1; m++) {
360 for (
int i = m;
i <= high;
i++) {
361 scale = scale + std::abs(
H(
i, m-1));
368 for (
int i = high;
i >= m;
i--) {
372 Real g = std::sqrt(h);
382 for (
int j = m;
j <
n_;
j++) {
384 for (
int i = high;
i >= m;
i--) {
388 for (
int i = m;
i <= high;
i++) {
393 for (
int i = 0;
i <= high;
i++) {
395 for (
int j = high;
j >= m;
j--) {
399 for (
int j = m;
j <= high;
j++) {
410 for (
int i = 0;
i <
n_;
i++) {
411 for (
int j = 0;
j <
n_;
j++) {
412 V(
i,
j) = (
i ==
j ? 1.0 : 0.0);
416 for (
int m = high-1; m >= low+1; m--) {
417 if (
H(m, m-1) != 0.0) {
418 for (
int i = m+1;
i <= high;
i++) {
421 for (
int j = m;
j <= high;
j++) {
423 for (
int i = m;
i <= high;
i++) {
427 g = (g /
ort_[m]) /
H(m, m-1);
428 for (
int i = m;
i <= high;
i++) {
446 Real eps = std::numeric_limits<Real>::epsilon();
448 Real p = 0, q = 0, r = 0, s = 0, z=0, t, w, x, y;
453 for (
int i = 0;
i < nn;
i++) {
454 if (i < low || i > high) {
458 for (
int j = std::max(
i-1, 0);
j < nn;
j++) {
459 norm = norm + std::abs(
H(
i,
j));
472 s = std::abs(
H(l-1, l-1)) + std::abs(
H(l, l));
476 if (std::abs(
H(l, l-1)) < eps * s) {
486 H(n, n) =
H(n, n) + exshift;
494 }
else if (l == n-1) {
495 w =
H(n, n-1) *
H(n-1, n);
496 p = (
H(n-1, n-1) -
H(n, n)) / 2.0;
498 z = std::sqrt(std::abs(q));
499 H(n, n) =
H(n, n) + exshift;
500 H(n-1, n-1) =
H(n-1, n-1) + exshift;
519 s = std::abs(x) + std::abs(z);
522 r = std::sqrt(p * p+q * q);
528 for (
int j = n-1;
j < nn;
j++) {
530 H(n-1,
j) = q * z + p *
H(n,
j);
531 H(n,
j) = q *
H(n,
j) - p * z;
536 for (
int i = 0;
i <=
n;
i++) {
538 H(
i, n-1) = q * z + p *
H(
i, n);
539 H(
i, n) = q *
H(
i, n) - p * z;
544 for (
int i = low;
i <= high;
i++) {
546 V(
i, n-1) = q * z + p *
V(
i, n);
547 V(
i, n) = q *
V(
i, n) - p * z;
572 w =
H(n, n-1) *
H(n-1, n);
579 for (
int i = low;
i <=
n;
i++) {
582 s = std::abs(
H(n, n-1)) + std::abs(
H(n-1, n-2));
597 s = x - w / ((y - x) / 2.0 + s);
598 for (
int i = low;
i <=
n;
i++) {
615 p = (r * s - w) /
H(m+1, m) +
H(m, m+1);
616 q =
H(m+1, m+1) - z - r - s;
618 s = std::abs(p) + std::abs(q) + std::abs(r);
625 if (std::abs(
H(m, m-1)) * (std::abs(q) + std::abs(r)) <
626 eps * (std::abs(p) * (std::abs(
H(m-1, m-1)) + std::abs(z) +
627 std::abs(
H(m+1, m+1))))) {
633 for (
int i = m+2;
i <=
n;
i++) {
642 for (
int k = m; k <= n-1; k++) {
643 bool notlast = (k != n-1);
647 r = (notlast ?
H(k+2, k-1) : 0.0);
648 x = std::abs(p) + std::abs(q) + std::abs(r);
658 s = std::sqrt(p * p + q * q + r * r);
666 H(k, k-1) = -
H(k, k-1);
677 for (
int j = k;
j < nn;
j++) {
678 p =
H(k,
j) + q *
H(k+1,
j);
680 p = p + r *
H(k+2,
j);
681 H(k+2,
j) =
H(k+2,
j) - p * z;
683 H(k,
j) =
H(k,
j) - p * x;
684 H(k+1,
j) =
H(k+1,
j) - p * y;
689 for (
int i = 0;
i <= std::min(n, k+3);
i++) {
690 p = x *
H(
i, k) + y *
H(
i, k+1);
692 p = p + z *
H(
i, k+2);
693 H(
i, k+2) =
H(
i, k+2) - p * r;
695 H(
i, k) =
H(
i, k) - p;
696 H(
i, k+1) =
H(
i, k+1) - p * q;
701 for (
int i = low;
i <= high;
i++) {
702 p = x *
V(
i, k) + y *
V(
i, k+1);
704 p = p + z *
V(
i, k+2);
705 V(
i, k+2) =
V(
i, k+2) - p * r;
707 V(
i, k) =
V(
i, k) - p;
708 V(
i, k+1) =
V(
i, k+1) - p * q;
721 for (n = nn-1; n >= 0; n--) {
730 for (
int i = n-1;
i >= 0;
i--) {
733 for (
int j = l;
j <=
n;
j++) {
734 r = r +
H(
i,
j) *
H(
j, n);
745 H(
i, n) = -r / (eps * norm);
754 t = (x * s - z * r) / q;
756 if (std::abs(x) > std::abs(z)) {
757 H(
i+1, n) = (-r - w * t) / x;
759 H(
i+1, n) = (-s - y * t) / z;
765 t = std::abs(
H(
i, n));
766 if ((eps * t) * t > 1) {
767 for (
int j =
i;
j <=
n;
j++) {
768 H(
j, n) =
H(
j, n) / t;
781 if (std::abs(
H(n, n-1)) > std::abs(
H(n-1, n))) {
782 H(n-1, n-1) = q /
H(n, n-1);
783 H(n-1, n) = -(
H(n, n) - p) /
H(n, n-1);
786 cdiv(0.0, -
H(n-1, n),
H(n-1, n-1)-p, q, &cdivr, &cdivi);
792 for (
int i = n-2;
i >= 0;
i--) {
796 for (
int j = l;
j <=
n;
j++) {
797 ra = ra +
H(
i,
j) *
H(
j, n-1);
798 sa = sa +
H(
i,
j) *
H(
j, n);
810 cdiv(-ra, -sa, w, q, &cdivr, &cdivi);
820 vi = (
d_[
i] - p) * 2.0 * q;
821 if (vr == 0.0 && vi == 0.0) {
822 vr = eps * norm * (std::abs(w) + std::abs(q) +
823 std::abs(x) + std::abs(y) + std::abs(z));
825 cdiv(x*r-z*ra+q*sa, x*s-z*sa-q*ra, vr, vi, &cdivr, &cdivi);
828 if (std::abs(x) > (std::abs(z) + std::abs(q))) {
829 H(
i+1, n-1) = (-ra - w *
H(
i, n-1) + q *
H(
i, n)) / x;
830 H(
i+1, n) = (-sa - w *
H(
i, n) - q *
H(
i, n-1)) / x;
832 cdiv(-r-y*
H(
i, n-1), -s-y*
H(
i, n), z, q, &cdivr, &cdivi);
840 t = std::max(std::abs(
H(
i, n-1)), std::abs(
H(
i, n)));
841 if ((eps * t) * t > 1) {
842 for (
int j =
i;
j <=
n;
j++) {
843 H(
j, n-1) =
H(
j, n-1) / t;
844 H(
j, n) =
H(
j, n) / t;
854 for (
int i = 0;
i < nn;
i++) {
855 if (i < low || i > high) {
856 for (
int j =
i;
j < nn;
j++) {
864 for (
int j = nn-1;
j >= low;
j--) {
865 for (
int i = low;
i <= high;
i++) {
867 for (
int k = low; k <= std::min(
j, high); k++) {
868 z = z +
V(
i, k) *
H(k,
j);
875 template<
typename Real>
879 V_ =
new Real[n_*
n_];
886 for (
int i = 0;
i <
n_;
i++)
887 for (
int j = 0;
j <
n_;
j++)
896 H_ =
new Real[n_*
n_];
898 for (
int i = 0;
i <
n_;
i++)
899 for (
int j = 0;
j <
n_;
j++)
910 template<
typename Real>
924 #endif // KALDI_MATRIX_JAMA_EIG_H_ This code computes Goodness of Pronunciation (GOP) and extracts phone-level pronunciation feature for...
MatrixIndexT NumCols() const
Returns number of columns (or zero for empty matrix).
Base class which provides matrix operations not involving resizing or allocation. ...
static void cdiv(Real xr, Real xi, Real yr, Real yi, Real *cdivr, Real *cdivi)
void GetImagEigenvalues(VectorBase< Real > *i_out)
bool IsSymmetric(Real cutoff=1.0e-05) const
Returns true if matrix is Symmetric.
void GetV(MatrixBase< Real > *V_out)
MatrixIndexT Dim() const
Returns the dimension of the vector.
~EigenvalueDecomposition()
void GetRealEigenvalues(VectorBase< Real > *r_out)
EigenvalueDecomposition(const MatrixBase< Real > &A)
#define KALDI_ASSERT(cond)
MatrixIndexT NumRows() const
Returns number of rows (or zero for empty matrix).
Provides a vector abstraction class.
double Hypot(double x, double y)