2017-08-10 133 views
1

我相信deeplearning4j和R完全相同的参数应该执行相同的可比较的MSE。但我不确定如何实现这一点。Deeplearning4j与R结果不同

我有一个csv文件,格式如下,其中包含46变量和2输出。完全有1,0000样本。所有数据都进行了归一化处理,模型用于回归分析。

S1 | S2 | ... | S46 | X | Y 

在R,我使用neuralnet包,以及将码是:

rn <- colnames(traindata) 
f <- as.formula(paste("X + Y ~", paste(rn[1:(length(rn)-2)], collapse="+"))) 
nn <- neuralnet(f, 
       rep=1, 
       data=traindata, 
       hidden=c(10), 
       linear.output=T, 
       threshold = 0.5) 

这是相当简单的。

由于我想将算法整合到Java项目中,所以我认为dl4j来训练模型。火车组与R代码完全一样。测试集是随机选择的。的dl4j代码是:

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() 
      .seed(rngSeed) //include a random seed for reproducibility 
      // use stochastic gradient descent as an optimization algorithm 
      .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) 
      .iterations(100) 
      .learningRate(0.0001) //specify the learning rate 
      .updater(Updater.NESTEROVS).momentum(0.9) //specify the rate of change of the learning rate. 
      .regularization(true).l2(0.0001) 
      .list() 
      .layer(0, new DenseLayer.Builder() //create the first, input layer with xavier initialization 
        .nIn(46) 
        .nOut(10) 
        .activation(Activation.TANH) 
        .weightInit(WeightInit.XAVIER) 
        .build()) 
      .layer(1, new OutputLayer.Builder(LossFunctions.LossFunction.MSE) //create hidden layer 
        .nIn(10) 
        .nOut(outputNum) 
        .activation(Activation.IDENTITY) 
        .build()) 
      .pretrain(false).backprop(true) //use backpropagation to adjust weights 
      .build(); 

时期的数量是10和batchsize是128

使用测试组,R的性能是 enter image description here

和dl4j的性能是以下,我认为它没有发挥其全部潜力。

dl4j的mornitor是

由于存在dl4j如updaterregulizationweightInit更多参数。所以我认为一些参数设置不正确。顺便说一句,为什么在mornitor图中有周期性的刺。

任何人都可以帮忙吗?

回答

1

大多数神经网络训练发生在minibatches。 Deeplearning4j假设默认情况下你没有玩玩具问题(内存中的所有数据< 10例子等)

神经网络配置有一个叫做minibatch的功能,你应该查找。

在配置上将minibatch设置为false,您应该得到相同的结果。

如果你想知道为什么会发生这种情况,这是因为小批次学习不同于记忆中的所有事情。小批次学习会自动按照小批量大小分配梯度。当你在记忆中做所有事情时,你都不想那样做。

当您运行其他实验时请注意这一点。 欲了解更多关于此,请参阅: https://deeplearning4j.org/toyproblems