📄 jsquared2.m
字号:
function [AT2ones] =Jsquared2(mode,m,n,f,iw,rw, ... w1,b1,Output_Layer2,Deriv_Layer2,w2,b2,Output_Layer3,Deriv_Layer3,P,T)%Call: [AT2ones] =Jsquared2(mode,m,n,f,iw,rw, ... %w1,b1,Output_Layer2,Deriv_Layer2,w2,b2,Output_Layer3,Deriv_Layer3,P,T)%%This routine computes A(T) .^2 * ones(m,1) where A is the Jacobian%corresponding to a FFANN with two hidden layers.%The idea is that element k of AT2ones should contain the sum of the%squared elements of the k:th column of the Jacobian%[Fst,q]=size(P); % # nodes in Input layer (first layer)[Snd,r]=size(w1); % # nodes in 1'st hidden layer (second layer)if Fst ~= r % q is # samples presented to the inputs error('In Jsquared2: Fst .ne. r');end[Thrd,r]=size(w2); % # nodes in output layer (third layer)if Snd ~= r error('In Jsquared2: Snd .ne. r')end%[Fth,r]=size(w3); % # nodes in output layer (forth layer)Om=Fst*Snd+Snd; % # weights in first hidden layerNm=Om+Snd*Thrd+Thrd; % # total weights%Mm=Nm+Thrd*Fth+Fth; % # total weights%lenf=max(size(f));%if (q*Fth) ~= lenf %error('In Jsquared2: q*Fth .ne. lenf '); %else AT2ones=zeros(Nm,1);%end%%Compute J(T) .^2 * ones(Nm,1)%i.e. find the sum of the squared elements of all columns in J%% time1=cputime; r1=Fst*Snd; r2=Om+Snd*Thrd; %r3=Nm+Thrd*Fth; %for i=1:q, %r4=(i-1)*Fth; %u(:,i)=f(r4+1:r4+Fth); %end %A3=Deriv_Layer4; %ta3=Deriv_Layer4 .^2; %w3bar=A3*Output_Layer3'; %Corresponding to w3bar %tw3bar=ta3 * (Output_Layer3 .^2)'; %Af(Nm+1:r3)=w3bar(:); %AT2ones(Nm+1:r3)=tw3bar(:); %S=w3'*A3; %S=w3(1,:)'*Deriv_Layer4(1,:); %tS=(w3 .^2)' * ta3; %A2=Deriv_Layer3 .* S; %A2=Deriv_Layer3; %ta2=(Deriv_Layer3 .^2) .* tS; ta2=Deriv_Layer3 .^2; %w2bar=A2*Output_Layer2'; %Corresponding to w2bar tw2bar=ta2 * (Output_Layer2 .^2)'; %Af(Om+1:r2)=w2bar(:); AT2ones(Om+1:r2)=tw2bar(:); S=w2(1,:)'*Deriv_Layer3(1,:); %tS=(w2 .^2)' * ta2; %A1=Deriv_Layer2 .* S; ta1=(Deriv_Layer2 .* S) .^2; %Af(r1+1:Om)=sum(A1')'; %Corresponding to b1 AT2ones(r1+1:Om)=sum(ta1')'; %w1bar=A1*P'; %Corresponding to w1bar tw1bar=ta1*(P .^2)'; %Af(1:r1)=w1bar(:); AT2ones(1:r1)=tw1bar(:); for i=2:Thrd, S=w2(i,:)'*Deriv_Layer3(i,:); ta1=(Deriv_Layer2 .* S) .^2; tw1bar=ta1*(P .^2)'; AT2ones(r1+1:Om)=AT2ones(r1+1:Om)+sum(ta1')'; AT2ones(1:r1)=AT2ones(1:r1)+tw1bar(:); end %for i=2:Fth, %S=w3(i,:)'*Deriv_Layer4(i,:); %A2=Deriv_Layer3 .* S; %S=w2'*A2; %ta1=(Deriv_Layer2 .* S) .^2; %tw1bar=ta1*(P .^2)'; %AT2ones(1:r1)=AT2ones(1:r1)+tw1bar(:); %AT2ones(r1+1:Om)=AT2ones(r1+1:Om)+sum(ta1')'; %end %Af(Mm-Fth+1:Mm)=sum(A3')'; %Corresponding to b3 %AT2ones(Mm-Fth+1:Mm)=sum(ta3')'; %Af(Nm-Thrd+1:Nm)=sum(A2')'; %Corresponding to b2 AT2ones(Nm-Thrd+1:Nm)=sum(ta2')';end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -