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

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

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

Nd4j.copy介绍

[英]Copy a to b
[中]复制a到b

代码示例

代码示例来源:origin: neo4j-graph-analytics/ml-models

  1. private INDArray pruneEmbedding(INDArray origEmbedding, int... featIdsToKeep) {
  2. INDArray ndPrunedEmbedding = Nd4j.create(origEmbedding.shape());
  3. Nd4j.copy(origEmbedding, ndPrunedEmbedding);
  4. return ndPrunedEmbedding.getColumns(featIdsToKeep);
  5. }

代码示例来源:origin: neo4j-graph-analytics/ml-models

  1. private void diffuse(List<Pruning.Feature> featuresList) {
  2. INDArray ndDiffused = Nd4j.create(embedding.shape());
  3. Nd4j.copy(embedding, ndDiffused);
  4. featuresList.addAll(featuresList);
  5. features = featuresList.toArray(new Pruning.Feature[0]);
  6. for (int i = features.length / 2; i < features.length; i++) {
  7. features[i] = new Pruning.Feature("diffuse", features[i]);
  8. }
  9. for (int diffIteration = 0; diffIteration < diffusionIterations; diffIteration++) {
  10. INDArray ndDiffusedTemp = Nd4j.create(embedding.shape());
  11. nodeQueue.set(0);
  12. final ArrayList<Future<?>> futures = new ArrayList<>();
  13. for (int i = 0; i < concurrency; i++) {
  14. futures.add(executorService.submit(new DiffusionTask(ndDiffused, ndDiffusedTemp)));
  15. }
  16. ParallelUtil.awaitTermination(futures);
  17. ndDiffused = ndDiffusedTemp;
  18. }
  19. embedding = Nd4j.concat(1, embedding, ndDiffused);
  20. }

代码示例来源:origin: CampagneLaboratory/variationanalysis

  1. private void keepLongestMask(int minibatchSize, INDArray mask, int[] randomIndex1, int[] randomIndex2) {
  2. if (mask == null) return;
  3. INDArray[] tmpBuffer = new INDArray[minibatchSize];
  4. // Find the longest mask and keep it as mixup ask:
  5. for (int exampleIndex = 0; exampleIndex < minibatchSize; exampleIndex++) {
  6. int random1 = randomIndex1[exampleIndex];
  7. int random2 = randomIndex2[exampleIndex];
  8. final INDArray mask1 = mask.getRow(random1);
  9. final INDArray mask2 = mask.getRow(random2);
  10. tmpBuffer[exampleIndex] = Nd4j.createUninitializedDetached(mask1.shape());
  11. if (mask1.sub(mask2).sumNumber().doubleValue() < 0) {
  12. // mask2 has more 1s than mask1, use mask2:
  13. Nd4j.copy(mask2, tmpBuffer[exampleIndex]);
  14. } else {
  15. Nd4j.copy(mask1, tmpBuffer[exampleIndex]);
  16. }
  17. }
  18. for (int exampleIndex = 0; exampleIndex < minibatchSize; exampleIndex++) {
  19. // assign tmpBuffer[inputIndex] back into the minibatch:
  20. mask.putRow(exampleIndex, tmpBuffer[exampleIndex]);
  21. }
  22. }

代码示例来源:origin: CampagneLaboratory/variationanalysis

  1. private DataSet enrichWithErrors(DataSet ds) {
  2. if (!args().errorEnrichment) {
  3. return ds;
  4. }
  5. if (queue.isEmpty()) {
  6. // no errors were collected yet. Return the un-enriched dataset.
  7. return ds;
  8. }
  9. int size = this.args().numErrorsAdded;
  10. INDArray inputs = Nd4j.zeros(size, featureCalculator.numberOfFeatures());
  11. INDArray labels = Nd4j.zeros(size, labelMapper.numberOfLabels());
  12. int i = 0;
  13. for (ErrorRecord errorRecord : queue.getRandomSample(size)) {
  14. // we are going to call nextRecord directly, without checking hasNextRecord, because we have
  15. // determined how many times we can call (in size). We should get the exception if we were
  16. // wrong in our estimate of size.
  17. // fill in features and labels for a given record i:
  18. Nd4j.copy(errorRecord.features.get(new PointIndex(0)), inputs.get(new PointIndex(i)));
  19. Nd4j.copy(errorRecord.label, labels.get(new PointIndex(i)));
  20. i++;
  21. }
  22. DataSet errorDataSet = new DataSet(inputs, labels);
  23. array[0] = ds;
  24. array[1] = errorDataSet;
  25. final DataSet enrichedDataset = DataSet.merge(ObjectArrayList.wrap(array));
  26. return enrichedDataset;
  27. }

代码示例来源:origin: neo4j-graph-analytics/ml-models

  1. final INDArray temp = Nd4j.zerosLike(transpose);
  2. for (int i = numPrevFeatures; i < embedding.columns(); i++) {
  3. Nd4j.copy(transpose, temp);
  4. final int[] total =
  5. temp.subiRowVector(transpose.getRow(i))

代码示例来源:origin: apache/opennlp-sandbox

  1. Nd4j.copy(hPrev, hs1);

相关文章