home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (TestSetGetParameters.java)

This example Java source code file (TestSetGetParameters.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

computationgraph, computationgraphconfiguration, different, indarray, map, same, string, test, testsetgetparameters, util

The TestSetGetParameters.java Java example source code

package org.deeplearning4j.nn.graph;

import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.*;
import org.junit.Test;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.lossfunctions.LossFunctions.LossFunction;

import java.util.Map;

import static org.junit.Assert.*;

public class TestSetGetParameters {

    public void testInitWithParamsCG() {


        //Create configuration. Doesn't matter if this doesn't actually work for forward/backward pass here
        ComputationGraphConfiguration conf = new NeuralNetConfiguration.Builder()
                .addLayer("0", new DenseLayer.Builder().nIn(10).nOut(10).build(),"in")
                .addLayer("1", new GravesLSTM.Builder().nIn(10).nOut(10).build(),"in")
                .addLayer("2", new GravesBidirectionalLSTM.Builder().nIn(10).nOut(10).build(),"in")
                .addLayer("3", new ConvolutionLayer.Builder().nIn(10).nOut(10).kernelSize(2, 2).stride(2, 2).padding(2, 2).build(), "in")
                .addLayer("4", new OutputLayer.Builder(LossFunction.MCXENT).nIn(10).nOut(10).build(),"3")
                .addLayer("5", new OutputLayer.Builder(LossFunction.MCXENT).nIn(10).nOut(10).build(),"0")
                .addLayer("6", new RnnOutputLayer.Builder(LossFunction.MCXENT).nIn(10).nOut(10).build(), "1","2")

        ComputationGraph net = new ComputationGraph(conf);
        INDArray params = net.params();

        ComputationGraph net2 = new ComputationGraph(conf);
        net2.init(params, true);

        ComputationGraph net3 = new ComputationGraph(conf);
        net3.init(params, false);

        assertEquals(params, net2.params());
        assertEquals(params, net3.params());

        assertFalse(params == net2.params());    //Different objects due to clone
        assertTrue(params == net3.params());    //Same object due to clone

        Map<String, INDArray> paramsMap = net.paramTable();
        Map<String, INDArray> paramsMap2 = net2.paramTable();
        Map<String, INDArray> paramsMap3 = net3.paramTable();
        for (String s : paramsMap.keySet()) {
            assertEquals(paramsMap.get(s), paramsMap2.get(s));
            assertEquals(paramsMap.get(s), paramsMap3.get(s));

Other Java examples (source code examples)

Here is a short list of links related to this Java TestSetGetParameters.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 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.