TwoDimensionalMap<String, String, double[][]> tempUnaryBetas = new TwoDimensionalMap<>(); ThreeDimensionalMap<String, String, String, double[][][]> tempBinaryBetas = new ThreeDimensionalMap<>(); for (String parent : unaryBetas.firstKeySet()) { for (String child : unaryBetas.get(parent).keySet()) { double[][] betas = unaryBetas.get(parent, child); int parentStates = betas.length; int childStates = betas[0].length; tempUnaryBetas.put(parent, child, betas); for (String left : binaryBetas.get(parent).firstKeySet()) { for (String right : binaryBetas.get(parent).get(left).keySet()) { double[][][] betas = binaryBetas.get(parent, left, right); int parentStates = betas.length;
public void clear() { backingMap.clear(); }
public static boolean entityIsAcronym(Document document, CorefCluster mentionCluster, CorefCluster potentialAntecedent) { int minId = Math.min(mentionCluster.clusterID, potentialAntecedent.clusterID); int maxId = Math.max(mentionCluster.clusterID, potentialAntecedent.clusterID); if(!document.acronymCache.contains(minId, maxId)) { boolean isAcronym = false; for(Mention m : mentionCluster.corefMentions){ if(m.isPronominal()) continue; for(Mention ant : potentialAntecedent.corefMentions){ if(isAcronym(m.originalSpan, ant.originalSpan)) isAcronym = true; } } document.acronymCache.put(minId, maxId, isAcronym); } return document.acronymCache.get(minId, maxId); }
public boolean contains(K1 key1, K2 key2) { if (!containsKey(key1)) { return false; } return getMap(key1).containsKey(key2); }
public boolean contains(K1 key1, K2 key2, K3 key3) { if (!map.containsKey(key1)) return false; if (!map.get(key1).containsKey(key2)) return false; if (!map.get(key1).get(key2).containsKey(key3)) return false; else return true; }
public Set<K3> thirdKeySet() { Set<K3> keys = Generics.newHashSet(); for (K1 k1 : map.keySet()) { TwoDimensionalMap<K2, K3, V> m = map.get(k1); for (K2 k2 : m.firstKeySet()) { keys.addAll(m.get(k2).keySet()); } } return keys; }
TwoDimensionalMap<Integer, Integer, IndexedWord> nodeMap = TwoDimensionalMap.hashMap(); for (IntermediateNode in: nodes){ CoreLabel token = sentence.get(in.index - 1); // index starts at 1! nodeMap.put(word.index(), word.copyCount(), word); graph.addVertex(word); if (in.isRoot) { IndexedWord source = nodeMap.get(ie.source, ie.sourceCopy); if (source == null) { throw new RuntimeIOException("Failed to find node " + ie.source + "-" + ie.sourceCopy); IndexedWord target = nodeMap.get(ie.target, ie.targetCopy); if (target == null) { throw new RuntimeIOException("Failed to find node " + ie.target + "-" + ie.targetCopy);
public static TwoDimensionalMap<String, String, SimpleMatrix> averageBinaryMatrices(List<TwoDimensionalMap<String, String, SimpleMatrix>> maps) { TwoDimensionalMap<String, String, SimpleMatrix> averages = TwoDimensionalMap.treeMap(); for (Pair<String, String> binary : getBinaryMatrixNames(maps)) { int count = 0; SimpleMatrix matrix = null; for (TwoDimensionalMap<String, String, SimpleMatrix> map : maps) { if (!map.contains(binary.first(), binary.second())) { continue; } SimpleMatrix original = map.get(binary.first(), binary.second()); ++count; if (matrix == null) { matrix = original; } else { matrix = matrix.plus(original); } } matrix = matrix.divide(count); averages.put(binary.first(), binary.second(), matrix); } return averages; }
binaryTransform = TwoDimensionalMap.treeMap(); binaryTensors = TwoDimensionalMap.treeMap(); binaryClassification = TwoDimensionalMap.treeMap(); String left = basicCategory(binary.first); String right = basicCategory(binary.second); if (binaryTransform.contains(left, right)) { continue; binaryTransform.put(left, right, randomTransformMatrix()); if (op.useTensors) { binaryTensors.put(left, right, randomBinaryTensor()); binaryClassification.put(left, right, randomClassificationMatrix()); numBinaryMatrices = binaryTransform.size(); binaryTransformSize = numHid * (2 * numHid + 1); if (op.useTensors) {
boolean createdCalledMap = (calledMap == null); if (createdCalledMap) { calledMap = TwoDimensionalMap.identityHashMap(); equalsCalled.set(calledMap); if (calledMap.contains(this, other)) { return true; calledMap.put(this, other, true); calledMap.put(other, this, true);
public void mergeAcronymCache(CorefCluster to, CorefCluster from) { TwoDimensionalSet<Integer, Integer> replacements = TwoDimensionalSet.hashSet(); for (Integer first : acronymCache.firstKeySet()) { for (Integer second : acronymCache.get(first).keySet()) { if (acronymCache.get(first, second)) { Integer other = null; if (first == from.clusterID) { other = second; } else if (second == from.clusterID) { other = first; } if (other != null && other != to.clusterID) { int cid1 = Math.min(other, to.clusterID); int cid2 = Math.max(other, to.clusterID); replacements.add(cid1, cid2); } } } } for (Integer first : replacements.firstKeySet()) { for (Integer second : replacements.secondKeySet(first)) { acronymCache.put(first, second, true); } } }
public TwoDimensionalSet() { this(new TwoDimensionalMap<>()); }
TwoDimensionalMap<String, String, double[][]> tempUnaryBetas = new TwoDimensionalMap<>(); ThreeDimensionalMap<String, String, String, double[][][]> tempBinaryBetas = new ThreeDimensionalMap<>(); Map<String, double[]> totalStateMass = Generics.newHashMap(); int parentStates = getStateSplitCount(parent); double[] stateTotal = totalStateMass.get(parent); for (String left : tempBinaryBetas.get(parent).firstKeySet()) { int leftStates = getStateSplitCount(left); for (String right : tempBinaryBetas.get(parent).get(left).keySet()) { int rightStates = getStateSplitCount(right); double[][][] betas = tempBinaryBetas.get(parent, left, right); for (String parent : tempUnaryBetas.firstKeySet()) { int parentStates = getStateSplitCount(parent); double[] stateTotal = totalStateMass.get(parent); for (String child : tempUnaryBetas.get(parent).keySet()) { int childStates = getStateSplitCount(child); double[][] betas = tempUnaryBetas.get(parent, child); for (int i = 0; i < parentStates; ++i) { if (stateTotal[i] < EPSILON) {
public V remove(K1 key1, K2 key2) { return get(key1).remove(key2); }
public Map<K2, V> get(K1 key1) { return getMap(key1); }
public static <K1, K2> TwoDimensionalSet<K1, K2> hashSet() { return new TwoDimensionalSet<>(TwoDimensionalMap.<K1, K2, Boolean>hashMap()); }
private static double scaleAndRegularizeTensor(TwoDimensionalMap<String, String, SimpleTensor> derivatives, TwoDimensionalMap<String, String, SimpleTensor> currentMatrices, double scale, double regCost) { double cost = 0.0; // the regularization cost 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; }
public Set<K1> firstKeySet() { return backingMap.firstKeySet(); }
@Override public boolean equals(Object o) { if (o == this) { return true; } if (!(o instanceof TwoDimensionalSet)) { return false; } TwoDimensionalSet<?, ?> other = (TwoDimensionalSet) o; return backingMap.equals(other.backingMap); }