import%20marimo%0A%0A__generated_with%20%3D%20%220.25.0%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20METADATA%20%3D%20%7B%0A%20%20%20%20%20%20%20%20%22id%22%3A%20%22derivatives%22%2C%0A%20%20%20%20%20%20%20%20%22name%22%3A%20%22Derivatives%20%26%20Gradients%22%2C%0A%20%20%20%20%20%20%20%20%22summary%22%3A%20%22Reference%20sheet%20for%20basic%2C%20second%2C%20partial%2C%20and%20composite%20derivatives%2C%20with%20one%20short%20example%20per%20rule.%22%2C%0A%20%20%20%20%20%20%20%20%22topics%22%3A%20%5B%22derivatives%22%2C%20%22gradient%22%2C%20%22chain_rule%22%2C%20%22optimization%22%5D%2C%0A%20%20%20%20%7D%0A%20%20%20%20mo.md(f%22%23%20Cheat%20Sheet%20%E2%80%94%20%7BMETADATA%5B'name'%5D%7D%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20read%20this%20sheet%0A%0A%20%20%20%20A%20derivative%20measures%20how%20one%20output%20changes%20when%20one%20input%20changes.%20For%20a%20function%0A%20%20%20%20with%20many%20inputs%2C%20each%20partial%20derivative%20changes%20one%20input%20at%20a%20time%2C%20and%20the%0A%20%20%20%20gradient%20collects%20all%20those%20partial%20derivatives%20into%20one%20vector.%0A%0A%20%20%20%20When%20functions%20are%20nested%2C%20start%20from%20the%20final%20output%20and%20apply%20the%20chain%20rule%20one%0A%20%20%20%20operation%20at%20a%20time.%20That%20is%20the%20calculation%20used%20by%20backpropagation.%0A%0A%20%20%20%20%23%23%20Notations%0A%0A%20%20%20%20%7C%20Type%20%7C%20Notation%20%7C%0A%20%20%20%20%7C---%7C---%7C%0A%20%20%20%20%7C%20derivative%20%7C%20%24f'(x)%3D%5Cdfrac%7Bdf%7D%7Bdx%7D%24%20%7C%0A%20%20%20%20%7C%20second%20derivative%20%7C%20%24f''(x)%3D%5Cdfrac%7Bd%5E2f%7D%7Bdx%5E2%7D%24%20%7C%0A%20%20%20%20%7C%20derivative%20of%20order%20%24n%24%20%7C%20%24f%5E%7B(n)%7D(x)%3D%5Cdfrac%7Bd%5Enf%7D%7Bdx%5En%7D%24%20%7C%0A%20%20%20%20%7C%20partial%20derivative%20%7C%20%24%5Cdfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%24%20%7C%0A%20%20%20%20%7C%20gradient%20%7C%20%24%5Cnabla%20f%24%20%7C%0A%20%20%20%20%7C%20Jacobian%20%7C%20%24J_f%24%20%7C%0A%20%20%20%20%7C%20Hessian%20%7C%20%24H_f%3D%5Cnabla%5E2f%24%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Common%20derivatives%20and%20basic%20operations%0A%0A%20%20%20%20%7C%20Function%20%24f(x)%24%20%7C%20Derivative%20%24f'(x)%24%20%7C%20Example%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20%24c%24%20%7C%20%240%24%20%7C%20%24(7)'%3D0%24%20%7C%0A%20%20%20%20%7C%20%24x%24%20%7C%20%241%24%20%7C%20%24(x)'%3D1%24%20%7C%0A%20%20%20%20%7C%20%24ax%2Bb%24%20%7C%20%24a%24%20%7C%20%24(3x%2B2)'%3D3%24%20%7C%0A%20%20%20%20%7C%20%24x%2B3%24%20%7C%20%241%24%20%7C%20%24(x%2B3)'%3D1%24%20%7C%0A%20%20%20%20%7C%20%24x-1%24%20%7C%20%241%24%20%7C%20%24(x-1)'%3D1%24%20%7C%0A%20%20%20%20%7C%20%24x%5Ctimes%20x%3Dx%5E2%24%20%7C%20%242x%24%20%7C%20%24(x%5Ctimes%20x)'%3D2x%24%20%7C%0A%20%20%20%20%7C%20%24x%5En%24%20%7C%20%24nx%5E%7Bn-1%7D%24%20%7C%20%24(x%5E5)'%3D5x%5E4%24%20%7C%0A%20%20%20%20%7C%20%24x%5E%7B-n%7D%24%20%7C%20%24-nx%5E%7B-n-1%7D%24%20%7C%20%24(1%2Fx%5E2)'%3D-2%2Fx%5E3%24%20%7C%0A%20%20%20%20%7C%20%24%5Csqrt%7Bx%7D%3Dx%5E%7B1%2F2%7D%24%20%7C%20%24%5Cdfrac%7B1%7D%7B2%5Csqrt%7Bx%7D%7D%24%20%7C%20%24(%5Csqrt%7Bx%7D)'%3D1%2F(2%5Csqrt%7Bx%7D)%24%20%7C%0A%20%20%20%20%7C%20%24%5Csqrt%5Bn%5D%7Bx%7D%3Dx%5E%7B1%2Fn%7D%24%20%7C%20%24%5Cdfrac1n%20x%5E%7B1%2Fn-1%7D%24%20%7C%20%24(%5Csqrt%5B3%5D%7Bx%7D)'%3D1%2F(3x%5E%7B2%2F3%7D)%24%20%7C%0A%20%20%20%20%7C%20%24e%5Ex%24%20%7C%20%24e%5Ex%24%20%7C%20%24(e%5Ex)'%3De%5Ex%24%20%7C%0A%20%20%20%20%7C%20%24a%5Ex%24%20%7C%20%24a%5Ex%5Cln%20a%24%20%7C%20%24(2%5Ex)'%3D2%5Ex%5Cln2%24%20%7C%0A%20%20%20%20%7C%20%24%5Cln%20x%24%20%7C%20%24%5Cdfrac1x%24%20%7C%20%24(%5Cln%20x)'%3D1%2Fx%24%20%7C%0A%20%20%20%20%7C%20%24%5Clog_a%20x%24%20%7C%20%24%5Cdfrac%7B1%7D%7Bx%5Cln%20a%7D%24%20%7C%20%24(%5Clog_2x)'%3D1%2F(x%5Cln2)%24%20%7C%0A%20%20%20%20%7C%20%24%7Cx%7C%24%20%7C%20%24%5Coperatorname%7Bsgn%7D(x)%24%20for%20%24x%5Cne0%24%20%7C%20%24(%7Cx%7C)'%3D-1%24%20if%20%24x%3C0%24%2C%20%241%24%20if%20%24x%3E0%24%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Trigonometric%20functions%0A%0A%20%20%20%20%7C%20Function%20%24f(x)%24%20%7C%20Derivative%20%24f'(x)%24%20%7C%20Example%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20%24%5Csin%20x%24%20%7C%20%24%5Ccos%20x%24%20%7C%20%24(%5Csin%20x)'%3D%5Ccos%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ccos%20x%24%20%7C%20%24-%5Csin%20x%24%20%7C%20%24(%5Ccos%20x)'%3D-%5Csin%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ctan%20x%24%20%7C%20%24%5Cdfrac1%7B%5Ccos%5E2x%7D%3D%5Csec%5E2x%24%20%7C%20%24(%5Ctan%20x)'%3D%5Csec%5E2x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ccot%20x%24%20%7C%20%24-%5Cdfrac1%7B%5Csin%5E2x%7D%3D-%5Ccsc%5E2x%24%20%7C%20%24(%5Ccot%20x)'%3D-%5Ccsc%5E2x%24%20%7C%0A%20%20%20%20%7C%20%24%5Carcsin%20x%24%20%7C%20%24%5Cdfrac1%7B%5Csqrt%7B1-x%5E2%7D%7D%24%20%7C%20%24(%5Carcsin%20x)'%3D1%2F%5Csqrt%7B1-x%5E2%7D%24%20%7C%0A%20%20%20%20%7C%20%24%5Carccos%20x%24%20%7C%20%24-%5Cdfrac1%7B%5Csqrt%7B1-x%5E2%7D%7D%24%20%7C%20%24(%5Carccos%20x)'%3D-1%2F%5Csqrt%7B1-x%5E2%7D%24%20%7C%0A%20%20%20%20%7C%20%24%5Carctan%20x%24%20%7C%20%24%5Cdfrac1%7B1%2Bx%5E2%7D%24%20%7C%20%24(%5Carctan%20x)'%3D1%2F(1%2Bx%5E2)%24%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Hyperbolic%20functions%20and%20activations%0A%0A%20%20%20%20%7C%20Function%20%24f(x)%24%20%7C%20Derivative%20%24f'(x)%24%20%7C%20Example%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20%24%5Csinh%20x%24%20%7C%20%24%5Ccosh%20x%24%20%7C%20%24(%5Csinh%20x)'%3D%5Ccosh%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ccosh%20x%24%20%7C%20%24%5Csinh%20x%24%20%7C%20%24(%5Ccosh%20x)'%3D%5Csinh%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ctanh%20x%24%20%7C%20%241-%5Ctanh%5E2x%24%20%7C%20%24(%5Ctanh%20x)'%3D1-%5Ctanh%5E2x%24%20%7C%0A%20%20%20%20%7C%20%24%5Csigma(x)%3D%5Cdfrac1%7B1%2Be%5E%7B-x%7D%7D%24%20%7C%20%24%5Csigma(x)(1-%5Csigma(x))%24%20%7C%20%24%5Csigma'(0)%3D1%2F4%24%20%7C%0A%20%20%20%20%7C%20%24%5Coperatorname%7BReLU%7D(x)%3D%5Cmax(0%2Cx)%24%20%7C%20%240%24%20if%20%24x%3C0%24%2C%20%241%24%20if%20%24x%3E0%24%20%7C%20not%20differentiable%20at%20%240%24%20%7C%0A%20%20%20%20%7C%20%24%5Coperatorname%7BLeakyReLU%7D(x)%24%20%7C%20%24%5Calpha%24%20if%20%24x%3C0%24%2C%20%241%24%20if%20%24x%3E0%24%20%7C%20with%20%24%5Calpha%3D0.01%24%3A%20left%20slope%20%240.01%24%20%7C%0A%20%20%20%20%7C%20%24%5Coperatorname%7BSoftplus%7D(x)%3D%5Cln(1%2Be%5Ex)%24%20%7C%20%24%5Csigma(x)%24%20%7C%20%24%5Coperatorname%7BSoftplus%7D'(0)%3D1%2F2%24%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Additional%20differentiation%20rules%0A%0A%20%20%20%20%7C%20Rule%20%7C%20Formula%20%7C%20Example%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20constant%20multiple%20%7C%20%24(af)'%3Daf'%24%20%7C%20%24(3x%5E2)'%3D6x%24%20%7C%0A%20%20%20%20%7C%20sum%20%7C%20%24(f%2Bg)'%3Df'%2Bg'%24%20%7C%20%24(x%5E2%2Be%5Ex)'%3D2x%2Be%5Ex%24%20%7C%0A%20%20%20%20%7C%20difference%20%7C%20%24(f-g)'%3Df'-g'%24%20%7C%20%24(x%5E3-%5Cln%20x)'%3D3x%5E2-1%2Fx%24%20%7C%0A%20%20%20%20%7C%20product%20%7C%20%24(fg)'%3Df'g%2Bfg'%24%20%7C%20%24(xe%5Ex)'%3De%5Ex%2Bxe%5Ex%24%20%7C%0A%20%20%20%20%7C%20quotient%20%7C%20%24%5Cleft(%5Cdfrac%20fg%5Cright)'%3D%5Cdfrac%7Bf'g-fg'%7D%7Bg%5E2%7D%24%20%7C%20%24%5Cleft(%5Cdfrac%7Bx%7D%7Bx%2B1%7D%5Cright)'%3D1%2F(x%2B1)%5E2%24%20%7C%0A%20%20%20%20%7C%20reciprocal%20%7C%20%24%5Cleft(%5Cdfrac1f%5Cright)'%3D-%5Cdfrac%7Bf'%7D%7Bf%5E2%7D%24%20%7C%20%24%5Cleft(1%2F(x%5E2%2B1)%5Cright)'%3D-2x%2F(x%5E2%2B1)%5E2%24%20%7C%0A%20%20%20%20%7C%20power%20%7C%20%24(f%5En)'%3Dnf%5E%7Bn-1%7Df'%24%20%7C%20%24((x%5E2%2B1)%5E3)'%3D6x(x%5E2%2B1)%5E2%24%20%7C%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Composite%20functions%20%E2%80%94%20chain%20rule%0A%0A%20%20%20%20The%20notation%20%24g%5Ccirc%20f%24%20means%20that%20%24f%24%20is%20applied%20first%2C%20then%20%24g%24%3A%0A%0A%20%20%20%20%24%24%5Cboxed%7B(g%5Ccirc%20f)(x)%3Dg(f(x))%7D%24%24%0A%0A%20%20%20%20Here%2C%20%24f%24%20is%20the%20**inner%20function**%20and%20%24g%24%20is%20the%20**outer%20function**.%20Differentiate%0A%20%20%20%20the%20outer%20function%20at%20%24f(x)%24%2C%20then%20multiply%20by%20the%20derivative%20of%20the%20inner%20function%3A%0A%0A%20%20%20%20%24%24%5Cboxed%7B(g%5Ccirc%20f)'(x)%3Dg'(f(x))%5C%2Cf'(x)%7D%24%24%0A%0A%20%20%20%20**Example%3A**%20let%20%24f(x)%3Dx%5E2%24%20and%20%24g(u)%3De%5Eu%24.%20Then%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(g%5Ccirc%20f)(x)%3Dg(f(x))%3De%5E%7Bx%5E2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(g%5Ccirc%20f)'(x)%3Dg'(f(x))f'(x)%3De%5E%7Bx%5E2%7D%5Ctimes%202x%3D2xe%5E%7Bx%5E2%7D.%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20order%20matters%3A%20%24g%5Ccirc%20f%24%20means%20%24g(f(x))%24%2C%20whereas%20%24f%5Ccirc%20g%24%20means%20%24f(g(x))%24.%0A%0A%20%20%20%20%7C%20Function%20%7C%20Derivative%20%7C%20Example%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20%24e%5E%7Bu(x)%7D%24%20%7C%20%24u'e%5Eu%24%20%7C%20%24(e%5E%7Bx%5E2%7D)'%3D2xe%5E%7Bx%5E2%7D%24%20%7C%0A%20%20%20%20%7C%20%24a%5E%7Bu(x)%7D%24%20%7C%20%24u'a%5Eu%5Cln%20a%24%20%7C%20%24(2%5E%7B3x%7D)'%3D3%5C%2C2%5E%7B3x%7D%5Cln2%24%20%7C%0A%20%20%20%20%7C%20%24%5Cln(u(x))%24%20%7C%20%24%5Cdfrac%7Bu'%7Du%24%20%7C%20%24(%5Cln(x%5E2%2B1))'%3D2x%2F(x%5E2%2B1)%24%20%7C%0A%20%20%20%20%7C%20%24%5Csqrt%7Bu(x)%7D%24%20%7C%20%24%5Cdfrac%7Bu'%7D%7B2%5Csqrt%20u%7D%24%20%7C%20%24(%5Csqrt%7B3x%2B1%7D)'%3D3%2F(2%5Csqrt%7B3x%2B1%7D)%24%20%7C%0A%20%20%20%20%7C%20%24%5Csin(u(x))%24%20%7C%20%24u'%5Ccos%20u%24%20%7C%20%24(%5Csin(x%5E2))'%3D2x%5Ccos(x%5E2)%24%20%7C%0A%20%20%20%20%7C%20%24%5Ccos(u(x))%24%20%7C%20%24-u'%5Csin%20u%24%20%7C%20%24(%5Ccos(3x))'%3D-3%5Csin(3x)%24%20%7C%0A%20%20%20%20%7C%20%24%5Ctan(u(x))%24%20%7C%20%24%5Cdfrac%7Bu'%7D%7B%5Ccos%5E2u%7D%24%20%7C%20%24(%5Ctan(x%5E2))'%3D2x%2F%5Ccos%5E2(x%5E2)%24%20%7C%0A%20%20%20%20%7C%20%24%5Csigma(u(x))%24%20%7C%20%24u'%5Csigma(u)(1-%5Csigma(u))%24%20%7C%20%24(%5Csigma(2x))'%3D2%5Csigma(2x)(1-%5Csigma(2x))%24%20%7C%0A%0A%20%20%20%20**Nested%20example%3A**%0A%0A%20%20%20%20%24%24f(x)%3D%5Cln(1%2Be%5E%7Bx%5E2%7D)%24%24%0A%0A%20%20%20%20%24%24f'(x)%3D%5Cfrac%7B1%7D%7B1%2Be%5E%7Bx%5E2%7D%7D%5Ctimes%20e%5E%7Bx%5E2%7D%5Ctimes2x%0A%20%20%20%20%3D%5Cfrac%7B2xe%5E%7Bx%5E2%7D%7D%7B1%2Be%5E%7Bx%5E2%7D%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Second%20derivatives%0A%0A%20%20%20%20%24%24f''(x)%3D%5Cfrac%7Bd%7D%7Bdx%7Df'(x)%24%24%0A%0A%20%20%20%20%7C%20%24f(x)%24%20%7C%20%24f'(x)%24%20%7C%20%24f''(x)%24%20%7C%0A%20%20%20%20%7C---%7C---%7C---%7C%0A%20%20%20%20%7C%20%24x%5E2%24%20%7C%20%242x%24%20%7C%20%242%24%20%7C%0A%20%20%20%20%7C%20%24x%5E3%24%20%7C%20%243x%5E2%24%20%7C%20%246x%24%20%7C%0A%20%20%20%20%7C%20%24x%5En%24%20%7C%20%24nx%5E%7Bn-1%7D%24%20%7C%20%24n(n-1)x%5E%7Bn-2%7D%24%20%7C%0A%20%20%20%20%7C%20%24e%5Ex%24%20%7C%20%24e%5Ex%24%20%7C%20%24e%5Ex%24%20%7C%0A%20%20%20%20%7C%20%24%5Cln%20x%24%20%7C%20%241%2Fx%24%20%7C%20%24-1%2Fx%5E2%24%20%7C%0A%20%20%20%20%7C%20%24%5Csin%20x%24%20%7C%20%24%5Ccos%20x%24%20%7C%20%24-%5Csin%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Ccos%20x%24%20%7C%20%24-%5Csin%20x%24%20%7C%20%24-%5Ccos%20x%24%20%7C%0A%20%20%20%20%7C%20%24%5Csigma(x)%24%20%7C%20%24%5Csigma(1-%5Csigma)%24%20%7C%20%24%5Csigma(1-%5Csigma)(1-2%5Csigma)%24%20%7C%0A%0A%20%20%20%20**Example%3A**%20%24f(x)%3Dx%5E4%2B2x%5E2%24%0A%0A%20%20%20%20%24%24f'(x)%3D4x%5E3%2B4x%20%5Cqquad%20f''(x)%3D12x%5E2%2B4%24%24%0A%0A%20%20%20%20%23%23%23%20Second%20derivative%20of%20a%20composition%0A%0A%20%20%20%20%24%24%5Cboxed%7B(f%5Ccirc%20g)''%3Df''(g)(g')%5E2%2Bf'(g)g''%7D%24%24%0A%0A%20%20%20%20**Example%3A**%20%24h(x)%3De%5E%7Bx%5E2%7D%24%0A%0A%20%20%20%20%24%24h'(x)%3D2xe%5E%7Bx%5E2%7D%24%24%0A%0A%20%20%20%20%24%24h''(x)%3D2e%5E%7Bx%5E2%7D%2B4x%5E2e%5E%7Bx%5E2%7D%3D(2%2B4x%5E2)e%5E%7Bx%5E2%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Partial%20derivatives%0A%0A%20%20%20%20For%20%24f(x%2Cy)%24%2C%20differentiate%20with%20respect%20to%20one%20variable%20while%20keeping%20the%20others%20constant.%0A%0A%20%20%20%20**Example%3A**%0A%0A%20%20%20%20%24%24f(x%2Cy)%3Dx%5E2y%2B3xy%5E2%24%24%0A%0A%20%20%20%20%24%24%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x%7D%3D2xy%2B3y%5E2%24%24%0A%0A%20%20%20%20%24%24%5Cfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20y%7D%3Dx%5E2%2B6xy%24%24%0A%0A%20%20%20%20%23%23%23%20Second%20partial%20derivatives%0A%0A%20%20%20%20%24%24f_%7Bxx%7D%3D%5Cfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20x%5E2%7D%2C%5Cquad%0A%20%20%20%20f_%7Byy%7D%3D%5Cfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20y%5E2%7D%2C%5Cquad%0A%20%20%20%20f_%7Bxy%7D%3D%5Cfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20y%5Cpartial%20x%7D%24%24%0A%0A%20%20%20%20For%20the%20same%20example%3A%0A%0A%20%20%20%20%24%24f_%7Bxx%7D%3D2y%2C%5Cqquad%20f_%7Byy%7D%3D6x%2C%5Cqquad%20f_%7Bxy%7D%3Df_%7Byx%7D%3D2x%2B6y%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Gradient%0A%0A%20%20%20%20For%20%24f%3A%5Cmathbb%20R%5En%5Crightarrow%5Cmathbb%20R%24%3A%0A%0A%20%20%20%20%24%24%5Cboxed%7B%5Cnabla%20f%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x_1%7D%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x_2%7D%5C%5C%0A%20%20%20%20%5Cvdots%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20f%7D%7B%5Cpartial%20x_n%7D%0A%20%20%20%20%5Cend%7Bpmatrix%7D%7D%24%24%0A%0A%20%20%20%20**Example%3A**%0A%0A%20%20%20%20%24%24f(x%2Cy)%3Dx%5E2%2B3xy%2By%5E2%24%24%0A%0A%20%20%20%20%24%24%5Cnabla%20f(x%2Cy)%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%202x%2B3y%5C%5C%0A%20%20%20%203x%2B2y%0A%20%20%20%20%5Cend%7Bpmatrix%7D%24%24%0A%0A%20%20%20%20At%20point%20%24(1%2C2)%24%3A%0A%0A%20%20%20%20%24%24%5Cnabla%20f(1%2C2)%3D%5Cbegin%7Bpmatrix%7D8%5C%5C7%5Cend%7Bpmatrix%7D%24%24%0A%0A%20%20%20%20%23%23%23%20Gradient%20descent%0A%0A%20%20%20%20%24%24%5Cboxed%7B%5Ctheta_%7Bt%2B1%7D%3D%5Ctheta_t-%5Ceta%5Cnabla_%5Ctheta%5Cmathcal%20L(%5Ctheta_t)%7D%24%24%0A%0A%20%20%20%20**Example%3A**%20%24%5Cmathcal%20L(w)%3Dw%5E2%24%2C%20%24w_0%3D3%24%2C%20%24%5Ceta%3D0.1%24%0A%0A%20%20%20%20%24%24%5Cnabla%5Cmathcal%20L(3)%3D6%24%24%0A%0A%20%20%20%20%24%24w_1%3D3-0.1%5Ctimes6%3D2.4%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Directional%20derivative%0A%0A%20%20%20%20For%20a%20unit%20vector%20%24u%24%3A%0A%0A%20%20%20%20%24%24D_uf(x)%3D%5Cnabla%20f(x)%5Ccdot%20u%24%24%0A%0A%20%20%20%20**Example%3A**%20%24f(x%2Cy)%3Dx%5E2%2By%5E2%24%2C%20at%20point%20%24(1%2C2)%24%2C%20in%20direction%20%24u%3D(1%2C0)%24%3A%0A%0A%20%20%20%20%24%24%5Cnabla%20f(1%2C2)%3D(2%2C4)%24%24%0A%0A%20%20%20%20%24%24D_uf(1%2C2)%3D(2%2C4)%5Ccdot(1%2C0)%3D2%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Jacobian%0A%0A%20%20%20%20For%20%24F%3A%5Cmathbb%20R%5En%5Crightarrow%5Cmathbb%20R%5Em%24%3A%0A%0A%20%20%20%20%24%24%5Cboxed%7BJ_F%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20F_1%7D%7B%5Cpartial%20x_1%7D%26%5Ccdots%26%5Cdfrac%7B%5Cpartial%20F_1%7D%7B%5Cpartial%20x_n%7D%5C%5C%0A%20%20%20%20%5Cvdots%26%5Cddots%26%5Cvdots%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20F_m%7D%7B%5Cpartial%20x_1%7D%26%5Ccdots%26%5Cdfrac%7B%5Cpartial%20F_m%7D%7B%5Cpartial%20x_n%7D%0A%20%20%20%20%5Cend%7Bpmatrix%7D%7D%24%24%0A%0A%20%20%20%20**Example%3A**%20%24F(x%2Cy)%3D(x%5E2y%2C%5C%20x%2By%5E2)%24%0A%0A%20%20%20%20%24%24J_F(x%2Cy)%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%202xy%26x%5E2%5C%5C%0A%20%20%20%201%262y%0A%20%20%20%20%5Cend%7Bpmatrix%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Hessian%0A%0A%20%20%20%20For%20%24f%3A%5Cmathbb%20R%5En%5Crightarrow%5Cmathbb%20R%24%3A%0A%0A%20%20%20%20%24%24%5Cboxed%7BH_f%3D%5Cnabla%5E2f%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20x_1%5E2%7D%26%5Ccdots%26%5Cdfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20x_1%5Cpartial%20x_n%7D%5C%5C%0A%20%20%20%20%5Cvdots%26%5Cddots%26%5Cvdots%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20x_n%5Cpartial%20x_1%7D%26%5Ccdots%26%5Cdfrac%7B%5Cpartial%5E2f%7D%7B%5Cpartial%20x_n%5E2%7D%0A%20%20%20%20%5Cend%7Bpmatrix%7D%7D%24%24%0A%0A%20%20%20%20**Example%3A**%20%24f(x%2Cy)%3Dx%5E2%2B3xy%2By%5E2%24%0A%0A%20%20%20%20%24%24H_f%3D%0A%20%20%20%20%5Cbegin%7Bpmatrix%7D%0A%20%20%20%202%263%5C%5C%0A%20%20%20%203%262%0A%20%20%20%20%5Cend%7Bpmatrix%7D%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Matrix%20derivatives%0A%0A%20%20%20%20Vectors%20are%20columns.%0A%0A%20%20%20%20%7C%20Function%20%7C%20Gradient%20%7C%0A%20%20%20%20%7C---%7C---%7C%0A%20%20%20%20%7C%20%24a%5ETx%24%20%7C%20%24%5Cnabla_x(a%5ETx)%3Da%24%20%7C%0A%20%20%20%20%7C%20%24x%5ETa%24%20%7C%20%24%5Cnabla_x(x%5ETa)%3Da%24%20%7C%0A%20%20%20%20%7C%20%24x%5ETx%24%20%7C%20%24%5Cnabla_x(x%5ETx)%3D2x%24%20%7C%0A%20%20%20%20%7C%20%24%5Cfrac12x%5ETx%24%20%7C%20%24%5Cnabla_x(%5Cfrac12x%5ETx)%3Dx%24%20%7C%0A%20%20%20%20%7C%20%24x%5ETAx%24%20%7C%20%24%5Cnabla_x(x%5ETAx)%3D(A%2BA%5ET)x%24%20%7C%0A%20%20%20%20%7C%20%24x%5ETAx%24%2C%20if%20%24A%3DA%5ET%24%20%7C%20%24%5Cnabla_x(x%5ETAx)%3D2Ax%24%20%7C%0A%20%20%20%20%7C%20%24%5Cfrac12%5C%7CAx-b%5C%7C_2%5E2%24%20%7C%20%24%5Cnabla_x%3DA%5ET(Ax-b)%24%20%7C%0A%20%20%20%20%7C%20%24%5C%7Cx%5C%7C_2%24%20%7C%20%24%5Cnabla_x%5C%7Cx%5C%7C_2%3Dx%2F%5C%7Cx%5C%7C_2%24%2C%20if%20%24x%5Cne0%24%20%7C%0A%0A%20%20%20%20**Example%3A**%20%24f(x)%3D%5Cfrac12%5C%7CAx-b%5C%7C_2%5E2%24%0A%0A%20%20%20%20%24%24%5Cnabla_xf%3DA%5ET(Ax-b)%24%24%0A%0A%20%20%20%20%23%23%20Related%20resources%0A%0A%20%20%20%20-%20%5BBackpropagation%5D(%2Fconcepts%2Fbackpropagation)%20%E2%80%94%20apply%20the%20chain%20rule%20to%20neural%20networks.%0A%20%20%20%20-%20%5BLoss%20and%20Optimization%5D(%2Fconcepts%2Floss_optimization)%20%E2%80%94%20use%20gradients%20to%20learn%20parameters.%0A%20%20%20%20-%20%5BFrom%20Bernoulli%20to%20Log%20Loss%5D(%2Fconcepts%2Flog_loss)%20%E2%80%94%20a%20complete%20example%20yielding%20%24%5Cpartial%20L%2F%5Cpartial%20z%3D%5Chat%20p-y%24.%0A%20%20%20%20-%20%5BDeep%20Learning%20Essential%20Formulas%5D(%2Fcheatsheets%2Fdeep_learning)%20%E2%80%94%20summary%20of%20layer%20gradients%20and%20optimizers.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
a9aa0d30898194f1fef61ea063410fe8