MCPcopy Index your code
hub / github.com/WinVector/Logistic / CountMapV

Class CountMapV

src/com/winvector/util/CountMapV.java:10–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9
10public class CountMapV<T> implements Serializable {
11 private static final long serialVersionUID = 1L;
12
13 private final int dim;
14 private final SortedMap<T,double[]> counts;
15
16 public CountMapV(final Comparator<T> comp, final int dim) {
17 this.dim = dim;
18 counts = new TreeMap<T,double[]>(comp);
19 }
20
21 public int dim() {
22 return dim;
23 }
24
25 /**
26 * Invariant: key set calls all keys ever observed (even those with net-zero count)
27 * @param key
28 * @param delta
29 */
30 public void observe(final T key, final int index, final double delta) {
31 double[] v = counts.get(key);
32 if(v==null) {
33 v = new double[dim];
34 counts.put(key,v);
35 }
36 v[index] += delta;
37 }
38
39 public boolean contains(final T key) {
40 return counts.containsKey(key);
41 }
42
43 public Set<T> keySet() {
44 return counts.keySet();
45 }
46
47 public double get(final T key, final int index) {
48 final double[] v = counts.get(key);
49 if(v!=null) {
50 return v[index];
51 } else {
52 return 0.0;
53 }
54 }
55}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected