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

Class SumMapper

src/com/winvector/logistic/mr/MapRedFn.java:134–263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132 }
133
134 public static final class SumMapper extends Mapper<LongWritable,Text,Text,DoubleWritable> {
135 private LineBurster burster = null;
136 // config
137 private JobStateDescr config = null;
138 // derived
139 private VariableEncodings defs = null;
140 private Log log = null;
141 private String hostDescr = null;
142 // scratch
143 private double[] pscratch = null;
144 // result
145 private long nProcessed = 0;
146 private VEval accum = null;
147
148 @Override
149 public void setup(final Context context) throws IOException {
150 // read side-channel configuration
151 log = LogFactory.getLog(SumMapper.class);
152 hostDescr = WritableUtils.hostDescr();
153 log.info(".setup() " + hostDescr);
154 try {
155 burster = SerialUtils.readSerialiazlabeFromString(context.getConfiguration().get(MapRedScan.BURSTERSERFIELD));
156 } catch (ClassNotFoundException e) {
157 throw new IOException(e.toString());
158 }
159 config = JobStateDescr.fromString(context.getConfiguration().get(MRFIELDNAME));
160 defs = new VariableEncodings(config.defs,config.useIntercept,config.weightKey);
161 accum = new VEval(config.x,config.wantGrad,config.wantHessian);
162 pscratch = new double[defs.noutcomes()];
163 nProcessed = 0;
164 }
165
166 @Override
167 public void map(final LongWritable key, final Text value, final Context context) {
168 final String origStr = value.toString();
169 final BurstMap parsed = burster.parse(origStr);
170 if(!parsed.isEmpty()) {
171 final String resStr = parsed.getAsString(config.defs.resultColumn);
172 if((resStr!=null)&&(resStr.length()>0)) {
173 final Integer category = defs.category(resStr.trim());
174 if((category!=null)&&(category>=0)) {
175 final SparseSemiVec v = defs.vector(parsed);
176 final double wt = defs.weight(parsed);
177 if((wt>0.0)&&(v!=null)) {
178 final ExampleRow r = new SparseExampleRow(v,wt,category);
179 config.underlying.addTerm(config.x, config.wantGrad, config.wantHessian, r, accum, pscratch);
180 ++nProcessed;
181 }
182 }
183 }
184 }
185 }
186
187 /**
188 * only write summing terms (fx,gx,hx) into Text,WritableDouble format
189 * @param v
190 * @param context
191 * @throws InterruptedException

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected