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

Class BStat

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

Source from the content-addressed store, hash-verified

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
79 /**
80 *
81 * @param outcome training outcome
82 * @param level level of variable
83 * @param pred current model predictions
84 * @param correct category
85 * @paream weight>0.0
86 */
87 public void observe(final String outcome, final String level, final double[] pred, final int category, final double weight) {
88 sumTotal += weight;
89 totalByCategory[category] += weight;
90 BLevelRow blevelRow = levelStats.get(level);
91 if(null==blevelRow) {
92 blevelRow = new BLevelRow();
93 levelStats.put(level,blevelRow);
94 }
95 blevelRow.totalForLevel += weight;
96 blevelRow.totalByCorrectCategory[category] += weight;
97 for(int i=0;i<noutcomes;++i) {
98 blevelRow.sumPFixedCategory[i] += weight*pred[i];
99 if(category==i) {
100 blevelRow.sumRunFixedCategory[i] += weight*1.0/Math.max(pred[i],smallValue);
101 } else {
102 blevelRow.sumRunFixedCategory[i] += weight*-1.0/Math.max(1.0-pred[i],smallValue);
103 }
104 }
105 blevelRow.sumRunCorrectCategory[category] += weight*1.0/Math.max(pred[category],smallValue);
106 blevelRow.sumPCorrectCategory[category] += weight*pred[category];
107 }
108
109 public void observe(final BStat o) {
110 sumTotal += o.sumTotal;
111 sumLeft(totalByCategory,o.totalByCategory);
112 for(final Map.Entry<String,BLevelRow> op: o.levelStats.entrySet()) {
113 final String key = op.getKey();
114 final BLevelRow ov = op.getValue();
115 BLevelRow val = levelStats.get(key);
116 if(val==null) {
117 val = new BLevelRow();
118 levelStats.put(key,val);
119 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected