Coder Social home page Coder Social logo

agerlach / integrals.jl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sciml/integrals.jl

0.0 0.0 0.0 402 KB

A common interface for quadrature and numerical integration for the SciML scientific machine learning organization

Home Page: https://docs.sciml.ai/Integrals/stable/

License: MIT License

Julia 100.00%

integrals.jl's Introduction

Integrals.jl

Join the chat at https://julialang.zulipchat.com #sciml-bridged Global Docs

codecov Build Status

ColPrac: Contributor's Guide on Collaborative Practices for Community Packages SciML Code Style

Integrals.jl is an instantiation of the SciML common IntegralProblem interface for the common numerical integration packages of Julia, including both those based upon quadrature as well as Monte-Carlo approaches. By using Integrals.jl, you get a single predictable interface where many of the arguments are standardized throughout the various integrator libraries. This can be useful for benchmarking or for library implementations, since libraries which internally use a quadrature can easily accept a integration method as an argument.

Tutorials and Documentation

For information on using the package, see the stable documentation. Use the in-development documentation for the version of the documentation, which contains the unreleased features.

Examples

To perform one-dimensional quadrature, we can simply construct an IntegralProblem. The code below evaluates $\int_{-2}^5 \sin(xp)~\mathrm{d}x$ with $p = 1.7$. This argument $p$ is passed into the problem as the fourth argument of IntegralProblem.

using Integrals
f(x, p) = sin(x * p)
p = 1.7
prob = IntegralProblem(f, -2, 5, p)
sol = solve(prob, QuadGKJL())

For basic multidimensional quadrature we can construct and solve a IntegralProblem. Since we are using no arguments p in this example, we omit the fourth argument of IntegralProblem from above. The lower and upper bounds are now passed as vectors, with the ith elements of the bounds giving the interval of integration for x[i].

using Integrals
f(x, p) = sum(sin.(x))
prob = IntegralProblem(f, ones(2), 3ones(2))
sol = solve(prob, HCubatureJL(), reltol = 1e-3, abstol = 1e-3)

If we would like to parallelize the computation, we can use the batch interface to compute multiple points at once. For example, here we do allocation-free multithreading with Cubature.jl:

using Integrals, Cubature, Base.Threads
function f(dx, x, p)
    Threads.@threads for i in 1:size(x, 2)
        dx[i] = sum(sin.(@view(x[:, i])))
    end
end
prob = IntegralProblem(f, ones(2), 3ones(2), batch = 2)
sol = solve(prob, CubatureJLh(), reltol = 1e-3, abstol = 1e-3)

If we would like to compare the results against Cuba.jl's Cuhre method, then the change is a one-argument change:

using IntegralsCuba
sol = solve(prob, CubaCuhre(), reltol = 1e-3, abstol = 1e-3)

integrals.jl's People

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.