use of edu.stanford.nlp.neural.SimpleTensor in project CoreNLP by stanfordnlp.
the class SentimentCostAndGradient method scaleAndRegularizeTensor.
private static double scaleAndRegularizeTensor(TwoDimensionalMap<String, String, SimpleTensor> derivatives, TwoDimensionalMap<String, String, SimpleTensor> currentMatrices, double scale, double regCost) {
// the regularization cost
double cost = 0.0;
for (TwoDimensionalMap.Entry<String, String, SimpleTensor> entry : currentMatrices) {
SimpleTensor D = derivatives.get(entry.getFirstKey(), entry.getSecondKey());
D = D.scale(scale).plus(entry.getValue().scale(regCost));
derivatives.put(entry.getFirstKey(), entry.getSecondKey(), D);
cost += entry.getValue().elementMult(entry.getValue()).elementSum() * regCost / 2.0;
}
return cost;
}
Aggregations