Search in sources :

Example 6 with NegativeDefaultStepFunction

use of org.deeplearning4j.optimize.stepfunctions.NegativeDefaultStepFunction in project deeplearning4j by deeplearning4j.

the class TestDecayPolicies method testLearningRateScoreDecay.

@Test
public void testLearningRateScoreDecay() {
    double lr = 0.01;
    double lrScoreDecay = 0.10;
    int[] nIns = { 4, 2 };
    int[] nOuts = { 2, 3 };
    int oldScore = 1;
    int newScore = 1;
    int iteration = 3;
    INDArray gradientW = Nd4j.ones(nIns[0], nOuts[0]);
    MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().learningRate(lr).learningRateDecayPolicy(LearningRatePolicy.Score).lrPolicyDecayRate(lrScoreDecay).list().layer(0, new DenseLayer.Builder().nIn(nIns[0]).nOut(nOuts[0]).updater(org.deeplearning4j.nn.conf.Updater.SGD).build()).layer(1, new OutputLayer.Builder().nIn(nIns[1]).nOut(nOuts[1]).updater(org.deeplearning4j.nn.conf.Updater.SGD).build()).backprop(true).pretrain(false).build();
    MultiLayerNetwork net = new MultiLayerNetwork(conf);
    net.init();
    ConvexOptimizer opt = new StochasticGradientDescent(net.getDefaultConfiguration(), new NegativeDefaultStepFunction(), null, net);
    opt.checkTerminalConditions(gradientW, oldScore, newScore, iteration);
    assertEquals(lrScoreDecay, net.getLayer(0).conf().getLrPolicyDecayRate(), 1e-4);
    assertEquals(lr * (lrScoreDecay + Nd4j.EPS_THRESHOLD), net.getLayer(0).conf().getLearningRateByParam("W"), 1e-4);
}
Also used : StochasticGradientDescent(org.deeplearning4j.optimize.solvers.StochasticGradientDescent) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) ConvexOptimizer(org.deeplearning4j.optimize.api.ConvexOptimizer) MultiLayerConfiguration(org.deeplearning4j.nn.conf.MultiLayerConfiguration) INDArray(org.nd4j.linalg.api.ndarray.INDArray) DenseLayer(org.deeplearning4j.nn.conf.layers.DenseLayer) MultiLayerNetwork(org.deeplearning4j.nn.multilayer.MultiLayerNetwork) NegativeDefaultStepFunction(org.deeplearning4j.optimize.stepfunctions.NegativeDefaultStepFunction) Test(org.junit.Test)

Aggregations

NegativeDefaultStepFunction (org.deeplearning4j.optimize.stepfunctions.NegativeDefaultStepFunction)6 Test (org.junit.Test)5 INDArray (org.nd4j.linalg.api.ndarray.INDArray)5 MultiLayerNetwork (org.deeplearning4j.nn.multilayer.MultiLayerNetwork)3 ConvexOptimizer (org.deeplearning4j.optimize.api.ConvexOptimizer)3 StochasticGradientDescent (org.deeplearning4j.optimize.solvers.StochasticGradientDescent)3 BatchNormalization (org.deeplearning4j.nn.conf.layers.BatchNormalization)2 OutputLayer (org.deeplearning4j.nn.layers.OutputLayer)2 BackTrackLineSearch (org.deeplearning4j.optimize.solvers.BackTrackLineSearch)2 MultiLayerConfiguration (org.deeplearning4j.nn.conf.MultiLayerConfiguration)1 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)1 DenseLayer (org.deeplearning4j.nn.conf.layers.DenseLayer)1 NegativeGradientStepFunction (org.deeplearning4j.nn.conf.stepfunctions.NegativeGradientStepFunction)1 Level1 (org.nd4j.linalg.api.blas.Level1)1 ScalarSetValue (org.nd4j.linalg.api.ops.impl.scalar.comparison.ScalarSetValue)1 Eps (org.nd4j.linalg.api.ops.impl.transforms.comparison.Eps)1