org.nd4j.linalg.factory.Nd4j.eye()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(173)

本文整理了Java中org.nd4j.linalg.factory.Nd4j.eye()方法的一些代码示例,展示了Nd4j.eye()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.eye()方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:eye

Nd4j.eye介绍

[英]Create the identity ndarray
[中]创建标识数组

代码示例

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray doCreate(long[] shape, INDArray paramsView) {
  3. if(shape.length != 2 || shape[0] != shape[1]){
  4. throw new IllegalStateException("Cannot use IDENTITY init with parameters of shape "
  5. + Arrays.toString(shape) + ": weights must be a square matrix for identity");
  6. }
  7. if(order() == Nd4j.order()){
  8. return Nd4j.eye(shape[0]);
  9. } else {
  10. return Nd4j.createUninitialized(shape, order()).assign(Nd4j.eye(shape[0]));
  11. }
  12. }

代码示例来源:origin: deeplearning4j/nd4j

  1. /**
  2. * Calculates the principal component vectors and their eigenvalues (lambda) for the covariance matrix.
  3. * The result includes two things: the eigenvectors (modes) as result[0] and the eigenvalues (lambda)
  4. * as result[1].
  5. *
  6. * @param cov The covariance matrix (calculated with the covarianceMatrix(in) method)
  7. * @return Array INDArray[2] "result". The principal component vectors in decreasing flexibility are
  8. * the columns of element 0 and the eigenvalues are element 1.
  9. */
  10. public static INDArray[] principalComponents(INDArray cov) {
  11. assert cov.rows() == cov.columns();
  12. INDArray[] result = new INDArray[2];
  13. result[0] = Nd4j.eye(cov.rows());
  14. result[1] = Eigen.symmetricGeneralizedEigenvalues(result[0], cov, true);
  15. return result;
  16. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. INDArray identityMatrix = Nd4j.eye(3);
  2. System.out.println("\n\n\nNd4j.eye(3):\n" + identityMatrix);
  3. INDArray linspace = Nd4j.linspace(1,10,10); //Values 1 to 10, in 10 steps

代码示例来源:origin: deeplearning4j/nd4j

  1. if (n == 0) {
  2. if (dup)
  3. return Nd4j.eye(in.rows());
  4. else
  5. return in.assign(Nd4j.eye(in.rows()));

代码示例来源:origin: deeplearning4j/nd4j

  1. @Override
  2. public INDArray getPFactor(int M, INDArray ipiv) {
  3. // The simplest permutation is the identity matrix
  4. INDArray P = Nd4j.eye(M); // result is a square matrix with given size
  5. for (int i = 0; i < ipiv.length(); i++) {
  6. int pivot = ipiv.getInt(i) - 1; // Did we swap row #i with anything?
  7. if (pivot > i) { // don't reswap when we get lower down in the vector
  8. INDArray v1 = P.getColumn(i).dup(); // because of row vs col major order we'll ...
  9. INDArray v2 = P.getColumn(pivot); // ... make a transposed matrix immediately
  10. P.putColumn(i, v2);
  11. P.putColumn(pivot, v1); // note dup() above is required - getColumn() is a 'view'
  12. }
  13. }
  14. return P; // the permutation matrix - contains a single 1 in any row and column
  15. }

代码示例来源:origin: deeplearning4j/dl4j-examples

  1. print("3x4 ones", threeByFourOnes);
  2. INDArray fiveByFiveIdentity = Nd4j.eye(5);
  3. print("5x5 Identity", fiveByFiveIdentity);

代码示例来源:origin: improbable-research/keanu

  1. public static INDArray eye(long n, DataBuffer.Type bufferType) {
  2. Nd4j.setDataType(bufferType);
  3. if (n == 0) {
  4. return scalar(1.0, bufferType);
  5. }
  6. return Nd4j.eye(n);
  7. }

代码示例来源:origin: org.nd4j/nd4j-api

  1. /**
  2. * Calculates the principal component vectors and their eigenvalues (lambda) for the covariance matrix.
  3. * The result includes two things: the eigenvectors (modes) as result[0] and the eigenvalues (lambda)
  4. * as result[1].
  5. *
  6. * @param cov The covariance matrix (calculated with the covarianceMatrix(in) method)
  7. * @return Array INDArray[2] "result". The principal component vectors in decreasing flexibility are
  8. * the columns of element 0 and the eigenvalues are element 1.
  9. */
  10. public static INDArray[] principalComponents(INDArray cov) {
  11. assert cov.rows() == cov.columns();
  12. INDArray[] result = new INDArray[2];
  13. result[0] = Nd4j.eye(cov.rows());
  14. result[1] = Eigen.symmetricGeneralizedEigenvalues(result[0], cov, true);
  15. return result;
  16. }

代码示例来源:origin: org.nd4j/nd4j-api

  1. assert in.rows() == in.columns();
  2. if (n == 0) {
  3. if (dup) return Nd4j.eye(in.rows());
  4. else return in.assign(Nd4j.eye(in.rows()));

代码示例来源:origin: org.nd4j/nd4j-api

  1. @Override
  2. public INDArray getPFactor(int M, INDArray ipiv) {
  3. // The simplest permutation is the identity matrix
  4. INDArray P = Nd4j.eye(M); // result is a square matrix with given size
  5. for (int i = 0; i < ipiv.length(); i++) {
  6. int pivot = ipiv.getInt(i) - 1; // Did we swap row #i with anything?
  7. if (pivot > i) { // don't reswap when we get lower down in the vector
  8. INDArray v1 = P.getColumn(i).dup(); // because of row vs col major order we'll ...
  9. INDArray v2 = P.getColumn(pivot); // ... make a transposed matrix immediately
  10. P.putColumn(i, v2);
  11. P.putColumn(pivot, v1); // note dup() above is required - getColumn() is a 'view'
  12. }
  13. }
  14. return P; // the permutation matrix - contains a single 1 in any row and column
  15. }

相关文章