Java EigenDecomposition类代码示例(javaeigendecomposition类代码示例汇总)

本文整理汇总了Java中org.apache.commons.math.linear.EigenDecomposition的典型用法代码示例。如果您正苦于以下问题:Java EigenDecomposition类的具体用法?Java EigenDecomposition怎么用?Java EigenDecomposition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Java EigenDecomposition类代码示例(javaeigendecomposition类代码示例汇总)

EigenDecomposition类属于org.apache.commons.math.linear包,在下文中一共展示了EigenDecomposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getPower

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Returns a real matrix raised to some real power 
 * Currently this method is limited to symmetric matrices only as Commons Math does not support the diagonalization of asymmetric matrices  
 * @param m The <strong>symmetric</strong> matrix to take the power of. 
 * @param p The power to raise to matrix to
 * @return The result
 */
@Override
public DoubleMatrix2D getPower(final Matrix<?> m, final double p) {
  if (m instanceof DoubleMatrix2D) {
    final RealMatrix temp = CommonsMathWrapper.wrap((DoubleMatrix2D) m);
    final EigenDecomposition eigen = new EigenDecompositionImpl(temp, 0.0);
    final double[] rEigenValues = eigen.getRealEigenvalues();
    final double[] iEigenValues = eigen.getImagEigenvalues();
    final int n = rEigenValues.length;
    final double[][] d = new double[n][n];
    for (int i = n - 1; i >= 0; --i) {
      d[i][i] = Math.pow(rEigenValues[i], p);
      if (iEigenValues[i] != 0.0) {
        throw new NotImplementedException("Cannot handle complex eigenvalues in getPower");
      }
    }
    final RealMatrix res = eigen.getV().multiply((new Array2DRowRealMatrix(d)).multiply(eigen.getVT()));
    return CommonsMathWrapper.unwrap(res);
  }
  throw new IllegalArgumentException("Can only find pow of DoubleMatrix2D; have " + m.getClass());
} 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:28,代码来源:CommonsMatrixAlgebra.java

示例2: testTridiagonal

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }

} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:EigenDecompositionImplTest.java

