MCPcopy Create free account
hub / github.com/WinVector/Logistic / BObserver

Class BObserver

src/com/winvector/variables/BObserver.java:21–196  ·  view source on GitHub ↗

statistics accumulator used by BTable builds stats on categorical variables with a very large number of levels @author johnmount

Source from the content-addressed store, hash-verified

19 *
20 */
21final class BObserver implements ReducibleObserver<BurstMap,BObserver> {
22 // def
23 public final int noutcomes;
24 public final double smallValue;
25
26 private static void sumLeft(final double[] x, final double[] delta) {
27 final int n = x.length;
28 for(int i=0;i<n;++i) {
29 x[i] += delta[i];
30 }
31 }
32
33 public final class BLevelRow {
34 public double totalForLevel = 0.0;
35 public final double[] totalByCorrectCategory;
36 public final double[] sumRunCorrectCategory;
37 public final double[] sumRunFixedCategory;
38 public final double[] sumPCorrectCategory;
39 public final double[] sumPFixedCategory;
40
41 public BLevelRow() {
42 totalByCorrectCategory = new double[noutcomes];
43 sumRunCorrectCategory = new double[noutcomes];
44 sumRunFixedCategory = new double[noutcomes];
45 sumPCorrectCategory = new double[noutcomes];
46 sumPFixedCategory = new double[noutcomes];
47 }
48
49 public void observe(final BLevelRow o) {
50 totalForLevel += o.totalForLevel;
51 sumLeft(totalByCorrectCategory,o.totalByCorrectCategory);
52 sumLeft(sumRunCorrectCategory,o.sumRunCorrectCategory);
53 sumLeft(sumRunFixedCategory,o.sumRunFixedCategory);
54 sumLeft(sumPCorrectCategory,o.sumPCorrectCategory);
55 sumLeft(sumPFixedCategory,o.sumPFixedCategory);
56 }
57 }
58
59 /*
60 * per-variable statistics
61 */
62 public final class BStat {
63 // def
64 public final VariableMapping oldAdaption;
65 // raw stats
66 public double sumTotal = 0.0;
67 public final double[] totalByCategory;
68 public final Map<String,BLevelRow> levelStats = new HashMap<String,BLevelRow>(1000);
69
70 public BStat(final VariableMapping oldAdaption) {
71 this.oldAdaption = oldAdaption;
72 totalByCategory = new double[noutcomes];
73 }
74
75 public BLevelRow newRow() {
76 return new BLevelRow();
77 }
78

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected