WinnowTrainer extends LinearTrainer { @Override protected void update(double label, Vector dataPoint, LinearModel model) { if (label > 0) { Vector updateVector = dataPoint.times(1 / this.promotionStep); log.info("Winnow update positive: {}", updateVector); Iterator<Vector.Element> iter = updateVector.iterateNonZero(); while (iter.hasNext()) { Vector.Element element = iter.next(); model.timesDelta(element.index(), element.get()); } } else { Vector updateVector = dataPoint.times(1 / this.promotionStep); log.info("Winnow update negative: {}", updateVector); Iterator<Vector.Element> iter = updateVector.iterateNonZero(); while (iter.hasNext()) { Vector.Element element = iter.next(); model.timesDelta(element.index(), element.get()); } } log.info(model.toString()); } WinnowTrainer(int dimension, double promotionStep,
                       double threshold, double init, double initBias);  WinnowTrainer(int dimension, double promotionStep);  WinnowTrainer(int dimension);   }
@Test public void testUpdate() throws Exception { double[] labels = { 0.0, 0.0, 0.0, 1.0 }; Vector labelset = new DenseVector(labels); double[][] values = new double[3][4]; for (int i = 0; i < 3; i++) { values[i][0] = 1.0; values[i][1] = 1.0; values[i][2] = 1.0; values[i][3] = 1.0; } values[1][0] = 0.0; values[2][0] = 0.0; values[1][1] = 0.0; values[2][2] = 0.0; Matrix dataset = new DenseMatrix(values); trainer.train(labelset, dataset); assertTrue(trainer.getModel().classify(dataset.getColumn(3))); assertFalse(trainer.getModel().classify(dataset.getColumn(0))); }