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))); }
/** * @param key * @param newValue * @return Previous value for the key */ public double set(T key, double newValue) { double preval = getT(key); m_map.put(key, newValue); m_sum += newValue - preval; return preval; }
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 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 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; }
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); int size = stream.readInt(); setUp(size); while (size-- > 0) { Object key = stream.readObject(); double val = stream.readDouble(); put(key, val); } } } // TObjectDoubleHashMap
public static TObjectDoubleHashMap<String> readOldModel(String idParamsFile) throws IOException { TObjectDoubleHashMap<String> params = new TObjectDoubleHashMap<String>(); int count = 0; String line; final BufferedReader input = Files.newReader(new File(idParamsFile), Charsets.UTF_8); try { while ((line = input.readLine()) != null) { final String[] nameAndVal = line.split("\t"); final String[] logAndSign = nameAndVal[1].split(", "); final double value = exp(Double.parseDouble(logAndSign[0])); final double sign = Boolean.parseBoolean(logAndSign[1]) ? 1.0 : -1.0; params.put(nameAndVal[0], value * sign); count++; if (count % 100000 == 0) System.err.print(count + " "); } } finally { closeQuietly(input); } return params; }
/** * Inserts a key/value pair into the map. * * @param key an <code>Object</code> value * @param value an <code>Object</code> value * @return the previous value associated with <tt>key</tt>, * or Integer(0) if none was found. */ public Object put(Object key, Object value) { return wrapValue(_map.put(unwrapKey(key), unwrapValue(value))); }
public Counter<T> toCounter() { TObjectDoubleHashMap<T> map = new TObjectDoubleHashMap<T>(); for (TObjectIntIterator<T> iter = getIterator(); iter.hasNext();) { iter.advance(); map.put(iter.key(), (double)iter.value()); } if (containsKey(null)) map.put(null, (double)getT(null)); return new Counter<T>(map); }
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; } }
/** * @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; }
double valInMap = valMap.get(nbr); double value = new Double(toks[j+1]); valMap.put(nbr, valInMap + value/(double)count);
m.savedValues.put(m_name, m_value.value);
m.savedValues.put(m_name, m_value.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; } }
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.getToken(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.getToken(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; } }
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; } }
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; } }