使用 darch 预测新样本 class

Using darch to predict new sample class

我正在尝试使用 darch 包创建一个包含多个堆叠 RBM 的 dbn。我是深度学习领域的新手,所以我的问题是:glmnet/randomForest/knn...etc 包中的预测函数等价于什么?

训练完 dbn 后,如何对外部样本进行预测?例如(这是包中提供的示例)

## Not run:
# 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=1000)
# 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=1000)
# Running the darch
darch <- darch <- getExecuteFunction(darch)(darch,inputs)
outputs <- getExecOutputs(darch)
cat(outputs[[length(outputs)]])

假设现在我们有

inputsTest <- matrix(c(0,1,0,0,0,0,1,1),ncol=2,byrow=TRUE)

如何获得输出?

另外,谁能解释一下这一行的作用:

darch <- darch <- getExecuteFunction(darch)(darch,inputs)

Darch 有一堆 getter 和 setter 方法,你可以自己访问这些字段。执行函数就是其中之一。

对我来说,最简单的方法就是做 darch <- darch@executeFunction(darch, inputs)

所有层的输出将在 darch@executeOutput

实际上,这真的很有帮助,有一个直接预测命令。 https://github.com/maddin79/darch