【发布时间】:2020-07-18 00:59:33
【问题描述】:
我考虑以下循环神经网络 (RNN):
其中 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