本文整理汇总了Java中org.apache.commons.math3.linear.EigenDecomposition.getV方法的典型用法代码示例。如果您正苦于以下问题:Java EigenDecomposition.getV方法的具体用法?Java EigenDecomposition.getV怎么用?Java EigenDecomposition.getV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.linear.EigenDecomposition
的用法示例。
在下文中一共展示了EigenDecomposition.getV方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: 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示例3: 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示例4: 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};
}
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:43,代码来源:LinalgUtil.java示例5: 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 ;}
}
开发者ID:SOCR,项目名称:HTML5_WebSite,代码行数:40,代码来源:pca_analysis.java示例6: reduceTraining
import org.apache.commons.math3.linear.EigenDecomposition; //导入方法依赖的package包/类
public double[][] reduceTraining(double[][] data, String[] classLabels) {
assert(data.length > 0);
assert(data[0].length == super.inputSize);
double[][] reducedData = changingValueReducer.reduceTraining(data, classLabels);
RealMatrix dataMatrix = new Array2DRowRealMatrix(reducedData);
// NOTE(eriq): The math says that we should first center our data.
// But, centering the data (subtracting the mean) gives up much worse results...
// RealMatrix centeredData = dataMatrix.subtract(getMeanMatrix(dataMatrix));
RealMatrix centeredData = dataMatrix;
Covariance covariance = new Covariance(reducedData);
EigenDecomposition eigenDecomp = new EigenDecomposition(covariance.getCovarianceMatrix());
// Get the eigen vectors.
// Transpose them (each eigen vector is now in a row).
// Take the top |reducedFeatureVectorLength| vectors.
// TODO(eriq): Verify |reducedFeatureVectorLength| > |num reduced features|.
// NOTE(eriq): Are the eigen vectors along the vertical or horizontal.
// transformationMatrix = eigenDecomp.getV().transpose();
transformationMatrix = eigenDecomp.getV();
// Get only the top |super.outputSize| eigen vectors.
transformationMatrix = transformationMatrix.getSubMatrix(0, super.outputSize - 1, 0, reducedData[0].length - 1);
RealMatrix finalData = transformationMatrix.multiply(centeredData.transpose()).transpose();
return finalData.getData();
}
开发者ID:eriq-augustine,项目名称:jocr,代码行数:32,代码来源:KLTReducer.java示例7: 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 };
}
开发者ID:apache,项目名称:systemml,代码行数:50,代码来源:LibCommonsMath.java本文标签属性:
示例:示例志愿表
代码:代码转换器
java:java自行车
EigenDecomposition:EigenDecomposition
getV:getvoice是什么意思