/** test matrices values */ @Test public void testMatricesValues1() { SingularValueDecomposition svd = new SingularValueDecomposition(new DenseMatrix(testSquare)); Matrix uRef = new DenseMatrix(new double[][] { { 3.0 / 5.0, 4.0 / 5.0 }, { 4.0 / 5.0, -3.0 / 5.0 } }); Matrix sRef = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 0.0, 1.0 } }); Matrix vRef = new DenseMatrix(new double[][] { { 4.0 / 5.0, -3.0 / 5.0 }, { 3.0 / 5.0, 4.0 / 5.0 } }); // check values against known references Matrix u = svd.getU(); assertEquals(0, Algebra.getNorm(u.minus(uRef)), NORM_TOLERANCE); Matrix s = svd.getS(); assertEquals(0, Algebra.getNorm(s.minus(sRef)), NORM_TOLERANCE); Matrix v = svd.getV(); assertEquals(0, Algebra.getNorm(v.minus(vRef)), NORM_TOLERANCE); }
s[k] = Algebra.hypot(s[k], a[i][k]); e[k] = Algebra.hypot(e[k], e[i]); e[p - 2] = 0.0; for (int j = p - 2; j >= k; j--) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; e[k - 1] = 0.0; for (int j = k; j < p; j++) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; double t = Algebra.hypot(f, g); double cs = f / t; double sn = g / t; t = Algebra.hypot(f, g); cs = f / t; sn = g / t;
/** * @param v The vector to compute the distance to * @return Mahalanobis distance of a multivariate vector */ public double distance(Vector v) { return Math.sqrt(v.minus(meanVector).dot(Algebra.mult(inverseCovarianceMatrix, v.minus(meanVector)))); }
/** * @param v The vector to compute the distance to * @return Mahalanobis distance of a multivariate vector */ public double distance(Vector v) { return Math.sqrt(v.minus(meanVector).dot(Algebra.mult(inverseCovarianceMatrix, v.minus(meanVector)))); }
/** * @param v The vector to compute the distance to * @return Mahalanobis distance of a multivariate vector */ public double distance(Vector v) { return Math.sqrt(v.minus(meanVector).dot(Algebra.mult(inverseCovarianceMatrix, v.minus(meanVector)))); }
public static void checkOrthogonal(Matrix m) { Matrix mTm = m.transpose().times(m); Matrix id = new DenseMatrix(mTm.numRows(),mTm.numRows()); for (int i = 0; i < mTm.numRows(); i++) { id.set(i, i, 1); } assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE); }
nrm = Algebra.hypot(nrm, qr.getQuick(i, k));
@Override public double distance(Vector v1, Vector v2) { if (v1.size() != v2.size()) { throw new CardinalityException(v1.size(), v2.size()); } return Math.sqrt(v1.minus(v2).dot(Algebra.mult(inverseCovarianceMatrix, v1.minus(v2)))); }
@Override public double distance(Vector v1, Vector v2) { if (v1.size() != v2.size()) { throw new CardinalityException(v1.size(), v2.size()); } return Math.sqrt(v1.minus(v2).dot(Algebra.mult(inverseCovarianceMatrix, v1.minus(v2)))); }
double norm = Algebra.getNorm(u.times(s).times(v.transpose()).minus(matrix)); assertEquals(0, norm, NORM_TOLERANCE);
s[k] = Algebra.hypot(s[k], a[i][k]); e[k] = Algebra.hypot(e[k], e[i]); e[p - 2] = 0.0; for (int j = p - 2; j >= k; j--) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; e[k - 1] = 0.0; for (int j = k; j < p; j++) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; double t = Algebra.hypot(f, g); double cs = f / t; double sn = g / t; t = Algebra.hypot(f, g); cs = f / t; sn = g / t;
@Override public double distance(Vector v1, Vector v2) { if (v1.size() != v2.size()) { throw new CardinalityException(v1.size(), v2.size()); } return Math.sqrt(v1.minus(v2).dot(Algebra.mult(inverseCovarianceMatrix, v1.minus(v2)))); }
/** test matrices values */ @Test public void testMatricesValues1() { SingularValueDecomposition svd = new SingularValueDecomposition(new DenseMatrix(testSquare)); Matrix uRef = new DenseMatrix(new double[][] { { 3.0 / 5.0, 4.0 / 5.0 }, { 4.0 / 5.0, -3.0 / 5.0 } }); Matrix sRef = new DenseMatrix(new double[][] { { 3.0, 0.0 }, { 0.0, 1.0 } }); Matrix vRef = new DenseMatrix(new double[][] { { 4.0 / 5.0, -3.0 / 5.0 }, { 3.0 / 5.0, 4.0 / 5.0 } }); // check values against known references Matrix u = svd.getU(); assertEquals(0, Algebra.getNorm(u.minus(uRef)), NORM_TOLERANCE); Matrix s = svd.getS(); assertEquals(0, Algebra.getNorm(s.minus(sRef)), NORM_TOLERANCE); Matrix v = svd.getV(); assertEquals(0, Algebra.getNorm(v.minus(vRef)), NORM_TOLERANCE); }
s[k] = Algebra.hypot(s[k], a[i][k]); e[k] = Algebra.hypot(e[k], e[i]); e[p - 2] = 0.0; for (int j = p - 2; j >= k; j--) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; e[k - 1] = 0.0; for (int j = k; j < p; j++) { double t = Algebra.hypot(s[j], f); double cs = s[j] / t; double sn = f / t; double t = Algebra.hypot(f, g); double cs = f / t; double sn = g / t; t = Algebra.hypot(f, g); cs = f / t; sn = g / t;
public static void checkOrthogonal(Matrix m) { Matrix mTm = m.transpose().times(m); Matrix id = new DenseMatrix(mTm.numRows(),mTm.numRows()); for (int i = 0; i < mTm.numRows(); i++) { id.set(i, i, 1); } assertEquals(0, Algebra.getNorm(mTm.minus(id)), NORM_TOLERANCE); }
nrm = Algebra.hypot(nrm, qr.getQuick(i, k));
nrm = Algebra.hypot(nrm, qr.getQuick(i, k));