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

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

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

Nd4j.tensorMmul介绍

[英]Tensor matrix multiplication. Both tensors must be the same rank
[中]张量矩阵乘法。两个张量的秩必须相同

代码示例

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

  1. /**
  2. * Take the data that has been transformed to the principal components about the mean and
  3. * transform it back into the original feature set. Make sure to fill in zeroes in columns
  4. * where components were dropped!
  5. * @param data Data of the same features used to construct the PCA object but as the components
  6. * @return The records in terms of the original features
  7. */
  8. public INDArray convertBackToFeatures(INDArray data) {
  9. return Nd4j.tensorMmul(eigenvectors, data, new int[][] {{1}, {1}}).transposei().addiRowVector(mean);
  10. }

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

  1. /**
  2. * Takes a set of data on each row, with the same number of features as the constructing data
  3. * and returns the data in the coordinates of the basis set about the mean.
  4. * @param data Data of the same features used to construct the PCA object
  5. * @return The record in terms of the principal component vectors, you can set unused ones to zero.
  6. */
  7. public INDArray convertToComponents(INDArray data) {
  8. INDArray dx = data.subRowVector(mean);
  9. return Nd4j.tensorMmul(eigenvectors.transpose(), dx, new int[][] {{1}, {1}}).transposei();
  10. }

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

  1. /**
  2. * Generates a set of <i>count</i> random samples with the same variance and mean and eigenvector/values
  3. * as the data set used to initialize the PCA object, with same number of features <i>N</i>.
  4. * @param count The number of samples to generate
  5. * @return A matrix of size <i>count</i> rows by <i>N</i> columns
  6. */
  7. public INDArray generateGaussianSamples(long count) {
  8. INDArray samples = Nd4j.randn(new long[] {count, eigenvalues.columns()});
  9. INDArray factors = Transforms.pow(eigenvalues, -0.5, true);
  10. samples.muliRowVector(factors);
  11. return Nd4j.tensorMmul(eigenvectors, samples, new int[][] {{1}, {1}}).transposei().addiRowVector(mean);
  12. }

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

  1. @Override
  2. public void exec() {
  3. if(this.z != null)
  4. this.z.assign(Nd4j.tensorMmul(x,y,z,axes));
  5. else
  6. this.z = Nd4j.tensorMmul(x,y,axes);
  7. }

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

  1. @Override
  2. public IntegerTensor tensorMultiply(IntegerTensor value, int[] dimLeft, int[] dimsRight) {
  3. INDArray tensorMmulResult = Nd4j.tensorMmul(tensor, unsafeGetNd4J(value), new int[][]{dimLeft, dimsRight});
  4. return new Nd4jIntegerTensor(tensorMmulResult);
  5. }

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

  1. @Override
  2. public DoubleTensor tensorMultiply(DoubleTensor value, int[] dimsLeft, int[] dimsRight) {
  3. INDArray tensorMmulResult = Nd4j.tensorMmul(tensor, unsafeGetNd4J(value), new int[][]{dimsLeft, dimsRight});
  4. return new Nd4jDoubleTensor(tensorMmulResult);
  5. }

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

  1. /**
  2. * Take the data that has been transformed to the principal components about the mean and
  3. * transform it back into the original feature set. Make sure to fill in zeroes in columns
  4. * where components were dropped!
  5. * @param data Data of the same features used to construct the PCA object but as the components
  6. * @return The records in terms of the original features
  7. */
  8. public INDArray convertBackToFeatures(INDArray data) {
  9. return Nd4j.tensorMmul(eigenvectors, data, new int[][] {{1}, {1}}).transposei().addiRowVector(mean);
  10. }

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

  1. /**
  2. * Takes a set of data on each row, with the same number of features as the constructing data
  3. * and returns the data in the coordinates of the basis set about the mean.
  4. * @param data Data of the same features used to construct the PCA object
  5. * @return The record in terms of the principal component vectors, you can set unused ones to zero.
  6. */
  7. public INDArray convertToComponents(INDArray data) {
  8. INDArray dx = data.subRowVector(mean);
  9. return Nd4j.tensorMmul(eigenvectors.transpose(), dx, new int[][] {{1},{1}}).transposei();
  10. }

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

  1. /**
  2. * Generates a set of <i>count</i> random samples with the same variance and mean and eigenvector/values
  3. * as the data set used to initialize the PCA object, with same number of features <i>N</i>.
  4. * @param count The number of samples to generate
  5. * @return A matrix of size <i>count</i> rows by <i>N</i> columns
  6. */
  7. public INDArray generateGaussianSamples(int count) {
  8. INDArray samples = Nd4j.randn(count, eigenvalues.columns());
  9. INDArray factors = Transforms.pow(eigenvalues, -0.5, true);
  10. samples.muliRowVector(factors);
  11. return Nd4j.tensorMmul(eigenvectors, samples, new int[][] {{1}, {1}}).transposei().addiRowVector(mean);
  12. }

相关文章