| 138 | } |
| 139 | |
| 140 | public long[] score(final double[] x) throws IOException, InterruptedException, ClassNotFoundException { |
| 141 | final String pathOutName = tmpPrefix + "_MPRedAcOut"; |
| 142 | final Path pathOut = new Path(pathOutName); |
| 143 | final JobStateDescr conf = new JobStateDescr(); |
| 144 | conf.underlying = underlying; |
| 145 | conf.defs = defs; |
| 146 | conf.x = x; |
| 147 | conf.useIntercept = useIntercept; |
| 148 | conf.wantGrad = false; |
| 149 | conf.wantHessian = false; |
| 150 | mrConfig.set(MRFIELDNAME,conf.toString()); // prepare config for distribution |
| 151 | // run the job |
| 152 | final Job job = WritableUtils.newJob(mrConfig); |
| 153 | job.setJarByClass(MapRedAccuracy.class); |
| 154 | job.setJobName("MapRedScoreStep"); |
| 155 | FileInputFormat.setMaxInputSplitSize(job,4*1024*1024L); |
| 156 | FileInputFormat.setMinInputSplitSize(job,4*1024L); |
| 157 | FileInputFormat.addInputPath(job,pathIn); |
| 158 | FileOutputFormat.setOutputPath(job,pathOut); |
| 159 | job.setMapperClass(AccuracyMapper.class); |
| 160 | job.setCombinerClass(SumReducer.class); |
| 161 | job.setReducerClass(SumReducer.class); |
| 162 | job.setNumReduceTasks(1); |
| 163 | job.setOutputKeyClass(LongWritable.class); |
| 164 | job.setOutputValueClass(LongWritable.class); |
| 165 | job.setInputFormatClass(TextInputFormat.class); |
| 166 | job.setOutputFormatClass(TextOutputFormat.class); |
| 167 | final long[] r = new long[2]; |
| 168 | if(job.waitForCompletion(false)) { |
| 169 | // collect results |
| 170 | final FSDataInputStream fdi = pathOut.getFileSystem(mrConfig).open(new Path(pathOut,"part-r-00000")); |
| 171 | final BufferedReader d = new BufferedReader(new InputStreamReader(fdi)); |
| 172 | String line = null; |
| 173 | while((line=d.readLine())!=null) { |
| 174 | final String[] flds = line.split("\t"); |
| 175 | if(flds.length==2) { |
| 176 | r[Integer.parseInt(flds[0])] = Long.parseLong(flds[1]); |
| 177 | } |
| 178 | } |
| 179 | d.close(); |
| 180 | } |
| 181 | // clean up |
| 182 | pathOut.getFileSystem(mrConfig).delete(pathOut,true); |
| 183 | return r; |
| 184 | } |
| 185 | } |