Search in sources :

Example 1 with OptimizationAlgorithm

use of org.deeplearning4j.nn.api.OptimizationAlgorithm in project deeplearning4j by deeplearning4j.

the class BackTrackLineSearchTest method testBackTrackLineLBFGS.

@Test
public void testBackTrackLineLBFGS() {
    OptimizationAlgorithm optimizer = OptimizationAlgorithm.LBFGS;
    DataSet data = irisIter.next();
    data.normalizeZeroMeanZeroUnitVariance();
    MultiLayerNetwork network = new MultiLayerNetwork(getIrisMultiLayerConfig(Activation.RELU, 5, optimizer));
    network.init();
    IterationListener listener = new ScoreIterationListener(1);
    network.setListeners(Collections.singletonList(listener));
    double oldScore = network.score(data);
    network.fit(data.getFeatureMatrix(), data.getLabels());
    double score = network.score();
    assertTrue(score < oldScore);
}
Also used : OptimizationAlgorithm(org.deeplearning4j.nn.api.OptimizationAlgorithm) DataSet(org.nd4j.linalg.dataset.DataSet) IterationListener(org.deeplearning4j.optimize.api.IterationListener) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Example 2 with OptimizationAlgorithm

use of org.deeplearning4j.nn.api.OptimizationAlgorithm in project deeplearning4j by deeplearning4j.

the class BackTrackLineSearchTest method testBackTrackLineHessian.

@Test(expected = Exception.class)
public void testBackTrackLineHessian() {
    OptimizationAlgorithm optimizer = OptimizationAlgorithm.HESSIAN_FREE;
    DataSet data = irisIter.next();
    MultiLayerNetwork network = new MultiLayerNetwork(getIrisMultiLayerConfig(Activation.RELU, 100, optimizer));
    network.init();
    IterationListener listener = new ScoreIterationListener(1);
    network.setListeners(Collections.singletonList(listener));
    network.fit(data.getFeatureMatrix(), data.getLabels());
}
Also used : OptimizationAlgorithm(org.deeplearning4j.nn.api.OptimizationAlgorithm) DataSet(org.nd4j.linalg.dataset.DataSet) IterationListener(org.deeplearning4j.optimize.api.IterationListener) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Example 3 with OptimizationAlgorithm

use of org.deeplearning4j.nn.api.OptimizationAlgorithm in project deeplearning4j by deeplearning4j.

the class TestOptimizers method testOptimizersBasicMLPBackprop.

@Test
public void testOptimizersBasicMLPBackprop() {
    //Basic tests of the 'does it throw an exception' variety.
    DataSetIterator iter = new IrisDataSetIterator(5, 50);
    OptimizationAlgorithm[] toTest = { OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT, OptimizationAlgorithm.LINE_GRADIENT_DESCENT, OptimizationAlgorithm.CONJUGATE_GRADIENT, OptimizationAlgorithm.LBFGS };
    for (OptimizationAlgorithm oa : toTest) {
        MultiLayerNetwork network = new MultiLayerNetwork(getMLPConfigIris(oa, 1));
        network.init();
        iter.reset();
        network.fit(iter);
    }
}
Also used : OptimizationAlgorithm(org.deeplearning4j.nn.api.OptimizationAlgorithm) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) Test(org.junit.Test)

Example 4 with OptimizationAlgorithm

use of org.deeplearning4j.nn.api.OptimizationAlgorithm in project deeplearning4j by deeplearning4j.

the class TestComputationGraphNetwork method testOptimizationAlgorithmsSearchBasic.

@Test
public void testOptimizationAlgorithmsSearchBasic() {
    DataSetIterator iter = new IrisDataSetIterator(1, 1);
    OptimizationAlgorithm[] oas = new OptimizationAlgorithm[] { OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT, OptimizationAlgorithm.LINE_GRADIENT_DESCENT, OptimizationAlgorithm.CONJUGATE_GRADIENT, OptimizationAlgorithm.LBFGS };
    for (OptimizationAlgorithm oa : oas) {
        System.out.println(oa);
        ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(oa).iterations(1).graphBuilder().addInputs("input").addLayer("first", new DenseLayer.Builder().nIn(4).nOut(5).build(), "input").addLayer("output", new OutputLayer.Builder().nIn(5).nOut(3).build(), "first").setOutputs("output").pretrain(false).backprop(true).build();
        ComputationGraph net = new ComputationGraph(conf);
        net.init();
        net.fit(iter.next());
    }
}
Also used : OptimizationAlgorithm(org.deeplearning4j.nn.api.OptimizationAlgorithm) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) RecordReaderMultiDataSetIterator(org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator) MultiDataSetIterator(org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator) Test(org.junit.Test)

Example 5 with OptimizationAlgorithm

use of org.deeplearning4j.nn.api.OptimizationAlgorithm in project deeplearning4j by deeplearning4j.

the class BackTrackLineSearchTest method testBackTrackLineCG.

@Test
public void testBackTrackLineCG() {
    OptimizationAlgorithm optimizer = OptimizationAlgorithm.CONJUGATE_GRADIENT;
    DataSet data = irisIter.next();
    data.normalizeZeroMeanZeroUnitVariance();
    MultiLayerNetwork network = new MultiLayerNetwork(getIrisMultiLayerConfig(Activation.RELU, 5, optimizer));
    network.init();
    IterationListener listener = new ScoreIterationListener(1);
    network.setListeners(Collections.singletonList(listener));
    double firstScore = network.score(data);
    network.fit(data.getFeatureMatrix(), data.getLabels());
    double score = network.score();
    assertTrue(score < firstScore);
}
Also used : OptimizationAlgorithm(org.deeplearning4j.nn.api.OptimizationAlgorithm) DataSet(org.nd4j.linalg.dataset.DataSet) IterationListener(org.deeplearning4j.optimize.api.IterationListener) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) ScoreIterationListener(org.deeplearning4j.optimize.listeners.ScoreIterationListener) Test(org.junit.Test)

Aggregations

OptimizationAlgorithm (org.deeplearning4j.nn.api.OptimizationAlgorithm)8 Test (org.junit.Test)8 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)7 IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)5 DataSet (org.nd4j.linalg.dataset.DataSet)5 DataSetIterator (org.nd4j.linalg.dataset.api.iterator.DataSetIterator)5 IterationListener (org.deeplearning4j.optimize.api.IterationListener)4 ScoreIterationListener (org.deeplearning4j.optimize.listeners.ScoreIterationListener)4 HashMap (java.util.HashMap)1 RecordReaderMultiDataSetIterator (org.deeplearning4j.datasets.datavec.RecordReaderMultiDataSetIterator)1 MnistDataSetIterator (org.deeplearning4j.datasets.iterator.impl.MnistDataSetIterator)1 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)1 OutputLayer (org.deeplearning4j.nn.conf.layers.OutputLayer)1 MultiDataSetIterator (org.nd4j.linalg.dataset.api.iterator.MultiDataSetIterator)1