-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | piecewise linear and cubic Hermite interpolation -- -- Represent real functions by linear or cubic polynomial segments. The -- package provides both data structures for efficient lookup of -- interpolation intervals, and computation of basis functions. -- -- There are two examples that can be built with -- --
--   cabal install -fbuildExamples
--   
-- -- -- -- The package needs only Haskell 98. Most of the package dependencies -- are only needed for the examples and are only installed if you enable -- to build them. @package interpolation @version 0.1.1.2 module Numeric.Interpolation.NodeList data T x y Interval :: T x y Node :: (x, y) -> T x y -> T x y -> T x y -- | list must be sorted with respect to first element fromList :: [(x, y)] -> T x y -- |
--   \xs -> xs == Nodes.toList (Nodes.fromList (xs::[(Integer,Char)]))
--   
toList :: T x y -> [(x, y)] -- |
--   \x y -> Nodes.singleton x y == Nodes.fromList [(x,y)::(Integer,Char)]
--   
singleton :: x -> y -> T x y -- |
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2::Int,'b')])) (-1)
--   (Nothing,Just (0,'a'))
--   
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2::Int,'b')])) 0
--   (Just (0,'a'),Just (2,'b'))
--   
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2::Int,'b')])) 1
--   (Just (0,'a'),Just (2,'b'))
--   
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2::Int,'b')])) 2
--   (Just (2,'b'),Nothing)
--   
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2::Int,'b')])) 3
--   (Just (2,'b'),Nothing)
--   
--   >>> Nodes.lookup (Nodes.fromList ([(0,'a'),(2,'b'),(5::Int,'c')])) 3
--   (Just (2,'b'),Just (5,'c'))
--   
lookup :: Ord x => T x y -> x -> (Maybe (x, y), Maybe (x, y)) instance (GHC.Show.Show x, GHC.Show.Show y) => GHC.Show.Show (Numeric.Interpolation.NodeList.T x y) instance (GHC.Classes.Ord x, GHC.Classes.Ord y) => GHC.Classes.Ord (Numeric.Interpolation.NodeList.T x y) instance (GHC.Classes.Eq x, GHC.Classes.Eq y) => GHC.Classes.Eq (Numeric.Interpolation.NodeList.T x y) instance GHC.Base.Functor (Numeric.Interpolation.NodeList.T x) instance Data.Foldable.Foldable (Numeric.Interpolation.NodeList.T x) instance Data.Traversable.Traversable (Numeric.Interpolation.NodeList.T x) -- | Interpolation basis functions using all given nodes. The represented -- functions are equivalent to the ones from -- Numeric.Interpolation.Basis.Compact but less efficient for -- evaluation. module Numeric.Interpolation.Basis.Full linear :: Num b => [a] -> [T a b] hermite1 :: Num b => [a] -> [T a (b, b)] -- | Interpolation basis functions represented with a minimum of required -- nodes. module Numeric.Interpolation.Basis.Compact linear :: Num b => [a] -> [T a b] hermite1 :: Num b => [a] -> [T a (b, b)] -- | Cubic interpolation where the derivative at a node is set to the slope -- of the two adjacent nodes. cubicLinear :: Fractional a => [a] -> [T a (a, a)] -- | Cubic interpolation where the derivative at a node is set to the slope -- of the parabola through the current and the two adjacent nodes. cubicParabola :: Fractional a => [a] -> [T a (a, a)] -- | Generate lists of basis functions with respect to interpolation nodes -- and generate functions from coefficients with respect to these bases. -- -- A basis function is one where all but one features are zero. E.g. in a -- linear basis a basis function is one at one node, and zero at all the -- other interpolation nodes. -- -- You need the basis functions for setting up the matrix for a linear -- least-squares solver for curve fitting. The solver computes some -- coefficients and in a second step you convert these coefficients to -- the piecewise interpolation function. module Numeric.Interpolation.Basis linear :: Num b => [a] -> [T a b] hermite1 :: Num b => [a] -> [T a (b, b)] -- | Cubic interpolation where the derivative at a node is set to the slope -- of the two adjacent nodes. cubicLinear :: Fractional a => [a] -> [T a (a, a)] -- | Cubic interpolation where the derivative at a node is set to the slope -- of the parabola through the current and the two adjacent nodes. cubicParabola :: Fractional a => [a] -> [T a (a, a)] -- | coefficientsToLinear nodes coefficients creates an -- interpolation function for nodes, where the -- coefficients correspond to the basis functions constructed -- with Basis.linear nodes. coefficientsToLinear :: [a] -> [b] -> T a b -- | Cf. coefficientsToLinear coefficientsToHermite1 :: [a] -> [b] -> T a (b, b) -- | Cf. coefficientsToLinear coefficientsToCubicLinear :: Fractional a => [a] -> [a] -> T a (a, a) -- | Cf. coefficientsToLinear coefficientsToCubicParabola :: Fractional a => [a] -> [a] -> T a (a, a) module Numeric.Interpolation.Piece type T x y ny = (x, ny) -> (x, ny) -> x -> y -- |
--   forAllDistinctPoints $ \p1 p2 x -> Piece.linear p1 p2 x == Piece.linear p2 p1 x
--   
linear :: Fractional a => T a a a -- | Hermite interpolation with one derivative per node. That is, the -- interpolating polynomial is cubic. -- --
--   forAllDistinctPoints $ \p1 p2 x -> Piece.hermite1 p1 p2 x == Piece.hermite1 p2 p1 x
--   
-- --
--   forAllDistinctPoints $ \p1@(x1,y1) p2@(x2,y2) x -> Piece.linear p1 p2 x == let slope = (y2-y1)/(x2-x1) in Piece.hermite1 (x1, (y1,slope)) (x2, (y2,slope)) x
--   
-- --
--   forAllDistinctPoints $ \p1 p2 x -> Piece.hermite1 p1 p2 x == PiecePriv.hermite1 p1 p2 x
--   
hermite1 :: Fractional a => T a a (a, a) module Numeric.Interpolation.Sample type T x y = [x] -> x -> [(Int, y)] linear :: (Fractional a, Ord a) => T a a hermite1 :: (Fractional a, Ord a) => T a a cubicLinear :: (Fractional a, Ord a) => T a a cubicParabola :: (Fractional a, Ord a) => T a a module Numeric.Interpolation.Type data T x y ny Cons :: ([x] -> [y] -> String) -> T x y ny -> Int -> ([x] -> [T x ny]) -> ([x] -> x -> [(Int, y)]) -> ([x] -> [y] -> T x ny) -> (ny -> y) -> T x y ny [ssvFromNodes] :: T x y ny -> [x] -> [y] -> String [interpolatePiece] :: T x y ny -> T x y ny -- | maximum difference of indices of basis functions that overlap plus one [basisOverlap] :: T x y ny -> Int [basisFunctions] :: T x y ny -> [x] -> [T x ny] [sampleBasisFunctions] :: T x y ny -> [x] -> x -> [(Int, y)] [coefficientsToInterpolator] :: T x y ny -> [x] -> [y] -> T x ny [valueFromNode] :: T x y ny -> ny -> y -- |
--   checkOverlap Type.linear
--   
linear :: (Fractional a, Ord a, Show a) => T a a a -- |
--   checkOverlap Type.hermite1
--   
hermite1 :: (Fractional a, Ord a, Show a) => T a a (a, a) -- |
--   checkOverlap Type.cubicLinear
--   
cubicLinear :: (Fractional a, Ord a, Show a) => T a a (a, a) -- |
--   checkOverlap Type.cubicParabola
--   
cubicParabola :: (Fractional a, Ord a, Show a) => T a a (a, a) module Numeric.Interpolation.Piecewise -- | It is a checked error to interpolate outside of the range of nodes. -- --
--   >>> Piecewise.interpolate Type.linear (Nodes.fromList [(0,0),(3,6),(5,10::Rational)]) 2
--   4 % 1
--   
--   >>> Piecewise.interpolate Type.hermite1 (Nodes.fromList [(0,(0,0)),(3,(9,6)),(5,(25,10::Rational))]) 2
--   4 % 1
--   
--   >>> Piecewise.interpolate Type.hermite1 (Nodes.fromList [(0,(1,-2)),(3,(4,4)),(5,(16,8::Rational))]) 2
--   1 % 1
--   
interpolate :: Ord x => T x y ny -> T x ny -> x -> y -- | Outside the range of nodes the interpolation function takes the value -- of the respective border. -- --
--   forAllSortedRatios $ checkEq Type.linear
--   
-- --
--   forAllSortedRatios $ checkEq Type.hermite1
--   
-- --
--   forAllSortedRatios $ \nodeXs x -> lengthAtLeast 4 nodeXs ==> checkEq Type.cubicLinear nodeXs x
--   
-- --
--   forAllSortedRatios $ \nodeXs x -> lengthAtLeast 4 nodeXs ==> checkEq Type.cubicParabola nodeXs x
--   
-- -- Linear interpolation can be used to compute the median, a quartile or -- any other quantile of a list of arbitrary numbers. -- --
--   >>> quantile [2,5,3::Rational] 0.5
--   3 % 1
--   
--   >>> quantile [2,5,3,7::Rational] 0.5
--   4 % 1
--   
--   >>> quantile [2,5,3,7::Rational] 0.25
--   11 % 4
--   
-- --
--   \(QC.NonEmpty xs) -> quantile (xs::[Rational]) 0 == minimum xs
--   
-- --
--   \(QC.NonEmpty xs) -> quantile (xs::[Rational]) 1 == maximum xs
--   
interpolateConstantExt :: Ord x => T x y ny -> T x ny -> x -> y