| 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); |
| 90 | final StringBuilder b = new StringBuilder(); |
| 91 | b.append(defs.outcome(argMax) + "\t" + pred[argMax] + "\t"); |
| 92 | for(final double pi: pred) { |
| 93 | b.append("" + pi + "\t"); |
| 94 | } |
| 95 | b.append(origStr); |
| 96 | context.write(new Text("Offset." + nf.format(key.get())),new Text(b.toString())); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void cleanup(final Context context) { |
| 103 | log.info(".cleanup() " + hostDescr); |
| 104 | burster = null; |
| 105 | config = null; |
| 106 | defs = null; |
| 107 | } |
| 108 | } |
| 109 |
nothing calls this directly
no outgoing calls
no test coverage detected