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


Java EigenDecomposition类代码示例

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


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

示例1: root

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * @param p
 * @return the p-th root matrix of this matrix
 */
public Matrix root (double p) {
	if (!isSquare())
		throw new IllegalArgumentException("No sqaure matrix.");
	if (p==1) return this;
	if (p<1) throw new IllegalArgumentException(String.format("Illegal fractional root: %f", p));
	EigenDecomposition ev = new EigenDecomposition(this);
	RealMatrix V = ev.getV();
	RealMatrix D = ev.getD();
	for (int i=0; i<D.getRowDimension(); i++) {
		if (D.getEntry(i,i)<0)
			throw new IllegalStateException("Root of the matrix is not defined.");
		D.setEntry(i,i,Math.pow(D.getEntry(i,i),1./p));
	}
	RealMatrix B = V.multiply(D).multiply(new LUDecomposition(V).getSolver().getInverse());
	return new Matrix(B.getData());
}
 
开发者ID:loehndorf,项目名称:scengen,代码行数:21,代码来源:Matrix.java

示例2: calculate

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
@Override
public Optional<Ellipsoid> calculate(final Matrix4d quadricSolution) {
	Vector3d center;
	try {
		center = findCenter(quadricSolution);
	}
	catch (SingularMatrixException sme) {
		return Optional.empty();
	}
	final Matrix4d translated = translateToCenter(quadricSolution, center);
	final EigenDecomposition decomposition = solveEigenDecomposition(
		translated);
	if (!isEllipsoid(decomposition.getRealEigenvalues())) {
		return Optional.empty();
	}
	final double[] radii = Arrays.stream(decomposition.getRealEigenvalues())
		.map(ev -> Math.sqrt(1.0 / ev)).toArray();
	final Ellipsoid ellipsoid = new Ellipsoid(radii[0], radii[1], radii[2]);
	ellipsoid.setCentroid(center);
	final Matrix3d orientation = toOrientationMatrix(decomposition);
	ellipsoid.setOrientation(orientation);
	return Optional.of(ellipsoid);
}
 
开发者ID:bonej-org,项目名称:BoneJ2,代码行数:24,代码来源:QuadricToEllipsoid.java

示例3: toOrientationMatrix

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
private Matrix3d toOrientationMatrix(final EigenDecomposition decomposition) {
	final RealVector e1 = decomposition.getEigenvector(0);
	final RealVector e2 = decomposition.getEigenvector(1);
	final RealVector e3 = decomposition.getEigenvector(2);
	final Vector3d x = new Vector3d(e1.getEntry(0), e1.getEntry(1), e1.getEntry(
		2));
	final Vector3d y = new Vector3d(e2.getEntry(0), e2.getEntry(1), e2.getEntry(
		2));
	final Vector3d z = new Vector3d(e3.getEntry(0), e3.getEntry(1), e3.getEntry(
		2));
	final Matrix3d orientation = new Matrix3d();
	orientation.setColumn(0, x);
	orientation.setColumn(1, y);
	orientation.setColumn(2, z);
	return orientation;
}
 
开发者ID:bonej-org,项目名称:BoneJ2,代码行数:17,代码来源:QuadricToEllipsoid.java

