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

Java example source code file (GRUParamInitializer.java)

This example Java source code file (GRUParamInitializer.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

bias_key, gruparaminitializer, indarray, input_weight_key, map, neuralnetconfiguration, not, override, recurrent_weight_key, string, todo, unsupportedoperationexception, util

The GRUParamInitializer.java Java example source code

 *  * Copyright 2015 Skymind,Inc.
 *  *
 *  *    Licensed under the Apache License, Version 2.0 (the "License");
 *  *    you may not use this file except in compliance with the License.
 *  *    You may obtain a copy of the License at
 *  *
 *  *        http://www.apache.org/licenses/LICENSE-2.0
 *  *
 *  *    Unless required by applicable law or agreed to in writing, software
 *  *    distributed under the License is distributed on an "AS IS" BASIS,
 *  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  *    See the License for the specific language governing permissions and
 *  *    limitations under the License.

package org.deeplearning4j.nn.params;

import org.canova.api.conf.Configuration;
import org.deeplearning4j.nn.api.ParamInitializer;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.distribution.Distributions;
import org.deeplearning4j.nn.weights.WeightInitUtil;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.api.rng.distribution.Distribution;
import org.nd4j.linalg.factory.Nd4j;

import java.util.Map;

public class GRUParamInitializer implements ParamInitializer {
	/** Weights for previous time step -> current time step connections */
    public final static String RECURRENT_WEIGHT_KEY = "RW";
    public final static String BIAS_KEY = DefaultParamInitializer.BIAS_KEY;
    public final static String INPUT_WEIGHT_KEY = DefaultParamInitializer.WEIGHT_KEY;

    public int numParams(NeuralNetConfiguration conf, boolean backprop) {
        throw new UnsupportedOperationException("Not yet implemented"); //TODO

    public void init(Map<String, INDArray> params, NeuralNetConfiguration conf, INDArray paramsView, boolean initializeParams) {
    	org.deeplearning4j.nn.conf.layers.GRU layerConf =
                (org.deeplearning4j.nn.conf.layers.GRU) conf.getLayer();
//        Distribution dist = Distributions.createDistribution(layerConf.getDist());
//        int nL = layerConf.getNOut();	//i.e., n neurons in this layer
//        int nLast = layerConf.getNIn();	//i.e., n neurons in previous layer
//        conf.addVariable(INPUT_WEIGHT_KEY);
//        conf.addVariable(RECURRENT_WEIGHT_KEY);
//        conf.addVariable(BIAS_KEY);
//        //Order: RUC - i.e., reset, update, candidate
//        params.put(INPUT_WEIGHT_KEY,WeightInitUtil.initWeights(nLast, 3 * nL, layerConf.getWeightInit(), dist));
//        params.put(RECURRENT_WEIGHT_KEY,WeightInitUtil.initWeights(nL, 3 * nL, layerConf.getWeightInit(), dist));
//        params.put(BIAS_KEY, Nd4j.zeros(1,3*nL));
//        params.get(INPUT_WEIGHT_KEY).data().persist();
//        params.get(RECURRENT_WEIGHT_KEY).data().persist();
//        params.get(BIAS_KEY).data().persist();

        throw new UnsupportedOperationException("Not yet implemented"); //TODO

    public Map<String, INDArray> getGradientsFromFlattened(NeuralNetConfiguration conf, INDArray gradientView) {
        throw new UnsupportedOperationException("Not yet implemented");

Other Java examples (source code examples)

Here is a short list of links related to this Java GRUParamInitializer.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.