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

Class StatMap

src/com/winvector/util/StatMap.java:9–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9public final class StatMap implements Serializable {
10 private static final long serialVersionUID = 1L;
11
12 public static final class SimpleStat implements Serializable {
13 private static final long serialVersionUID = 1L;
14 public double sumW = 0.0;
15 public double sumWX = 0.0;
16 }
17
18 private final Map<String,SimpleStat> counts = new HashMap<String,SimpleStat>();
19
20 /**
21 * Invariant: key set calls all keys ever observed (even those with net-zero count)
22 */
23 public void observe(final String key, final double x, final double wt) {
24 SimpleStat v = counts.get(key);
25 if(v==null) {
26 v = new SimpleStat();
27 counts.put(key,v);
28 }
29 v.sumW += wt;
30 v.sumWX += wt*x;
31 }
32
33 public void observe(final String key, final SimpleStat val) {
34 SimpleStat v = counts.get(key);
35 if(v==null) {
36 v = new SimpleStat();
37 counts.put(key,v);
38 }
39 v.sumW += val.sumW;
40 v.sumWX += val.sumWX;
41 }
42
43 public boolean contains(final String key) {
44 return counts.containsKey(key);
45 }
46
47 public Set<String> keySet() {
48 return counts.keySet();
49 }
50
51 public SimpleStat get(final String key) {
52 final SimpleStat v = counts.get(key);
53 if(v!=null) {
54 return v;
55 } else {
56 return new SimpleStat();
57 }
58 }
59
60 public SimpleStat remove(final String key) {
61 final SimpleStat v = counts.remove(key);
62 return v;
63 }
64}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected