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


Java EigenvalueDecomposition类代码示例

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


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

示例1: getRoots

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Double[] getRoots(final RealPolynomialFunction1D function) {
  Validate.notNull(function, "function");
  final double[] coeffs = function.getCoefficients();
  final int l = coeffs.length - 1;
  final DoubleMatrix2D hessian = DoubleFactory2D.dense.make(l, l);
  for (int i = 0; i < l; i++) {
    hessian.setQuick(0, i, -coeffs[l - i - 1] / coeffs[l]);
    for (int j = 1; j < l; j++) {
      hessian.setQuick(j, i, 0);
      if (i != l - 1) {
        hessian.setQuick(i + 1, i, 1);
      }
    }
  }
  final double[] d = new EigenvalueDecomposition(hessian).getRealEigenvalues().toArray();
  final Double[] result = new Double[d.length];
  for (int i = 0; i < d.length; i++) {
    result[i] = d[i];
  }
  return result;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:26,代码来源:EigenvaluePolynomialRootFinder.java

示例2: getGt

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
private static DoubleMatrix2D getGt(final DenseDoubleMatrix2D p, final DenseDoubleMatrix2D q, double lambda) {
    final int K = p.columns();

    DenseDoubleMatrix2D A1 = new DenseDoubleMatrix2D(K, K);
    q.zMult(q, A1, 1.0, 0.0, true, false);
    for (int k = 0; k < K; k++) {
        A1.setQuick(k, k, lambda + A1.getQuick(k, k));
    }

    EigenvalueDecomposition eig = new EigenvalueDecomposition(A1);
    DoubleMatrix1D d = eig.getRealEigenvalues();
    DoubleMatrix2D gt = eig.getV();
    for (int k = 0; k < K; k++) {
        double a = sqrt(d.get(k));
        gt.viewColumn(k).assign(x -> a * x);
    }

    return gt;
}
 
开发者ID:RankSys,项目名称:RankSys,代码行数:20,代码来源:PZTFactorizer.java

示例3: SolveSpectralClustering

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
/**
 * Finds the clusters using algorithm version 1.
 * 
 * @param similarityMatrix
 *            the similarity matrix
 * @param numCluster
 *            the number of clusters to construct
 */
public static void SolveSpectralClustering(DenseDoubleMatrix2D similarityMatrix, int numCluster,
        SimilarityMatrixTransformer transformer) {
    for (int r = 0; r < similarityMatrix.rows(); r++) {
        for (int c = 0; c < similarityMatrix.columns(); c++) {
            System.out.print(similarityMatrix.getQuick(r, c) + " ");
        }
        System.out.println();
    }

    DenseDoubleMatrix2D weightedMatrix = transformer.transform(similarityMatrix);
    DenseDoubleMatrix2D laplacianMatrix = getLaplacian(weightedMatrix);
    EigenvalueDecomposition eigenDecomposition = new EigenvalueDecomposition(laplacianMatrix);
    DoubleMatrix2D eigenVectors = eigenDecomposition.getV();
    DoubleMatrix1D eigenValues = eigenDecomposition.getRealEigenvalues();
    System.out.println("EigenValues:");
    EigenValueSortHelper[] eigenvaluesToSort = new EigenValueSortHelper[eigenValues.size()];
    for (int iEigen = 0; iEigen < eigenValues.size(); iEigen++) {
        eigenvaluesToSort[iEigen] = new EigenValueSortHelper(eigenValues.getQuick(iEigen), iEigen);
        System.out.print(eigenValues.getQuick(iEigen) + " ");
    }
    System.out.println();
    Arrays.sort(eigenvaluesToSort);

    for (int iEigen = 0; iEigen < eigenValues.size(); iEigen++) {
        System.out.print(eigenvaluesToSort[iEigen].getIndex() + ":"
                + eigenValues.getQuick(eigenvaluesToSort[iEigen].getIndex()) + " ");
    }
    System.out.println();
    System.out.println("EigenVectors:");
    for (int iEigen = 0; iEigen < eigenVectors.columns(); iEigen++) {
        System.out.print("[");
        for (int r = 0; r < eigenVectors.rows(); r++) {
            System.out.print(eigenVectors.getQuick(r, eigenvaluesToSort[iEigen].getIndex()) + " ");
        }
        System.out.println("]");
    }
}
 
开发者ID:dexyko,项目名称:spectralclustering,代码行数:46,代码来源:SpectralClusteringSolver.java

示例4: getEigenvectors

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
public double[][] getEigenvectors(){ 
       EigenvalueDecomposition eigenDecomp = new EigenvalueDecomposition(matrix);
DoubleMatrix2D eigenVectorMatrix = eigenDecomp.getV();
       return eigenVectorMatrix.toArray();
       
   }
 
开发者ID:rafaelmss,项目名称:GraphClustering,代码行数:7,代码来源:MatrixColt.java

示例5: calEigen

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
public int calEigen() {
EigenvalueDecomposition eigen_cal = new EigenvalueDecomposition(
	x_matrix);
eigen_matrix = eigen_cal.getD();
@SuppressWarnings("unused")
int[] result = getEigen();
sort();
return 0;
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:10,代码来源:Eigen.java

示例6: calculateEigenvalues

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
private void calculateEigenvalues(DoubleMatrix2D matrix) {
	EigenvalueDecomposition evd = new EigenvalueDecomposition(matrix);
	DoubleMatrix2D D = evd.getD();
	DoubleMatrix2D V = evd.getV();
	System.out.println("here");
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:7,代码来源:RandomNetworkGenerator.java

示例7: getSpectralRadius

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
public static double getSpectralRadius(DoubleMatrix2D A){
	
	EigenvalueDecomposition eigen = new EigenvalueDecomposition(A);
	DoubleMatrix1D eigenValues = eigen.getRealEigenvalues();
	return eigenValues.assign(Functions.abs).viewSorted().get(eigenValues.size()-1);
}
 
开发者ID:wil3,项目名称:lacus,代码行数:7,代码来源:MLMatrixUtils.java

示例8: runPCA

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
static public EigenvalueDecomposition runPCA(DoubleMatrix2D matrix) {
return runPCA(matrix, true);
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:4,代码来源:PCAMR.java

示例9: EMPCA

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
/**
    * Compute Principal Component Analysis with EM method.
    * 
    * @param matrix
    *            the matrix to do PCA, needs not to be centerized already. This
    *            method will centerize it. Each row is a data point.
    * @param pcNum
    * @return a {@link DoubleMatrix2D} of size [pcNum x (dim +1)], the first
    *         column is the variance of each PC in descending order. The remain
    *         of each row is a PC
    */
   static DoubleMatrix2D EMPCA(DoubleMatrix2D matrix, final int pcNum) {
// System.out.println(matrix);

if (matrix instanceof LargeDenseDoubleMatrix2D)
    return EMPCALarge((LargeDenseDoubleMatrix2D) matrix, pcNum);

final int iterNum = 20;
// final int size = matrix.rows();
final int dim = matrix.columns();

// center the matrix
// System.out.println(matrix);
centerize(matrix);
DoubleMatrix2D data = matrix.viewDice();

// initialization
Random r = new Random();
double[][] CData = new double[dim][pcNum];
for (int i = 0; i < dim; i++)
    for (int j = 0; j < pcNum; j++)
	CData[i][j] = r.nextDouble() - 0.5;
DoubleMatrix2D C = new DenseDoubleMatrix2D(CData);
DoubleMatrix2D x = null;
Algebra alg = new Algebra();

for (int i = 0; i < iterNum; i++) {
    x = alg.mult(
	    alg.mult(alg.inverse(alg.mult(C.viewDice(), C)),
		    C.viewDice()), data);
    C = alg.mult(alg.mult(data, x.viewDice()),
	    alg.inverse(alg.mult(x, x.viewDice())));
}

C = orthonormalization(C);

DoubleMatrix2D cov = Statistic.covariance(alg.mult(C.viewDice(), data)
	.viewDice());

EigenvalueDecomposition evd = new EigenvalueDecomposition(cov);

DenseDoubleMatrix2D result = new DenseDoubleMatrix2D(dim + 1, pcNum);
result.viewPart(1, 0, dim, pcNum).assign(
	alg.mult(C, evd.getV().viewColumnFlip()));
result.viewRow(0).assign(evd.getRealEigenvalues().viewFlip());

return result.viewDice();
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:59,代码来源:PCAMR.java

示例10: EMPCALarge

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
static DoubleMatrix2D EMPCALarge(LargeDenseDoubleMatrix2D matrix,
    final int pcNum) {
final int iterNum = 20;
final int dim = matrix.columns();

// center the matrix
centerize(matrix);

// initialization
Random r = new Random();
double[][] CData = new double[dim][pcNum];
for (int i = 0; i < dim; i++)
    for (int j = 0; j < pcNum; j++)
	CData[i][j] = r.nextDouble() - 0.5;
DoubleMatrix2D C = new DenseDoubleMatrix2D(CData);
DoubleMatrix2D x = null;
Algebra alg = new Algebra();

for (int i = 0; i < iterNum; i++) {
    x = LargeDenseDoubleMatrix2D.mult(LargeDenseDoubleMatrix2D.mult(alg
	    .inverse(LargeDenseDoubleMatrix2D.mult(C, true, C, false)),
	    false, C, true), false, matrix, true);
    C = LargeDenseDoubleMatrix2D.mult(LargeDenseDoubleMatrix2D.mult(
	    matrix, true, x, true), false, alg
	    .inverse(LargeDenseDoubleMatrix2D.mult(x, false, x, true)),
	    false);
}

C = orthonormalization(C);

DoubleMatrix2D cov = LargeDenseDoubleMatrix2D
	.covariance(LargeDenseDoubleMatrix2D.mult(C.viewDice(), false,
		matrix, true), true);

EigenvalueDecomposition evd = new EigenvalueDecomposition(cov);

DenseDoubleMatrix2D result = new DenseDoubleMatrix2D(dim + 1, pcNum);
result.viewPart(1, 0, dim, pcNum).assign(
	alg.mult(C, evd.getV().viewColumnFlip()));
result.viewRow(0).assign(evd.getRealEigenvalues().viewFlip());

return result.viewDice();
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:44,代码来源:PCAMR.java

示例11: EMPCA

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
/**
    * Compute Principal Component Analysis with EM method.
    * 
    * @param matrix
    *            the matrix to do PCA, needs not to be centerized already. This
    *            method will centerize it. Each row is a data point.
    * @param pcNum
    * @return a {@link DoubleMatrix2D} of size [pcNum x (dim +1)], the first
    *         column is the variance of each PC in descending order. The remain
    *         of each row is a PC
    */
   static DoubleMatrix2D EMPCA(DoubleMatrix2D matrix, final int pcNum) {
// System.out.println(matrix);

if (matrix instanceof LargeDenseDoubleMatrix2D)
    return EMPCALarge((LargeDenseDoubleMatrix2D) matrix, pcNum);

final int iterNum = 20;
// final int size = matrix.rows();
final int dim = matrix.columns();

// center the matrix
// System.out.println(matrix);
centerize(matrix);
DoubleMatrix2D data = matrix.viewDice();


// initialization
Random r = new Random();
double[][] CData = new double[dim][pcNum];
for (int i = 0; i < dim; i++)
    for (int j = 0; j < pcNum; j++)
	CData[i][j] = r.nextDouble() - 0.5;
DoubleMatrix2D C = new DenseDoubleMatrix2D(CData);
DoubleMatrix2D x = null;
Algebra alg = new Algebra();

for (int i = 0; i < iterNum; i++) {
    x = alg.mult(
	    alg.mult(alg.inverse(alg.mult(C.viewDice(), C)),
		    C.viewDice()), data);
    C = alg.mult(alg.mult(data, x.viewDice()),
	    alg.inverse(alg.mult(x, x.viewDice())));
}

C = orthonormalization(C);

DoubleMatrix2D cov = Statistic.covariance(alg.mult(C.viewDice(), data)
	.viewDice());

EigenvalueDecomposition evd = new EigenvalueDecomposition(cov);

DenseDoubleMatrix2D result = new DenseDoubleMatrix2D(dim + 1, pcNum);
result.viewPart(1, 0, dim, pcNum).assign(
	alg.mult(C, evd.getV().viewColumnFlip()));
result.viewRow(0).assign(evd.getRealEigenvalues().viewFlip());
return result.viewDice();
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:59,代码来源:PCA.java

示例12: EMPCALarge

import cern.colt.matrix.linalg.EigenvalueDecomposition; //导入依赖的package包/类
static DoubleMatrix2D EMPCALarge(LargeDenseDoubleMatrix2D matrix,
    final int pcNum) {
final int iterNum = 20;
final int dim = matrix.columns();

// center the matrix
centerize(matrix);
// initialization
Random r = new Random();
double[][] CData = new double[dim][pcNum];
for (int i = 0; i < dim; i++)
    for (int j = 0; j < pcNum; j++)
	CData[i][j] = r.nextDouble() - 0.5;
DoubleMatrix2D C = new DenseDoubleMatrix2D(CData);
DoubleMatrix2D x = null;
Algebra alg = new Algebra();

for (int i = 0; i < iterNum; i++) {
    x = LargeDenseDoubleMatrix2D.mult(LargeDenseDoubleMatrix2D.mult(alg
	    .inverse(LargeDenseDoubleMatrix2D.mult(C, true, C, false)),
	    false, C, true), false, matrix, true);
    C = LargeDenseDoubleMatrix2D.mult(LargeDenseDoubleMatrix2D.mult(
	    matrix, true, x, true), false, alg
	    .inverse(LargeDenseDoubleMatrix2D.mult(x, false, x, true)),
	    false);
}

C = orthonormalization(C);

DoubleMatrix2D cov = LargeDenseDoubleMatrix2D
	.covariance(LargeDenseDoubleMatrix2D.mult(C.viewDice(), false,
		matrix, true), true);

EigenvalueDecomposition evd = new EigenvalueDecomposition(cov);

DenseDoubleMatrix2D result = new DenseDoubleMatrix2D(dim + 1, pcNum);
result.viewPart(1, 0, dim, pcNum).assign(
	alg.mult(C, evd.getV().viewColumnFlip()));
result.viewRow(0).assign(evd.getRealEigenvalues().viewFlip());

return result.viewDice();
   }
 
开发者ID:kewei-ma,项目名称:GeDBIT,代码行数:43,代码来源:PCA.java


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