Generating Adjoint Expressions For Matlab

2y ago
26 Views
4 Downloads
815.06 KB
29 Pages
Last View : 25d ago
Last Download : 2m ago
Upload by : Aarya Seiber
Transcription

MotivationAnalysisSolutionResults and ConclusionGenerating adjoint expressions for MatlabJohannes WillkommInstitute of Scientific ComputingRWTH Aachen UniversityTenth European Workshop on Automatic DifferentiationJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionGenerating adjoint code for MatlabScalar adjoint rules are not enoughOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionGenerating adjoint code for MatlabScalar adjoint rules are not enoughExtending our tool ADiMat with reverse modeADiMat implements AD source transformation of Matlab code.Consider a function with signature function z f (a)Forward mode: adimat f .m producesfunction [g z, z] g f(g a, a)Reverse mode: admproc f.m producesfunction [a a, z] a f(a, a z)via XSL transformationsIn both cases the derivative variables can be either nativedoubles, which (in general) results in scalar mode or one canuse one of several derivative classes, which allows vectormode.Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionGenerating adjoint code for MatlabScalar adjoint rules are not enoughOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionGenerating adjoint code for MatlabScalar adjoint rules are not enoughAdjoint code rulesTransformation rules found in the literature are for scalar valuedvariablesConsider z e(x)Adjoint statement: x e x zWhat happens when e(x) a x b and the variables arematrices?What is e xin this case?Dimensions of e xand z will not fit in general.Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationAdjoint rules: SineSine: Z sin(A) ZsinAA Z . cos(A) dAUse upper case lettersto indicate rule placeholders.The place where dZ Zoccurs is the adjointposition.*cosDerivative variableshave the samedimension as thevariable they areassociated with.dZAJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationAdjoint rules: MultiplicationMultiplicationZ A B, w.r.t. AZ A B, w.r.t. B Z *AZBAA Z B TdZBB AT Z dA* *dB*TTBAJohannes WillkommdZAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationExample statementConsider the statement: z sin(a b) cSyntax tree z*sinc*abJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationCanonicalized statementCanonicalization: s a b, t sin(s), z t cSyntax trees s *atb sinsJohannes Willkommz*tcAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationAdjoint canonicalized statementsReverse adjoint statements:t z c T , s cos(s) . t, b aT sSyntax trees dt *dz ds.*Tcoscsdbdt*TdsaJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAdjoint rulesExample statementIntermediate canonicalizationPutting it back togetherSingle adjoint statement: b aT (cos(a b) . (z c T ))Merged syntax tree db*T.*acos*sdzTcJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationObservationsThe outermost -operator has the adjoint of the statementLHS at the adjoint position.The second level operator sin has at the adjoint positionthe expression sub-tree that was produced by theoutermost operator.The evalation order is inverted.Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationRecursive procedureConsider a statement z e, assigning expression e(x) toz. What is the adjoint expression w.r.t. x for that statement.Let a1 adjexp(e, a0 ) be the adjoint expression of theoutermost operation in expression e, where a0 z.Then, a2 adjexp(active-child(e), a1 ) is the adjointexpression of the second level operator, where active-childselects the child of the top along the path to variable x.Finally, ak is the adjoint of the expression e w.r.t. variablex, where k is the depth of x in e.Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationRecursive template callsTraverse the expression tree in top down order withapply-templatePass along two parameterswrt – id of variable node in the expressionadj – adjoint constructed so farxsl :apply templates to that child which has the node withid wrt among its descendant or self::.wrt – wrtadj – new expression according to rule for current node,inserting adj at the adjoint position of the ruleJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationTemplate For Sinecallidnameparam-listexprexpr x s l : t e m p l a t e match " c a l l [ i d ’ s i n ’ ] " mode " d i f f " xsl:param name " w r t " / xsl:param name " a d j " / xsl:apply templates s e l e c t " [ 2 ] / " mode " d i f f " xsl:with param name " w r t " s e l e c t " w r t " / xsl:with param name " a d j " b i n a r y op " . " call i d cos / i d xsl:apply templates s e l e c t " [ 2 ] " / expr / call xsl:copy of s e l e c t " a d j " / / binary / xsl:with param / xsl:apply templates / xsl:template Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationTemplate For Multiplicationbinary@op *exprexpr x s l : t e m p l a t e match " b i n a r y [@op ’ ’ ] " mode " d i f f " xsl:param name " w r t " / xsl:param name " a d j " / x s l : v a r i a b l e name " which "s e l e c t " [ descendant or self:: [ generate id ( . ) w r t ] ] " / xsl:apply templates s e l e c t " which " mode " d i f f " xsl:with param name " w r t " s e l e c t " w r t " / xsl:with param name " a d j " xsl:choose xsl:when t e s t " count ( which / f o l l o w i n g s i b l i n g : : ) " adjoint left multiplication xsl:copy of s e l e c t " which " / xsl:copy of s e l e c t " a d j " / xsl:copy of s e l e c t " [ 2 ] " / / adjoint left multiplication / xsl:when xsl:otherwise ! . . . / xsl:otherwise / xsl:choose / xsl:with param / xsl:apply templates / xsl:template Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationTemplate For Variable Nodesvaridname x s l : t e m p l a t e match " v a r " mode " d i f f " xsl:param name " w r t " / xsl:param name " a d j " / xsl:choose xsl:when t e s t " generate id ( ) w r t " xsl:copy of s e l e c t " a d j " / / xsl:when x s l : o t h e rw i s e l i t e r a l 0 / l i t e r a l / x s l : o t h e rw i s e / xsl:choose / xsl:template Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionRecursive constructionXSLT implementationTemplate For Statement x s l : t e m p l a t e match " b i n a r y [@op ’ ’ ] " mode " a d j o i n t " ! pop v a r i a b l e s , . . . xsl:apply templates mode " adjoint assignment "s e l e c t " [ 2 ] / descendant or self::var " xsl:with param name " t h i s " s e l e c t " . " / / xsl:apply templates ! zero a d j o i n t o f v a r i a b l e w r i t t e n , . . . / xsl:template x s l : t e m p l a t e match " v a r " mode " adjoint assignment " xsl:param name " t h i s " / xsl:param name " a d j " xsl:apply templates s e l e c t " a n c e s t o r : : b i n a r y [@op ’ ’ ] [ 1 ] / [ 1 ] "mode " adjoint var of statement " / / xsl:param x s l : v a r i a b l e name " myid " s e l e c t " generate id ( ) " / adjoint increment target xsl:apply templates s e l e c t " ( p a r e n t : : a r r a y . ) [ 1 ] " / / target incr xsl:apply templates s e l e c t " t h i s / [ 2 ] " mode " d i f f " xsl:with param name " w r t " s e l e c t " generate id ( . ) " / xsl:with param name " a d j " s e l e c t " a d j " / / xsl:apply templates / incr / adjoint increment / xsl:template Johannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAn exampleConclusionOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAn exampleConclusionExample: A Times B Times Cfunction z mult3 ( a , b , c )z a b c;endfunction [ a a , a b , a c , nr z ] a mult3 ( a , b , c , a z )z a b c;nr z z ;[ a a a b a c ] a zeros ( a , b , c ) ;a a a a a z ( b c ) . ’ ;a b a b a . ’ a z c . ’ ;a c a c b . ’ a . ’ a z ;endadmproc s adjoint reductions ’no’ nocanonicalize mult3.mJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAn exampleConclusionOutline1MotivationGenerating adjoint code for MatlabScalar adjoint rules are not enough2AnalysisAdjoint rulesExample statementIntermediate canonicalization3SolutionRecursive constructionXSLT implementation4Results and ConclusionAn exampleConclusionJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAn exampleConclusionConclusionAdjoints of arbitrarily nested expressionsAbility to turn off code canonicalizationAbility to generate code for only scalars or only matricesSimple implementation in XSLTJohannes WillkommAdjoint expressions for Matlab

