本文整理了Java中org.nd4j.linalg.factory.Nd4j.copy()
方法的一些代码示例,展示了Nd4j.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Nd4j.copy()
方法的具体详情如下:
包路径:org.nd4j.linalg.factory.Nd4j
类名称:Nd4j
方法名:copy
[英]Copy a to b
[中]复制a到b
代码示例来源:origin: neo4j-graph-analytics/ml-models
private INDArray pruneEmbedding(INDArray origEmbedding, int... featIdsToKeep) {
INDArray ndPrunedEmbedding = Nd4j.create(origEmbedding.shape());
Nd4j.copy(origEmbedding, ndPrunedEmbedding);
return ndPrunedEmbedding.getColumns(featIdsToKeep);
}
代码示例来源:origin: neo4j-graph-analytics/ml-models
private void diffuse(List<Pruning.Feature> featuresList) {
INDArray ndDiffused = Nd4j.create(embedding.shape());
Nd4j.copy(embedding, ndDiffused);
featuresList.addAll(featuresList);
features = featuresList.toArray(new Pruning.Feature[0]);
for (int i = features.length / 2; i < features.length; i++) {
features[i] = new Pruning.Feature("diffuse", features[i]);
}
for (int diffIteration = 0; diffIteration < diffusionIterations; diffIteration++) {
INDArray ndDiffusedTemp = Nd4j.create(embedding.shape());
nodeQueue.set(0);
final ArrayList<Future<?>> futures = new ArrayList<>();
for (int i = 0; i < concurrency; i++) {
futures.add(executorService.submit(new DiffusionTask(ndDiffused, ndDiffusedTemp)));
}
ParallelUtil.awaitTermination(futures);
ndDiffused = ndDiffusedTemp;
}
embedding = Nd4j.concat(1, embedding, ndDiffused);
}
代码示例来源:origin: CampagneLaboratory/variationanalysis
private void keepLongestMask(int minibatchSize, INDArray mask, int[] randomIndex1, int[] randomIndex2) {
if (mask == null) return;
INDArray[] tmpBuffer = new INDArray[minibatchSize];
// Find the longest mask and keep it as mixup ask:
for (int exampleIndex = 0; exampleIndex < minibatchSize; exampleIndex++) {
int random1 = randomIndex1[exampleIndex];
int random2 = randomIndex2[exampleIndex];
final INDArray mask1 = mask.getRow(random1);
final INDArray mask2 = mask.getRow(random2);
tmpBuffer[exampleIndex] = Nd4j.createUninitializedDetached(mask1.shape());
if (mask1.sub(mask2).sumNumber().doubleValue() < 0) {
// mask2 has more 1s than mask1, use mask2:
Nd4j.copy(mask2, tmpBuffer[exampleIndex]);
} else {
Nd4j.copy(mask1, tmpBuffer[exampleIndex]);
}
}
for (int exampleIndex = 0; exampleIndex < minibatchSize; exampleIndex++) {
// assign tmpBuffer[inputIndex] back into the minibatch:
mask.putRow(exampleIndex, tmpBuffer[exampleIndex]);
}
}
代码示例来源:origin: CampagneLaboratory/variationanalysis
private DataSet enrichWithErrors(DataSet ds) {
if (!args().errorEnrichment) {
return ds;
}
if (queue.isEmpty()) {
// no errors were collected yet. Return the un-enriched dataset.
return ds;
}
int size = this.args().numErrorsAdded;
INDArray inputs = Nd4j.zeros(size, featureCalculator.numberOfFeatures());
INDArray labels = Nd4j.zeros(size, labelMapper.numberOfLabels());
int i = 0;
for (ErrorRecord errorRecord : queue.getRandomSample(size)) {
// we are going to call nextRecord directly, without checking hasNextRecord, because we have
// determined how many times we can call (in size). We should get the exception if we were
// wrong in our estimate of size.
// fill in features and labels for a given record i:
Nd4j.copy(errorRecord.features.get(new PointIndex(0)), inputs.get(new PointIndex(i)));
Nd4j.copy(errorRecord.label, labels.get(new PointIndex(i)));
i++;
}
DataSet errorDataSet = new DataSet(inputs, labels);
array[0] = ds;
array[1] = errorDataSet;
final DataSet enrichedDataset = DataSet.merge(ObjectArrayList.wrap(array));
return enrichedDataset;
}
代码示例来源:origin: neo4j-graph-analytics/ml-models
final INDArray temp = Nd4j.zerosLike(transpose);
for (int i = numPrevFeatures; i < embedding.columns(); i++) {
Nd4j.copy(transpose, temp);
final int[] total =
temp.subiRowVector(transpose.getRow(i))
代码示例来源:origin: apache/opennlp-sandbox
Nd4j.copy(hPrev, hs1);
内容来源于网络,如有侵权,请联系作者删除!