本文整理匯總了Java中org.nd4j.linalg.api.ndarray.INDArray.div方法的典型用法代碼示例。如果您正苦於以下問題:Java INDArray.div方法的具體用法?Java INDArray.div怎麽用?Java INDArray.div使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.nd4j.linalg.api.ndarray.INDArray
的用法示例。
在下文中一共展示了INDArray.div方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getContextVectorMean
import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
/** @return mean vector, built from contexts passed in */
public INDArray getContextVectorMean (List<String> contexts) {
INDArray res = zeros();
if (contexts == null || contexts.isEmpty()) return res;
for (String context : contexts) res.addi(getContextVector(context));
return res.div(Nd4j.scalar(contexts.size()));
}
示例2: getWordVectorMean
import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
/** @return mean vector, built from words passed in */
public INDArray getWordVectorMean (List<String> words) {
INDArray res = zeros();
if (words == null || words.isEmpty()) return res;
for (String word : words) res.addi(getWordVector(word));
return res.div(Nd4j.scalar(words.size()));
}
示例3: sample
import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
/**
* sample a sequence of integers from the model
* h is memory state, seed_ix is seed letter for first time step
* @param h
* @param seedIdx
* @param n
* @return
*/
private int[] sample(INDArray h, int seedIdx, int n) {
// Use a seed character to start the sampling from
INDArray x = oneHotEncoding(seedIdx);
int[] ixes = new int[n];
// Do forward pass
for (int t = 0; t < n; t++) {
// Input to hidden
INDArray dot1 = Wxh.mmul(x);
// Hidden layer to hidden
INDArray dot2 = Whh.mmul(h).add(bh);
// Hidden state step, squash with tanh to -1 to 1
h = Transforms.tanh(dot1.add(dot2));
// Output - Y
// Dot product between weights from h to y and hidden state, plus bias
INDArray y = Why.mmul(h).add(by);
// Normalised Probabilities - P
INDArray exp = Transforms.exp(y);
INDArray cumExp = Nd4j.sum(exp);
INDArray p = exp.div(cumExp);
int[] to_select = new int[vocabSize];
for (int i = 0; i < vocabSize; i++){
to_select[i] = i;
}
// Given the probabilities of the characters, pick "random characters" to generate the text
int idx = randChoice(to_select, p);
// Next character in the sequence
x = oneHotEncoding(idx);
// Store the chosen character
ixes[t] = idx;
}
return ixes;
}
示例4: aggregate
import org.nd4j.linalg.api.ndarray.INDArray; //導入方法依賴的package包/類
@Override
public SeldonMessage aggregate(List<SeldonMessage> outputs, PredictiveUnitState state){
if (outputs.size()==0){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Combiner received no inputs"));
}
int[] shape = PredictorUtils.getShape(outputs.get(0).getData());
if (shape == null){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Combiner cannot extract data shape"));
}
if (shape.length!=2){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Combiner received data that is not 2 dimensional"));
}
INDArray currentSum = Nd4j.zeros(shape[0],shape[1]);
SeldonMessage.Builder respBuilder = SeldonMessage.newBuilder();
for (Iterator<SeldonMessage> i = outputs.iterator(); i.hasNext();)
{
DefaultData inputData = i.next().getData();
int[] inputShape = PredictorUtils.getShape(inputData);
if (inputShape == null){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Combiner cannot extract data shape"));
}
if (inputShape.length!=2){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Combiner received data that is not 2 dimensional"));
}
if (inputShape[0] != shape[0]){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Expected batch length %d but found %d",shape[0],inputShape[0]));
}
if (inputShape[1] != shape[1]){
throw new APIException(APIException.ApiExceptionType.ENGINE_INVALID_COMBINER_RESPONSE, String.format("Expected batch length %d but found %d",shape[1],inputShape[1]));
}
INDArray inputArr = PredictorUtils.getINDArray(inputData);
currentSum = currentSum.add(inputArr);
}
currentSum = currentSum.div((float)outputs.size());
DefaultData newData = PredictorUtils.updateData(outputs.get(0).getData(), currentSum);
respBuilder.setData(newData);
respBuilder.setMeta(outputs.get(0).getMeta());
respBuilder.setStatus(outputs.get(0).getStatus());
return respBuilder.build();
}