示例4: setup

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
@Before
public void setup() {
    assertEquals(weights.length, showerPixelIds.length);
    assertEquals(valuesNotWeighted.length, weights.length);

    Weighted2dStatistics stats2d = Weighted2dStatistics.ofArrays(pixelX, pixelY, weights);

    cog = stats2d.mean;
    covarianceMatrix = stats2d.covarianceMatrix;
    eig = new EigenDecomposition(covarianceMatrix);


    //get statistics
    for (double value : valuesWeighted) {
        s.addValue(value);
    }
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:18,代码来源:HillasTest.java

示例5: findFeatureSpace

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Find feature space tensor [ ].
 *
 * @param log            the log
 * @param featureVectors the feature vectors
 * @param components     the components
 * @return the tensor [ ]
 */
protected Tensor[] findFeatureSpace(final NotebookOutput log, final Supplier<Stream<Tensor[]>> featureVectors, final int components) {
  return log.code(() -> {
    final int column = 1;
    final Tensor[] prototype = featureVectors.get().findAny().get();
    final int[] dimensions = prototype[column].getDimensions();
    final EigenDecomposition decomposition = new EigenDecomposition(FindPCAFeatures.getCovariance(() -> featureVectors.get().map(x -> x[column].getData())));
    final int[] orderedVectors = IntStream.range(0, components).mapToObj(x -> x)
                                          .sorted(Comparator.comparing(x -> -decomposition.getRealEigenvalue(x))).mapToInt(x -> x).toArray();
    return IntStream.range(0, orderedVectors.length)
                    .mapToObj(i -> {
                                final Tensor src = new Tensor(decomposition.getEigenvector(orderedVectors[i]).toArray(), dimensions).copy();
                                return src
                                  .scale(1.0 / src.rms())
                                  //.scale((decomposition.getRealEigenvalue(orderedVectors[i]) / decomposition.getRealEigenvalue(orderedVectors[orderedVectors.length - 1])))
                                  .scale(Math.sqrt(6. / (components + prototype[column].dim() + 1)))
                                  ;
                              }
                             ).toArray(i -> new Tensor[i]);
  });
}
 
开发者ID:SimiaCryptus,项目名称:MindsEye,代码行数:29,代码来源:FindPCAFeatures.java

示例6: compute

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
@Override
public void compute(final Mesh input, final DoubleType output) {

	final RealMatrix it = inertiaTensor.calculate(input);
	final EigenDecomposition ed = new EigenDecomposition(it);

	final double l1 = ed.getRealEigenvalue(0) - ed.getRealEigenvalue(2) + ed.getRealEigenvalue(1);
	final double l2 = ed.getRealEigenvalue(0) - ed.getRealEigenvalue(1) + ed.getRealEigenvalue(2);
	final double l3 = ed.getRealEigenvalue(2) - ed.getRealEigenvalue(0) + ed.getRealEigenvalue(1);

	final double g = 1 / (8 * Math.PI / 15);

	final double a = Math.pow(g * l1 * l1 / Math.sqrt(l2 * l3), 1 / 5d);
	final double b = Math.pow(g * l2 * l2 / Math.sqrt(l1 * l3), 1 / 5d);
	final double c = Math.pow(g * l3 * l3 / Math.sqrt(l1 * l2), 1 / 5d);

	double volumeEllipsoid = (4 / 3d * Math.PI * a * b * c);

	output.set(volume.calculate(input).get() / volumeEllipsoid);
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:21,代码来源:DefaultSparenessMesh.java

示例7: getRoots

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
@Override
public Double[] getRoots(RealPolynomialFunction1D function) {
  ArgChecker.notNull(function, "function");
  double[] coeffs = function.getCoefficients();
  int l = coeffs.length - 1;
  double[][] hessianDeref = new double[l][l];
  for (int i = 0; i < l; i++) {
    hessianDeref[0][i] = -coeffs[l - i - 1] / coeffs[l];
    for (int j = 1; j < l; j++) {
      hessianDeref[j][i] = 0;
      if (i != l - 1) {
        hessianDeref[i + 1][i] = 1;
      }
    }
  }
  RealMatrix hessian = new Array2DRowRealMatrix(hessianDeref);
  double[] d = new EigenDecomposition(hessian).getRealEigenvalues();
  Double[] result = new Double[d.length];
  for (int i = 0; i < d.length; i++) {
    result[i] = d[i];
  }
  return result;
}
 
开发者ID:OpenGamma,项目名称:Strata,代码行数:24,代码来源:EigenvaluePolynomialRootFinder.java

示例8: computeCriticalDelay

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
private void computeCriticalDelay() {
    EigenDecomposition e = new EigenDecomposition(effortMatrix_T);
    double[] realParts = e.getRealEigenvalues();
    double[] imagParts = e.getImagEigenvalues();

    double largestAbsoluteEigenvalue = 0;
    for (int i = 0; i < realParts.length; i++) {
        if (imagParts[i] < 0.0000000001 & realParts[i] > largestAbsoluteEigenvalue) {
            largestAbsoluteEigenvalue = realParts[i];
        }
    }
    this.criticalDelay = largestAbsoluteEigenvalue;
}
 
开发者ID:hpiasg,项目名称:asgdrivestrength,代码行数:14,代码来源:EqualDelayMatrixOptimizer.java

示例9: conditionCovarianceMatrix

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Conditions the supplied covariance matrix by enforcing
 * positive eigenvalues along its main diagonal. 
 * @param S original covariance matrix
 * @return modified covariance matrix
 */
private RealMatrix conditionCovarianceMatrix(RealMatrix S) {
	EigenDecomposition ed = new EigenDecomposition(S);  // S  ->  V . D . V^T
	RealMatrix V  = ed.getV();
	RealMatrix D  = ed.getD();	// diagonal matrix of eigenvalues
	RealMatrix VT = ed.getVT();
	for (int i = 0; i < D.getRowDimension(); i++) {
		D.setEntry(i, i, Math.max(D.getEntry(i, i), 10E-6));	// setting eigenvalues to zero is not enough!
	}
	return V.multiply(D).multiply(VT);
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:17,代码来源:MahalanobisDistance.java

示例10: XEVD

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Constructor
 * @param matrix     the input matrix
 */
XEVD(RealMatrix matrix) {
    final EigenDecomposition evd = new EigenDecomposition(matrix);
    this.d = toDataFrame(evd.getD());
    this.v = toDataFrame(evd.getV());
    this.eigenValues = Array.of(evd.getRealEigenvalues());
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:11,代码来源:XDataFrameAlgebraApache.java

示例11: calcEigenvalues

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * @param a
 * @return dataset of eigenvalues (can be double or complex double)
 */
public static Dataset calcEigenvalues(Dataset a) {
	EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
	double[] rev = evd.getRealEigenvalues();

	if (evd.hasComplexEigenvalues()) {
		double[] iev = evd.getImagEigenvalues();
		return DatasetFactory.createComplexDataset(ComplexDoubleDataset.class, rev, iev);
	}
	return DatasetFactory.createFromObject(rev);
}
 
开发者ID:eclipse,项目名称:january,代码行数:15,代码来源:LinearAlgebra.java

示例12: calcEigenDecomposition

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
/**
 * Calculate eigen-decomposition A = V D V^T
 * @param a
 * @return array of D eigenvalues (can be double or complex double) and V eigenvectors
 */
public static Dataset[] calcEigenDecomposition(Dataset a) {
	EigenDecomposition evd = new EigenDecomposition(createRealMatrix(a));
	Dataset[] results = new Dataset[2];

	double[] rev = evd.getRealEigenvalues();
	if (evd.hasComplexEigenvalues()) {
		double[] iev = evd.getImagEigenvalues();
		results[0] = DatasetFactory.createComplexDataset(ComplexDoubleDataset.class, rev, iev);
	} else {
		results[0] = DatasetFactory.createFromObject(rev);
	}
	results[1] = createDataset(evd.getV());
	return results;
}
 
开发者ID:eclipse,项目名称:january,代码行数:20,代码来源:LinearAlgebra.java

示例13: matrixLog

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
static double[][] matrixLog (double[][] matrix) {
	if (matrix.length==1)
		return new double[][]{{Math.log(matrix[0][0])}};
	if (matrix.length!=matrix[0].length)
		throw new IllegalArgumentException("No sqaure matrix.");
	RealMatrix A = new Array2DRowRealMatrix(matrix);
	EigenDecomposition ev = new EigenDecomposition(A);
	RealMatrix V = ev.getV();
	RealMatrix Vinv = (new LUDecomposition(V).getSolver().getInverse());
	RealMatrix logA = Vinv.multiply(A).multiply(V);
	for (int i=0; i<matrix.length; i++)
		logA.setEntry(i, i,Math.log(logA.getEntry(i, i)));
	return V.multiply(logA).multiply(Vinv).getData();
}
 
开发者ID:loehndorf,项目名称:scengen,代码行数:15,代码来源:CovarianceDiscrepancy.java

示例14: solveEigenDecomposition

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
private static EigenDecomposition solveEigenDecomposition(
	final Matrix4d quadric)
{
	// @formatter:off
	final RealMatrix input = new Array2DRowRealMatrix(new double[][]{
			{quadric.m00, quadric.m01, quadric.m02},
			{quadric.m10, quadric.m11, quadric.m12},
			{quadric.m20, quadric.m21, quadric.m22},
	}).scalarMultiply(-1.0 / quadric.m33);
	// @formatter:on
	return new EigenDecomposition(input);
}
 
开发者ID:bonej-org,项目名称:BoneJ2,代码行数:13,代码来源:QuadricToEllipsoid.java

示例15: calculateDelta

import org.apache.commons.math3.linear.EigenDecomposition; //导入依赖的package包/类
public double calculateDelta(EigenDecomposition eig) {
    // calculate the angle between the eigenvector and the camera axis.
    // So basicly the angle between the major-axis of the ellipse and the
    // camrera axis.
    // this will be written in radians.
    double longitudinalComponent = eig.getEigenvector(0).getEntry(0);
    double transverseComponent = eig.getEigenvector(0).getEntry(1);
    return Math.atan(transverseComponent / longitudinalComponent);
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:10,代码来源:HillasParameters.java


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