Giter Club home page Giter Club logo

lina.jl's Introduction

LinA.jl

LinA is a state-of-the-art piecewise linear approximation package which approximates (or over/under-estimates) univariate diffentiable $\mathbb{R} \rightarrow \mathbb{R}$ functions with an optimal (in term of number of segments) piecewise linear function given an error metric. Both absolute and relative errors are implemented. It is also possible to add custom error types. LinA works with expressions as well as with native Julia functions. Details of the algorithms can be found in this paper.

Installation

To install LinA, first enter Pkg mode by hitting ], and then run the following command:

pkg> add https://github.com/LICO-labs/LinA.jl

Usage of the LinA package

For the full documentation, see the documentation webpage.

Basic use

To linearize $f(x) = x^2$ from -10 to 10 with a maximum absolute error of $2$ simply do

julia> using LinA

julia> pwl = Linearize(:(x^2),-10,10,Absolute(2))
5-element Vector{LinA.LinearPiece}:
 -16.000000000000004 x -62.00000000000003 from -10.0 to -6.0
 -8.0 x -14.0 from -6.0 to -2.0
 0.0 x + 2.0 from -2.0 to 2.0
 8.0 x -14.0 from 2.0 to 5.999999999999999
 15.999999999999996 x -61.99999999999998 from 5.999999999999999 to 10.0

Note: by default LinA uses the hybrid heuristic algorithm. To use the (slightly slower) exact algorithm simply add ExactLin() as an argument.

You can now call pwl as a julia function such as

julia> pwl(2)
4.470129472588532

But also as an array to get the individual linear segments such as

julia> pwl[2]
-8.0 x -14.0 from -6.0 to -2.0

julia> pwl[2].xMax
-2.0

Plotting

Pwl functions are compatible with Plots.jl. To plot a pwl function simply do

using Plots

plot(x->pwl(x),-10,10)

alt text

Citing

If you have used our library and wish to cite our work (which we greatly encourage) use the reference of our paper. Starring the LinA.jl repository on GitHub is also appreciated.

lina.jl's People

Contributors

codsilla avatar ngueveu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

claud10cv

lina.jl's Issues

PWL on LOESS smoothers?

Hi there,

How much work would it be to enable piecewise linear approximations of functions that aren't supplied as expressions?

In particular, I have a 2-D scatter plot which I convert into a smooth continuous function using Loess.jl. Since the resulting loess object is made up of cubic splines, at any point the derivatives are easily computable.

When I tried putting this through pwl, I get an error because the differentiate function failed.
What needs to happen to get this working? Implement a differentiate function for the loess object?

Cheers,
Jock

Inifinite loop for precisions <= 1e-5

In the current version, LinA loops when trying to run the exact solver with low precisions. To reproduce, consider the following piece of code

julia> f(x) = 3.0374999999999974e-7 * x ^ 3 + -0.0016874999999999985 * x ^ 2 + 3.0937499999999982 * x ^ 1 + 3750.0
julia> LinA.Linearize(f, 0.0, 5000.0, LinA.Relative(1e+1), LinA.ExactLin(); bounding = LinA.Under())

I am proposing a workaround in a separate branch.

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.