Search in sources :

Example 1 with AutoEncoder

use of org.deeplearning4j.nn.conf.layers.AutoEncoder in project deeplearning4j by deeplearning4j.

the class SeedTest method testAutoEncoderSeed.

@Test
public void testAutoEncoderSeed() {
    AutoEncoder layerType = new AutoEncoder.Builder().nIn(4).nOut(3).corruptionLevel(0.0).activation(Activation.SIGMOID).build();
    NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder().iterations(1).layer(layerType).seed(123).build();
    int numParams = conf.getLayer().initializer().numParams(conf);
    INDArray params = Nd4j.create(1, numParams);
    Layer layer = conf.getLayer().instantiate(conf, null, 0, params, true);
    layer.fit(data.getFeatureMatrix());
    layer.computeGradientAndScore();
    double score = layer.score();
    INDArray parameters = layer.params();
    layer.setParams(parameters);
    layer.computeGradientAndScore();
    double score2 = layer.score();
    assertEquals(parameters, layer.params());
    assertEquals(score, score2, 1e-4);
}
Also used : INDArray(org.nd4j.linalg.api.ndarray.INDArray) NeuralNetConfiguration(org.deeplearning4j.nn.conf.NeuralNetConfiguration) AutoEncoder(org.deeplearning4j.nn.conf.layers.AutoEncoder) Layer(org.deeplearning4j.nn.api.Layer) Test(org.junit.Test)

Aggregations

Layer (org.deeplearning4j.nn.api.Layer)1 NeuralNetConfiguration (org.deeplearning4j.nn.conf.NeuralNetConfiguration)1 AutoEncoder (org.deeplearning4j.nn.conf.layers.AutoEncoder)1 Test (org.junit.Test)1 INDArray (org.nd4j.linalg.api.ndarray.INDArray)1