Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexDBlack committed Oct 27, 2018
1 parent 2cbdfa5 commit b772694
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
Expand Up @@ -51,6 +51,8 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.nd4j.linalg.indexing.NDArrayIndex.all;
import static org.nd4j.linalg.indexing.NDArrayIndex.point;

/**
* Created by Alex on 12/09/2016.
Expand Down Expand Up @@ -411,7 +413,9 @@ public static INDArray[] getFeaturesAndLabels(ILossFunction l, long[] featuresSh
case "LossKLD":
//KL divergence: should be a probability distribution for labels??
ret[1] = Nd4j.rand(labelsShape);
Nd4j.getExecutioner().exec(new OldSoftMax(ret[1]), 1);
for(int i=0; i<labelsShape[2]; i++ ) {
Nd4j.getExecutioner().exec(new OldSoftMax(ret[1].get(all(), all(), point(i))), 1);
}
break;
case "LossMCXENT":
case "LossNegativeLogLikelihood":
Expand Down
Expand Up @@ -495,7 +495,7 @@ public void testYoloOverfitting() throws Exception {

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
.convolutionMode(ConvolutionMode.Same)
.updater(new Adam(1e-3))
.updater(new Adam(2e-3))
.gradientNormalization(GradientNormalization.ClipElementWiseAbsoluteValue)
.gradientNormalizationThreshold(3)
.activation(Activation.LEAKYRELU)
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.nd4j.linalg.dataset.DataSet;
import org.nd4j.linalg.dataset.api.iterator.DataSetIterator;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.learning.config.Adam;
import org.nd4j.linalg.learning.config.Nesterovs;
import org.nd4j.linalg.lossfunctions.LossFunctions;

Expand Down Expand Up @@ -240,7 +241,7 @@ public void testBackTrackLineLBFGS() {

private static MultiLayerConfiguration getIrisMultiLayerConfig(Activation activationFunction, OptimizationAlgorithm optimizer) {
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder().optimizationAlgo(optimizer)
.miniBatch(false).updater(new Nesterovs(0.9)).seed(12345L).list()
.updater(new Adam(0.1)).seed(12345L).list()
.layer(0, new DenseLayer.Builder().nIn(4).nOut(100).weightInit(WeightInit.XAVIER)
.activation(activationFunction).build())
.layer(1, new org.deeplearning4j.nn.conf.layers.OutputLayer.Builder(
Expand Down
Expand Up @@ -166,7 +166,9 @@ public INDArray activate(boolean training, LayerWorkspaceMgr workspaceMgr) {
throw new UnsupportedOperationException(
"Input must be rank 3. Got input with rank " + input.rank() + " " + layerId());

return layerConf().getActivationFn().getActivation(workspaceMgr.dup(ArrayType.ACTIVATIONS, input), training);
INDArray as2d = TimeSeriesUtils.reshape3dTo2d(input);
INDArray out2d = layerConf().getActivationFn().getActivation(workspaceMgr.dup(ArrayType.ACTIVATIONS, as2d, as2d.ordering()), training);
return workspaceMgr.leverageTo(ArrayType.ACTIVATIONS, TimeSeriesUtils.reshape2dTo3d(out2d, (int)input.size(0), workspaceMgr, ArrayType.ACTIVATIONS));
}

@Override
Expand Down
Expand Up @@ -245,7 +245,7 @@ public void computeGradientAndScore(LayerWorkspaceMgr workspaceMgr) {
INDArray temp = meanZ.mul(meanZ).addi(pzxSigmaSquared).negi();
temp.addi(logStdev2Z).addi(1.0);
double scorePt1 = -0.5 / minibatch * temp.sumNumber().doubleValue();
this.score = scorePt1 + (calcL1(false) + calcL2(false)) / minibatch;
this.score = scorePt1 + (calcL1(false) + calcL2(false));
}

INDArray pxzDistributionPreOut = current.mmul(pxzw).addiRowVector(pxzb);
Expand Down

0 comments on commit b772694

Please sign in to comment.