示例3: testBigMatrix

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test eigenvalues for a big matrix. */
public void testBigMatrix() {
    Random r = new Random(17748333525117l);
    double[] bigValues = new double[200];
    for (int i = 0; i < bigValues.length; ++i) {
        bigValues[i] = 2 * r.nextDouble() - 1;
    }
    Arrays.sort(bigValues);
    EigenDecomposition ed =
        new EigenDecompositionImpl(createTestMatrix(r, bigValues), MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(bigValues.length, eigenValues.length);
    for (int i = 0; i < bigValues.length; ++i) {
        assertEquals(bigValues[bigValues.length - i - 1], eigenValues[i], 2.0e-14);
    }
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:EigenDecompositionImplTest.java

示例4: testZeroDivide

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Verifies operation on indefinite matrix
 */
public void testZeroDivide() {
    RealMatrix indefinite = MatrixUtils.createRealMatrix(new double [][] {
            { 0.0, 1.0, -1.0 }, 
            { 1.0, 1.0, 0.0 }, 
            { -1.0,0.0, 1.0 }        
    });
    EigenDecomposition ed = new EigenDecompositionImpl(indefinite, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {2, 1, -1}), ed, 1E-12);
    double isqrt3 = 1/Math.sqrt(3.0);
    checkEigenVector((new double[] {isqrt3,isqrt3,-isqrt3}), ed, 1E-12);
    double isqrt2 = 1/Math.sqrt(2.0);
    checkEigenVector((new double[] {0.0,-isqrt2,-isqrt2}), ed, 1E-12);
    double isqrt6 = 1/Math.sqrt(6.0);
    checkEigenVector((new double[] {2*isqrt6,-isqrt6,isqrt6}), ed, 1E-12);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:EigenDecompositionImplTest.java

示例5: testTridiagonal

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test a matrix already in tridiagonal form. */
public void testTridiagonal() {
    Random r = new Random(4366663527842l);
    double[] ref = new double[30];
    for (int i = 0; i < ref.length; ++i) {
        if (i < 5) {
            ref[i] = 2 * r.nextDouble() - 1;
        } else {
            ref[i] = 0.0001 * r.nextDouble() + 6;                
        }
    }
    Arrays.sort(ref);
    TriDiagonalTransformer t =
        new TriDiagonalTransformer(createTestMatrix(r, ref));
    EigenDecomposition ed =
        new EigenDecompositionImpl(t.getMainDiagonalRef(),
                                   t.getSecondaryDiagonalRef(),
                                   MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(ref.length, eigenValues.length);
    for (int i = 0; i < ref.length; ++i) {
        assertEquals(ref[ref.length - i - 1], eigenValues[i], 2.0e-14);
    }
    
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:EigenDecompositionImplTest.java

示例6: testDimension2

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
public void testDimension2() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                { 59.0, 12.0 },
                { 12.0, 66.0 }
        });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(75.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(50.0, ed.getRealEigenvalue(1), 1.0e-15);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:EigenDecompositionImplTest.java

示例7: testDimension3

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
public void testDimension3() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  39632.0, -4824.0, -16560.0 },
                               {  -4824.0,  8693.0,   7920.0 },
                               { -16560.0,  7920.0,  17300.0 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(50000.0, ed.getRealEigenvalue(0), 3.0e-11);
    assertEquals(12500.0, ed.getRealEigenvalue(1), 3.0e-11);
    assertEquals( 3125.0, ed.getRealEigenvalue(2), 3.0e-11);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:13,代码来源:EigenDecompositionImplTest.java

示例8: testDimension4WithSplit

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
public void testDimension4WithSplit() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  0.784, -0.288,  0.000,  0.000 },
                               { -0.288,  0.616,  0.000,  0.000 },
                               {  0.000,  0.000,  0.164, -0.048 },
                               {  0.000,  0.000, -0.048,  0.136 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
    assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
    assertEquals(0.1, ed.getRealEigenvalue(3), 1.0e-15);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:EigenDecompositionImplTest.java

示例9: testDimension4WithoutSplit

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
public void testDimension4WithoutSplit() {
    RealMatrix matrix =
        MatrixUtils.createRealMatrix(new double[][] {
                               {  0.5608, -0.2016,  0.1152, -0.2976 },
                               { -0.2016,  0.4432, -0.2304,  0.1152 },
                               {  0.1152, -0.2304,  0.3088, -0.1344 },
                               { -0.2976,  0.1152, -0.1344,  0.3872 }
                           });
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(1.0, ed.getRealEigenvalue(0), 1.0e-15);
    assertEquals(0.4, ed.getRealEigenvalue(1), 1.0e-15);
    assertEquals(0.2, ed.getRealEigenvalue(2), 1.0e-15);
    assertEquals(0.1, ed.getRealEigenvalue(3), 1.0e-15);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:15,代码来源:EigenDecompositionImplTest.java

示例10: testDimensions

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test dimensions */
public void testDimensions() {
    final int m = matrix.getRowDimension();
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    assertEquals(m, ed.getV().getRowDimension());
    assertEquals(m, ed.getV().getColumnDimension());
    assertEquals(m, ed.getD().getColumnDimension());
    assertEquals(m, ed.getD().getColumnDimension());
    assertEquals(m, ed.getVT().getRowDimension());
    assertEquals(m, ed.getVT().getColumnDimension());
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:12,代码来源:EigenDecompositionImplTest.java

示例11: testEigenvalues

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test eigenvalues */
public void testEigenvalues() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    double[] eigenValues = ed.getRealEigenvalues();
    assertEquals(refValues.length, eigenValues.length);
    for (int i = 0; i < refValues.length; ++i) {
        assertEquals(refValues[i], eigenValues[i], 3.0e-15);
    }
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:EigenDecompositionImplTest.java

示例12: testEigenvectors

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test eigenvectors */
public void testEigenvectors() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    for (int i = 0; i < matrix.getRowDimension(); ++i) {
        double lambda = ed.getRealEigenvalue(i);
        RealVector v  = ed.getEigenvector(i);
        RealVector mV = matrix.operate(v);
        assertEquals(0, mV.subtract(v.mapMultiplyToSelf(lambda)).getNorm(), 1.0e-13);
    }
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:EigenDecompositionImplTest.java

示例13: testAEqualVDVt

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test A = VDVt */
public void testAEqualVDVt() {
    EigenDecomposition ed = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN);
    RealMatrix v  = ed.getV();
    RealMatrix d  = ed.getD();
    RealMatrix vT = ed.getVT();
    double norm = v.multiply(d).multiply(vT).subtract(matrix).getNorm();
    assertEquals(0, norm, 6.0e-13);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:10,代码来源:EigenDecompositionImplTest.java

示例14: testDiagonal

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/** test diagonal matrix */
public void testDiagonal() {
    double[] diagonal = new double[] { -3.0, -2.0, 2.0, 5.0 };
    RealMatrix m = createDiagonalMatrix(diagonal, diagonal.length, diagonal.length);
    EigenDecomposition ed = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN);
    assertEquals(diagonal[0], ed.getRealEigenvalue(3), 2.0e-15);
    assertEquals(diagonal[1], ed.getRealEigenvalue(2), 2.0e-15);
    assertEquals(diagonal[2], ed.getRealEigenvalue(1), 2.0e-15);
    assertEquals(diagonal[3], ed.getRealEigenvalue(0), 2.0e-15);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:EigenDecompositionImplTest.java

示例15: testRepeatedEigenvalue

import org.apache.commons.math.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Matrix with eigenvalues {8, -1, -1}
 */
public void testRepeatedEigenvalue() {
    RealMatrix repeated = MatrixUtils.createRealMatrix(new double[][] {
            {3,  2,  4},
            {2,  0,  2},
            {4,  2,  3}
    });
    EigenDecomposition ed = new EigenDecompositionImpl(repeated, MathUtils.SAFE_MIN);
    checkEigenValues((new double[] {8, -1, -1}), ed, 1E-12);
    checkEigenVector((new double[] {2, 1, 2}), ed, 1E-12);
} 
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:EigenDecompositionImplTest.java

本文标签属性:

示例:示例英文

代码:代码编程

java:java面试题

EigenDecomposition:EigenDecomposition

上一篇:Java CalendarProvider类代码示例(javacalendarprovider类代码示例汇总)
下一篇:什么“幸福之花”的名字是什么?(幸福花是什么花啊?)

为您推荐