Public Types | Public Attributes | Protected Attributes | List of all members
o2scl::interpm_idw< vec_t > Class Template Reference

Multi-dimensional interpolation by inverse distance weighting. More...

#include <interpm_idw.h>

Detailed Description

template<class vec_t = boost::numeric::ublas::vector<double>>
class o2scl::interpm_idw< vec_t >

This class is experimental, particularly the evaluation of derivatives.

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. This should be superior to Gaussian process interpolation as the typical distance betweeen samples becomes smaller than the correlation length. (?)

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 number of nearby points which are averaged defaults to 3 and can be changed by set_points(). To obtain interpolation uncertainties, this class finds one additional nearby point and returns the standard deviation of the interpolated value for all subsets which are missing one nearby point. One-point interpolation 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().

Increasing the value of n_extra away from zero allows the interpolation to ignore points in the data set which are degenerate because they are too close to each other. Points with a distance (normalized by the scales) less than min_dist are automatically considered degenerate and only the single point closest to the requested coordinate is considered. Increasing the value of n_extra increases the computational time required to compute the nearest points which are nondegenerate.

Todo:
Make verbose output consistent between the various eval() functions.
Idea for Future:
Share code between the various functions

Definition at line 113 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

Get and set functions
void set_points (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...
 
Evaluate interpolation
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 giving uncertainties and the sorted index vector. More...
 
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.
 
Evaluate derivatives
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)
 
size_t n_extra
 The number of extra nearest neighbors to include to avoid degeneracies (default 0)
 
double min_dist
 The minimum distance to consider points as non-degenerate (default $ 10^{-6} $ )
 

Protected Attributes

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 points
 Number of points to include in each interpolation (default 3)
 

Distance determination [protected]

ubvector scales
 Distance scales for each coordinate.
 
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.
 
double dist (size_t j, size_t k) const
 Compute the distance between two points in the data set.
 

Member Function Documentation

◆ derivs_err()

template<class vec_t = boost::numeric::ublas::vector<double>>
template<class vec3_t >
void o2scl::interpm_idw< vec_t >::derivs_err ( size_t  func_index,
size_t  point_index,
vec3_t &  derivs,
vec3_t &  errs 
) const
inline
Note
This function ignores the points chosen by set_points() and always chooses to average derivative calculations determined from n_in+1 combinations of n_in points .
Todo:
Use the mechanism provided by n_extra above to remove degenerate points.
Idea for Future:
This function requires an extra copy from "ders" to "ders2" which could be removed.

Definition at line 649 of file interpm_idw.h.

◆ eval_err_index()

template<class vec_t = boost::numeric::ublas::vector<double>>
template<class vec2_t , class vec3_t , class vec4_t >
void o2scl::interpm_idw< vec_t >::eval_err_index ( const vec2_t &  x,
vec3_t &  val,
vec4_t &  err,
std::vector< size_t > &  index 
) const
inline

The vector index is automatically resized to a size equal to n_points+1+n_extra be larger than

Definition at line 535 of file interpm_idw.h.

◆ set_data() [1/2]

template<class vec_t = boost::numeric::ublas::vector<double>>
template<class vec_vec_t >
void o2scl::interpm_idw< vec_t >::set_data ( size_t  n_in,
size_t  n_out,
size_t  n_points,
vec_vec_t &  vecs,
bool  auto_scale_flag = true 
)
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 190 of file interpm_idw.h.

◆ set_data() [2/2]

template<class vec_t = boost::numeric::ublas::vector<double>>
template<class vec_vec_t >
void o2scl::interpm_idw< vec_t >::set_data ( size_t  n_in,
size_t  n_points,
vec_vec_t &  vecs,
bool  auto_scale = true 
)
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 262 of file interpm_idw.h.

◆ set_scales()

template<class vec_t = boost::numeric::ublas::vector<double>>
template<class vec2_t >
void o2scl::interpm_idw< vec_t >::set_scales ( size_t  n,
vec2_t &  v 
)
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 166 of file interpm_idw.h.


The documentation for this class was generated from the following file:

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).