Coder Social home page Coder Social logo

briochemc / hyperdualmatrixtools.jl Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 0.0 162 KB

A little Julia module to allow factorization and backslash to work with hyperdual-valued arrays and sparse arrays.

License: MIT License

Julia 100.00%
julia julia-language julialang julia-package matrix-factorization backslash sparse-matrices

hyperdualmatrixtools.jl's Introduction

HyperDualMatrixTools.jl

DOI Build Status Coverage Status License: MIT

This package provides an overloaded factorize and \ that work with hyperdual-valued arrays.

It uses the hyper dual type defined by the HyperDualNumbers.jl package. The idea is that for a hyperdual-valued matrix

,

its inverse is given by

.

Therefore, only the inverse of is required to evaluate the inverse of . This package makes available a HyperDualFactors type which containts the factors of and the non-real parts of , and overloads factorize to create an instance of HyperDualFactors, which can then be called with \ to efficiently solve hyperdual-valued linear systems of the type .

This package should be useful for autodifferentiation of functions that use \. Note that this package is the equivalent of the DualMatrixTools.jl package, but for hyperdual numbers instead of dual numbers.

Usage

  • Create your hyperdual-valued matrix M:

    julia> M = A + ε₁ * B + ε₂ * C + ε₁ε₂ * D
  • Factorize M:

    julia> Mf = factorize(M)
  • Apply \ to solve systems of the type M * x = b

    julia> x = Mf \ b

Advanced usage

In the context of iterative processes with multiple factorizations and forward and back substitutions, you may want to propagate hyperdual-valued numbers while leveraging (potentially) the fact the real part of the matrices to be factorized remains the same throughout. This package provides an in-place factorize, with a flag to update (or not) the factors. Usage is straightforward. By default, factorize does not update the factors

julia> factorize(Mf, M) # only Mf.B, Mf.C, and Mf.D is updated

If you want to update the real-valued factors too, use

julia> factorize(Mf, M, update_factors=true) # The factors in Mf.Af are also updated

Citation

If you use this package, please cite it! You can export the citation by first clicking on the DOI badge at the top, which links to the Zenodo record of the package, and then clicking on the citation format you want in the "Export" box at the bottom of the page.

hyperdualmatrixtools.jl's People

Contributors

briochemc avatar juliatagbot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperdualmatrixtools.jl's Issues

Too tight tolerance in tests?

It seems the tests of this package sometimes error with:

Testing `\` without factorization: Test Failed at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:25
  Expression: M \ (M * x) ≈ x
   Evaluated: Hyper{Float64}[0.21700599673055138 - 5.2644536474387325e-11ε₁ - 1.4419931228313968e-11ε₂ + 2.13689271727612e-8ε₁ε₂, 0.20521839166655595 - 3.307815617231149e-12ε₁ - 8.800208540989263e-13ε₂ + 1.3216834134633939e-9ε₁ε₂, -1.7630692037932103 - 5.7516717399316695e-11ε₁ - 1.547372794740089e-11ε₂ + 2.313441454892825e-8ε₁ε₂, -0.4131632281642887 - 2.4388720593571027e-11ε₁ - 6.190140165781152e-12ε₂ + 9.529072706704845e-9ε₁ε₂, -0.20635972859101911 + 4.573170307493896e-11ε₁ + 1.236850727997306e-11ε₂ - 1.8443226223928467e-8ε₁ε₂, -0.17899018882277362 - 1.18907832958658e-10ε₁ - 3.248779077374308e-11ε₂ + 4.820244824184862e-8ε₁ε₂, -0.44677750445983966 + 5.946328634689264e-11ε₁ + 1.5887476733794532e-11ε₂ - 2.3834254534943157e-8ε₁ε₂, 0.04649040001171151 - 3.822133397801211e-13ε₁ + 6.434486974174879e-14ε₂ + 2.5440704857731757e-11ε₁ε₂, 1.2911834120380346 + 8.30013097781335e-11ε₁ + 2.2683990907591605e-11ε₂ - 3.3651800863129013e-8ε₁ε₂, 0.39065914181488626 + 3.530647488698436e-12ε₁ + 1.1711904397923588e-12ε₂ - 1.5878076651820345e-9ε₁ε₂] ≈ [0.21700599673048115, 0.2052183916665514, -1.7630692037932874, -0.41316322816432133, -0.20635972859095808, -0.17899018882293227, -0.44677750445976, 0.046490400011710745, 1.2911834120381458, 0.39065914181489064]
Stacktrace:
 [1] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:25
 [2] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [3] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:24
 [4] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [5] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:23
 [6] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [7] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:8
Testing `\` with factorization: Test Failed at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:38
  Expression: Mf \ (M * x) ≈ x
   Evaluated: Hyper{Float64}[0.21700599673055138 - 5.2644536474387325e-11ε₁ - 1.4419931228313968e-11ε₂ + 2.13689271727612e-8ε₁ε₂, 0.20521839166655595 - 3.307815617231149e-12ε₁ - 8.800208540989263e-13ε₂ + 1.3216834134633939e-9ε₁ε₂, -1.7630692037932103 - 5.7516717399316695e-11ε₁ - 1.547372794740089e-11ε₂ + 2.313441454892825e-8ε₁ε₂, -0.4131632281642887 - 2.4388720593571027e-11ε₁ - 6.190140165781152e-12ε₂ + 9.529072706704845e-9ε₁ε₂, -0.20635972859101911 + 4.573170307493896e-11ε₁ + 1.236850727997306e-11ε₂ - 1.8443226223928467e-8ε₁ε₂, -0.17899018882277362 - 1.18907832958658e-10ε₁ - 3.248779077374308e-11ε₂ + 4.820244824184862e-8ε₁ε₂, -0.44677750445983966 + 5.946328634689264e-11ε₁ + 1.5887476733794532e-11ε₂ - 2.3834254534943157e-8ε₁ε₂, 0.04649040001171151 - 3.822133397801211e-13ε₁ + 6.434486974174879e-14ε₂ + 2.5440704857731757e-11ε₁ε₂, 1.2911834120380346 + 8.30013097781335e-11ε₁ + 2.2683990907591605e-11ε₂ - 3.3651800863129013e-8ε₁ε₂, 0.39065914181488626 + 3.530647488698436e-12ε₁ + 1.1711904397923588e-12ε₂ - 1.5878076651820345e-9ε₁ε₂] ≈ [0.21700599673048115, 0.2052183916665514, -1.7630692037932874, -0.41316322816432133, -0.20635972859095808, -0.17899018882293227, -0.44677750445976, 0.046490400011710745, 1.2911834120381458, 0.39065914181489064]
Stacktrace:
 [1] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:38
 [2] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [3] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:35
 [4] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [5] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:23
 [6] top-level scope at /workspace/srcdir/julia/usr/share/julia/stdlib/v1.3/Test/src/Test.jl:1107
 [7] top-level scope at /home/pkgeval/.julia/packages/HyperDualMatrixTools/iXGeI/test/runtests.jl:8
Test Summary:                         | Pass  Fail  Total

from https://github.com/maleadt/BasePkgEvalReports/blob/df660562b2dd1fc99b44e1ea582934701d8d421f/8639e57_vs_46ce4d7/logs/HyperDualMatrixTools/1.3.1-pre-8639e5771d.log#L90-L111.

It would be good if that could be fixed since it is contributing some noise to the automatic tests we run on packages to check new Julia versions for regressions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.