interpolate

package module
v0.0.0-...-13d6b0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2021 License: MIT Imports: 3 Imported by: 1

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func TriDiag

func TriDiag(as, bs, cs, rs []float64) []float64

TriTiag solves the system of equations

| b0 c0 .. | | u0 | | r0 | | a1 a2 c2 .. | | u1 | | r1 | | .. | * | .. | = | .. | | .. an bn | | un | | rn |

For u0 .. un.

func TriDiagAt

func TriDiagAt(as, bs, cs, rs, out []float64)

TriTiagAt solves the system of equations

| b0 c0 .. | | out0 | | r0 | | a1 a2 c2 .. | | out1 | | r1 | | .. | * | .. | = | .. | | .. an bn | | outn | | rn |

For out0 .. outn in place in the given slice.

Types

type BiCubic

type BiCubic struct {
	// contains filtered or unexported fields
}

func NewBiCubic

func NewBiCubic(xs, ys, vals []float64) *BiCubic

func NewUniformBiCubic

func NewUniformBiCubic(
	x0, dx float64, nx int,
	y0, dy float64, ny int,
	vals []float64,
) *BiCubic

func (*BiCubic) Eval

func (bi *BiCubic) Eval(x, y float64) float64

func (*BiCubic) EvalAll

func (bi *BiCubic) EvalAll(xs, ys []float64, out ...[]float64) []float64

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

func NewUniformBiCubicInterpolator

func NewUniformBiCubicInterpolator(
	x0, dx float64, nx int,
	y0, dy float64, ny int, vals []float64,
) BiInterpolator

func NewUniformBiLinearInterpolator

func NewUniformBiLinearInterpolator(
	x0, dx float64, nx int,
	y0, dy float64, ny int, vals []float64,
) BiInterpolator

type BiLinear

type BiLinear struct {
	// contains filtered or unexported fields
}

BiLinear is a bi-linear interpolator.

func NewBiLinear

func NewBiLinear(xs, ys, vals []float64) *BiLinear

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

func (bi *BiLinear) Eval(x, y float64) float64

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

func (bi *BiLinear) EvalAll(xs, ys []float64, out ...[]float64) []float64

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
)

func (BoundaryCondition) Get

func (b BoundaryCondition) Get(xs []float64, i int) float64

Get returns the value in xs that corresponds to the given index for a particular choice of bounday conditions.

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

func NewGaussianKernel(width int, sigma, dx float64) *Kernel

NewGaussianKernel creates a Gaussian kernel, exp(-(x - x0)^2 / (2 sigma)) with the given window width, width, and point separation, dx.

func NewSavGolDerivKernel

func NewSavGolDerivKernel(dx float64, dOrder, pOrder, width int) *Kernel

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

func NewSavGolKernel(order, width int) *Kernel

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

func NewTophatKernel(width int) *Kernel

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

func NewLinear(xs, vals []float64) *Linear

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

func NewUniformLinear(x0, dx float64, vals []float64) *Linear

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

func (lin *Linear) Eval(x float64) float64

Eval returns the interpolated value at x.

Eval panics if called on a values outside the supplied range on inputs.

func (*Linear) EvalAll

func (lin *Linear) EvalAll(xs []float64, out ...[]float64) []float64

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

func NewSpline(xs, ys []float64) *Spline

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

func (sp *Spline) Deriv(x float64, order int) float64

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

func (sp *Spline) Eval(x float64) float64

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) EvalAll

func (sp *Spline) EvalAll(xs []float64, out ...[]float64) []float64

EvalAll computes the value of the spline as a seqeunce of points.

func (*Spline) Init

func (sp *Spline) Init(xs, ys []float64)

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) Integrate

func (sp *Spline) Integrate(lo, hi float64) float64

Integrate integrates the spline from lo to hi.

func (*Spline) Ref

func (sp *Spline) Ref() Interpolator

type TriCubic

type TriCubic struct {
	// contains filtered or unexported fields
}

func NewTriCubic

func NewTriCubic(xs, ys, zs, vals []float64) *TriCubic

func NewUniformTriCubic

func NewUniformTriCubic(
	x0, dx float64, nx int,
	y0, dy float64, ny int,
	z0, dz float64, nz int,
	vals []float64,
) *TriCubic

func (*TriCubic) Eval

func (tri *TriCubic) Eval(x, y, z float64) float64

func (*TriCubic) EvalAll

func (tri *TriCubic) EvalAll(xs, ys, zs []float64, out ...[]float64) []float64

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

func NewUniformTriCubicInterpolator

func NewUniformTriCubicInterpolator(
	x0, dx float64, nx int,
	y0, dy float64, ny int,
	z0, dz float64, nz int, vals []float64,
) TriInterpolator

func NewUniformTriLinearInterpolator

func NewUniformTriLinearInterpolator(
	x0, dx float64, nx int,
	y0, dy float64, ny int,
	z0, dz float64, nz int, vals []float64,
) TriInterpolator

type TriLinear

type TriLinear struct {
	// contains filtered or unexported fields
}

TriLinear is a tri-linear interpolator.

func NewTriLinear

func NewTriLinear(xs, ys, zs, vals []float64) *TriLinear

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) Eval

func (tri *TriLinear) Eval(x, y, z float64) float64

func (*TriLinear) EvalAll

func (tri *TriLinear) EvalAll(xs, ys, zs []float64, out ...[]float64) []float64

func (*TriLinear) Ref

func (tri *TriLinear) Ref() TriInterpolator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL