Approximation

Approximation

Let obj be a subclass of MwlsObject. The function call obj(pt::Point) returns the approximated function value at pt. This calls the approximate function.

Example

Let's initialize a dataset with input data xs and output data fs.

xs = collect(-2:0.1:2);
fs = [sin(x) for x in xs];

Now let's construct an approximation object obj. Let's choose a weighting function $\theta(d) = \exp(d^2)$.

obj = mwls_kd(xs, fs, 0.5, (d, e) -> (exp(-d^2)));

The approximation at 1 can be obtained by using

obj(1)
0.8412373623098394

If a different range of neighbor data is needed, then use

obj(1, 1)
0.838852039621788

Relevant documentation

approximate(obj::MwlsObject, pt::Point)
approximate(obj::MwlsObject, pt::Point; dist::Real = obj.EPS)

This calculates the approximated value at pt for each dimension of output data. The approximated value is returned.

source
mwls_coefficients(obj::MwlsObject, pt::Point, dist::Real)

Calculates the coefficients of the linear combination of polynomials used for approximation. This is done for each dimension of output data.

Note

If the matrix in the system of linear equations used to find the coefficients is singular, then zero coefficients are returned!

source

Approximation of derivative

Example

Approximation of first derivative on the dataset from the previous example can be done by using

mwls_diff(obj, 1, 1)
0.5249474991880441

Formally a tuple is required for specifying the orders of derivates for each variable. Let $f$ be the approximated function. For an example a tuple (1, 2) calculates

\[\frac{\partial^3}{\partial x_1 \partial x_2^2}f.\]

Relevant documentation

mwls_diff(obj::MwlsNaiveObject, inPt::Real, dirs::Integer; dist::Real = obj.EPS)
source
mwls_diff(obj::MwlsNaiveObject, inPt::Point, dirs::Integer; dist::Real = obj.EPS)
source
mwls_diff(obj::MwlsNaiveObject, inPt::Real, dirs::NTuple{N, Integer}; dist::Real = obj.EPS) where {N}
source
mwls_diff(obj::MwlsObject, inPt::Real, dirs::Integer; dist::Real = obj.EPS)
source
mwls_diff(obj::MwlsObject, inPt::Real, dirs::NTuple{N, Integer}; dist::Real = obj.EPS) where {N}
source
mwls_diff(obj::MwlsObject, inPt::Point, dirs::Integer; dist::Real = obj.EPS)
source
mwls_diff(obj::MwlsObject, inPt::Point, dirs::NTuple{N, Integer}; dist::Real = obj.EPS)

Calculates the approximated derivative at inPt, where x[i] is differentiated dirs[i] times.

source
mwls_diff_polys(obj::MwlsObject, inPt::Point, dirs::NTuple{N, Integer}; dist::Real = obj.EPS) where {N}

Polynomials created by mwls_coefficients are differentiated according to dirs. For an example if $f$ is the polynomial used for approximation, then $dirs = (1,2)$ returns $\frac{\partial^3}{\partial x_1 \partial x_2^2}f$.

source