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

Class MapRedScore

src/com/winvector/logistic/mr/MapRedScore.java:32–145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30import com.winvector.variables.VariableEncodings;
31
32public final class MapRedScore {
33 private static final String MRFIELDNAME = "MapRedSc.MRBlock";
34 public static final String IDEALHEADERFIELD = "MapRedSc.IdealHeader";
35 private final SigmoidLossMultinomial underlying;
36 private final WritableVariableList defs;
37 private final boolean useIntercept;
38 private final Configuration mrConfig;
39 private final Path pathIn;
40
41
42 public MapRedScore(final SigmoidLossMultinomial underlying, final WritableVariableList defs, final boolean useIntercept,
43 final Configuration mrConfig, final Path pathIn) {
44 this.underlying = underlying;
45 this.useIntercept = useIntercept;
46 this.defs = defs;
47 this.pathIn = pathIn;
48 this.mrConfig = mrConfig;
49 }
50
51
52 public static final class ScoreMapper extends Mapper<LongWritable,Text,Text,Text> {
53 private final NumberFormat nf = new DecimalFormat("000000000000");
54 private LineBurster burster = null;
55 // config
56 private JobStateDescr config = null;
57 // derived
58 private VariableEncodings defs = null;
59 private Log log = null;
60 private String hostDescr = null;
61
62
63 @Override
64 public void setup(final Context context) throws IOException {
65 log = LogFactory.getLog(ScoreMapper.class);
66 hostDescr = WritableUtils.hostDescr();
67 log.info(".setup() " + hostDescr);
68 // read side-channel configuration
69 try {
70 burster = SerialUtils.readSerialiazlabeFromString(context.getConfiguration().get(MapRedScan.BURSTERSERFIELD));
71 } catch (ClassNotFoundException e) {
72 throw new IOException(e.toString());
73 }
74 config = JobStateDescr.fromString(context.getConfiguration().get(MRFIELDNAME));
75 defs = new VariableEncodings(config.defs,config.useIntercept,config.weightKey);
76 }
77
78 @Override
79 public void map(final LongWritable key, final Text value, final Context context) throws IOException, InterruptedException {
80 final String origStr = value.toString();
81 final BurstMap parsed = burster.parse(origStr);
82 if(!parsed.isEmpty()) {
83 final SparseSemiVec v = defs.vector(parsed);
84 if(v!=null) {
85 final double wt = defs.weight(parsed);
86 final int catInt = -1;
87 final Datum r = new SparseExampleRow(v,wt,catInt);
88 final double[] pred = config.underlying.predict(config.x,r);
89 final int argMax = HelperFns.argmax(pred);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected