Search in sources :

Example 6 with TwoDimensionalMap

use of edu.stanford.nlp.util.TwoDimensionalMap 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;
}
Also used : SimpleTensor(edu.stanford.nlp.neural.SimpleTensor) TwoDimensionalMap(edu.stanford.nlp.util.TwoDimensionalMap)

Aggregations

TwoDimensionalMap (edu.stanford.nlp.util.TwoDimensionalMap)6 Tree (edu.stanford.nlp.trees.Tree)3 SimpleMatrix (org.ejml.simple.SimpleMatrix)3 ThreeDimensionalMap (edu.stanford.nlp.util.ThreeDimensionalMap)2 IdentityHashMap (java.util.IdentityHashMap)2 Map (java.util.Map)2 SimpleTensor (edu.stanford.nlp.neural.SimpleTensor)1 LexicalizedParser (edu.stanford.nlp.parser.lexparser.LexicalizedParser)1 DeepTree (edu.stanford.nlp.trees.DeepTree)1 IntPair (edu.stanford.nlp.util.IntPair)1 MutableDouble (edu.stanford.nlp.util.MutableDouble)1 Pair (edu.stanford.nlp.util.Pair)1 Timing (edu.stanford.nlp.util.Timing)1 Triple (edu.stanford.nlp.util.Triple)1 MulticoreWrapper (edu.stanford.nlp.util.concurrent.MulticoreWrapper)1 ArrayList (java.util.ArrayList)1 Formatter (java.util.Formatter)1 TreeMap (java.util.TreeMap)1