/** @return a set of keys whose values are greater than the specific cutoff. */ public Set<T> keySet(int cutoff) { Set<T> set = new HashSet<>(); for (Entry<T> p : count_map.object2IntEntrySet()) { if (p.getValue() > cutoff) set.add(p.getKey()); } return set; }
/** * Serializes the map. * * @param out where to write the raw byte representation */ public void write(DataOutput out) throws IOException { // Write out the number of entries in the map out.writeInt(size()); if (size() == 0) return; // Write out the class names for keys and values // assuming that data is homogeneous (i.e., all entries have same types) Set<Object2IntMap.Entry<K>> entries = object2IntEntrySet(); Object2IntMap.Entry<K> first = entries.iterator().next(); K objK = first.getKey(); out.writeUTF(objK.getClass().getCanonicalName()); // Then write out each key/value pair for (Object2IntMap.Entry<K> e : object2IntEntrySet()) { e.getKey().write(out); out.writeInt(e.getValue()); } }
public Set<T> keySet(double threshold) { Set<T> set = new HashSet<>(); double d; for (Entry<T> p : count_map.object2IntEntrySet()) { d = MathUtils.divide(p.getValue(), total_count); if (d > threshold) set.add(p.getKey()); } return set; } }
/** * Serializes this object. * * @param out where to write the raw byte representation */ public void write(DataOutput out) throws IOException { // Write out the number of entries in the map. out.writeInt(size()); if (size() == 0) return; // Then write out each key/value pair. for (Object2IntMap.Entry<String> e : object2IntEntrySet()) { out.writeUTF(e.getKey()); out.writeInt(e.getValue()); } }
/** * Computes the dot product of this map with another map. * * @param m the other map */ public int dot(String2IntOpenHashMapWritable m) { int s = 0; for (Object2IntMap.Entry<String> e : m.object2IntEntrySet()) { String key = e.getKey(); if (this.containsKey(key)) { s += this.get(key) * e.getValue(); } } return s; }
/** * Adds values of keys from another map to this map. * * @param m the other map */ public void plus(String2IntOpenHashMapWritable m) { for (Object2IntMap.Entry<String> e : m.object2IntEntrySet()) { String key = e.getKey(); if (this.containsKey(key)) { this.put(key, this.get(key) + e.getValue()); } else { this.put(key, e.getValue()); } } }
/** * Adds values of keys from another map to this map. * * @param m the other map */ public void plus(Object2IntOpenHashMapWritable<K> m) { for (Object2IntMap.Entry<K> e : m.object2IntEntrySet()) { K key = e.getKey(); if (this.containsKey(key)) { this.put(key, this.get(key) + e.getValue()); } else { this.put(key, e.getValue()); } } }
/** * Computes the dot product of this map with another map. * * @param m the other map */ public int dot(Object2IntOpenHashMapWritable<K> m) { int s = 0; for (Object2IntMap.Entry<K> e : m.object2IntEntrySet()) { K key = e.getKey(); if (this.containsKey(key)) { s += this.get(key) * e.getValue(); } } return s; }
public List<ObjectDoublePair<T>> toList(double threshold) { List<ObjectDoublePair<T>> list = new ArrayList<>(); double d; for (Entry<T> p : count_map.object2IntEntrySet()) { d = MathUtils.divide(p.getValue(), total_count); if (d > threshold) list.add(new ObjectDoublePair<T>(p.getKey(), d)); } return list; }