Você está na página 1de 56
Apéndice B Programas de Cémputo B.1, Aproximacién de una Funcién No Lineal por Medio de una RN- MC 4% DICIEMBRE, 2001 % CENTRO DE THVESTIGACION Y ESTUDIOS AVANZADOS DEL 1PN 4% DEPTO. DE CONTROL AUTOMATIC PROGRAMADOR: JOSE MARTIN FLORES ALBINO 4% COMPILADOR: MATLAB VER.5.0 4 INPLEMENTA UNA RED NEURONAL(RN) MULTI-CAPA PARA LA APROXIMACTON DE UNA FUNCION NO LINEAL 4% SE UTILIZA EL ALGORITMO DE ENTRENAMIENTO DEL TIPO RETRO-PROPAGACION DEL ERROR X LA RN TIENE UNA ENTRADA, DOS CAPAS OCULTAS Y UNA SALIDA INICIO PROGRAMA: MENNAPHINIULAIIL clear all close all step=100; 1% Paso de graficacion nun_ep=800; % Numero de epocas % No. de entradas. % No. de Nodos, primer capa oculta. J, No. de Nodes, Segunda capa oculta. Wo. de Wodos, Salidas BAER EEE De ed wd etha0.15; Constante de aprendizaje % Pesos iniciales(incluye bias) Wi-0.t#rand(ni not); W2=0. 1+rand(n2,n1+1) ; W3+0.4erand(n3,n2+1) Ke(1:0.1:1)7; % Entradas K.maxemax(X) ; Bun_data=size(X,1); {Numero de datos Ya=tesin((pi/1)*X); % Valor deseado (Funcion) Y4_max=max(¥d) ; % Inicializaciones 181 B.1. Aproximacién de una Funcién No Lineal por Medio de una RNMC__ Capitulo B._ Programas de Cémputo Ec=0; MSI ai hfigisfigure(1); sev(hfigt,*position’, [0 460 672 $04]) Figure(bfigt); plot(x,¥,"0"); axis({min(K)#1.1 max(X)e4t min(¥a)*1.1 wax(Ya)*1.1]); draunow; hold on; for datast:nuz data ‘Paso hacia adelante Si=Wi*[1;X(data)]; anh ($1) ; ae (430115, anb ($2) ; e3* (1,02) Y(datal end Sigure(nfigh); if (exist (id?) & exist(?iaplot’)), delete (id) ;delete(sdpiot) send id=text (X_max+0.5,¥d_uax+0.8,0,nun2str(0)); set (id, "FontWeight’, ’bold? , color’, black’) idplot=plot (X,Y, ?-"); dravnow; for ep=4:num_op; 1% Por cada epoca for datai:num_data; % Para cada dato 4% Paso hacia adelante (1; x(data)): anb(S1) ; % Salida de 1a primera capa U4; 01); O2=tanh($2) ; Salida de 1s segunda capa S3-W3*[1; 02]; 3; 4% Salida (Lineal) de 1a RN ‘a(dava)-Y; % Error EosEc+(E°2); % Suma de.b-2 4% paso hacia atras, gradi_local=-E; Ui Gradiente local de salida gradi=gradi_local+([1; 02])"; % Gradiente de salida grad2_loca! grad2=grad) 1-02.°2) .*((W3(: ,2:n241) *)*(grad{_local)); % Gradiente local capa oculta 2 locals ({1; 01])?; 4 Gradiente capa oculta 2 jS_ocal= (1-01. ~2).*((W2(: ,2:n141)")*(grad2_locel)); % Gradiente local capa oculta 4 srad3_local*({1; X(data)])°; 4% Gradiente capa oculta 1 grad grad 4% Actualizacion de Pesos W3eW3-ethaxexp (—ep/mum_ep) #gradi; W2-W2-ethaexp(~ep/num_ep)+grad?; Wi-Wi-ethavexp(~ep/num_ep) gra: 182 | ncién No Lineal por Medio de una RNFRB Capitulo B. Programns de Computo__ B.2. Aproximacién de vi end MSE=[NSE Be/2] 5 Ece0; if rem(ep, step) for data=1:nun_date wWeaso hacia adelante Wi [15 X(data)} tank (S1) ; o1 s2suoe(1 011; o2etanh ($2); sigoretnrie); Hf Cexist("i0") & exiet(*idplot?)), deleveCia) ;delete(apiot) send * detent (K.naxv0.5,Y4.2axe0.1,0, Ep? munzetr(ep)]); hold on sev(id, FontWeight' , bold’, "color” , *black") i Adplot=plot(x,¥,?="); i plot (X,¥d,°0") axis((minQQe1.1 max(Qe1.1 min(¥d)e1.1 max(¥d)*1.1]); dravnow; end bfig2=figure(2); sev(hfig?, "position’, [620 460 672 504]); figure(hfig2); plot(1:nun_ep.MSE) ; id2=text (num_ep+0.6,max(MSE)+0.5,0, UMSE=? ,mum2str (HSE (max (size(MSE,2))))1)5 set (id2, "Fontieight’, "bold? ‘color’, *black") 4% PIN PROGRAMA: MLNNOPUAIII B.2. Aproximacién de una Funcién No Lineal por Medio de una RN- FRB % BNERD,2002 i 4% CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN 4% DEPTO. DE CONTROL AUTOKATICO % PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 5.0 % 4 IMPLEMENTA UMA RED NEURONAL(RN) DE FRB PARA LA APROXIMACTON DE UNA FUNCION NO LINEAL TNICIO PROGRAMA: RBF2.minnicNIith W(-1:0.1:1) 5 ‘Watos de entrenamiento (entradas) nug_dataesize(t, 1); Ynumero de datos de entrenamiento Yaetssin((pi/1)#X); Yates de entrenaniento(Salidas) | 2.3, Algoritmo de Proyeccics jtulo B. Programas de Computo 1:0.251)75 wentros de les FRB tum_datal+size(Ke,1); Yertvsin( (pi/1)*Ke) 5 =0.5; i=); for i=t:num_data; for j=1:mum_datal; RA (i,j) =gaus(K(4)-Ke(j) 5895 end nd IeCinv(Ri’#Ri)*(RE))#¥a; YCalculo de Pesos peRieW; Agure(1); plot(X,¥a,?~") hold on plot(x,¥p,’x") hold on Mov(xe,¥e,"+?) hold off axis({-1.1 1.1 1.7 1.13) | PIN PROGRAMA: RBF2.m MMII . Funcion gaussiana rr expansion Inicia Funcion gaus 1KMI2KiCI% wnetion y>gaus(x,r) exp (-0.5(3/1)°2)5 3.3. Algoritmo de Proyeccién avo, 2002 CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN DEPTO. DE CONTROL AUTOMATICO PROGRAMADOR: JOSE MARTIN FLORES ALBINO COMPILADOR: MATLAB 5.0 ALGORITMO DE PROYECCTON INICIO PROGRAMA: proyec mM lear close all ‘TIEMPOS ; Ts=0.01; t=0:Ts:TE; rv Capitulo B__ Programas de Computo APRECUENCIAS s1e1/1; 12 XCONSTANTES 50-5 ¢#0.001; ‘PARAMETROS par=[-295.803F-3; 703.648E-3; 10607.5116- 10607. 511E~3); wesTIMADO INICTAL pe(:,1:2)©{0 030 0:0 030 0); SALIDA INICTAL, y(1:2)*£050) ; XENTRADA TNICIAL C1=2)=£050) (Tf/Ts)+4 ‘YREGRESOR reg=[y(k-1) ;y(k-2) 5u(ie-1) ju(k-1)1; ‘SALIDA DEL SISTEMA yCK)=(reg?)*par; ‘MODELO ye(k)=(reg’)*peC: k-1); ‘WERROR DE SALIDA e(d=y(k) yoo ‘YALGORITMO DE PROYECCION erreg/(reg’+regt c); YACTUALIZACION DE LA ESTIMACION pe(:,k)=pe(:,k-1)4a¥gee(k) ; ‘ENTRADA Cd) Lesin (aepavtis (kt) ts) Hesin Qepiet 20 (et) Ts) ; ena Ti2=(1/2)*1£; 12=0:Te:T42; resize (t2,2 ye(i:r)1); 5 phov(t2,fy(:r); figure Line({0 0 0 O;T¢ TE TE TH, [par’ par’); hold on Plot(t,pe) hold off figure subplot (4,1,1) plot (t,e)% subplot (41,2) plot(t pet, :)-par (19% subplot (4,1,3) plot (t, pe(2, :)-par(2))% subplot (4,14) plot (t,pe(3, :)-par(3))% {L TERMINA PROGRAMA: proyec wLKUQII B.3. Algoritmo de Proyeceién 1, Algoritmo de Proveccién Ortogonal 3.4. Algoritmo de Proyeccién Ortogonal mavo,2002 CENTRO DE JHVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN DEPTO. DE CONTROL AUTOMATICO PROGRAMADOR: JOSE MARTIN FLORES ALBINO COMPILADOR: MATLAB 5.0 ALGORITMO DE PROYECCION ORTOGONAL, INICIO PROGRAMA: porto .xiKih lear close all TIEMPOS Te=0.008; Teitt ONSTANTES 20.001; ar=[-295,803E-3; 703.6488-3; 10607.511E-3; 10607.611£-3] ; STIMADO INTCIAL 2G ,1:2)=[0 050 050 050 0); SALIDA INICIAL (4:2)=[050]; SNTRADA INICTAL (1:2)=0; seye(4); ok + (TE/Ts)44; {REGRESOR rege Ly (i=1) 5 (k-2) su (kA) 5uCk-1)) 5 y= (reg? )*par; ‘%MODELO yetk)=(reg’)*pe ‘WERROR DE SALIDA eC =y(K) -yo(k) ; YALGORITMO DE PROYECCION ORTOGONAL g=Pereg/(ctreg’*Psreg) ; Capitulo B. Programas de Cémputo = BadoGE2 O18 g Capitulo B Programas de Computo B.S, Algoritino de Minimos Cuadrados peC: K=pe(: sket)egee(k) ; -Paregerog! +P/(chreg'#Pareg) ‘VENTRADA ua(ke)*E>sin (Qepief te (k-1) 478) +14ein(2epint 2e (k-1)#Ts) end THeL; t2O:Ts:T82; r=size(e2,2); plot (t2, lyin); yen); Figure Line {0 0 0 O;TF TH TE TE], (par’s par’]); held on plot(t,pe) hold off figure subplot (4,1,1) plot(t,e) subplot (4,1,2) plot(t,pe(s,:)-par(1)) subplot (4,1,3) plot (t,pe(2,:)-par(2)) subplot (4,1,4) plot (t,pe(3, :)-par(3)) 1% FIN PROGRAMA: porto .eiCKQiQienich B.5. Algoritmo de Minimos Cuadrados Kayo ,2002 CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN DEPTO. DE CONTROL AUTOMATICO PROGRAMADOR: JOSE MARTIN FLORES ALBINO COMPILADOR: MATLAB 5.0 ALGORITHO MINIMOS CUADRADOS % a INICIO PROGRAMA: Ams. mKIIIQII clear close all urzenPos Tt=2; Ts=0.01; t: :Te:Tf; ‘WERECUENCIAS {1-15 £2610; YCONSTANTES et; 298 .B03E-3 par 5 703.648E-3; 10607.514E~3; 10607. 511E~3) ‘WESTIMADO INICTAL eC: ,1:2)=[0 0:0 0;0 0;0 01; YSALIDA INICTAL yC4:2)«10;01; FPU0V0OECEGPSOCOHUWUUeUUBsBEWUTHSC YS 187 rs B.O. Ident. Vel. Motor ce. con RN Estiitica Capitulo B_ Programas de Cémputo ENTRADA INTCIAL u(1:2)=0; Peteeye(4); for ke3:(Tf/Ts) 41; {URECRESOR ay reg [y (k-1) ;¥ Qk-2) juCe=4) 5uCe-1)] 5 1 yO0= (reg! )#par; % ‘MODELO ‘ce yetk)=(reg’)*pe(: 5k-4) 5 WERROR DE SALIDA ek) =¥ (kK) -yeCe YWALGORITMO MINTNOS CUADRADOS gaPereg/ (140g! Psreg) te pe(:,K)=pe(: ,k-t)4g4e(8) 5 es —Paregtreg’ *P/(treg’*Per0e) 5 18, wi ENTRADA (i) e14ein (2epie£ + (kot 47s) +1485 (24pia£24 (ket) #T) 5 “ee end w2=0 rons; weose:0t2 restze(e22); plove2, (94:23 yet) 5 Coad par=l figure Line([0 0 0 0;T£ Tf TE T£,Epar’; par']); hold on plot (type) hold off 3 yee figure subplot(4,1,1) plot (t,e) ont subplot (4,1,2) plot(t,pe(t, :)-par(1)) wa? subplot (4,1,3) plot(t,pe(2, :)-par(2)) CZ ‘ subplot (4,1,4) plot(t,pe(S, :)-par(3)) in FIN PROGRAMA: Ime .mhQ%1i cmd Fe ting B.6, Identificacién de la velocidad de un Motor de cc. usando una RN Estatica for e 4% son10,2002 4 CENTRO DE TWVESTIGACTON Y ESTUDTOS AVANZADOS DEL. IPH 4 DEPTO.. DE CONTROL, AUTOMATICO -f @ 188 a Capitulo B. Programas de Cémputo 4% PROGRAMADOR : JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB §.2 4% IDENTIFICACION DEL MODELO DE VELOCIDAD DE UN MOTOR DE CO 4 USANDO UNA RED NEURONAL. ESTATICA x INICIO PROGRAMA: nn not .wiIILKIRILI clear all close all ‘urTEMPOS Tt=5; Te=0.005; Ts:Tf; % # Numero de Epocas epf=360; 4% Parametros de entrenamiento eta=0.00007; alfa=0.00001; Wt de entradas ;# nodos ocultes;# salidas no=4;n1=10; n2=1; Wg escala para Tanh 8200; esos iniciales . Wi=0.001+rand(n1,1#n0); DWiszeros(nt, 1+n0); W2=0.001+rand(n2,n1+1); DW2-zeros(n2.ni+1), Waranetros del Motor (velocidad) Par=[-295.803E-3; 703.6485-3; 10607.8118-3; 10607.511E-8); YSALIDA INICTAL YC1i2)~zer0s(1,2); yeCt:2)=zeros(1,2); yang(1:2)=zeros (1,2); ‘ENTRADA INICTAL 9(1:2)=2eros(1,2); ug(1:2)=zeros(1,2); ‘HERECUENCIAS 1150.8; £2=2; £3-10; Wnicializaciones :TsiTE; t2=0:Ts: £2 for ep=t:epf, % EPOCAS for k=3:(Tt/Te)41, YSIMULACION ‘UREGRESOR B.6. Ident. Vol. Motor ce. con RN Retiitica 3.6. Ident. Vel. Motor oc. con RN Estética Capitulo BL Programas de Cémputo reg Ly (e-1) sy (k-2) su (k-1) 50-29) ‘WWelocidad Motor y(e)=(reg”)+par hacia adelante 1+ [biast;reg); +vanh (S1/g) 5 Pa: S2eW2* [bies2)01} ; ynn(k)=82; % Salida de 1a RN 4 paso hacia atras e=y(k)-ynn(k) ; % Error Ec=Ec+(e"2); % Suma de e°2 Ex (k)*(0.5/K)*Ec; gradis-e; % Gradiente de selida grad2=(1-(O4/g) .°2).«W2(1,2:ni+1) gradi; % Gradiente? % Aetualizacion de Pesos ‘emp2-W2; i2-etargradi+(bias?;01] "+alfa¥DW2; exp(-keTe/1) 5 AR ARTA 4; |\-etargrad2s [bias! ;reg] '+alfasbwt Dw1eWs-tmpt; iwexp(-k#T8/1) ; ‘UENTRADA ‘u(k)=1*cos (2epitf skaTs) +28cos (2epiet2ekeTa) ... 40.Seein(2epief3ekeTe) ; PhD end ep figure(1) subplot (2, 1,1) plot(tt, Ly; yan), subplot(2,1,2) plot (t1,£1) drannow Eee0; t 4. Generatizacion (7192/7) 41, 1REGRESOR reg [yg (k-1) syg(k-2) sug (k-1) 10g (K-2)1 5 Welocidad Kotor ye (k)= (reg! par; for reg2= [ynng (k-1) synng (k-2) sug (k-1) ;ug(-2] 4% Paso hacia adelante Si-¥ie [bias ;reg2]; Capitulo B. Programas de Cémputo Bi. Ident. No lineal con RN Ol=getanh(S1/g) 28 (bias?;01] ; yong(k)*S2; % Salida de 1a RN Ukrror emye(k)-ynng(k) ; % Exror EcrEct(e"2); % Suma de 072 E2(k)=(0.5/K) Fe ENTRADA ug(k)=0. 145in (2epss2ekeTe elseif keTs<0.75 vg (0 elseif keTe0.9) ; if “isempty(ji), Gis k#1)=0. 8esign(ICja,k+1)); end Dye s)k+1)-Jtemp; B.S. Ident. Vel. Motor ec. con RNRE B.S. Ident, Vel. Motor ec. con RNRE Capitulo B. Programas de Computo Beemp=B; BeBeotade (gradx* [biasb; u(:,k-1)]")4alfa3DB; DB=B-Btewp; end t90:Te:TE Sagure(1) plot (t, [yd(3:size(yd,2)) sy (8:sizely,2))]); tithe( Ident ficacin-Entrenaniento’) dravnow 2e0:Ts:T12;% JdeIG 13 4% Generalizacion (142/Ts)43, for ‘YENTRADA Af keTect, ug()=0, tin (4epirkeTs) ; elseif keTsc1.5. ug(1=0.08; elseif keTs<2 ug Ge elseif keTs<=(142/Ts)43, ‘ug(k)=0.1+cos(2*piek+Ta) ; end sistema a identificar yiModelo de 1a Velocidad de un Motor de CD" ie (x) =-295. 803E-Seug (e-1)+ 103.648E-2ewg(k-2)+ 10607. 5118-3» (ug (k-1)-+ug(k-2)) ; Paso hacia adelante sisBe[biasb; ug(: 1]; XG: kH)@II9xG 10481; Scistanb(x(:,k)/Sc1); ie[biasc; 2]; yea: .k)=¥g 0K) end ep fagure(2) plov(t2, (ydg(3:size(ydg,2)); yng(3:size(yng,2))]) title( Identificacin-Generalizacin’) drawnow end % PIN PROGRAMA: rnre_id3 .miL2AIQUIII e e € € « « é é é= & le : 196 Capitulo B_ Programas de Cémputo B9, Ident. No Lineal con RNRE B.9._ Identificacién de un Sistema No Lineal Usando una Red Neuronal Recurrente Entrenable nmI0,2002 CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL. IPH DEPTG. DE CONTROL aUTOMATICO , PROGRAMADOR: JOSE MARTIN FLORES ALBINO COMPILADOR: MATLAB 5.2 IDEXTIFICACION DE UN SISTEMA NO LINEAL 4% USANDO UNA RED NEURONAL. RECURRENTE) ENTRENABLE 4 INICTO PROGRAMA: rnre_sa2.91 clear all cle clear epoca ep! wRazon de aprendizaje etat=0.05; alfat=0.05; eta2*0.005; alfa2-0.005; eta3=0.08; alfa3-0.05; Yescals para tank Bet Wet inicion de bias biasc=-1; Xbiasc=0; bet; Wbiasl ‘Wimensiones de 1a RN Wt Entradas Nodos ue Salidas no=4 Wnicislizacion de pesos Be0.001*randn(n,ni+1) ; Dk eros(n,ni+1); 350.00i+randn(n,3); Di=zeros(n,1); C=0.00i+randn(no,n+1); DC-zeros(no,n41); x=0.001+randn(u,3); Uimicializacion sistena S)=zeros(1,3); ypg(1:3)=zeros (1,3); yng(1:3)=zeros(1,3); uszeros (1:2); ugszeros(1:2); for ep=i:epf B9, Ident. No Lineal con RNRE Capitulo B. Programas de Cémputo Eci=0; for k=3:999, YReferencia de entrads u(k)=0.80¢sin(2*pivk/250)4,, 0. 34cos (24pi¢k/25) ; YMODELO NO LINEAL Wum=yp (k) *yp (-1) *yp (i: Den=4+yp(k-2)"2+yp(ke-1) yp(k+4)=Nun/Den; ) eC 1) + (ype 2)-1) 400) 5 ‘Waso hacia adelante si=B+[biasb; uC: ,10J; XG KD ATC 1) 026 0481; Sctatanh(x(: k)/Scl) ; 92C+[biasc; 2]; yn: ,k)=1# (82); werror enypC: R)-yn CD; ECL*ECI+e~ SEL (k)=(0.6/k) ¥EC1 ; pase Hacia atras ‘WEntrenamiento lgradi=er1; Agradx=(((1gradt') #C(: ,2:n+1))).#(1-(@/Set) .°2); YActualizacion de pesos Cteap=¢; C=Ceotaie(1gradi+{biasc; 2]’)+alfal*pc; pe=C-Ctesp; Stemp=IC: 5k) 5 JG) ke14G: ke) eta2e (grads exC: Jiefind (abs (J(: ,k+1))>0-9); Le “ieempty(ji), J(J4,k41)=0. Beg (3.94, k41)); end DJeJ(:k41)-Jtemp; Beeep=B; BeBvetade(Igradxe[biasb; u(:,k-1)]’)+alfa3*DB; DB+B-Btemp; end figure(1) subplot(2,1,1) plot(0:998, [yp(2:size(yp,2)); yn]; ARAAAAAARA AAA 198 Capitulo B_ Programas de Computo title( Identificacsn-Fatrenamiento’) subplot (2,1,2) plot (0:998,MSE1) 020. JIG 4k); % Goneralizacion for k=3:599, ENTRADA if k<150, ug(k)=0..Sssin(2eps4k/50) ; seit k<200 ug (i) =0 elseif k<250 ug()=-0.83 elseif ke=600 ug (1) =0.44c05 (2epii ¢/200) ; end YMODELO NO LINEAL fomeype Ck) *ype (k-1) pg (k-2) sug (k-1) (ype (k-2)~1) Huge) Den=1+ypg(k-2)"2+ype(k-1) ~ ype (k+i)=tun/Den; Paso hacia adelante si=Be[biasb; ug(:,1)]; CG ke) 33 9x(: W481; jcdtamh(x(: ,k)/Se1) ; 82=C*[biase; 2]; yng(:,k)=1* (#2); ‘Brror emype(: sk) -yng(: 10); ep figure(2) subplot (2,1,1); title( Tdentificacin-Generalizacin’) subplot (21,2); plot(0:598,MSE2) drawnow end 4% PIN PROGRAMA: rnre_ia2.munqninennny, B.10. Identificacion de un Sistema No Lineal Neuronal Recurrente Entrenable % sunt, 2002 4% CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPH 4% DEPTO. DE CONTROL AUTOMATICO 4% PROGRAMADOR: JOSE MARTIN FLORES ALBINO B.10. Ident. No Lineal MIMO con RNRE plot (0:598, [ypg(2:size(ypg,2)); yng)) MIMO Usando una Red tCc3wryvywerevewvewvuewvevewvwveveevvve 199 B.10. Ident. No Lineal MIMO con RNRE Capitulo B. Programas de Cémputo % COMPILADOR: MATLAB 5.2 % 4 IDENTIFICACTON DE UN SISTEMA NO LINEAL MIMO % USANDO UNA RED NEURONAL RECURRENTE ENTRENABLE % INICIO PROGRAMA: rore_id3.n' clear all cle close ct epoca epf=20; ‘Razon de aprendizaje evai=0.01; alfat=0.01; eta2=0.001; alfa2=0.001; etas: 0.01 01; alfa3-0.01; Yescala para tanh Sci=0.5; WeFinicion de bias biasce-1; bias! ‘Wimensiones de a RN ni=2; iit Entradas n=10; — %# Nodes no=2; # Salidas Kinicializacion de pesos BO. 003#randn(n,nit) ; DB*zeros(n,nit1); J+0.001¢randn(n,3); DJ=zeros(n,1); -0.001*randn(no,nt1); Do=zeros(no,m+1); x=0.001*randa(n,3); Ynicializacion sistewa yp-zeros(2,3); yn=zeros(2,3); ypg=zeros(2,3); yngezeros(2,3) ; uezeros(2,3); ugezeros(2,3); for ep=t:ept Eci=0; for k=2:500, ‘YReferencia de entrada 84sin(2epirk/100)+0,.3¢c08 (24pi4k/10) ; 5#cos (2+pi+k/200)+0, 34sin(2+piek/20) ‘YMODELO WO LINEAL Youbsistena 1 yp(t ,k#4)=0.5* (yp (1,0 / A4yp(2,k)“2)40(1,1)) 5 00 fi i FR RRR A fl fl ¥BC2,91)=0. 88 ypC4, kD*yp(2,4)/14yp(2,k)"2)4u(2,2)); WPaso hacia adelante si-Bs(biasb; u(:,k)); XC RN)2IG 10 RC: jk) 48; jctetamh(x(: ,k)/Se1) ; Celbiasc; 2] yn: k)=14(92); Error eryp(: sk) -yn(: 8); ECI-ECi+e. (0.5/k)+EC1; Paso Hacia atras Ueptrenamiente Agradi=e*1; Daradne(( gradi ")*C(: ,2:061))) .*(4-(2/8e1) .-2); Uactualizacion de pesos Ctemp=c; tetals(gradi+[biasc; 2}')+alfatspc; -Ctemp; Seemp=J(: 4); TCAD 9IC sk) 40t02+ Ogradx.ex(:,kot))4alfa24D3; Siefind(abs(J(:,k+1))>0.9); if “isoapty(ji), 38K) =0. 853 gm(9(j5,k+1)); DI=J¢:,k#4)~Jtemp; Btemp=B; PeBeevads (grades (biasb; u(:,k-1)]/)ealfadeDB; DB-B-Beemp; end figore(1) subplot(2, 1,1) Plot (0:499, Lyp(: ,2:size(yp,2)) :yn}) title( Identificacin-Entrenaniento") subplot (2,1,2) plot (0:499,4SE1) dravnow Eo2=0; % Generalizacion ISIC: JR); for k=2:600, Capitulo BL Programas de Cémputo B.10. Ident, No Lineal MIMO con RNRE 201 B.11. Ident. Miltimodelo No Lineal MIMO con RNRE Capitulo B. Programas de Computo uReferencia de evtrade end AAATAR ug (2, elseif ke ug(2,X elseif ke elseif k< ug(2, 1 Tesin(2epirk/100) ; YSTSTEMA Se (ype (tk) / (L+ype (2) 2) 4ug (1 K)); 5» (ypg (1) 4ypg(2,K)/ L4ypg (2 i) °2) Fug 2,1) 5 ‘wWpaso hacia adelante ei=B*[biasb; ug(: 1]; xG: jkeA)=J3 x(k) 481; zeSe1*tanh(x(: 1) /Sc1) ; s2=C*[biase; 2]; yng(: ,W=t*(s2) ; wsrror erypg(: ,)-yng(: 1); AAAARAAR 2; 0.5/) +EC2; Figure(2) subplot (21,1); phot (0:499, [ypg(: ,2:size(ype,2)); yng]) title(’Identificacin-Generalizacin’) subplot (21,2); plot (0:499,NSE2) drano end {UL FIN PROGRAMA: rnre_id3.n% th B.11. Identificacién Multimodelo de un Sistema No Lineal MIMO Us- ando una Red Neuronal Recurrente Entrenable 4% Junt0,2002 202 Capitulo B. Programas de Computo ‘% CENTRO DE TNVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN 4% DEPTO. DE CONTROL AUTOMATICO ‘ PROGRAMADOR: JOSE MARTIN. FLORES ALBINO % COMPTLADOR: MATLAB 5.2 % DENTIFICACION MULTI-MODELO DE UN SISTEMA NO LINEAL MIMO % USANDO UNA RED NEURONAL RECURRENTE ENTRENABLE % 4 INEGIO PROGRAMA: rnre_ia4.1% clear all “4 le close ‘hepoca epi=40; Yhazon de aprendizaje etate0.01; alfat-0.01; etad=0.003; alfa20.001; on 01; alte: ova Yescala para tanh Sein0.55 Wetinicion de bias biare bias’! biasc2=-1; Xbiasc=0; biasb2e-1; Y{biasd=0; wDimensiones de 1a RN ni=2; it Entradas 10; it Nodos noe2; tt Salad: Ynicializacion de pesos RURES Bi-0.001+randn(n,ni*1); DB1=zeros(n,ni+1); J1=0.001+randu(n,3) ; D1=zeros(n, 1); C1#0.0014randn(no,n+1); DC1=zeros(no,n+1); x1=0,001randn(n,3); KInicializacion de pesos RNREL B2-0.001+randn(n,ni+1); DB2=2eros(n,ni+1); 3200..001+randn(n,3) ; DJ2~zeros(n, 1); €2#0.001#randn(no,nt1); DC2=2eros(no,n+1) x20,00f*randn(n,3) ; Wnicializacion sistema B.11. Ident. Milltimodelo No Lineal MIMO con RNRE 203 B.L yp= 1. Ident. Miltimodela No Lineal MIMO con RNRE Capitulo B. -zeros(2,3); ypg=zeros(2,3); seros(2,3); ug=zeroe(2 for k=2:500, Besin(2+pi+k/100)+0.3ecos(26pi+k/10) ; 5408 (2epiek/200)40.3¢sin(2epi+k/20); ind (uC: ,k)<0) ; if ~isempty(nn) up(nn, k)=zeros(size(nn,4),1); ppefind(u(: ,k)>0); if “isempty (pp) un(pp,k)=zeros(size(pp,1),1); end wMODELO KO _LINEAL Ysubsistena 1 YPC #1) =0.54 (YPC IO /C4yp(2 8°20 KD) 5 yP(2,K+1)=0. 5» (yp (1,1) #yp (2,1) / (4902, 8) 72) 40(2, 1); ind (yp: 5K)<0); YPP=YP3 Af “isempty(nn) ypp(un,k)=2eres(size(an,1),1); end pp=find(yp(:,4)20) ; yap=ypi if “isempty pp) yup(pp,k)=20r08(size(pp, 1), 1); end ‘taso hacia adelante RNREt sii-Biefoiasbt; uC: 0); XAG RDI Ha Jk) 4811; zisSclstauh (xt (:,k)/Se1); s2=Cie[biaset; 21]; ypn(: ,X)=1+(621); WPaso hacia adelante RNRE2 812B2*[biasb2; un(:,k)]; x2(: )k#1)=IZC: 5k) 4x2C: 1) 4812; z22-Scietanh(x2(: ,k)/Se1); 822=02+[biase2; 22]; yan(:,k)=14(222) ; Progra nas de Compute M Capitulo B. Programas de Cémputo BAL. Ident Mii jipsodelo No Lineal MIMO con RNRE error 1 etmyppC: ,X)-ypn(: k) ‘terror 2 e2eymp(: k)-ynm(: 51); easelte2 ECI*ECI+e1.~2; SEA (: ,k)*(0.8/k) 401; EC2=EC2+e2.-2; MSE2(: ,k)=(0-5/K) #EC2; EC3*ECS+03.°2; SE3(: ,K)= (0.6/4) B03; wWPaso Hacia atras 1 wSntrenamiento 1 Agradi=ete1; Agradx=(((Agradi’)*C1(: ,2:mt1))?) .#(4-(2t/Se1) .-2); ‘thctualizacion de pesos 1 Cteapi=ci; CieCtsetate (gradi [biasel; 21) *)+alfasDc1; ci=C1-Ctempt; ~~7T~wTrTweweweowewewe Jeempt=J1(: 5k); JAC: ROD =14 Ck) et a2" Qgradx ext (: gisfind(abs(I1(:,i41))>0.9); 3 “isemptyQa) 34.54, ke 1) 0, Bese (91 94,444); end Dyi=31(: ,k+1)-stempt; Beespi=Bi; Bi-Bitetade (igradx*[biasb1; up(:,k-1)]’)+alfa3*DB1; DBi=B1-Btemp!; Waco Hacia atras 2 ‘entrenamiento 2 Igradi=e2*1; Agragxe(((1gradi’)*C2(:,2:nt1))?) .#(4-(22/Se1) ."2) 5 HActualizacion de pesos 1 cuemp2=c2; Ca=c2+etats (gradi (biasc2; 22)’)+alfe1+Dc2; Dc29¢2-Ceemp2; Seomp2=J2¢: 5); JC; ,k#4)=32G: ke) 4eta24 grads. #x2(: ,ke1))4alfa2*d2; Jiefind (abs (32(: ,k#1))>0.9); 205 int. Miiltimodelo No Lineal MIMO con RNRE Bf “Asempty(i), 32()3 +1) =0.Besgn(52(53, W419) ; end J232(: ,k+1)—Jtemp2s Btemp2=B2; B2=H2+etade(Igradx+ [biasb2; un(:,k-1)]*)+alfaSeDB2; DB2=B2-Btomp2; end figure(1) subplot (2,1,1) plot (0:498, [yp(: ,2:size(yp,2)) :ypn]) title( Identificacin-Entrenaniento RNREI?) subplot (2,1,2) plot (0:498, [yp(: ,2:size(yp,2)) ;ymn]) eitle( Identificacin-Entrenamiento RNR2") dravnoy ECI=0;EC2ECI ;EC ‘General izacion WIHAG Os u 2): for k-2:500, UReferencia de entrada if ke=150, ug (1 Ie elseif ke=2 ug (10 elseif hem ug(1,10*-0.75 elseif k<=500 ug(1,k) 0. 749i (2epi+k/100) ; end 02; Senin (2epiek/50) 5 nnefind(ug(: ,1)<0) 5 UPEmUE; if ~isempty (nn) ‘upg(an,k)=zeros(size(nn,1),1)5 end pprfind(ug(:,k)20) ; ung=ugi if “isempty (pp) Capitulo B. Programas de Cémputo 206 AAAAAAAAANAANANNANN Capitulo B. Prowramas de Cémputo B11. Idewt, Miihtimodelo No Lineal MIMO con RNRE ue (PP) =zeros (size(pp, 1) ,1); ond SISTEMA YEE H41)"0.5s (ppg tI /C+ype(2,k)°2)40g(4 Xd); YEON =O. 86 spgC4,W)eypRC2,H)/(14ypq C2, I3"2)4062,%)) 5 an-find (pg: ,) <0) ; YPPE=Ype Af “a5ompty (any spPe(2n-k)=zeros(size(nn,1),1); end Pp=find(yPaC: ,4)>0); yapenype: $f “iseepty(pp) YAPE(DP,k)=zer08(size(pp,1),1) ona Waso hacia adelante NREL st=B1*(biasbi; upg(: 10}; AG KDI ext skal; 2sScl*tanh (x1 (:,4)/Se1); 82-C1*(biaset; 2); ypng(:.k)=16(39), ‘Paso hacia adelante ANRE? 21°82 (biasb2; ung¢: x) 22C s64)=392 9x 9C: je) 4a; jet*tanh (x2: ,k) /Se1); 52=C2*[biasct; 2); yang: ,k)=14(59) ; werror Werror etyppec: s1)~ypng (1); e2-ympg: 3) ~ynng +k); e8re1+¢2; ECi*ECI+e1.-2; MSEAC:,4)=(0.5 4) sEC1; EC2=EC2+e2.~2. NSES(: ,k)=(0.5/1) +E¢2; BC3-EC3+63.~2; NSEC: ,K)=(0.5/4) #Eca; end ep figure(2) subplot (2, 1,1); 12. Modelado de Controlador Capitulo B. Programas de Cémputo plot(0:499, {ypg(: ,2:size(ypg,2)); ypngl) title( Ident ficacin-Generalizacin RMREI?) subplot(2,1,2)5 plot (0:498, fypg(:,2:8izeCype,2)); yang) title( Téentificacin-General izacin RNRE2’) éravnow figure(3) subplot (2,1,1)5 plot (0:499, MSE1) title(*Tdentificacin-Entrenamiento MSE-RNREL?) subplot(2, 1,2); plot (0:499, MSE4) vitle( Identificacin-Generalizacin MSE-RNRE1’) dravnow fagure(4) subplot (2,1,1) plot(0:498, MSE) ‘vitle(’Identificacin-Entrenamiento NSE-RNRE2’) subplot (2,1,2); plot (0:499,MSES) title( Identificacin-General izacin NSE-RNRE2’) dramnow rr) gure(5) subplot (2,1,1); plot (0:499, [yp(: ,2:size(yp,2)); mntynn]) title( Identificacin-Entrenamiento RNREL+RNR2’ ) ‘bplot(2,1,2); plot (0:499, [ypg(: .2:size(ype,2)); ypnetynng] ) tle(*Tdentificacin-Generalizacin RNRE1+RNRE2’) gure(6) subplot (2,1,1); plot (0:499, MSE3) tle(’ Identificacin-Entrenamiento MSE-RNREL+RNRE2’) Ibplot(2,1,2); plot (0:499,MSE6) tle( Identificacin-Generalizacin MSE-RNREI+RNRE2*) FIN PROGRAMA: rnre_id4.mXKMWUUIKIC% ‘12. Modelado de Controlador SEPTIEMBRE, 2002 CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPH DEPTO. DE CONTROL AUTOMATICO PROGRAMADOR: JOSE MARTIN FLORES ALBINO COMPILADOR: MATLAB 5.2 ENTRENAMTENTO DE UNA RN FF PARA EL CONTROL DEL MODELO DE UN MOTOR DE cD INICIO PROGRAMA: modctrL .mAKQHKWNII ear all Capitulo B. Programas de Compare disp('>>>> Programa en ejecucion 111°) tfinal=10; Ts=0.005; nsamples=tfinal/T3; t0:Te:tfanal; ‘PID PARAMETROS Ki=0.05; tact WPoves inicaales Wi=0. terandn(n1,1+n0); DWi=zeros(n1,1¢n0); tmp1=Dut; W2-0. terandn(n2,ni+1); Dit eros (n2,ni+1); tmp2=D¥2; biast=1; bias2=1; przeros (no,nsamples) ; ynn-zeros(i ,nsamples) ; e=zeros(1,nsamples) eros(i ,neamples); AE-3)*randn (1,3); u=(E-3)*zandn (1,3); indi=0; for keS:nsamples+2, % PLANTA ‘theta(k+1)=(703.922E-3) +theta(k) , +(999,725E-3)rtheta(k-1) ~ (703. 6488-3) *theta(k-2). + (53. 038E-3)+(u(k-1) 4uCK-2)) ; if mod(k nsamples/g5)==0 ref (k)=not (ref (k-1))4(1E-1)#randa; else ref (k)=ref(k-1) end % ERROR DE conTROL ek) =ref (k)-theta(h) ; % CONTROLADOR PID u(k) *Kp# (e(k)~e(k-1))+KisTs#eCk) , B32 Modeladu de Coutrutador 209 B.12, Modelado de Controlador Capitulo BL Programas de C + (Ka/Ts)* (eC) -24e(K-1) +e (h-2)) u(t); % RED NEURONAL % Paso hacia adelante Be [ulle-1); w(k-2); eC) ;eCK-1) 50-27; sisWie(biast;p]; O1=tanh(S1) ;% S2+W2+[bias2;01] ; ynn(k)=S2;% Salida de Ja RN Exggeu(k)-yun(k); % Error de la Ri % JUSTE DE PESOS (BACKPROPAGATION) i paso hacia atras gradi=-F; ‘t Gradiente de salida grad2=((1-01,72)) .*(W2(: ,2:m1+4) gradi); Gradiente? 1% Actualizacion de Pesos emp2=02; WorW2-etarexp(-ined/ep)*gradt# (bias? ;01) "4... alfarexp(-itg4/ep) +DW2;% Dw2=W2~tmp2; mp Wi=Wi-etavexp(-ieg4/ep)*grad2e[biasi;p) "+. ‘alfavexp(-i+g4/ep)*D¥1;% Dyi>>> Programa verminado 1117); % FIN PROGRAMA: modcte 14 -mYIIUIIIUIIE B.13. Cinematica Inversa de dos Eslabones 4% aGosTo, 2002 % CENTRO DE INVESTIGAGION Y ESTUDIOS AVANZADOS DEL. IPN % DEPTO. DE CONTROL AUTOMATICO % PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 5.2 % 4% CINEMATICA TIVERSA DE DOS ESLABONES 4% RED NEURONAL DE MULTIPLES CAPAS x % INICIO PROGRAMA: CINVI .wif sent clear all; close all; Miunere de datos 19; 1000; iltumero de Epocas eg=10; {Repeticion de Graficas A)enep; ti=1; gt0.8; Bm OB-4 eta=0.01; alfa=0.01; Zetha;alfa W# de entradas;# nodos ocultos;# salidas no=2; 01-25; n2=25; u3e2; bias bias2=1 ; biasse1; alfa (3/2) *pi/t: (3/2)4pi; alfa2=-pi spi/t:0; alfai2=[]; for i-t:t41, ‘tup= [alfat ;a1fa2(4)*ones(size(alfat))]; . alfai2=[alfa12 tap]; ond ‘longitudes 11=0.531 B.13, Cinemética Inversa de dos Eslabones 2 B.13. Cinemética Inversa de dos Eslabones Capitulo B. +12)412¢sin(sum(alfa12)); X¥=0%;¥); x=-0.7:1.4/t:0.7; yox; xye(]; for i=t:041, ‘tmps [x;y(4) 4onen (size (x))} xys xy tmp] ; end xyp=[0.5 1.0 0.5 0.5 0.00. 5 -0.5 0.0 1.0 0.5 0.00.00 1 0 0.80.0 0.0); WI uPesos inics Wisrandn(ni,1*n0); tmpi=zeros(nt ,t4n0) ; W2=rendn(u2,n1*1); tmp2ezeroa(n2,ni41); w3erandn (x n2#1); tap9=zeros(n3,n2+1) ; figure(1) grid view({135 60]) colermap({0 0 0)) xlabel (’x!) ;ylabel (°y?) ;z2abel (\alpha_{1)?); title(‘Cinemtica Inversa: \alpha_{1)’) hold on h2=[1; figure(2) grid view([135 60]) colormap({0 0 0) xlabel (?x?) :ylabel (°y?) ;zTabel (’\alpha_{2}7); title(Cinemtica Inversa: \alpba_{2}’) hold on b3={}; disp(’Presione una tecla para continuar’); pause Erret; epsi; while (epenep & Err>Enax), Ei for 4: (0449-2, % Paso hacia adelante Si=Wis(biast;xY(:,K)]; Oi=g3./(+exp(-Si/t1)); S2-W2s(bias2;01) ; O2eg1./(1+exp(-82/t1)); yan=¥3* [bias3; 02); Eralfai2(:,k)-yan; 4% paso hacia atras gradi=~(40-39¥exp(~ep/500)) +E; ‘t Gradientet grad2=((gi/t1)» (1-02) .#02).#(W3(: ,2:n2+1) 'agradi); ‘ Gradiente2 gradd=((gt/t4)* (1-01) 401). (W2(: ,2:nt41) '¥grad2); % Gradientes 4% Actualizacion de Pesos W3-W3-etavexp(~ep/g2)*gradi+[bias3;02) ’+alfatexp(-ep/42)*D¥3; Dw2-W2-tmp2; ‘tmp: W2-W2-etarexp(-ep/g2)+grad2« [bias2;01] ’+alfasexp(—ep/g2)*DW2; Programas de Cémputo 212 AAAAANAANAANAN nAAAAA Capital B. Programas de Cémputo, ~tmpt enpiWi; Wi-Wi-ctasexp(-ep/g2)*grad3e [biasi :XY(: ,k)] +alfasexp(-ep/g2)*D¥I; end xyp=(1; ynne (1; 1, Si=Wie [biast;xyp(: i); Ot=gi./CitexpCS1/t1)); 82-026 (bias? ;01] O2egt. / Atexp(-82/t1)) 3+ [bias3 02); xp(4)*11¢cos(ynn(1))+124cos (sum(ynn)) ; ‘YpGi)=11eein(ynn(1))+124sin(sua(yan)); end xyp=[Xxp:Yp] err=(xyp-X¥p); err2-err."2; errs=0.5+sum(sum(err2)) ; Erreerrs/11; Af (rea(ep,eg) (ea, SisWie(biaedjxy(:.4)]; Ot=gi ./(1+exp-S1/t1)) 5 2-42" (bias2;01) Oaegi ./(1+exp(-S2/t4)); ynn(:,§)=W3* [bias3;02) ; end Yoni=(] ;¥on2=05 for i=1:(v+l), top teynn (i, FC -1)*Ct41) 56 (O17; Yont=[¥nni ;tmpi4) j tmp22eynn (2,14 (4-1) (tet) si4(t44)) Ynn2; mp2] ; if isempty(h2)"=1, delete(n2) ; delete (h3) ; ond figure(1) no=mesh(x,y,Yans) 5 arawnow B.13. Cinematica Inversi de dos Eslatvones 213 B14. Cinematiea Directa de dos Eslabones Capitulo B. Programas de Cmputo figure(2) b3enesh (x,y, Yun2) ; aravnow figure(3) plot (xyp(1,:) ,xyp(2,:) 20" .XYpCL,:),X¥p(2,:),7#°) axis((-1.1 1.1 “1.4 1.1]) axis(’square") ; grid dravnow © Err end randporm(size(X¥,2)); YG ind) elfai2~alfai2(: ,ind); peli end Figure (3) plot Gxyp(1,:),xyp(2,:),70? ,A¥p(1,2) XYp(2, 2,74) axis({[-1.1 1.1 1.1 4.1]) axis( square’); grid ep, Err save c:\temp\Wi.mat W1; save c:\temp\W2.mat W2; save c:\tomp\W3.mat. W3; % PIN PROGRAMA: CIHVS .mif ot, B.14. Cinematica Directa de dos Eslabones 4% acosto,2002 4% CENTRO DE TNVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN 4% DEPTO. DE CONTROL AUTOMATICO 4% PROGRAMADOR: JOSE MARTIN FLORES ALBINO 4% COMPILADOR: MATLAB 5.2 % % DINAMICA DIRECTA DE DOS ESLABONES RED NEUROWAL.DE. MULTIPLES GAPAS. % Y%INTCTO PROGRAMA: DDIRECH .wAICKIIAIUI clear 611; close all; ‘tuner de datos 115; alfal=0:2¢pi/t:2epi; alfa2e-pi:pi/t:0; alfai2-(); for is1:t+1, for jai:te1, tmp=[alfat (5) ;1f42()1; alfal end [elfai2 tmp); 214 Capitulo B._ Programas de Cémputo end ‘longitudes xeO1s¥ X(i)=L1ecos (altat2(1,1))412+cos(sum(alfa32( :,3))) 5 ¥()=14esin(alfai2(13))412¢8in(oum(alfa12(:,4))):; end X¥2 0570; xeO:¥eU; for ietste1, tmpiexY (4, 1+ (io) (ev) ha (t44))5 X[k; mpi]; tmp2>KV(2, 14 (G-4) (e441) sie (t42)) 5 ye(v; tmp]; cu ‘URepeticion de Graficas eg-10; Yorha;alte 1; alfa=0.0; g=0.5; WH de entradae;# nodos ocultos;# salidas no*2; nl*20; n2=20; n3=2; wpesos iniciales Wi=0, terandn(nJ ,1#n0); DWi=zeros (nt, 14n0) ; W2-0. terandn(n2,n141); DW2=zeros(n2,n1+1); Ws Aerandn(n3,n2+1); DW3zeros(n3,n241); bias: bias 5 bias2=1; figure(1) mesh(alfal,alfa2,X) Ygria colormap([0 0.0}) title(*Cinomtica directa:x!) Hlabel( \alphe.{i)") ylabel \alphe-(2)") zlabel ay” view TS 2s}) wxia(l0 2epi ~pl 0 =2.4 2.1), dravnoy hold on 22-(1; figure (2) mech(alfet ,alfa2,Y) " deria colormap({0 0 0}) title(*Cinemtica directa:y’) B.14, Cinemética Directa de dos Eslubones xlabel(?\alphe_{1}’) ylabel(’\alpha_{2}") zlabel(y’) view( (45 45) axis([0 2#pi -pi 0 -2.1 2.1]); dravnow hold on b3=(]; h4=0; Ei ;MSE=[]; for ep=i:nep, Bes for ket: (t41)"2, J Paso hacia adelante si-Wi+[biast jalfai2(:,k)); B.14. Cinemrica Directa de dos Eslabones Capitulo B. Programas de Cémputo ote1./(1+exp(~(1/g)481)) 42+ [bias2;01) ; /Gsexp(- (i/g)*82)) sKC4/ A+exp(-82))) 38 [bias3;02) ; 3; % Salida de 1a RN VC R)-ynn; Error WBeEcesum(E.“2); % Suma de B-2 WHSE.(K)=0-5*Ee/ke; 4 paso hacia atras Gradiente de salida (1/g)*(4-02) 02)» (W8C:,2:0241) 'egradt) ; % Gradiente? grads ((1/q)*(1-01) 01) (2: ,2:n41) egred2); Gradiented 4% Actualizacion de Pesos ‘tmp3-W3; ;3-etarexp(~k/500) +gradi* [bias3;02] ’+alfaeexp(-k/500) *DW3;Keexp(-k/100) ; (2-etasgrad2+exp(-k/500)« (bia? ;01) ’+alfasexp(-k/S00) +DW2; K+exp(-k/100) ; DW2=W2-tmp2; AAR AARAARAAH tmpiEnax), ep yp(1:2)=0,5erandn; for kel:nsamples, ‘Planta; yp ict) =(yp Ch) /Ci+yp (k)°2)) +up (i) "3; 4% Paso hacia adelante 1p) sypCR) 3]; 1+ (biget ;unnl ; cftanh (gl ,S1,%4); 12» (biac2;01] ; O2=acftanh(g1,82,t1)3; yon (k+1)=W3e [biae3;02] ygrror co=yp(k+1)-ynn (k+1) ; % paso hacia atras 4% Gradientet gradi=-e} % Gradiente2 28 AAA AAA AAARA Copitnio B. Programas de Cémputo gra2-der_acftanh(gi,02,t1) .+(W3(: ,2:n241) *gradi); 4 Gradiente3 grad3eder_acftanh(g3 ,04,t1) .*(W2(: ,2:m1+1) "egrad2); % Actualizacion de Pesos DW3*¥3-tmp3; tmp3-W3; W3=W3-etasexp(-ep/e2)*gradt* [bias3 ;02] "+ alfasexp(-ep/g2)*DW3; Dw2=W2-tep2; ap2=W2 W2=W2-etarexp (~ep/g2)*grad2*[bias2;01) '+ alfavexp(-ep/g2)*DW2 Dwi=Wi-tmp1; ‘empi=W1; Wi=ki-etarexp(-ep/g2)*grad3+(biast junn) "+. alfavexp(-ep/g2)*0¥1; end if (ren(ep.eg) ypp(d:2) yanp(1:2)=0; for j=4:neamples wranta; pp (j+1)=Cypp(4)/ Cs+ypp(3)"2)2+upP C4935 i Paso hacia adelante sunn= [upp (5) symnp (4) 5 Stewie [biast;una]; Oieacftanh(g1,S1,t1); S2=W2e(bias?;01) ; O2*acftanh(gi ,82,t1)5 yanp(j+1)=W3e (bia89;02) ; ena 0), errs-0.5esun(err2); Exreerrs/size(err2,2); figure(1) plot (O:nsamples-1,ynn(J:nsamples), "ky... O:nsamples-1,yp(1 :nsamples)) title(’Entrenamiento’) gid drawnow ‘figure(2) plot (O:nsamplee-1,ynnp(1:nsamples),"k",... O:nsamples-1,ypp(1 :nsamples)) title(’Generalizacion’) grid draynow Err end IIIA ep=eptt; end Ysave c:\ump\W Wi W2 W4 disp(’>>> Termina Programa !! B.15. Ctrl, Inverso: Ident. Mod. Directo 219 BIG. Ctrl. Inverso: Método especializado Capitulo BL Program: de Cémputo 1% FIN PROGRAMA: ‘LMHIIICIICL B.16. Control inverso: Método especializado 4% OCTUBRE, 2002 4% CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN % DEPTO. DE CONTROL AUTOMATICO % PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 5.2 % % CONTROL INVERSO (METODO ESPECIALIZADO) % SISTEMA WO LINEAL INVERTIBLE % INICIO PROGRAMA: 10% ra clear #12; close all; lead c:\tmp\pesos\Wat WideW; W2a=W2: woasws; Waranetros aaaples=1000¢3; nep-50; tit; gist; fta=0.008; alfa0.005; Yetha;alfa 4 de entradas;# nodos ocultos;# salidas no=2; 1-60; 1250; n3e4; biasi=0; bias2+0; bias i Entrada Planta #200; uref=(1; for pp=i:nsanples/(6ep), uref_tap-[2vones(iup) 0.1+0nes(1p) ~2eones(1,p) -0.1%ones(1,p) 2*ones(1,p+i)); ref “uref “tap] end 15; refezeros( ;nsaiples); for ist:nsamples ref (it1)=(1/t)#((t-1)*ref (i) +uref (i); ond § g2=(nep/20) ; fref=1+sin(2epi* (O:nsamples)/50)+.. % 0,5%cos(2+pis(O:nsamples) /(50410)) ; LIU | Pesos iniciales O1*randn(ni ,1*n0); tmpt=zeros(nt ,14n0) ; Ot+randn(n2,ni+1); tap2ezeros(n2,n141); Ot*randn(n3,n2+1) ;,tmp3-zeros(n3,n241) ; { Funciones de Activacion icf logsig= ipline(?x1 ./(1+exp(-x2/x3))? x1? ,°x2?,?x3?); ter_acflogsigs.. Anime (? (x1 /x3) (1-22) 4x2? x1", °x2 7x3"); weftanh= imbine(?x1+tamh(x2/x3)?,?x1” x2? ,?x3"); ler_acftanb> imLime(? (xi /x3)# (1-42.72)? xt? 132°, 1x3"); » Graficas igure(1) isp(’Presione una tecla para continuar’); pause; disp(’Inicia rograma’); ep=1; ne AAPA AAD AAAAAAA 20 Capitulo B._ Programas de Computo yprzeros(1,nsamples); ynn=zeros (J ,nsamples) ; ypp=zeros(1,nsamples); ynnpezeros(1,nsamples) ; while (epe=nep), ep yp(1:2)=0.54randn; for ket:nsamples, 4 Paso hacia adelante vonn= [ref (+1) syp0) 5 sieWis (biased junn] ; Otmacftanb(gi,S1,t1); S2eW2+ [bies2;01] ; O2=acftanh(g1,82,t1); p(k) =W3* [biae3;02) ; wlanta yp (K+ 1)= (yp G0) / (1+yp CK) -2))4up (40 “3; ‘unnp= Cop() ;ynnp (i); sid-wide [0;unnp] ; Oid-acttanh(1.2,S14,1.2)5 S2deW2de (1014) ; O2deacftanh(1.2,824,1.2); ynnp (+1) =W3a+ (05024) ; ‘terror eceref (k)-ynnp(k) ; % Retro propagacion del errer de contro} jer_acf tanh (1.2,02d, 1.2) .+(W3d(: 2:61) "#gradid) ; jer_acf tanh (12,014, 1.2) .*(W2d(; 2:51) "grad2a) dC: 2:3) "*grad3d5 4% paso hacia atras 4% Entrenaniento de 1a Red de Control gradi=r(2); % Gradientei 4% Gradiente2 grad2=der_acftanh (1 ,02,t1) .+(W3(: ,2:m264) ’egrada) 1 Gradiente3 gradd-der_acftanh (gi 01,1) .6 W2(!,2:8i41) "sered2) ; 41 kctualizacion de Pesos Du3=W3-tmp3; vap3=W3 wWa=¥3-etasexp(-ep/g2)*gradi+[bias3;02] "+... alfarexp(-ep/e2)*DW3; Du2r¥2-tmp2; tmp2-W2; W2=W2-etarexp(-op/e2) *grad2[bias2;01] "+ alfavexp(-op/g2)#D¥2; DuteWi-tapt; ‘tmpi=Wl; Wis¥1-etatexp(-ep/g2)*grad3+(bias! junn] "+. alfavexp(-ep/g2)*D¥1; end 22 B.17. Curl. Adaptable Indirecto Capitulo B. Programas de Cémputo plot (O:nsamples,ref,’? ,O:nsamp! axis({0 nsanples -4 4)) rid dravnoy sean ep=eptt; pause; end disp(?>>> Te % FIN PROGRAMA sp) ‘ina Programa !11°); 3 h B.17. Control Adaptable Indirecto % Abrit, 2004 % CENTRO DE TNVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN % DEPTO. DE CONTROL AUTOMATICO % PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 5.2 % % CONTROL ADAPTABLE INDIRECTO % % YL ANTCIO PROGRAMA: “UILIIIIII close all; clear all; 100; ‘ivumero de epocas psamples=100; ‘iiumero de muestras tietigi=1; Yetha alfa alfa=0,1;etas0.1 4% # de entradas, nodos ocultos y salidas n1=10;n2=10; n3e1 €2=(1/2)*nepjeg=5; YPESOS INICIALES Rea ALFA Wi0.Serandn(n1,14no); tmpi=zeros(nt,1+n0); W2=0.5erandn(n2,1+n1); tmp2=zeros(n1,, 141); W3=0,Serandn(n3,14m2);. tmpSezeros(n3,1#n2); hed BETA 2°0.S+randn(n1, 14no); tepi2-zeros(ni ,14n0) ; Jen1); tmp22=zeros(nt,14m1); W32=0.5erandn(n3,1#n2); tmp32=zeros(n3,1+n2) ; ‘UFunciones de activacion acttanh= jnLine(?xt+tanb (22/3) ", 'x1" x2", 1x3"); der_acttanh= ilime(? (x1/x3)*(1-x2.72)*,?x2", x27, 'x3°) 5 Walores Iniciales 222 AAR ARAAARAAA Capitulo B. Programas de Cémputo BAZ. Ctrh Adaptable indirecto te0:0.4545 104°0.8e8. /C440.-2); st2eC490) ; figure(i); figure(2); figure(3); cle disp(*Presione alguna techa para continuar’) pause ep=1; NSE: J; Ec2=0;MSE2*(]; while (ep: Ee ep) ep for ke-L:neamples; ENTRADA u(k)=0.5+0, 254sin (2+ (k)*pi/10)+0.5¥co8(2ekepi /2.5) 5 yeLaNTA alphaso.54y(k) /(1+y (4) -2) ; betanity(i); ylk+t)=alphatbetarutk); RED ALPHA sunny) Si-Wi+ (biesdjunn) ; Otmact tanh (gt 51,11); S2-W2+ [bias2;01); O2=acftanh(gi,82,e1); yant=W3+ [biae3;02] ; error alpha eimelpha-ynnt; Ecl*Eci+e1"2; NSE! (k)=0.5¥Eet /k; YAJUSTE RED ALPHA WGradientot gradi=~e1; Wradiente2 grad2eder_acftanh(g1 ,02,t1) .+(w3t WGradientes grad3der_acftanh(g1 ,01,r1) -©(W2(: 2:n244)*gradi) ; itt) egrad2); WASUSTE DE PESOS DE RED ALPHA DWS*WS= Emp; ‘eap3-W3; 'S-etavexp(~ep/g2)+gradie[bias3;02] +. alfarexp(~ep/g2) «DW3; Dw2=W2-tmp2; tmp2=¥2; W2°W2-etarexp(—ep/g2)*grad2+[bias2;01) "+. . alfasexp(-ep/g2) *DW2; Dui=Wi-tmpi; et asexp (-ep/g2)+grad3+(biast umn) +... alfasexp(-op/g2)*D¥; RED BETA B.I7. Curt, Adaptable Indirecto. Capitulo B. Programas de Cémputo SisW124(biast;unn) ; Dieacttanh(g!,S1,t1); 82=H22+ (bias2;01); O2eacs tanh (g1,82,t1); ynn2=W32¢ [bi as3;02] 5 [Error beta e2ebeta-ynn2; YASUSTE RED ALPHA Yoradiented gradi=-e2; YWoradiente? gred2=der_acftanb (gi ,02,11) + (W32(:,2:n241) gradi) ; ‘oradientes grod3-der_acftanb(gi,01,t1) .+(#22(: ,2:n141) '*grad2) ; ‘YAIUSTE DE PESOS DE RED ALPHA ~etasexp(—ep/g2)*gradi* [bias3;02] "+ alfavexp(—ep/g2)*DW32;, u226W22-tmp2 2-evatexp(-ep/g2)*grad2* [bias2;01] "+. alfavexp(~ep/g2)*DW22;, DwI2=W42-tmp12; topi2-412; 12-etasexp (~ep/g2)*erad3e [biast junn) +... (~ep/g2)*D¥12; ef tanh (g1,82,%3) 5 ALFA=W34 [bias3; 02! 12 (biast junn} cftanb (g1,S1,t1); 82622 ([bias2;01] ; O2-acftanh(gt,S2,t1); BETA=W32¢ [bia93;02]; yon (k+1)©ALFA +BETA*u(K) ; ond epreptts figure(1) plot (O:neamples,y,’k? ,O:nsamples,ynn,’b?); grid ALFAT( 5 224 Capitulo B. Programas de Cémputo B.17. Curl. Adaptable Indirecto for(i=0:0.1:1) want; 1 (biast jun] ; .cftamb (gt, 81,04); W2* [bias2;01] ; D2-acftanh(g1 82,1); ALFAL#W3+ [bsas3;02) ; ena figure(2) plot (tft, "k? ,,ALFA,"»*); grid BETA=(1; for(i0:0.1:1) unmet; Si=Wi2e [biast jumn) ; Olmacftanh(g1 ,81,04); 'S2-W226 [bias2;01) ; O2-acftanh(gi,52,t1); BETA1=W32+(bias3 02) ; BETA=[BETA BETAI) ; end Figure (3) plot(t,ft2, "k?,t BETA, "b’); grid figure(4) plot (O:nsamples~ grid SEA, °°) aravnow end yada) :nsamples; wReferencia re=r 00; if mod(k,20)==0, rOk+i)="r (cet) ; end 55 r(1:2)=z0res(4 “RED ALPHA 1.0K) 5 . Wi* (bias! ;unn] ; acftanh(gi,$1,t1); ‘2« [bias2; 01]; acftanh(gi,S2,11); ALFAI=W3e [biae3;02] ; URED BETA uunn=y1 (1) ; Si-Wi2«[bias1 ;unn) ; Ot=acftanh(gi,S1,t1); B.18. Ctrl. Adaptable Indirecto 2 122¢{[bias2;01]; O2eact tanh (gi ,$2,t1); BETAL=W32* (bias3;02]; YWontrol vue (k)=(-ALFA1+3 (243)) /BETA; YPLANTA Bey Ce) (Cty "25 +y 100 5 yee pha¢betaruc(k) ‘error control ec (k+1)=r(ic+1) yi Chet) 5 EcQeRe2+ec (k+1)~ MSE2(k)=0.5*Ec2/k; end figure(S) plot( eamples,r,"X? ,O:neamples,yi,’b'); grid figure(6) plot(O:nsamples,ec,"k’); grid figure(7) plot (O:saaples-t,ue,*k!); grid £3gure(9) plot (O:neamples-1,SE2,°K°); grid % FIM PROGRAMA: YXIIUI B.18. Control Adaptable Indirecto 2 % nr, 2004 4% CENTRO DE INVESTIGACION Y ESTUDTOS AVANZADOS DEL 1P1 4 DEPTO. DE CONTROL. auToMATICO 1 PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 8.2 % 4 CONTROL ADAPTABLE anprRECTO 2 Kh x ‘INICIO PROGRAMA: %22KUUILIN close all; clear all; 0; Thlumero de epocas noamples=100; {iumero de muestras ti=1;gt Yetha alfa alfa-0.1;eta=0.1; 4% # de entradas, nodos ocultos y salidas }0;n2=10; n3e1; biasi=0; bias2=1; bias3-0; g2(1/2)*nep;eg-5; Capitulo BL Programas de Computo AA AR ¢ & = ¢€ Ee e Ee e eo ec 226 Capitulo B. Programas de Cmputo ‘ypeSos INICTALES Red MFA Wi=0.01#xandn(nt ,14n0) 2-0. 01#zandn(n2,14n1) 5 3-0. 01+randn(n3,1#n2); tmp3-zeros(n3,1+n2) ; Red BETA Wi20.0tranda (nl ,1+ne); tmp12=zeros(n3 ,14n0) ; Olerandn(n2,1+n1); tmp22=zeros(n4,14n1) ; eros(n3,14n2); wa W32-0.01+randn(n3,1+n2); taps de activacion indine(?xtetamh (22/13) 'x3 7x2! 1x37); der_acttanh’ Gnd ine? (x1 /x3)# (1x22) "7d? 92? 103°) Ywalores Iniciales ya) te0:0.4:1; F120. 5eb./(4t.°2); HI=CA4e) cle disp(*Presione alguna techa para continuar’) pause ep=1; Eci=0;NSE1=[]; Ec2=0;MSE2=(] ; while (epe=nep) ©p for k=1:nsamples; WENTRADA ‘u(k)=0.5+0.25ee:n (2+ (k) 4pi/10)+0.5xcos(2+k=pi/2.5); PLANTA alphar0.S+y (ke) /(1+y(h)"2) beani+yQ0 5 y(itt2 )malpharbetaru (i) 5 URED ALPHA unn=y (le) 5 SicWi* (biasi sunnl ; Oleacttanh(g! ,S1,t1); S2eW2« [bias2;01); O2-acttanh(gi,S2,t1) 5 yani=W3e [bias3;02]; Yerror alpha et=alpha-yna!; EcleEcivet"2; NSE1 G0) *0.5*Ee1/e; YASUSTE RED ALPHA ‘Yoradienvet pradi=-e! BAS, Ctrl. Adaptable Indirceta 2 B.18. Ctrl. Adaptable Indirecto 2 Yoradiente2 grad2-der_acttanh(gi ,02,t1) .*(W3(:,2:n241) egradi) ; UGradientes grad3-der_acttanh(g1 01,1) .*(W2 ni41)/sgrad2); YAJUSTE DE PESOS DE RED ALPHA DW3=W3-tmp3; ump3=W3; ‘etasexp(~ep/g2)+gradi+ [biae3;02] '+ alfarexp(—op/g2)=DH3; DW2°W2-tmp2; ‘emp2=W2; WorW2-etarexp(~ep/g2) sgrad2«[bias2;01) 7+, alfatexp(-ep/g2)*D¥2; Dwi=Wi-tmpt; twpi=W1; ‘Wi-etavexp(-ep/g2)grad3e [biast jun] +. . alfavexp(-ep/g2) «DK; RED BETA S1=W12*[biaet junn] ; O1sacftanh(gi,$1,t1) 82-0224 [bias2;01] ; O2-acf tanh (g1,$2,t1); ynn2+W32+[biae3;02] ; error beta e2-beta-yan2; YAIUSTE RED ALPHA UGradientet gradi=-e2; ‘UGradienvez grad2-der_acftanh(gi,02,t1).*(W32(; UGradientes gradeder_acttanh(gi,01,11).» (W221 :n244)’ *gradi) ; p41) #grad2) ; YAJUSTE DE PESOS DE RED ALPHA DW32=W32-tmp32; ‘emp32=W32; W32-W32-etavexp(-ep/g2)sgradl*[biae3 ;02] "+ alfaxexp(~ep/g2) +D¥32; Dw22=W22-tmp22; tmp22=W22; W22:W22-etarexp (—ep/p2)+grad2« (bias2;01) "+ alfa*exp(-0p/g2)+D¥22; DW12-Wi2-tmp12; ‘umpl2=W12; W12-W12-etasexp(~op/g2)*grad3*[biaet junn] °4.., alfavexp(-ep/g2)+D¥12; nai weccnnen, SisWi+ [bist jump) ; apitulo B. Programas de Cémputo 228 ANMAAAAAARHANAARAR Otwacftanh(gi,S1,t1); ‘S2+W2s [bias?;01]; O2eacftanh(gi ,S2,t1); ALFA=W3* [bia63;02) ; 5120126 [bast jun} ; Oteact tanb(gi, 81,14); 826226 (bia82/01]; O2=acf tanh (gi, 82,1); BETASWS2* [bia03302] ; ymn (k+1)=ALFA 4BETAUCK) ; end epzepti; end yiel; yi(1)=0; r(4:2)= for kei :nsamples; YReferencia (0.5,0.5]; nsamples=500; alfa-0.4;etan x(kt1)= 0.540. 254sin(2epiek/50) ; Yr Qe) =r 0K) Wat moa (k, 20): dr (ksi) tend URED ALPHA 0; S1-Wi+ [biaed ;unn) ; Ot-acftanh(gi ,S1,t1) ; S2eW2s [bias?; 01]; O2-acftanh(gi,S2,%1); ALFAI=W3+ [bsas3;02] ; (kt) RED BETA vunn=y1 Ck) ; $12-W12¢ (bias junn) ; O12-acftanh (gi ,S12,t1); '822-W22s (bias2;012] ; O22eact tanh (gt 822,01); BETA1=W32+([bsa3;022] ; Wontro1 yeh) = (ALFAI +r (+41) /BETAL ; PLANTA alpha-0. Sey (1) /(A4y1 (2) °2) 5 beta=t+yi (i) ; y1(k+1)=alphatbetasuc (i) ; werror control ecktt)=r(ke+1)-y1 Ge+4) ; Ec2eEe2tec (i+) “2; ‘apitulo B. Programas de Cémputo B.I8. Ctrl. Adaptable Indirecto 2 ~-wrwrewrwrwrwrewreweowreweowewewewewewewwo ww 229 BIS. Ctrl. Adaptable Indivecto 2 MSE2(K)=0.5*Fe2/k; ‘error alpha el=aipha-ALFA1; YAJUSTE RED ALPHA YGradientet grad2=der_acf tanh (gt ,02,01) .+(W3C: ,2:n241) gradi); ‘Gradients gradS=der_acftamh (gi 04,1) .*(W2(:,2:m1+1) /sgrad2) ; YAJUSTE DE PESOS DE RED ALPHA DW3*W3-emp3; ‘ep3 i3-etatgradi* [bias3;02]"+.. alfa*DW3; Dw2-W2-tmp2; 2 (2-etasgradz* [bias2;01] +. alfa+DW2; DWieWi-tapt; ‘umplsWi; H~etaegrad3s (biasi junn] +. . alfasDWi; WBrror beta e2ebeta-BETAI; YAJUSTE RED BETA YGradienter eradl=-e2; ‘Yoradienve2 grad2-der_acftanh(gi ,022,t1) .*(W32(: ,2:n2+1) *gradi) ; Yoradientes gradd=der_acftanh(gi,012,t1) + (W22(:,2:n1+1) sgrad2); YAJUSTE DE, PESOS DE RED BETA DW32=W32-tmp32; ‘tmp32-W32; W32-W32-etargradi+ (bias: alfaxD¥32; Dw22=W22~tmp22; ‘ump22=022; W22-W22-etargrad2+[biae2;012] +. alfa*DW22; DW12=W12-tapi2; ‘tmpi2-w12; Wi12-W12-ctargrad3+ (bias! junn) "+. alfa*DWi2; end 022) °+ figure(1) 230 rwwewvewewewewrewewewewreweweweweweweweweweowewewewwew we wo Capitulo B. Programas de Cémputo B.19. Ctrl. Adaptable Directo prot(o grid sonples,r,’k?,O:nsamples,y1,°b?); fagure(2) plot (O:nsanples,ec, *k?); erid fagure(3) plot (O:nsamples-1,uc,"k?) ; grid Figure(4) plot (O:nsamples-1,MSE2,’k?); grid FIN PROGRAMA ui B.19. Control Adaptable Directo % Abra, 2004 % CENTRO DE INVESTIGACION Y ESTUDIOS AVAN: % DEPTO. DE CONTROL. AUTOMATICO % PROGRAMADOR: JOSE MARTIN FLORES ALBINO 4% COMPILADOR: MATLAB 8.2 % % CONTROL ADAPTABLE DIRECTO % % close all; clear all; nep=i00; {Numero de epocas nsamples+250; {Nunero de muestras e Yetha alfa alfa~0.005;eta-0.05; : 4 # do entradas,, nodes oculten y salidas 0; n3=1; (1/2) nop; eg-5; PESOS THICTALES ‘Red AFA Wi=0. 1erandn(at,1+m0); tmpi=zeros(n1,1+no); ¥2=0.1erandn(n?,14n1) ; tmp2-zeros(ni,1¢ni); WS=0.1*randn(n3,1+n2); tup3-20roe(n3,14n2); ‘Uunciones de activacion acftanh=... imine (?xitamh (22/3)? ?x1? ,?x2? 7x3?) ; der_acftanh=... in ime (? (14/3) #152")? 2x1? 2x2? 73"); 231 Nu B.19. Curl. Adaptable Directo Capitulo B. Programas de Computo Walores Iniciales yC)=0; 1(1)=0.8; u(1)=0; figure(1) ;figure(2) ;Figure(3) ;figure(4) ; cle disp(Presione alguna techa para continuar') pause ep=!; Eci=0;MSEI=[]; while (epe=nep) ep for ket:nsamples; UREFERENCTA 1 (c41)=0.540, 25¢85m(2ek«pi /50) ; URED ALPHA unp=[r(k+1) ; yG0)]; Si=Wis[biastjunn) ; Oi=acftanh(gi,S1,t1); ‘W2e (bias2;01) ; -acf tanh (g! ,S2,t1); uC) =W3e [osae3 02) ; PLANTA alpha=0..5+y(k)/(1+y() “2; 49) 5 Apha*beta*u(k) ; error alpha ec (eter (ett) ~y (ke) ; Eci=Ecivec(k+1)"2; MSE1 (#1) =0..8+Ec /k; YAIUSTE RED ALPHA UCradientet gradi=-ec(k+1) ; WGradiente2 gred2-der_acftanh(gi ,02,t1) .*(W3(: ,2:n244) egradi) ; ‘Yoradientes grad3=der_acftanh(gi ,01,01) .«(W2 2eni4i) agrad2); YAJUSTE DE PESOS DE RED ALPHA DW3=¥3-tap3; ‘tapaeW3; WS=W3-etaroxp (-ep/g2)*gradi+[bias3;02)'+. alfavexp(~ep/g2)*D43; 242 tap2; 2 2-etarexp(—ep/g2) grad? (bias2;01) + alfarexp(-ep/g2)*D¥2; Dui=Wi-tmp’; tmpi=vi WieW1-etavexp(-~ep/g2)*grad3«(biast junn] "+. alfasexp(-ep/g2)*DW1 ; end ep=ept. RARAAAAATAAAAAARAANADA 232 'e9euvusvuvuvauugeevegeugceeugeges Capitulo B. Programas de fagure(1) plot (O:neamples,r,’k? ,O:neamples,y,’b?); grid figure(2) plot (O:nsamples ec); grid Ligure(3) plot (O:neamples~1,u) grid figure (4) plot (O:nsamples ,NSE1) ; grid dravnow Yaisp('Presione alguna techa para continuar’) pause end % FIN PROGRAMA B.20. Ctrl. por Modelo de Referencia: Motor de CD. % OCTUBRE, 2003 ‘% CENTRO DE INVESTIGACION Y ESTUDIOS AVANZADOS DEL IPN % DEPTO. DE CORTROL aUTOMATICO 4% PROGRAMADOR: JOSE MARTIN FLORES ALBINO % COMPILADOR: MATLAB 5.2 % % EL CONTROL DEL MODELO DE UN MOTOR DE cD % POR MODELO DE REFERENCIA INICIO. PROGRAMA: -MRCD .miAHAKit clear all WModelo de Referencia Ki=20,k2=1/10, sisti=te (Cet) ,[k2 31) Wlodelo de Referencia Discreto Ts=0.008 sist2=c2d(sisti,Ts) 4% Condiciones iniciales w(1:2)=05 woC4:2)=0; e(1:2)=05 y(1:2)=05 r(4:2)0; u(4:2)=0; 8; ME=TE/Ts; fact4=1/(10607 .611410" (-3)); Mee B.20, Cirl_por Modelo de Referencia Motor de CD ‘0. Curl, por Modelo de Referencia: Motor de CD Capitulo B_ Programas de Cémpuro (i+ 1) =-295 803410" (~3) #51 () +703.648+10" (-3) +w0K-1)+ 10607 .811#10" (~3)=(e(k) +e (k-1) ) r=; yer. 0. 95124y (i) +0.97544r (8) 5 h 4% Ley de Control por Modelo de Referncia u(k)=fact 4+ (~10607 .611*10" (~3) +01) +0. 9754er (0+ 1. 2470+ we (k) -703.648* 10" (~3) #¥0(K-1)) ¢ 4% Sistoma (Motor de cb) \yc (+ 1) =-295 . 803410" (~3) 4we (k) #703. 648410" (~3) #we (k-1)+ 10607 .511#10" (-3)» (Ck) +0 (K-1)); 1 “AME; TeTset; (15 y2=0; we jet:size(T,2) if moa(j,4) 72 T3015 y2 yO): feed wo(j)1; weTw, JT, y,?sk?,T2,we2, ak!) grid on “IN PROGRAMA: MRCD n't {indice alfabético actos reflejos, 89 aprendizaje, 13, algoritmos, 15 BPTT, 19 competitive, 20 ccorreccién por error, 15 ley hebbiana, 19 Retropropagacién, 16 No supervisado, 15 reforzado, 15 supervisado, 15 aproximacién de funciones, 9, 43, lasiticacién de patrones , 9 control ‘modelo inverso, 94 Control Adaptable, 102 Directo, 112 Indirecto, 104 Control PID., 162 central, Def, 90 Epoca de entrenamiento, 16 fesquema serie-paralelo, 62 exitacién persistente, 61 Filtrado, 163 filtro Butterworth, 164 filtro pasa-altos, 164 filtro pasa-bajos, 165 filtro pasa-banda, 164 Frecuencia de Nyquis, 164 frecuencia de Nyquist, 163 funcién de activacion, 4 derivada, 4 tipos, 4 generalizacién, 15, 94 Bradiente local, 17, 158, Heliotropismo, 89 homedstasis, 89 ientificaci6n, 43, $1 métodos ‘minimos cuadrades, 56 Proyeccién, 52 proyeccién ortogonal, 55 RN dingmicas, 67 RNMC, 63 RNRE, 70 miltimodelo, 76 memoria asociativa, 9 ‘modelado de controlador, 91 Modelo de referencia, 117 modelo de sensitividad, 19, 159 Modelo Interno, 126 Modelo inverso, 94 modelo inverso método directo, 96 modelo inveso método especializado, 97 modelo NARMA, 11 momento, 27 Motor de CC... 173 modelo discreto, 175 modelo matemstico, 173 modelo matemético, 2 nneuronas, 1 dentritas, 2 sinapsis, 2 soma, 1 neurotransmisor, 2 PID, 91 Prob. de Asignacién de crédito . 15 problema de Hilbert, 45 propiedad de independencia, 23 : redes neuronales, estiticas, 6 aplicaciones, 8 redes neuronales artificiales, 3 dindmicas, 9 Boltzmann, 10 Hopfield, 10 Jordan, Elman, 12 recurtentes localmente, 11 estéticas 235

Você também pode gostar