R神经网络将不同的输入链接到不同的隐藏层
R neural networks linking different input to different hidden layers
我正在尝试像这样对神经网络建模:
但是在 neuralnet 包中,神经网络公式有一个语法,据我所知不能用于这种模型。
net <- neuralnet(Output~LOC+PREC_n+FLEX_n+RESL_n,data, hidden=2) #, threshold=0.01)
这是我正在使用的代码。例如,我想 link LOC 和 PREC_n 输入到第一个隐藏层,FLEX_n 和 RESL_n 输入到第二个。我怎样才能做到这一点?
我找到了解决办法。神经网络函数参数中有 "exclude"。您应该指定将被排除在这样的矩阵中的权重:
# exclude matrix
# first column is layer
# second column is input neuron
# third column is output neuron
# exclude links from first five neurons to second hidden neuron, links from last 17 neurons to first hidden neuron and output bias.
# ordering is as in weight vector
e = matrix(
c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,
2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
nrow=23,
ncol=3)
排序 -> 从输入神经元到第一个隐藏神经元的连接(第一个连接是偏置,所以 1 是偏置权重,2 是第一个神经元的连接。这就是为什么第二列从 2....23 开始)。并遵循这个逻辑......
我正在尝试像这样对神经网络建模:
但是在 neuralnet 包中,神经网络公式有一个语法,据我所知不能用于这种模型。
net <- neuralnet(Output~LOC+PREC_n+FLEX_n+RESL_n,data, hidden=2) #, threshold=0.01)
这是我正在使用的代码。例如,我想 link LOC 和 PREC_n 输入到第一个隐藏层,FLEX_n 和 RESL_n 输入到第二个。我怎样才能做到这一点?
我找到了解决办法。神经网络函数参数中有 "exclude"。您应该指定将被排除在这样的矩阵中的权重:
# exclude matrix
# first column is layer
# second column is input neuron
# third column is output neuron
# exclude links from first five neurons to second hidden neuron, links from last 17 neurons to first hidden neuron and output bias.
# ordering is as in weight vector
e = matrix(
c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,
2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,1,
2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1),
nrow=23,
ncol=3)
排序 -> 从输入神经元到第一个隐藏神经元的连接(第一个连接是偏置,所以 1 是偏置权重,2 是第一个神经元的连接。这就是为什么第二列从 2....23 开始)。并遵循这个逻辑......