(final Iterable<BurstMap> trainSource, final Formula f, final String weightKey)
| 302 | } |
| 303 | |
| 304 | public Model train(final Iterable<BurstMap> trainSource, final Formula f, final String weightKey) { |
| 305 | final Log log = LogFactory.getLog(LogisticTrain.class); |
| 306 | final VariableEncodings adapter = buildAdpater(f,weightKey,trainSource); |
| 307 | final Iterable<ExampleRow> asTrain = new ExampleRowIterable(adapter,trainSource); |
| 308 | final LinearContribution<ExampleRow> sigmoidLoss = new SigmoidLossMultinomial(adapter.dim(),adapter.noutcomes()); |
| 309 | final VectorFn sl = NormPenalty.addPenalty(new DataFn<ExampleRow>(sigmoidLoss,asTrain),1.0e-5,adapter.adaptions); |
| 310 | final VectorOptimizer nwt = new Newton(); |
| 311 | final VEval opt = nwt.maximize(sl,null,10); |
| 312 | log.info("done training"); |
| 313 | log.info("soln vector: " + LinUtil.toString(opt.x)); |
| 314 | log.info("soln details:\n" + adapter.formatSoln(opt.x)); |
| 315 | final Model model = new Model(); |
| 316 | model.config = adapter; |
| 317 | model.coefs = opt.x; |
| 318 | model.origFormula = f; |
| 319 | return model; |
| 320 | } |
| 321 | |
| 322 | |
| 323 | public final void run(final Iterable<BurstMap> trainSource, final Formula f, final String weightKey, |
no test coverage detected