public static TObjectDoubleHashMap<String> add(TObjectDoubleHashMap<String> vector, TObjectDoubleHashMap<String> oldVector, int count) { TObjectDoubleHashMap<String> res = new TObjectDoubleHashMap<String>(); if (oldVector == null) { oldVector = new TObjectDoubleHashMap<String>(); } String[] vKeys = new String[vector.size()]; vector.keys(vKeys); for (int i = 0; i < vKeys.length; i++) { double value = vector.get(vKeys[i]) / (double)count; if (oldVector.contains(vKeys[i])) { res.put(vKeys[i], value + oldVector.get(vKeys[i])); oldVector.remove(vKeys[i]); } else { res.put(vKeys[i], value); } } String[] oldKeys = new String[oldVector.size()]; oldVector.keys(oldKeys); for (int i = 0; i < oldKeys.length; i++) { res.put(oldKeys[i], oldVector.get(oldKeys[i])); } return res; } }
/** Propagate a topic weight to a node and all its children. weight is assumed to be a log. */ public void propagateTopicWeight(TObjectDoubleHashMap<NCRPNode> nodeWeights, NCRPNode node, double weight) { if (! nodeWeights.containsKey(node)) { // calculating the NCRP prior proceeds from the // root down (ie following child links), // but adding the word-topic weights comes from // the bottom up, following parent links and then // child links. It's possible that the leaf node may have // been removed just prior to this round, so the current // node may not have an NCRP weight. If so, it's not // going to be sampled anyway, so ditch it. return; } for (NCRPNode child: node.children) { propagateTopicWeight(nodeWeights, child, weight); } nodeWeights.adjustValue(node, weight); }
/** Returns the key in map that has the greatest score */ public static Object argmax (TObjectDoubleHashMap map) { // A local class! Yes, Virginia, this is legal Java. class Accumulator implements TObjectDoubleProcedure { double bestVal = Double.NEGATIVE_INFINITY; Object bestObj = null; public boolean execute (Object a, double b) { if (b > bestVal) { bestVal = b; bestObj = a; } return true; } } Accumulator procedure = new Accumulator (); map.forEachEntry (procedure); return procedure.bestObj; }
/** * @param key * @return The value stored for a particular key (if present), or 0 otherwise */ public double getT(T key) { if (m_map.containsKey(key)) return m_map.get(key); return DEFAULT_VALUE; }
public Instance pipe (Instance carrier) { TokenSequence seq = (TokenSequence)carrier.getData(); TObjectDoubleHashMap[] original = new TObjectDoubleHashMap[seq.size()]; for (int i=0; i<seq.size(); i++) { Token t = seq.get(i); original[i] = new TObjectDoubleHashMap(); PropertyList.Iterator pl = t.getFeatures().iterator(); while (pl.hasNext()) { pl.nextProperty(); original[i].put(pl.getKey(), pl.getNumericValue()); } } for (int i=0; i<original.length; i++) { // add to features of token i... for (int j = -1 * left; j <= right; j++) { int index = i + j; //...the features of token index String append = (j < 0) ? "/"+j : "/+"+j; if (index<0 || index==i || index>=original.length) continue; Token t = seq.get(i); Object[] features = original[index].keys(); for (int k=0; k<features.length; k++) t.setFeatureValue((String)features[k]+append, original[index].get(features[k])); } } return carrier; } }
new TObjectDoubleHashMap<NCRPNode>(); NCRPNode[] nodes = nodeWeights.keys(new NCRPNode[] {}); double[] weights = new double[nodes.length]; double sum = 0.0; if (nodeWeights.get(nodes[i]) > max) { max = nodeWeights.get(nodes[i]); weights[i] = Math.exp(nodeWeights.get(nodes[i]) - max);
if (m.savedValues.containsKey(m_name)) { double v = m.savedValues.get(m_name); m_value.reset(v); } else { m.savedValues.put(m_name, m_value.value);
/** * @param _m le table a copier * @return la table copiee */ public static TObjectDoubleHashMap copy(final TObjectDoubleHashMap _m) { final TObjectDoubleHashMap r = new TObjectDoubleHashMap(_m); final TObjectDoubleIterator it = _m.iterator(); for (int i = _m.size(); i-- > 0;) { it.advance(); r.put(it.key(), it.value()); } return r; }
public static TObjectDoubleHashMap<String> readModel(Collection<String> featureLines) { final TObjectDoubleHashMap<String> model = new TObjectDoubleHashMap<String>(featureLines.size()); int count = 0; for (String line : featureLines) { String[] fields = line.split("\t"); final String featureName = fields[0].trim(); final Double featureValue = Double.parseDouble(fields[1].trim()); model.put(featureName, featureValue); count++; if (count % 100000 == 0) System.err.print(count + " "); } return model; }
map.put(nbr, count + 1); TObjectDoubleHashMap<String> valMap = new TObjectDoubleHashMap<String>(); for (int j = 1; j < toks.length; j = j + 2) { String nbr = toks[j]; int count = map.get(nbr); double valInMap = valMap.get(nbr); double value = new Double(toks[j+1]); valMap.put(nbr, valInMap + value/(double)count);
if (_map.equals(other)) { return true; // comparing two trove maps } else if (other instanceof Map) { Map that = (Map)other; if (that.size() != _map.size()) { return false; // different sizes, no need to compare } else { // now we have to do it the hard way Object k = unwrapKey(key); double v = unwrapValue(val); if (_map.containsKey(k) && v == _map.get(k)) {
public void calculateNCRP(TObjectDoubleHashMap<NCRPNode> nodeWeights, NCRPNode node, double weight) { for (NCRPNode child: node.children) { calculateNCRP(nodeWeights, child, weight + Math.log((double) child.customers / (node.customers + gamma))); } nodeWeights.put(node, weight + Math.log(gamma / (node.customers + gamma))); }
public Counter() { m_map = new TObjectDoubleHashMap<T>(); }
/** * Compares this map with another map for equality of their stored * entries. * * @param other an <code>Object</code> value * @return a <code>boolean</code> value */ public boolean equals(Object other) { if (! (other instanceof TObjectDoubleHashMap)) { return false; } TObjectDoubleHashMap that = (TObjectDoubleHashMap)other; if (that.size() != this.size()) { return false; } return forEachEntry(new EqProcedure(that)); }
/** * Increments the primitive value mapped to key by 1 * * @param key the key of the value to increment * @return true if a mapping was found and modified. */ public boolean increment(Object key) { return adjustValue(key, (double)1); }
public boolean containsKeyT(T key) { return m_map.containsKey(key); }
public T[] keys(T[] array) { return m_map.keys(array); }