Multi-dimensional interpolation by inverse distance weighting. More...
#include <interpm_idw.h>
This class performs interpolation on a multi-dimensional data set specified as a series of scattered points using the inverse distance-weighted average of nearby points. The function set_data() takes as input: the number of input dimensions, the number of output functions, the number of points which specify the data, and a "vector of vectors" which contains the data for all the points. The vector of vectors must be of a type which allows std::swap on individual elements (which are of type vec_t
).
The "order" of the interpolation, i.e. the number of nearby points which are averaged, defaults to 3 and can be changed by set_order(). To obtain interpolation uncertainties, this class finds the nearest order+1
points and returns the standard deviation of the interpolated value over all of the subsets of order
points. The value order=1
corresponds to nearest-neighbor interpolation.
This class requires a distance metric to weight the interpolation, and a Euclidean distance is used. By default, the length scales in each direction are automatically determined by extent of the data (absolute value of max minus min in each direction), but the user can specify the length scales manually in set_scales() .
First derivatives can be obtained using derivs_err() , but these derivatives are not obtained from the same approximation used in the interpolation. That is, the derivatives returned are not equal to exact derivatives from the interpolated function (as is the case in, e.g., cubic spline interpolation in one dimension). This will typically only be particularly noticable near discontinuities.
If the user specifies an array of pointers, the data can be changed between calls to the interpolation, but data points cannot be added (as set data separately stores the total number of data points) without a new call to set_data(). Also, the automatically-determined length scales may need to be recomputed by calling auto_scale().
Definition at line 92 of file interpm_idw.h.
Public Types | |
typedef boost::numeric::ublas::vector< double > | ubvector |
typedef boost::numeric::ublas::matrix< double > | ubmatrix |
typedef boost::numeric::ublas::vector< size_t > | ubvector_size_t |
Public Member Functions | |
void | set_order (size_t n) |
Set the number of closest points to use for each interpolation (default 3) | |
template<class vec2_t > | |
void | set_scales (size_t n, vec2_t &v) |
Set the scales for the distance metric. More... | |
template<class vec_vec_t > | |
void | set_data (size_t n_in, size_t n_out, size_t n_points, vec_vec_t &vecs, bool auto_scale_flag=true) |
Initialize the data for the interpolation. More... | |
template<class vec_vec_t > | |
void | get_data (size_t &n_in, size_t &n_out, size_t &n_points, vec_vec_t &vecs) |
Get the data used for interpolation. | |
void | auto_scale () |
Automatically determine the length scales from the data. | |
template<class vec_vec_t > | |
void | set_data (size_t n_in, size_t n_points, vec_vec_t &vecs, bool auto_scale=true) |
Initialize the data for the interpolation for only one output function. More... | |
template<class vec2_t > | |
double | operator() (const vec2_t &x) const |
Perform the interpolation over the first function. | |
template<class vec2_t > | |
double | eval (const vec2_t &x) const |
Perform the interpolation over the first function. | |
template<class vec2_t > | |
void | eval_err (const vec2_t &x, double &val, double &err) const |
Perform the interpolation over the first function with uncertainty. | |
template<class vec2_t , class vec3_t > | |
void | eval (vec2_t &x, vec3_t &y) const |
Perform the interpolation over all the functions, storing the result in y . | |
template<class vec2_t , class vec3_t , class vec4_t > | |
void | eval_err_index (const vec2_t &x, vec3_t &val, vec4_t &err, std::vector< size_t > &index) const |
Perform the interpolation over all the functions with uncertainties. | |
template<class vec2_t , class vec3_t , class vec4_t > | |
void | eval_err (const vec2_t &x, vec3_t &val, vec4_t &err) const |
Perform the interpolation over all the functions with uncertainties. | |
template<class vec3_t > | |
void | derivs_err (size_t func_index, size_t point_index, vec3_t &derivs, vec3_t &errs) const |
For one of the functions, compute the partial derivatives (and uncertainties) with respect to all of the inputs at one data point. More... | |
Public Attributes | |
int | verbose |
Verbosity parameter (default 0) | |
Protected Member Functions | |
template<class vec2_t > | |
double | dist (size_t index, const vec2_t &x) const |
Compute the distance between x and the point at index index . | |
Protected Attributes | |
ubvector | scales |
Distance scales for each coordinate. | |
size_t | np |
The number of points. | |
size_t | nd_in |
The number of dimensions of the inputs. | |
size_t | nd_out |
The number of dimensions of the outputs. | |
std::vector< vec_t > | ptrs |
A vector of pointers holding the data. | |
bool | data_set |
True if the data has been specified. | |
size_t | order |
Number of points to include in each interpolation (default 3) | |
|
inline |
n_in+1
combinations of n_in
points .Definition at line 528 of file interpm_idw.h.
|
inline |
The object vecs
should be a vector (of size n_in+n_out
) of vectors (all of size n_points
). It may have be any time which allows the use of std::swap
for each vector in the list.
Definition at line 155 of file interpm_idw.h.
|
inline |
The object vecs
should be a vector (of size n_in+1
) of vectors (all of size n_points
). It may be any type which allows the use of std::swap
for each vector in the list.
Definition at line 227 of file interpm_idw.h.
|
inline |
All the scales must be positive and non-zero. The size of the vector (specified in
n
) must be larger than zero.
Definition at line 131 of file interpm_idw.h.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).