Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAUSSIAN hidden unit causing IndexOutOfBound exception #189

Closed
winstonquock opened this issue Mar 6, 2015 · 4 comments
Closed

GAUSSIAN hidden unit causing IndexOutOfBound exception #189

winstonquock opened this issue Mar 6, 2015 · 4 comments

Comments

@winstonquock
Copy link

Exception in thread "main" java.lang.IllegalArgumentException: Illegal index 5599 derived from 5599 with offset of 0 and stride of 1
    at org.nd4j.linalg.api.ndarray.BaseNDArray.linearIndex(BaseNDArray.java:2569)
    at org.nd4j.linalg.api.ndarray.BaseNDArray.getDouble(BaseNDArray.java:2852)
    at org.nd4j.linalg.sampling.Sampling.normal(Sampling.java:49)
    at org.deeplearning4j.models.featuredetectors.rbm.RBM.sampleHiddenGivenVisible(RBM.java:263)
    at org.deeplearning4j.models.featuredetectors.rbm.RBM.gradient(RBM.java:123)
    at org.deeplearning4j.nn.layers.BaseLayer.gradientAndScore(BaseLayer.java:325)
    at org.deeplearning4j.optimize.solvers.BaseOptimizer.gradientAndScore(BaseOptimizer.java:117)
    at org.deeplearning4j.optimize.solvers.BaseOptimizer.optimize(BaseOptimizer.java:131)
    at org.deeplearning4j.optimize.Solver.optimize(Solver.java:41)
    at org.deeplearning4j.nn.layers.BaseLayer.fit(BaseLayer.java:319)
    at org.deeplearning4j.models.featuredetectors.rbm.RBM.fit(RBM.java:451)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.pretrain(MultiLayerNetwork.java:215)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:1138)
    at org.deeplearning4j.nn.multilayer.MultiLayerNetwork.fit(MultiLayerNetwork.java:1173)

network config:

    // in kotlin syntax
    val hiddenLayerSizes = array(500, 100, 10) // 500, 100, 10
    val gen = MersenneTwister(123)

    val iteration = 10
    val layerFactory = LayerFactories.getFactory(javaClass<RBM>())
    val listBuilder = NeuralNetConfiguration.Builder()
            .iterations(iteration)!!
            .weightInit(WeightInit.DISTRIBUTION)!!
            .dist(Distributions.normal(gen, 1e-2))!!
            .activationFunction("tanh")!!
            .hiddenUnit(RBM.HiddenUnit.GAUSSIAN)!!
            .visibleUnit(RBM.VisibleUnit.GAUSSIAN)!!
            .layerFactory(layerFactory)!!
            .constrainGradientToUnitNorm(true )!!
            .optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT)!!
            .rng(gen)!!
            .learningRate(5e-2.toDouble())!!
            .nIn(trainingSet.numInputs())!!
            .nOut(trainingSet.numOutcomes())!!
            .list(hiddenLayerSizes.size() + 1)!!
            .hiddenLayerSizes(*hiddenLayerSizes.toIntArray())

    listBuilder.override({ i, builder ->
                if (i >= hiddenLayerSizes.size() ) { // 0 based, last one is output
                    builder.layerFactory(DefaultLayerFactory(javaClass<OutputLayer>()))
                    builder.activationFunction("tanh")
                    builder.lossFunction(LossFunctions.LossFunction.MSE)
                    builder.iterations(iteration * 5)
                }
            })
    val conf = listBuilder.build()!!
    val nn = MultiLayerNetwork(conf)
@winstonquock winstonquock changed the title GUASIAN hidden unit causing IndexOutOfBoundError GUASIAN hidden unit causing IndexOutOfBound exception Mar 6, 2015
@winstonquock winstonquock changed the title GUASIAN hidden unit causing IndexOutOfBound exception GAUSIAN hidden unit causing IndexOutOfBound exception Mar 6, 2015
@winstonquock winstonquock changed the title GAUSIAN hidden unit causing IndexOutOfBound exception GAUSSIAN hidden unit causing IndexOutOfBound exception Mar 6, 2015
@agibsonccc
Copy link
Contributor

Do you have the latest verison of nd4j?

@winstonquock
Copy link
Author

Yes, I just retrieved the latest nd4j and dl4j. Still same problem. Note: only GAUSSIAN hidden units cause problem; the GAUSSIAN visible units are OK.

@agibsonccc
Copy link
Contributor

Fixed.

nightscape pushed a commit to nightscape/deeplearning4j that referenced this issue Jul 4, 2018
Set type alias Data as Tensor instead of CachedTensor
@lock
Copy link

lock bot commented Jan 22, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants