Class interp2_neigh (o2scl)¶
-
template<class
vec_t
>
classo2scl
::
interp2_neigh
¶ Nearest-neighbor interpolation in two dimensions.
This class performs nearest-neighbor interpolation when the data points are not arranged in a specified order (i.e. not on a grid). For a set of data \( {x_i,y_i,f_i} \), the value of \( f \) is predicted given a new value of x and y. Distances are determined with
\[ d_{ij} = \sqrt{\left(\frac{x_i-x_j}{\Delta x}\right)^2 + \left(\frac{y_i-y_j}{\Delta y}\right)^2} \]The values \( \Delta_x \) and \( \Delta_y \) are specified in x_scale and y_scale, respectively. If these values are negative (the default) then they are computed with \( \Delta x = x_{\mathrm{max}}-x_{\mathrm{min}} \) and \( \Delta y = y_{\mathrm{max}}-y_{\mathrm{min}} \) .This class stores pointers to the data, not a copy. The data can be changed between interpolations without an additional call to set_data(), but the scales may need to be recomputed with compute_scale().
The vector type can be any type with a suitably defined
operator
[].- Idea for Future:
Make a parent class for this and o2scl::interp2_planar.
- Note
This class operates by performing a \( {\cal O}(N) \) brute-force search to find the closest points.
- Idea for Future:
Maybe interpm_idw subsumes this functionality and makes this class obsolete? Or is this specialization particularly efficient?
Public Types
-
typedef boost::numeric::ublas::vector<double>
ubvector
¶
-
typedef boost::numeric::ublas::vector<size_t>
ubvector_size_t
¶
Public Functions
-
interp2_neigh
()¶
-
void
compute_scale
()¶ Find scaling.
-
void
set_data
(size_t n_points, vec_t &x, vec_t &y, vec_t &f)¶ Initialize the data for the neigh interpolation.
This function will call the error handler if
n_points
is zero.
-
double
eval
(double x, double y) const¶ Perform the interpolation.
-
double
operator()
(double x, double y) const¶ Perform the interpolation.
-
template<class
vec2_t
>
doubleoperator()
(vec2_t &v) const¶ Perform the planar interpolation using the first two elements of
v
as input.
-
void
eval_point
(double x, double y, double &f, size_t &i1, double &x1, double &y1) const¶ Interpolation returning the closest point.
This function interpolates
x
andy
into the data returningf
. It also returns the closest x- and y-values found.