Skip to content

Hessian sparsity detection #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 11, 2019
Merged

Conversation

shashi
Copy link
Contributor

@shashi shashi commented Jul 6, 2019

Hessian sparsity detection works by propagating linearity information. See linearity.jl for various definitions derived from DiffRules.jl (found by differentiating twice and checking for zero-ness on a number of primitive functions). See combine_terms for how every linearity case is handled.

Demo:

julia> hsparsity(x->x[1]+x[2], [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠀⠀⠀⠀│ > 0
   2 │⠀⠀⠀⠀⠀│ < 0
     └─────┘
     1     2
     nz = 0

julia> hsparsity(x->x[1]*x[2], [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠀⠀⠄⠀│ > 0
   2 │⠀⠐⠀⠀⠀│ < 0
     └─────┘
     1     2
     nz = 2

julia> hsparsity(x->x[1]^2*x[2], [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠠⠀⠄⠀│ > 0
   2 │⠀⠐⠀⠀⠀│ < 0
     └─────┘
     1     2
     nz = 3

julia> hsparsity(x->x[1]/x[2], [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠀⠀⠄⠀│ > 0
   2 │⠀⠐⠀⠂⠀│ < 0
     └─────┘
     1     2
     nz = 3

julia> hsparsity(x->x[1]\x[2], [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠠⠀⠄⠀│ > 0
   2 │⠀⠐⠀⠀⠀│ < 0
     └─────┘
     1     2
     nz = 3


julia> hsparsity(x->sin(x[1]+x[2]), [1,2]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠠⠀⠄⠀│ > 0
   2 │⠀⠐⠀⠂⠀│ < 0
     └─────┘
     1     2
     nz = 4

julia> hsparsity(x->sin(x[1]+x[2])*x[3], [1,2,3]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠄⠠⠠⠀│ > 0
   3 │⠀⠅⠨⠈⠀│ < 0
     └─────┘
     1     3
     nz = 8

julia> hsparsity(x->sin(x[1]+x[2])*x[3], [1,2,3]) |> spy
     Sparsity Pattern
     ┌─────┐
   1 │⠀⠄⠠⠠⠀│ > 0
   3 │⠀⠅⠨⠈⠀│ < 0
     └─────┘
     1     3
     nz = 8
julia> hsparsity(x->sum(x[1:5])/sum(x[6:10]), rand(10)) |> spy
      Sparsity Pattern
      ┌─────┐
    1 │⠀⠀⢰⣶⣶│ > 0
      │⣤⣤⣼⣿⣿│ < 0
   10 │⠿⠿⠿⠿⠿│
      └─────┘
      1    10
      nz = 75

TODO:

  • Add tests
  • Throw when a tainted leaf-node function call is of unknown linearity
  • Use take-all-branches cassette pass

@shashi shashi changed the title [wip] Hessian sparsity detection Hessian sparsity detection Jul 8, 2019

const monadic_nonlinear = [asind, log1p, acsch, erfc, digamma, acos, asec, acosh, airybiprime, acsc, cscd, log, tand, log10, csch, asinh, airyai, abs2, gamma, lgamma, erfcx, bessely0, cosh, sin, cos, atan, cospi, cbrt, acosd, bessely1, acoth, erfcinv, erf, dawson, inv, acotd, airyaiprime, erfinv, trigamma, asecd, besselj1, exp, acot, sqrt, sind, sinpi, asech, log2, tan, invdigamma, airybi, exp10, sech, erfi, coth, asin, cotd, cosd, sinh, abs, besselj0, csc, tanh, secd, atand, sec, acscd, cot, exp2, expm1, atanh]

diadic_of_linearity(::Val{(true, true, true)}) = [+, rem2pi, -, >, isless, <, isequal, max, min, convert]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment that

@ChrisRackauckas ChrisRackauckas merged commit 6341f93 into JuliaDiff:master Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants