|
Java example source code file (SeedTest.java)
The SeedTest.java Java example source codepackage org.deeplearning4j.nn.layers; import org.nd4j.linalg.dataset.api.iterator.DataSetIterator; import org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator; import org.deeplearning4j.nn.api.*; import org.deeplearning4j.nn.api.Layer; import org.deeplearning4j.nn.conf.NeuralNetConfiguration; import org.deeplearning4j.nn.conf.layers.*; import org.deeplearning4j.nn.layers.factory.LayerFactories; import org.junit.Test; import org.nd4j.linalg.api.ndarray.INDArray; import org.nd4j.linalg.dataset.DataSet; import org.nd4j.linalg.factory.Nd4j; import static org.junit.Assert.assertEquals; /** */ public class SeedTest { private DataSetIterator irisIter = new IrisDataSetIterator(50,50); private DataSet data = irisIter.next(); @Test public void testAutoEncoderSeed() { AutoEncoder layerType = new AutoEncoder.Builder() .nIn(4) .nOut(3).corruptionLevel(0.0) .activation("sigmoid") .build(); NeuralNetConfiguration conf = new NeuralNetConfiguration.Builder() .iterations(1) .layer(layerType) .seed(123) .build(); int numParams = LayerFactories.getFactory(conf).initializer().numParams(conf,true); INDArray params = Nd4j.create(1, numParams); Layer layer = LayerFactories.getFactory(conf).create(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); } } Other Java examples (source code examples)Here is a short list of links related to this Java SeedTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.