Example for <strong>Differentiation</strong> of Numerical L<strong>in</strong>ear Algebra Compute directional derivatives of the largest eigenvalue, „ J T ∇ qλ max (I, 0) 1 J 1 J2 T « −1 „ « ! I . J 2 0 0 import numpy from a l g o p y import CGraph , F unction , UTPM, dot , <strong>in</strong>v , z e r o s , e i g h def P h i f c n (C ) : ””” return max e i g e n v a l u e ””” return e i g h (C) [ 0 ] [ − 1 ] def Cfcn ( J1 , J2 ) : ””” compute c o v a r i a n c e matrix ””” Np = J1 . shape [ 1 ] ; Nr = J2 . shape [ 0 ] tmp = z e r o s ( ( Np+Nr , Np+Nr ) , d t y p e =J1 ) tmp [ : Np , : Np ] = d o t ( J1 . T , J1 ) tmp [ Np : , : Np ] = J2 tmp [ : Np , Np : ] = J2 . T return i n v ( tmp ) [ : Np , : Np ] D, P ,Nm, Np , Nr = 2 , 1 , 2 0 0 0 , 6 , 3 cg = CGraph ( ) J1 = F u n c t i o n (UTPM( numpy . random . r and (D, P ,Nm, Np ) ) ) J2 = F u n c t i o n (UTPM( numpy . random . r and (D, P , Nr , Np ) ) ) Phi = P h i f c n ( Cfcn ( J1 , J2 ) ) cg . i n d e p e n d e n t F u n c t i o n L i s t = [ J1 , J2 ] ; cg . d e p e n d e n t F u n c t i o n L i s t = [ Phi ] p r i n t ’ o b j e c t i v e f u n c t i o n Phi =\n ’ , Phi Sebastian # cg F. . Walter, p l o t Humboldt-Universität ( ’ odoe cgraph zu Berl<strong>in</strong> . svg <strong>Algorithmic</strong> () ’ ) <strong>Differentiation</strong> <strong>in</strong> <strong>Python</strong> <strong>with</strong> <strong>Application</strong> <strong>Examples</strong> Wednesday, 10.07.2010 28 / 27
Sebastian F. Walter, Humboldt-Universität zu Berl<strong>in</strong> <strong>Algorithmic</strong> () <strong>Differentiation</strong> <strong>in</strong> <strong>Python</strong> <strong>with</strong> <strong>Application</strong> <strong>Examples</strong> Wednesday, 10.07.2010 29 / 27