MotivationAnalysisSolutionResults and ConclusionAn exampleConclusionOutlookRepresent derivative rules in one format for both forwardand reverse?Handle cases where adjoints are given by algorithm, notan expressionJohannes WillkommAdjoint expressions for Matlab

Generating adjoint expressions for Matlab . RWTH Aachen University Tenth European Workshop on Automatic Differentiation Johannes Willkomm Adjoint expressions for Matlab. Motivation Analysis Solution Results and Conclusion Outline 1 Motivation Generating adjoint code for Matlab Scalar adjoint rules are not enough

Related Documents:

Bruksanvisning för bilstereo . Bruksanvisning for bilstereo . Instrukcja obsługi samochodowego odtwarzacza stereo . Operating Instructions for Car Stereo . 610-104 . SV . Bruksanvisning i original

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .

Asam folat dapat diperoleh dari daging, sayuran berwarna hijau, dan susu. Gizi buruk (malnutrisi) merupakan penyebab utamanya. Anemia jenis ini jugaberkaitan dengan pengerutan hati (sirosis). Sirosis hati menyebabkan cadangan asam folat di dalamnya menjadi sedikit sekali. Kekurangan asam folat juga dapat menyebabkan gangguan kepribadian dan hilangnya daya ingat. Gejala-gejalanya hampir sama .