当前位置: 首页>>代码示例>>Java>>正文


Java EigenDecompositionImpl类代码示例

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


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

示例1: getPower

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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.EigenDecompositionImpl; //导入依赖的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.EigenDecompositionImpl; //导入依赖的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.EigenDecompositionImpl; //导入依赖的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: testNonInvertible

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的package包/类
/** test non invertible matrix */
public void testNonInvertible() {
    Random r = new Random(9994100315209l);
    RealMatrix m =
        EigenDecompositionImplTest.createTestMatrix(r, new double[] { 1.0, 0.0, -1.0, -2.0, -3.0 });
    DecompositionSolver es = new EigenDecompositionImpl(m, MathUtils.SAFE_MIN).getSolver();
    assertFalse(es.isNonSingular());
    try {
        es.getInverse();
        fail("an exception should have been thrown");
    } catch (InvalidMatrixException ime) {
        // expected behavior
    } catch (Exception e) {
        fail("wrong exception caught");
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:EigenSolverTest.java

示例6: testTridiagonal

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例7: testDimension2

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例8: testDimension3

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例9: testDimension4WithSplit

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例10: testDimension4WithoutSplit

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例11: testDimensions

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例12: testEigenvalues

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例13: testEigenvectors

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例14: testAEqualVDVt

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的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

示例15: testVOrthogonal

import org.apache.commons.math.linear.EigenDecompositionImpl; //导入依赖的package包/类
/** test that V is orthogonal */
public void testVOrthogonal() {
    RealMatrix v = new EigenDecompositionImpl(matrix, MathUtils.SAFE_MIN).getV();
    RealMatrix vTv = v.transpose().multiply(v);
    RealMatrix id  = MatrixUtils.createRealIdentityMatrix(vTv.getRowDimension());
    assertEquals(0, vTv.subtract(id).getNorm(), 2.0e-13);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:EigenDecompositionImplTest.java


注:本文中的org.apache.commons.math.linear.EigenDecompositionImpl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。