📄 rgnn_sim.m
字号:
function [Y_hat x]=rgnn_sim(U,W,activation,x,n)%[Y_hat x]=rgnn_sim(U,W,activation,x,n)%this calculates feedback gnn with selectable activation function%U=input (one column is one time step) The last row should be ones%W=weights%activation=vector of activation functions:% 0=sigmoid% 1=tanh% 2=linear% 3=bipolar squash (x/(abs(x)+1))%n=number of outputs% Copyright Travis Wiens 2008%% This program is free software: you can redistribute it and/or modify% it under the terms of the GNU General Public License as published by% the Free Software Foundation, either version 3 of the License, or% (at your option) any later version.%% This program is distributed in the hope that it will be useful,% but WITHOUT ANY WARRANTY; without even the implied warranty of% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the% GNU General Public License for more details.%% You should have received a copy of the GNU General Public License% along with this program. If not, see <http://www.gnu.org/licenses/>.%% If you would like to request a commerical (or other) license, please% feel free to contact travis.mlfx@nutaksas.comif nargin<5 n=1;%default to one outputendif nargin<4 x=zeros(size(W,1));endif nargin<3 activation=ones(size(W,1),1);%default to tanh activation(end)=2;%linear outputendif n~=1 error('This function currently only works with single outputs (n=1)')end[N_t1 N_t2]=size(W);if N_t1~=N_t2 error('W must be square')endN_t=N_t1;[m K]=size(U);%number of inputs, number of time stepsN=N_t1-n;%number of input + hidden neuronsx=zeros(N+n,K);%initialize neuron outputsY_hat=zeros(n,K);%initialize network outputsfor k=1:K;%loop through time steps if k>1 x(:,k)=x(:,k-1); end x(1:m,k)=U(:,k);%copy inputs to net for i=m+1:N_t;%loop through neurons net=0; for j=1:N_t;%calculate wieghted sum net=net+W(i,j)*x(j,k); end if activation(i)==0;%%sigmoid x(i,k)=1/(1+exp(-net)); elseif activation(i)==1;%tanh x(i,k)=tanh(net); elseif activation(i)==2;%linear x(i,k)=net; elseif activation(i)==3;%bipolar squash x(i,k)=net/(abs(net)+1); else error('Unknown Activation function') end end Y_hat(:,k)=x(N+1:n+N,k);%outputend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -