R包DARCH深度信念神经网络似乎无法学习 'exclusive or'

标签 r neural-network deep-learning

预先感谢您的帮助。我正在尝试实现一个深度学习神经网络来预测许多变量(一种多元非线性回归)。第一步,我查看 R 中的 Darch 包并处理

中的代码片段

http://cran.r-project.org/web/packages/darch/darch.pdf

当我从第 10 页运行以下代码时,该代码似乎正在对“异或”进行训练,然后生成的神经网络似乎无法学习该函数。它要么学习 (1,0) 模式,要么学习 (0,1) 模式为 true,但不能同时学习两者,有时还学习 (1,1) 模式,这应该是 false。我的理解是,这些类型的网络应该能够学习几乎任何功能,包括对于初学者的“异或”:这个网络在微调中使用的原始反向传播工作是否没有解决这个问题。我想我可能会错过一些东西,所以非常感谢任何建议或帮助? (我什至将纪元增加到 10,000,但没有效果。)

# Generating the datasets
inputs <- matrix(c(0,0,0,1,1,0,1,1),ncol=2,byrow=TRUE)
outputs <- matrix(c(0,1,1,0),nrow=4)
# Generating the darch
darch <- newDArch(c(2,4,1),batchSize=2)
# Pre-Train the darch
darch <- preTrainDArch(darch,inputs,maxEpoch=100)
# Prepare the layers for backpropagation training for
# backpropagation training the layer functions must be
# set to the unit functions which calculates the also
# derivatives of the function result.
layers <- getLayers(darch)
for(i in length(layers):1){
    layers[[i]][[2]] <- sigmoidUnitDerivative

}
setLayers(darch) <- layers
rm(layers)
# Setting and running the Fine-Tune function
setFineTuneFunction(darch) <- backpropagation
darch <- fineTuneDArch(darch,inputs,outputs,maxEpoch=100)
# Running the darch
darch <- darch <- getExecuteFunction(darch)(darch,inputs)
outputs <- getExecOutputs(darch)
cat(outputs[[length(outputs)]])
## End(Not run)


#### Example results


> cat(outputs[[length(outputs)]])
0.02520016 0.8923063 0.1264799 0.9803244

## Different run

> cat(outputs[[length(outputs)]])
0.02702418 0.1061477 0.9833059 0.9813462

最佳答案

就其值(value)而言,以下内容对我有用:

# Generating the datasets
inputs <- matrix(c(0,0,0,1,1,0,1,1),ncol=2,byrow=TRUE)
print(inputs)

outputs <- matrix(c(0,1,1,0),nrow=4)
print(outputs)


# Generating the darch
darch <- newDArch(c(2,4,1),batchSize=4,ff=F)

# Pre-Train the darch
darch <- preTrainDArch(darch,inputs,maxEpoch=200,numCD=4)

# Prepare the layers for backpropagation training for
# backpropagation training the layer functions must be
# set to the unit functions which calculates the also
# derivatives of the function result.
layers <- getLayers(darch)
for(i in length(layers):1){
  layers[[i]][[2]] <- sigmoidUnitDerivative
}

setLayers(darch) <- layers
rm(layers)

# Setting and running the Fine-Tune function
setFineTuneFunction(darch) <- rpropagation
darch <- fineTuneDArch(darch,trainData=inputs,targetData=outputs,
                       maxEpoch=200,
                       isBin=T)

# Running the darch
darch <- darch <- getExecuteFunction(darch)(darch,inputs)
outputs2 <- getExecOutputs(darch)
cat(outputs2[[length(outputs2)]])
## End(Not run)

得到以下结果

> # Running the darch
> darch <- darch <- getExecuteFunction(darch)(darch,inputs)

> outputs2 <- getExecOutputs(darch)

> cat(outputs2[[length(outputs2)]])
1.213234e-21 1 1 1.213234e-21
> ## End(Not run)
1.213234e-21 1 1 1.213234e-21

因此进行了以下更改:

  • 学习从经典反向传播更改为弹性反向传播
  • 批量大小设置为 4
  • numCD 设置为 4

因为我本质上是在表演 Voodoo(直到我练习了一些),所以我似乎无法将错误率保持在 17% 以下。

编辑:

所以我一直在阅读并倾向于认为系统的每个独特状态都与单个内部神经元相关。如果您有两位逻辑,则有四种独特的输入组合,因此有四种独特的输入状态。如果您想要一个能够处理该问题的系统,那么您需要 4 个内部节点。这意味着对于 8 位操作,您可能需要 256 个内部节点。

atari-game folks具有模型自适应控制,因此通过一个网络,他们可以预测系统的下一个状态,而通过另一个网络,他们可以在给定当前状态和预期下一个状态的情况下确定最佳控制策略。

当我重新运行数千次时,长时间训练后的输出大约有 18% 的时间是错误的。我真的不喜欢这样。

想法:

  • 如果我添加正确的噪音,我可以恢复 simulated annealing 的效果吗?关于稳定性?
  • 如果我在输入中添加汉明码之类的内容,我可以交换空间大小以获得稳定性吗?
  • 输出错误稳定的时间是当两个输出完全相等时。我可以在训练算法中构建对此的检测,并用它来更新一个“权重”而不是另一个“权重”,从而解耦(据称是解耦的)神经元吗?
  • 列出项目

关于R包DARCH深度信念神经网络似乎无法学习 'exclusive or',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782006/

相关文章:

tensorflow - 训练精度良好,但评估较差

python - 卷积层特征图上的特殊函数

r - 重复时如何根据优先级重新分类/替换值

r - 使用 lubridate 提取数年中的月份

r - 替换列名gsub中的字符

python - Keras:从 HDF5 和 CSV 加载小批量

python - 连接层的 ValueError(Keras 函数式 API)

r - 哪个 "geom_"用于为从 x 轴开始的每个观察绘制一条条/线?

python - 准确率始终为零

neural-network - 在 pycaffe 中创建简单的身份层后网络不收敛