Search in sources :

Example 1 with BaseOutputLayer

use of org.deeplearning4j.nn.layers.BaseOutputLayer in project deeplearning4j by deeplearning4j.

the class MultiLayerTest method testGradientWithAsList.

@Test
public void testGradientWithAsList() {
    MultiLayerNetwork net1 = new MultiLayerNetwork(getConf());
    MultiLayerNetwork net2 = new MultiLayerNetwork(getConf());
    net1.init();
    net2.init();
    DataSet x1 = new IrisDataSetIterator(1, 150).next();
    DataSet all = new IrisDataSetIterator(150, 150).next();
    DataSet x2 = all.asList().get(0);
    //x1 and x2 contain identical data
    assertArrayEquals(asFloat(x1.getFeatureMatrix()), asFloat(x2.getFeatureMatrix()), 0.0f);
    assertArrayEquals(asFloat(x1.getLabels()), asFloat(x2.getLabels()), 0.0f);
    assertEquals(x1, x2);
    //Set inputs/outputs so gradient can be calculated:
    net1.feedForward(x1.getFeatureMatrix());
    net2.feedForward(x2.getFeatureMatrix());
    ((BaseOutputLayer) net1.getLayer(1)).setLabels(x1.getLabels());
    ((BaseOutputLayer) net2.getLayer(1)).setLabels(x2.getLabels());
    net1.gradient();
    net2.gradient();
}
Also used : BaseOutputLayer(org.deeplearning4j.nn.layers.BaseOutputLayer) IrisDataSetIterator(org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator) DataSet(org.nd4j.linalg.dataset.DataSet) Test(org.junit.Test)

Aggregations

IrisDataSetIterator (org.deeplearning4j.datasets.iterator.impl.IrisDataSetIterator)1 BaseOutputLayer (org.deeplearning4j.nn.layers.BaseOutputLayer)1 Test (org.junit.Test)1 DataSet (org.nd4j.linalg.dataset.DataSet)1