org.ujmp.core.Matrix.svd()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中org.ujmp.core.Matrix.svd()方法的一些代码示例,展示了Matrix.svd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.svd()方法的具体详情如下:
包路径:org.ujmp.core.Matrix
类名称:Matrix
方法名:svd

Matrix.svd介绍

暂无

代码示例

代码示例来源:origin: ujmp/universal-java-matrix-package

public double getDouble(long... coordinates) {
  if (pca == null) {
    Matrix[] usv;
    usv = getSource().svd();
    Matrix u = usv[0];
    Matrix s = usv[1];
    pca = u.mtimes(s);
  }
  return pca.getAsDouble(coordinates);
}

代码示例来源:origin: nativelibs4java/JavaCL

public Void perform() {
    Matrix[] svd = m.svd();
    for (Matrix s : svd)
      s.getAsDouble(0, 0);
    return null;
  }
});

代码示例来源:origin: ujmp/universal-java-matrix-package

public Object call() {
  Matrix[] result = getMatrixObject().getMatrix().svd();
  result[0].showGUI();
  result[1].showGUI();
  result[2].showGUI();
  return result;
}

代码示例来源:origin: ujmp/universal-java-matrix-package

public double getDouble(long... coordinates) {
  if (pinv == null) {
    Matrix[] usv = getSource().svd();
    Matrix u = usv[0];
    Matrix s = usv[1];
    Matrix v = usv[2];
    for (int i = (int) Math.min(s.getRowCount(), s.getColumnCount()); --i >= 0;) {
      double d = s.getAsDouble(i, i);
      if (Math.abs(d) > UJMPSettings.getInstance().getTolerance()) {
        s.setAsDouble(1.0 / d, i, i);
      } else {
        s.setAsDouble(0.0, i, i);
      }
    }
    pinv = v.mtimes(s.transpose()).mtimes(u.transpose());
  }
  return pinv.getAsDouble(coordinates);
}

代码示例来源:origin: jdmp/java-data-mining-package

Matrix[] svd;
if (numberOfPrincipalComponents == 0) {
  svd = xtx.svd();
} else {
  svd = xtx.svd(numberOfPrincipalComponents);

代码示例来源:origin: ujmp/universal-java-matrix-package

Matrix[] svd = a.svd();
Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
Matrix diff = prod.minus(a);

代码示例来源:origin: ujmp/universal-java-matrix-package

public final Matrix[] svd(int k) {
  // how many iterations for self-multiplication, good values seem to be
  // in the range 3 to 8
  final int iterations = 3;
  // self-multiplication
  Matrix aSquared = this.mtimes(transpose());
  for (int i = 0; i < iterations; i++) {
    aSquared = aSquared.mtimes(aSquared);
  }
  // multiply with random matrix
  Matrix o = Matrix.Factory.randn(getRowCount(), k);
  Matrix y = aSquared.mtimes(this).mtimes(o);
  // decompose
  Matrix[] qr = y.qr();
  Matrix q = qr[0];
  // calculate low rank SVD
  Matrix b = q.transpose().mtimes(this);
  Matrix[] svd = b.svd();
  Matrix uHat = svd[0];
  Matrix s = svd[1];
  Matrix v = svd[2];
  Matrix u = q.mtimes(uHat);
  return new Matrix[] { u, s, v };
}

代码示例来源:origin: org.ujmp/ujmp-examples

double determinant = dense.det();
Matrix[] singularValueDecomposition = dense.svd();
Matrix[] eigenValueDecomposition = dense.eig();
Matrix[] luDecomposition = dense.lu();

代码示例来源:origin: ujmp/universal-java-matrix-package

double determinant = dense.det();
Matrix[] singularValueDecomposition = dense.svd();
Matrix[] eigenValueDecomposition = dense.eig();
Matrix[] luDecomposition = dense.lu();

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDSquareRandLarge() throws Exception {
  if (!isTestLarge()) {
    return;
  }
  Matrix a = createMatrixWithAnnotation(109, 109);
  a.randn(Ret.ORIG);
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDSquareRandSmall() throws Exception {
  Matrix a = createMatrixWithAnnotation(10, 10);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.SQUARE, Size.SMALL, EntryType.RANDN)) {
    return;
  }
  a.randn(Ret.ORIG);
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDSquareLarge() throws Exception {
  if (!isTestLarge()) {
    return;
  }
  Matrix a = createMatrixWithAnnotation(107, 107);
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDFatSmall() throws Exception {
  Matrix a = createMatrixWithAnnotation(4, 6);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.FAT, Size.SMALL, null)) {
    return;
  }
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDSquareSmall() throws Exception {
  Matrix a = createMatrixWithAnnotation(5, 5);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.SQUARE, Size.SMALL, null)) {
    return;
  }
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDTallSmall() throws Exception {
  Matrix a = createMatrixWithAnnotation(6, 4);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.TALL, Size.SMALL, null)) {
    return;
  }
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDTallLarge() throws Exception {
  if (!isTestLarge()) {
    return;
  }
  Matrix a = createMatrixWithAnnotation(140, 121);
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDWikipedia() throws Exception {
  Matrix a = createMatrixWithAnnotation(4, 5);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.FAT, Size.SMALL, null)) {
    return;
  }
  a.setAsDouble(1, 0, 0);
  a.setAsDouble(2, 0, 4);
  a.setAsDouble(3, 1, 2);
  a.setAsDouble(4, 3, 1);
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

代码示例来源:origin: ujmp/universal-java-matrix-package

@Test
public final void testSVDFatLarge() throws Exception {
  if (!isTestLarge()) {
    return;
  }
  Matrix a = createMatrixWithAnnotation(123, 142);
  if (!isSupported(a, MatrixLibraries.SVD, MatrixLayout.FAT, Size.LARGE, null)) {
    return;
  }
  for (int r = 0, v = 1; r < a.getRowCount(); r++) {
    for (int c = 0; c < a.getColumnCount(); c++) {
      a.setAsDouble(v++, r, c);
    }
  }
  Matrix[] svd = a.svd();
  Matrix prod = svd[0].mtimes(svd[1]).mtimes(svd[2].transpose());
  assertEquals(0.0, prod.minus(a).getRMS(), TOLERANCE);
  if (a instanceof Erasable) {
    ((Erasable) a).erase();
  }
}

相关文章

Matrix类方法