Documentation ¶
Overview ¶
package interpolate implements interpolators in various dimensions as well as filters.
package interpolate provides routines for creating smooth analytic funcitons through sparse or noisy data.
Index ¶
- func TriDiag(as, bs, cs, rs []float64) []float64
- func TriDiagAt(as, bs, cs, rs, out []float64)
- type BiCubic
- type BiInterpolator
- func NewBiCubicInterpolator(xs, ys, vals []float64) BiInterpolator
- func NewBiLinearInterpolator(xs, ys, vals []float64) BiInterpolator
- func NewUniformBiCubicInterpolator(x0, dx float64, nx int, y0, dy float64, ny int, vals []float64) BiInterpolator
- func NewUniformBiLinearInterpolator(x0, dx float64, nx int, y0, dy float64, ny int, vals []float64) BiInterpolator
- type BiLinear
- type BoundaryCondition
- type Interpolator
- type Kernel
- type Linear
- type Spline
- type TriCubic
- type TriInterpolator
- func NewTriCubicInterpolator(xs, ys, zs, vals []float64) TriInterpolator
- func NewTriLinearInterpolator(xs, ys, zs, vals []float64) TriInterpolator
- func NewUniformTriCubicInterpolator(x0, dx float64, nx int, y0, dy float64, ny int, z0, dz float64, nz int, ...) TriInterpolator
- func NewUniformTriLinearInterpolator(x0, dx float64, nx int, y0, dy float64, ny int, z0, dz float64, nz int, ...) TriInterpolator
- type TriLinear
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BiCubic ¶
type BiCubic struct {
// contains filtered or unexported fields
}
func NewBiCubic ¶
func NewUniformBiCubic ¶
func (*BiCubic) Ref ¶
func (bi *BiCubic) Ref() BiInterpolator
type BiInterpolator ¶
type BiInterpolator interface { // Eval evaluates the interpolator at a point. Eval(x, y float64) float64 // EvalAll evaluates a sequeunce of points and returns the result. An // optional output array can be supplied to prevent unneeded heap // allocations. EvalAll(xs, ys []float64, out ...[]float64) []float64 // Ref creates a shallow copy of the interpolator with its own cache. // Each thread using the saem interpolator must make a copy with Ref // first. Ref() BiInterpolator }
BiInterpolator is a 2D interpolator. These interpolators all use caching, so they are not thread safe.
func NewBiCubicInterpolator ¶
func NewBiCubicInterpolator(xs, ys, vals []float64) BiInterpolator
func NewBiLinearInterpolator ¶
func NewBiLinearInterpolator(xs, ys, vals []float64) BiInterpolator
type BiLinear ¶
type BiLinear struct {
// contains filtered or unexported fields
}
BiLinear is a bi-linear interpolator.
func NewBiLinear ¶
NewBiLinear creates a bi-linear interpolator on top of a grid with the values given by vals. The values of the x and y grid lines are given by xs ans ys. The vals grid is indexed in the usual way: vals(ix, iy) -> vals[ix + iy*nx].
Panics if len(xs) * len(ys) != len(vals).
func NewUniformBiLinear ¶
func NewUniformBiLinear( x0, dx float64, nx int, y0, dy float64, ny int, vals []float64, ) *BiLinear
NewUniformBiLinear creates a bi-linear interpolator on top of a uniform grid with the values given by vals. The values of the x and y grid lines start at x0 and y0 and increase with steps of dx and dy, respectively. The vals grid is indexed in the usual way: vals(ix, iy) -> vals[ix + iy*nx].
Panics if len(xs) * len(ys) != len(vals).
func (*BiLinear) Eval ¶
Eval evaluates the bi-linear interpolator at the coordinate (x, y).
Panics if (x, y) is outside the range of the starting grid.
func (*BiLinear) EvalAll ¶
EvalAll evaluates the interpolator at all the given (x, y) values. If an output array is given, the output is written to that array (the array is still returned as a convenience).
If more than one output array is provided, only the first is used.
func (*BiLinear) Ref ¶
func (bi *BiLinear) Ref() BiInterpolator
type BoundaryCondition ¶
type BoundaryCondition int
BoundaryCondition is a flag representing the rule used when the smoothing window extends outside the data range.
Ideally iy would be good to apply a fit of the appropriate shape to the bounadary points, atificially extend the sequence that way, then remove those points after the smoothing. If you don't want to do that, Extension is a pretty good default.
const ( Periodic BoundaryCondition = iota Reflection ZeroPad Extension )
type Interpolator ¶
type Interpolator interface { // Eval evaluates the interpolator at x. Eval(x float64) float64 // EvalAll evaluates a sequeunce of values and returns the result. An // optional output array can be supplied to prevent unneeded heap // allocations. EvalAll(xs []float64, out ...[]float64) []float64 // Ref creates a shallow copy of the interpolator with its own cache. // Each thread using the same interpolator must make a copy with Ref // first. Ref() Interpolator }
Interpolator is a 1D interpolator. These interpolators all use caching, so they are not thread safe.
func NewLinearInterpolator ¶
func NewLinearInterpolator(xs, vals []float64) Interpolator
func NewSplineInterpolator ¶
func NewSplineInterpolator(xs, vals []float64) Interpolator
func NewUniformLinearInterpolator ¶
func NewUniformLinearInterpolator( x0, dx float64, vals []float64, ) Interpolator
type Kernel ¶
type Kernel struct {
// contains filtered or unexported fields
}
Kernel is a 1D smoothing kernel corresponding to some smoothing strategy and some window width.
func NewGaussianKernel ¶
NewGaussianKernel creates a Gaussian kernel, exp(-(x - x0)^2 / (2 sigma)) with the given window width, width, and point separation, dx.
func NewSavGolDerivKernel ¶
NewSavGOlDerivKernel creates a kernel which evaluates to the analytic (as opposed to numeric) derivative of the function created via Savitzky-Golay smoothing. The separation between points is given by d and the window width is given by width. The derivative and polynomial orders are given by dOrder and pOrder, respectively.
For good results, try to ensure that dOrder + 3 <= pOrder
You should never use these smoothing filters for non-uniformly spaced points, but you should *definitely* never use this particular kernel on non-uniformly spaced points.
func NewSavGolKernel ¶
NewSavGolKernel creates a smoothing kernel using the Savitzky-Golay scheme. WIndow width is given by width and polynomial order is given by order.
func NewTophatKernel ¶
NewTophatKernel creates a constant smoothing kernel of the given width.
func (*Kernel) Convolve ¶
func (k *Kernel) Convolve(xs []float64, b BoundaryCondition) []float64
Convolve convolves a 1d data set according to the filter f. Boundary conditions are specified with b.
Make sure that xs corresponds to some uniformly-spaced sequence.
func (*Kernel) ConvolveAt ¶
func (k *Kernel) ConvolveAt(xs []float64, b BoundaryCondition, out []float64)
ConvolveAt convolves a 1d data set according to the filter f. Boundary conditions are specified with b and the output is written to out.
type Linear ¶
type Linear struct {
// contains filtered or unexported fields
}
Linear is a linear interpolator.
func NewLinear ¶
NewLinear creates a linear interpolator for a sequence of strictly increasing or strictly decreasing point, xs, which take on the values given by vals.
Lookups will occur in O(log |xs|), possibly faster depending on the access pattern and data layout.
func NewUniformLinear ¶
NewUniformLinear creates a linear interplator where a uniformly spaced sequence of x values starting at x0 and separated by dx and whose values are given by vals.
Lookups will be O(1).
func (*Linear) Eval ¶
Eval returns the interpolated value at x.
Eval panics if called on a values outside the supplied range on inputs.
func (*Linear) EvalAll ¶
EvalAll evaluates the interpolator at all the given x values. If an output array is given, the output is written to that array (the array is still returned as a convenience).
If more than one output array is provided, only the first is used.
func (*Linear) Ref ¶
func (lin *Linear) Ref() Interpolator
type Spline ¶
type Spline struct {
// contains filtered or unexported fields
}
Spline represents a 1D cubic spline which can be used to interpolate between points.
func NewSpline ¶
NewSpline creates a spline based off a table of x and y values. The values must be sorted in increasing or decreasing order in x.
func (*Spline) Deriv ¶
Deriv computes the derivative of spline at the given point to the specified order.
x must be within the range of x values given to NewSpline().
func (*Spline) Eval ¶
Eval computes the value of the spline at the given point.
x must be within the range of x values given to NewSpline().
func (*Spline) Init ¶
Init reinitializes a spline to use a new sequence of points without doing any additional heap allocations. |xs| and |ys| must be the same as the previous point set.
func (*Spline) Ref ¶
func (sp *Spline) Ref() Interpolator
type TriCubic ¶
type TriCubic struct {
// contains filtered or unexported fields
}
func NewTriCubic ¶
func NewUniformTriCubic ¶
func (*TriCubic) Ref ¶
func (tri *TriCubic) Ref() TriInterpolator
type TriInterpolator ¶
type TriInterpolator interface { // Eval evaluates the interpolator at a point. Eval(x, y, z float64) float64 // EvalAll evaluates a sequeunce of points and returns the result. An // optional output array can be supplied to prevent unneeded heap // allocations. EvalAll(xs, ys, zs []float64, out ...[]float64) []float64 // Ref creates a shallow copy of the interpolator with its own cache. // Each thread using the saem interpolator must make a copy with Ref // first. Ref() TriInterpolator }
BiInterpolator is a 2D interpolator. These interpolators all use caching, so they are not thread safe.
func NewTriCubicInterpolator ¶
func NewTriCubicInterpolator(xs, ys, zs, vals []float64) TriInterpolator
func NewTriLinearInterpolator ¶
func NewTriLinearInterpolator(xs, ys, zs, vals []float64) TriInterpolator
type TriLinear ¶
type TriLinear struct {
// contains filtered or unexported fields
}
TriLinear is a tri-linear interpolator.
func NewTriLinear ¶
NewTriLinear creates a tri-linear interpolator on top of a grid with the values given by vals. The values of the x, y, and z grid lines are given by xs, ys, and zs respectively. The vals grid is indexed in the usual way: vals(ix, iy, iz) -> vals[ix + iy*nx + iz*nx*ny].
Panics if len(xs) * len(ys) * len(zs) != len(vals).
func NewUniformTriLinear ¶
func NewUniformTriLinear( x0, dx float64, nx int, y0, dy float64, ny int, z0, dz float64, nz int, vals []float64, ) *TriLinear
NewUniformTriLinear creates a tri-linear interpolator on top of a uniform grid with the values given by vals. The values of the x, y, and z grid lines start at x0, y0, and z0 and increase with steps of dx, dy, and dz, respectively. The vals grid is indexed in the usual way: vals(ix, iy, iz) -> vals[ix + iy*nx + iz*nx*ny].
Panics if len(xs) * len(ys) != len(vals).
func (*TriLinear) Ref ¶
func (tri *TriLinear) Ref() TriInterpolator