如何使用neuralnet包初始化权重?

时间:2015-03-05 14:43:01

标签: r

我在R中使用神经网络包,但是当我想为网络初始化一定数量的初始权重时,我遇到了问题。我试图根据我从生成的默认随机权重得到的结果来做,但根本没有运气。

这是我应该放置初始权重的部分:

weigths<-c(-0.3,0.2,
    0.2,0.05,
    0,2,-0.1,
    -0.1,0.2,0.2)
net=neuralnet(to~x1+x2,tdata,hidden=2,threshold=0.01,constant.weights=weights) 

因为我认为权重遵循这种模式:

Intercept.to.1layhid1  -5.0556934519949
x1.to.1layhid1         10.9208362719511
x2.to.1layhid1         12.9996270590530
Intercept.to.1layhid2   3.7047601228351
x1.to.1layhid2         -2.5636252939619
x2.to.1layhid2         -2.5759077405754
Intercept.to.to        -1.6494794336705
1layhid.1.to.to         1.3502874764968
1layhid.2.to.to         1.6969811621181

但是当我申请时,我收到了错误:

Error in constant.weights != 0

任何帮助?

由于

1 个答案:

答案 0 :(得分:3)

您正在寻找startweights参数来初始化自定义权重。这在文档中:

help(neuralnet)

startweights:
  a vector containing starting values for the weights. 
  The weights will not be randomly initialized.

constant.weights用于指定您使用exclude agrument排除的固定权重。