Module Core.Piecewise_linear.Int

type ('k, 'v) t_
type key = int
type value = float
type t = (keyvaluet_
include sig ... end
val compare : t ‑> t ‑> int
val t_of_sexp : Sexplib.Sexp.t ‑> t
val sexp_of_t : t ‑> Sexplib.Sexp.t
val bin_read_t : t Bin_prot.Read.reader
val __bin_read_t__ : (int ‑> t) Bin_prot.Read.reader
val bin_reader_t : t Bin_prot.Type_class.reader
val bin_size_t : t Bin_prot.Size.sizer
val bin_write_t : t Bin_prot.Write.writer
val bin_writer_t : t Bin_prot.Type_class.writer
val bin_shape_t : Bin_prot.Shape.t
val create : (key * value) list ‑> t Core__.Import.Or_error.t

create enforces that x (key) values are non-decreasing.

It also enforces certain finiteness conditions: the x and y values must be finite (non-nan, and non-infinite), and differences of consecutive x values and consecutive y values must be finite.

val get : t ‑> key ‑> value

get t x evaluates the piecewise linear function t at x.

It is possible to get discontinuous functions by using repeated x-values in the knots. In that case, the function is evaluated in such a way that it is right-continuous. For example, if t has knots [(0.,0.5); (1.,1.5); (1.,10.); (2.,11.)], then get t 1. returns 10., get t 0.999 returns 1.499, and get t 1.001 returns 10.001.

val first_knot : t ‑> (key * value) option

O(1)

val last_knot : t ‑> (key * value) option
val to_knots : t ‑> (key * value) list

O(n)

val to_knots' : t ‑> key array * value array

O(n)

val precache : ?density:float ‑> t ‑> unit

precache t computes and stores a lookup table in t that speeds up subsequent calls to get t. Any call to get needs to find the knots that define the interval in which the key lies. This is done by bisection. Ordinarily the bisection starts on the whole domain of the piecewise linear function. Precaching builds a lookup table based on an equispaced division of the domain. This allows get to quickly determine a (potentially very) small initial interval on which to start the bisection.

This works best for knots that are reasonably evenly distributed.

density is the ratio of the size of the lookup table to the size of the knot array.

Calling precache multiple times is safe. If the existing lookup density is the same or higher density than the requested density, the lookup table will not be recomputed.

val create_from_linear_combination : (t * float) list ‑> t Core__.Import.Or_error.t

Returns the t such that get t key = sum (get t_i key) * weight_i. This will fail if given an empty list as an argument, if any weights are not finite, or if any of the input ts has a discontinuity.

The domain of each t does not have to be the same. The domain of the t that is returned will be the connected union of the domains.

There are cases in S_invertible in which all ts could be valid and invertible, but the linear combination is not invertible. I.e. if one t is downward sloping, the other t is upward sloping, and the linear combination is sometimes upward and sometimes downward sloping.