Giter VIP home page Giter VIP logo

pchip.jl's Introduction

PCHIP

Package for fitting of data with a Piecewise Cubic Hermite Interpolating Polynomial (PCHIP).

Installation

PCHIP is an unregistered Julia package, but can be installed by the package manager with:

julia> ]
pkg> add https://github.com/pb866/PCHIP.jl.git
pkg> instantiate

PCHIP is tested against the latest stable release (1.5.2).

Usage

Import the package with

using PCHIP

PCHIP has 2 exported functions and an exported struct:

  • pchip
  • interpolate
  • Polynomial

Load your x and y data with the pchip function to the Polynomial{T<:Real} struct, which stores the breaks at which the second order derivate is allowed to be discontinuous and corresponds to the x coordinates of the original or measured data. Additional fields of Polynomial are coeffs with the matrix holding the coefficients of the polynomial, the number of intervals between breaks, the order of the polynomial, and the dimensions dim of the y data in x-direction.

The x data must be a monotonic vector (either ascending or descending); y data must be of the same length as x data in the first dimension. Duplicate x values are allowed; at sites with multiple x values, NaN is returned as corresponding y value.

Optionally, instead of the polynomial, the interpolated values can be returned if xi are given to pchip as third optional argument; xi must be a Real number, a Vector{<:Real} or an AbstractArray{<:Real}.

pchip(x::Vector{<:Real}, y::AbstractArray{T,N} where T<:Real where N, xi=nothing)

The interpolate function evaluates the Polynomial{T} struct at a given data point or data range (v of type Real, Vector{<:Real} or AbstractRange{<:Real}). The returned interpolated y value gets promoted to the same type T as the data held in Polynomial{T} no matter of the type of the input value.

interpolate(pc::Polynomial{T}, v::Real) where {T}

Output of interpolate or pchip if xi is given is of the following format:

  • if original y data is a vector and v <: Real, a Real of type v is returned
  • if y is a vector and v is a vector or range, a Vector of element type v is returned
  • if y is an N×M matrix, a vector of length M is returned for a v of type Real and a length(v)×M matrix, if v is a vector or range
  • for N-dimensional input with N ≥ 3, output is of the dimensions in x-direction of the y data for a Real v or a vector of those output arrays for vectors or ranges of v

Examples

x = cumsum(rand(10))
y = cos.(x)
p = pchip(x,y)
v = interpolate(p, [1.2, 2.1, 3.0])
x = cumsum(-rand(10))
y = cos.(x)
p = pchip(x,y, -3:0.01:-1)

pchip.jl's People

Contributors

pb866 avatar

Watchers

James Cloos avatar

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.