【问题标题】:Why modifying the weights of a recurrent neural network in MATLAB does not cause the output to change when predicting on same data?为什么在 MATLAB 中修改循环神经网络的权重不会导致在对相同数据进行预测时改变输出?
【发布时间】:2020-07-18 00:59:33
【问题描述】:

我考虑以下循环神经网络 (RNN):

RNN under consideration

其中 x 是输入(实数向量),h 是隐藏状态向量,y 是输出向量。我使用一些数据x在 Matlab 上训练了网络,得到了 W、V 和 U。

但是,在MATLAB中,将矩阵W改为W',并保持U,V不变,使用W的RNN的输出(y)与输出(y') 使用 W' 的 RNN 在对相同数据 x 进行预测时。仅通过查看上面的等式,这两个输出应该是不同的,但我似乎无法在 MATLAB 中做到这一点(当我修改 V 或 U 时,输出确实会改变)。我该如何修复代码,以使输出 (y) 和 (y') 与应有的不同?

相关代码如下:

[x,t] = simplefit_dataset;  % x: input data ; t: targets
net = newelm(x,t,5);  % Recurrent neural net with 1 hidden layer (5 nodes) and 1 output layer (1 node)
net.layers{1}.transferFcn = 'tansig'; % 'tansig': equivalent to tanh and also is the activation function used for hidden layer 
net.biasConnect = [0;0]; % biases set to zero for easier experimenting 
net.derivFcn ='defaultderiv'; % defaultderiv: tells Matlab to pick whatever derivative scheme works best for this net
view(net) % displays the network topology
net = train(net,x,t); % trains the network
W = net.LW{1,1}; U = net.IW{1,1}; V = net.LW{2,1}; % network matrices

Y = net(x); % Y: output when predicting on data x using W

net.LW{1,1} = rand(5,5); % This is the modified matrix W, W'
Y_prime = net(x) % Y_prime: output when predicting on data x using W'

max(abs(Y-Y_prime )); % The difference between the two outputs is 0 when it probably shouldn't be. 

编辑:小幅修正。

【问题讨论】:

    标签: matlab machine-learning neural-network regression recurrent-neural-network


    【解决方案1】:

    这是您第一层的递归:(来自文档)

    从第 j 层到第 i 层的权重矩阵 层(或空矩阵 [ ])位于 net.LW{i,j} 如果 net.layerConnect(i,j) 为 1(或 0)。

    所以net.LW{1,1} 是从第一层到第一层的权重(即递归),而net.LW{2,1} 存储从第一层到第二层的权重。现在,当一个人可以随机更改递归的权重而没有任何影响时,这意味着什么(实际上,您可以将它们设置为零net.LW{1,1} = zeros(size(W)); 而不会产生任何影响)。请注意,这本质上与您放弃递归并创建简单的前馈网络相同:

    假设:递归没有效果。

    你会注意到,如果你将权重从第一层(5个神经元)net.LW{2,1} = zeros(size(V));更改为第二层(1个神经元),它会影响你的预测(如果你改变输入权重当然也是如此net.IW)。

    为什么递归没有效果? 嗯,这打败了我。我不知道这个特殊故障在哪里,也不知道newelm 网络背后的理论是什么。

    【讨论】:

      猜你喜欢
      • 2020-09-05
      • 1970-01-01
      • 2021-01-07
      • 2016-09-28
      • 2014-09-13
      • 2013-01-17
      • 2016-01-21
      • 2013-05-12
      • 1970-01-01
      相关资源
      最近更新 更多