@Test public void testSegment() { System.out.println("Segment"); MathEx.setSeed(19650218); WinsorScaler scaler = WinsorScaler.fit(Segment.x, 0.01, 0.99); double[][] x = scaler.transform(Segment.x); double[][] testx = scaler.transform(Segment.testx); int p = x[0].length; int k = MathEx.max(Segment.y) + 1; System.out.format("----- Online Learning -----%n"); MLP model = new MLP(p, Layer.sigmoid(50), Layer.mle(k, OutputFunction.SOFTMAX) ); model.setLearningRate(TimeFunction.constant(0.2)); int error = 0; for (int epoch = 1; epoch <= 30; epoch++) { System.out.format("----- epoch %d -----%n", epoch); int[] permutation = MathEx.permutate(x.length); for (int i : permutation) { model.update(x[i], Segment.y[i]); } int[] prediction = Validation.test(model, testx); error = Error.of(Segment.testy, prediction); System.out.println("Test Error = " + error); } assertEquals(30, error); System.out.format("----- Mini-Batch Learning -----%n"); model = new MLP(p, Layer.sigmoid(50), Layer.mle(k, OutputFunction.SOFTMAX) ); model.setLearningRate(TimeFunction.constant(0.2)); model.setRMSProp(0.9, 1E-7); int batch = 20; double[][] batchx = new double[batch][]; int[] batchy = new int[batch]; for (int epoch = 1; epoch <= 14; epoch++) { System.out.format("----- epoch %d -----%n", epoch); int[] permutation = MathEx.permutate(x.length); int i = 0; for (; i < x.length-batch;) { for (int j = 0; j < batch; j++, i++) { batchx[j] = x[permutation[i]]; batchy[j] = Segment.y[permutation[i]]; } model.update(batchx, batchy); } for (; i < x.length; i++) { model.update(x[permutation[i]], Segment.y[permutation[i]]); } int[] prediction = Validation.test(model, testx); error = Error.of(Segment.testy, prediction); System.out.println("Test Error = " + error); } assertEquals(28, error); }
@Override public void update(double[] x, int y) { propagate(x); setTarget(labels.indexOf(y)); backpropagate(x, true); t++; }
MLP extends MultilayerPerceptron implements OnlineClassifier<double[]>, SoftClassifier<double[]>, Serializable { @Override public void update(double[] x, int y) { propagate(x); setTarget(labels.indexOf(y)); backpropagate(x, true); t++; } }
MLP extends MultilayerPerceptron implements OnlineClassifier<double[]>, SoftClassifier<double[]>, Serializable { @Override public void update(double[] x, int y) { propagate(x); setTarget(labels.indexOf(y)); backpropagate(x, true); t++; } MLP(int p, LayerBuilder... builders);  MLP(IntSet labels, int p, LayerBuilder... builders); }
MLP extends MultilayerPerceptron implements OnlineClassifier<double[]>, SoftClassifier<double[]>, Serializable { @Override public void update(double[] x, int y) { propagate(x); setTarget(labels.indexOf(y)); backpropagate(x, true); t++; } MLP(int p, LayerBuilder... builders);  MLP(IntSet labels, int p, LayerBuilder... builders); @Override int predict(double[] x, double[] posteriori); @Override int predict(double[] x); @Override void update(double[] x, int y); @Override void update(double[][] x, int[] y); }
MLP extends MultilayerPerceptron implements OnlineClassifier<double[]>, SoftClassifier<double[]>, Serializable { @Override public void update(double[] x, int y) { propagate(x); setTarget(labels.indexOf(y)); backpropagate(x, true); t++; } MLP(int p, LayerBuilder... builders);  MLP(IntSet labels, int p, LayerBuilder... builders); @Override int predict(double[] x, double[] posteriori); @Override int predict(double[] x); @Override void update(double[] x, int y); @Override void update(double[][] x, int[] y);  }