本文整理汇总了Java中org.apache.commons.math3.linear.EigenDecomposition.getRealEigenvalues方法的典型用法代码示例。如果您正苦于以下问题:Java EigenDecomposition.getRealEigenvalues方法的具体用法?Java EigenDecomposition.getRealEigenvalues怎么用?Java EigenDecomposition.getRealEigenvalues使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.EigenDecomposition
的用法示例。
在下文中一共展示了EigenDecomposition.getRealEigenvalues方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: fitEllipsoid
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Fit points to the polynomial expression Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz
* + 2Fyz + 2Gx + 2Hy + 2Iz = 1 and determine the center and radii of the
* fit ellipsoid.
*
* @param points
* the points to be fit to the ellipsoid.
*/
public void fitEllipsoid(ArrayList<ThreeSpacePoint> points)
{
// Fit the points to Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz
// + 2Fyz + 2Gx + 2Hy + 2Iz = 1 and solve the system.
// v = (( d' * d )^-1) * ( d' * ones.mapAddToSelf(1));
RealVector v = solveSystem(points);
// Form the algebraic form of the ellipsoid.
RealMatrix a = formAlgebraicMatrix(v);
// Find the center of the ellipsoid.
center = findCenter(a);
// Translate the algebraic form of the ellipsoid to the center.
RealMatrix r = translateToCenter(center, a);
// Generate a submatrix of r.
RealMatrix subr = r.getSubMatrix(0, 2, 0, 2);
// subr[i][j] = subr[i][j] / -r[3][3]).
double divr = -r.getEntry(3, 3);
for (int i = 0; i < subr.getRowDimension(); i++)
{
for (int j = 0; j < subr.getRowDimension(); j++)
{
subr.setEntry(i, j, subr.getEntry(i, j) / divr);
}
}
// Get the eigenvalues and eigenvectors.
EigenDecomposition ed = new EigenDecomposition(subr, 0);
evals = ed.getRealEigenvalues();
evecs = ed.getEigenvector(0);
evecs1 = ed.getEigenvector(1);
evecs2 = ed.getEigenvector(2);
// Find the radii of the ellipsoid.
radii = findRadii(evals);
}
示例5: eigen_bak
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Calculates the eigen decomposition of a real matrix. The eigen
* decomposition of matrix A is a set of two matrices: V and D such that A =
* V × D × VT. A, V and D are all m × m matrices.
*
* @param a Given matrix.
* @return Result W/V arrays.
*/
public static Array[] eigen_bak(Array a) {
int m = a.getShape()[0];
Array Wa;
Array Va = Array.factory(DataType.DOUBLE, new int[]{m, m});
double[][] aa = (double[][]) ArrayUtil.copyToNDJavaArray(a);
RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
EigenDecomposition decomposition = new EigenDecomposition(matrix);
if (decomposition.hasComplexEigenvalues()) {
Wa = Array.factory(DataType.OBJECT, new int[]{m});
double[] rev = decomposition.getRealEigenvalues();
double[] iev = decomposition.getImagEigenvalues();
for (int i = 0; i < m; i++) {
Wa.setObject(i, new Complex(rev[i], iev[i]));
RealVector v = decomposition.getEigenvector(i);
for (int j = 0; j < v.getDimension(); j++) {
Va.setDouble(j * m + i, v.getEntry(j));
}
}
} else {
RealMatrix V = decomposition.getV();
RealMatrix D = decomposition.getD();
Wa = Array.factory(DataType.DOUBLE, new int[]{m});
for (int i = 0; i < m; i++) {
for (int j = 0; j < m; j++) {
Va.setDouble(i * m + (m - j - 1), V.getEntry(i, j));
if (i == j) {
Wa.setDouble(m - i - 1, D.getEntry(i, j));
}
}
}
}
return new Array[]{Wa, Va};
}
示例6: componize
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
public void componize(double [][] covariate){
// replace the initial data set the same values minus the means from each variable-column
for (int j=0; j < covariate[0].length; j++ ) {
DescriptiveStatistics stats = new DescriptiveStatistics();
for (int k=0 ; k < covariate.length ; k++){
stats.addValue(covariate[k][j]);}
double mean=stats.getMean();
for (int k=0 ; k < covariate.length ; k++){
covariate[k][j]= covariate[k][j]-mean;}
// here ends the iteration that replaces all values with the value minus the mean of the respective column
}
// We get the Covariance matrix for the "adjusted by mean" data set
RealMatrix covariance_matrix= new PearsonsCorrelation(covariate).getCorrelationMatrix();
// we get the Eigen values and the Eigen Vectors Via Eigen Value Decomposition.
EigenDecomposition Eig = new EigenDecomposition(covariance_matrix, 1);
// get the Eigen Values
double Eigenvaluess [] =Eig.getRealEigenvalues();
// Get the Eigen vectors
RealMatrix Eigenvec = Eig.getV();
double [][] EigenVecors=Eigenvec.getData();
//Sort everything to get the Vectors with the highest significance
SortTableDouble sort = new SortTableDouble();
sort.sorting (Eigenvaluess,EigenVecors );
EigenVecor =sort.value_matrix();
Eigenvalues=sort.scanned_values();
Perchentages= new double[Eigenvalues.length];
for (int k=0 ; k < Eigenvalues.length ; k++){
Perchentages[k]= Eigenvalues[k]/Eigenvalues.length ;}
}
示例7: MultivariateNormalDistribution
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Creates a multivariate normal distribution with the given mean vector and
* covariance matrix.
* <br/>
* The number of dimensions is equal to the length of the mean vector
* and to the number of rows and columns of the covariance matrix.
* It is frequently written as "p" in formulae.
*
* @param rng Random Number Generator.
* @param means Vector of means.
* @param covariances Covariance matrix.
* @throws DimensionMismatchException if the arrays length are
* inconsistent.
* @throws SingularMatrixException if the eigenvalue decomposition cannot
* be performed on the provided covariance matrix.
* @throws NonPositiveDefiniteMatrixException if any of the eigenvalues is
* negative.
*/
public MultivariateNormalDistribution(RandomGenerator rng,
final double[] means,
final double[][] covariances)
throws SingularMatrixException,
DimensionMismatchException,
NonPositiveDefiniteMatrixException {
super(rng, means.length);
final int dim = means.length;
if (covariances.length != dim) {
throw new DimensionMismatchException(covariances.length, dim);
}
for (int i = 0; i < dim; i++) {
if (dim != covariances[i].length) {
throw new DimensionMismatchException(covariances[i].length, dim);
}
}
this.means = MathArrays.copyOf(means);
covarianceMatrix = new Array2DRowRealMatrix(covariances);
// Covariance matrix eigen decomposition.
final EigenDecomposition covMatDec = new EigenDecomposition(covarianceMatrix);
// Compute and store the inverse.
covarianceMatrixInverse = covMatDec.getSolver().getInverse();
// Compute and store the determinant.
covarianceMatrixDeterminant = covMatDec.getDeterminant();
// Eigenvalues of the covariance matrix.
final double[] covMatEigenvalues = covMatDec.getRealEigenvalues();
for (int i = 0; i < covMatEigenvalues.length; i++) {
if (covMatEigenvalues[i] < 0) {
throw new NonPositiveDefiniteMatrixException(covMatEigenvalues[i], i, 0);
}
}
// Matrix where each column is an eigenvector of the covariance matrix.
final Array2DRowRealMatrix covMatEigenvectors = new Array2DRowRealMatrix(dim, dim);
for (int v = 0; v < dim; v++) {
final double[] evec = covMatDec.getEigenvector(v).toArray();
covMatEigenvectors.setColumn(v, evec);
}
final RealMatrix tmpMatrix = covMatEigenvectors.transpose();
// Scale each eigenvector by the square root of its eigenvalue.
for (int row = 0; row < dim; row++) {
final double factor = FastMath.sqrt(covMatEigenvalues[row]);
for (int col = 0; col < dim; col++) {
tmpMatrix.multiplyEntry(row, col, factor);
}
}
samplingMatrix = covMatEigenvectors.multiply(tmpMatrix);
}
示例8: fitEllipsoid
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Fit points to the polynomial expression Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz
* + 2Fyz + 2Gx + 2Hy + 2Iz = 1 and determine the center and radii of the
* fit ellipsoid.
*
* @param points the points to be fit to the ellipsoid.
*/
public boolean fitEllipsoid(List<? extends ThreeSpacePoint> points) {
// Fit the points to Ax^2 + By^2 + Cz^2 + 2Dxy + 2Exz
// + 2Fyz + 2Gx + 2Hy + 2Iz = 1 and solve the system.
// v = (( d' * d )^-1) * ( d' * ones.mapAddToSelf(1));
RealVector v = solveSystem(points);
if (v == null) {
return false;
}
// Form the algebraic form of the ellipsoid.
RealMatrix a = formAlgebraicMatrix(v);
// Find the center of the ellipsoid.
center = findCenter(a);
// Translate the algebraic form of the ellipsoid to the center.
RealMatrix r = translateToCenter(center, a);
// Generate a submatrix of r.
RealMatrix subr = r.getSubMatrix(0, 2, 0, 2);
// subr[i][j] = subr[i][j] / -r[3][3]).
double divr = -r.getEntry(3, 3);
for (int i = 0; i < subr.getRowDimension(); i++) {
for (int j = 0; j < subr.getRowDimension(); j++) {
subr.setEntry(i, j, subr.getEntry(i, j) / divr);
}
}
// Get the eigenvalues and eigenvectors.
EigenDecomposition ed = new EigenDecomposition(subr, 0);
evals = ed.getRealEigenvalues();
evecs = ed.getEigenvector(0);
evecs1 = ed.getEigenvector(1);
evecs2 = ed.getEigenvector(2);
// Find the radii of the ellipsoid.
radii = findRadii(evals);
return true;
}
示例9: computeEigen
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Function to perform Eigen decomposition on a given matrix.
* Input must be a symmetric matrix.
*
* @param in matrix object
* @return array of matrix blocks
* @throws DMLRuntimeException if DMLRuntimeException occurs
*/
private static MatrixBlock[] computeEigen(MatrixObject in)
throws DMLRuntimeException
{
if ( in.getNumRows() != in.getNumColumns() ) {
throw new DMLRuntimeException("Eigen Decomposition can only be done on a square matrix. Input matrix is rectangular (rows=" + in.getNumRows() + ", cols="+ in.getNumColumns() +")");
}
Array2DRowRealMatrix matrixInput = DataConverter.convertToArray2DRowRealMatrix(in);
EigenDecomposition eigendecompose = new EigenDecomposition(matrixInput);
RealMatrix eVectorsMatrix = eigendecompose.getV();
double[][] eVectors = eVectorsMatrix.getData();
double[] eValues = eigendecompose.getRealEigenvalues();
//Sort the eigen values (and vectors) in increasing order (to be compatible w/ LAPACK.DSYEVR())
int n = eValues.length;
for (int i = 0; i < n; i++) {
int k = i;
double p = eValues[i];
for (int j = i + 1; j < n; j++) {
if (eValues[j] < p) {
k = j;
p = eValues[j];
}
}
if (k != i) {
eValues[k] = eValues[i];
eValues[i] = p;
for (int j = 0; j < n; j++) {
p = eVectors[j][i];
eVectors[j][i] = eVectors[j][k];
eVectors[j][k] = p;
}
}
}
MatrixBlock mbValues = DataConverter.convertToMatrixBlock(eValues, true);
MatrixBlock mbVectors = DataConverter.convertToMatrixBlock(eVectors);
return new MatrixBlock[] { mbValues, mbVectors };
}
示例10: complexRoots
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
/**
* Complex root approximation using companion matrix.
* @param a squarefree univariate polynomial
* @return list of approximations of complex roots of the polynomial
*/
public List<Complex<BigDecimal>> complexRoots(GenPolynomial<C> a) {
List<Complex<BigDecimal>> r = new ArrayList<Complex<BigDecimal>>();
ComplexRing<BigDecimal> cr = new ComplexRing<BigDecimal>(new BigDecimal(0.0, MathContext.DECIMAL64));
Complex<BigDecimal> cc = new Complex<BigDecimal>(cr);
if (a == null || a.isZERO()) {
r.add(cc);
return r;
}
if (a.isConstant()) {
return r;
}
a = a.monic();
UnivPowerSeriesRing<C> pr = new UnivPowerSeriesRing<C>(a.ring);
UnivPowerSeries<C> ps = pr.fromPolynomial(a);
// Construct the companion matrix
int N = (int) a.degree();
RealMatrix A = new Array2DRowRealMatrix(N, N);
for (int i = 0; i < N; i++) {
A.setEntry(i, N - 1, -ps.coefficient(i).getRational().doubleValue());
}
for (int i = 1; i < N; i++) {
A.setEntry(i, i - 1, 1.0);
}
//System.out.println("A = " + A);
// compute eigenvalues
EigenDecomposition ed = new EigenDecomposition(A);
double[] realValues = ed.getRealEigenvalues();
double[] imagValues = ed.getImagEigenvalues();
//RealMatrix V = ed.getV();
//System.out.println("V = " + V);
//RealMatrix D = ed.getD();
//System.out.println("D = " + D);
// construct root list
for (int i = 0; i < N; i++) {
cc = new Complex<BigDecimal>(cr, new BigDecimal(realValues[i], MathContext.DECIMAL64),
new BigDecimal(imagValues[i], MathContext.DECIMAL64));
//System.out.println("cc = " + cc + ", re = " + realValues[i] + ", im = " + imagValues[i]);
r.add(cc);
}
return r;
}