/usr/include/idwint.h is in libalglib-dev 2.6.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | /*************************************************************************
Copyright (c) 2007-2010, Sergey Bochkanov (ALGLIB project).
>>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
#ifndef _idwint_h
#define _idwint_h
#include "ap.h"
#include "ialglib.h"
#include "tsort.h"
#include "nearestneighbor.h"
#include "reflections.h"
#include "hblas.h"
#include "creflections.h"
#include "sblas.h"
#include "ablasf.h"
#include "ablas.h"
#include "ortfac.h"
#include "blas.h"
#include "rotations.h"
#include "bdsvd.h"
#include "svd.h"
#include "hqrnd.h"
#include "matgen.h"
#include "trfac.h"
#include "trlinsolve.h"
#include "safesolve.h"
#include "rcond.h"
#include "xblas.h"
#include "densesolver.h"
/*************************************************************************
IDW interpolant.
*************************************************************************/
struct idwinterpolant
{
int n;
int nx;
int d;
double r;
int nw;
kdtree tree;
int modeltype;
ap::real_2d_array q;
ap::real_1d_array xbuf;
ap::integer_1d_array tbuf;
ap::real_1d_array rbuf;
ap::real_2d_array xybuf;
int debugsolverfailures;
double debugworstrcond;
double debugbestrcond;
};
/*************************************************************************
IDW interpolation
INPUT PARAMETERS:
Z - IDW interpolant built with one of model building
subroutines.
X - array[0..NX-1], interpolation point
Result:
IDW interpolant Z(X)
-- ALGLIB --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
double idwcalc(idwinterpolant& z, const ap::real_1d_array& x);
/*************************************************************************
IDW interpolant using modified Shepard method for uniform point
distributions.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function type, either:
* 0 constant model. Just for demonstration only, worst
model ever.
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
* -1 "fast" linear model, use with caution!!! It is
significantly faster than linear/quadratic and better
than constant model. But it is less robust (especially
in the presence of noise).
NQ - number of points used to calculate nodal functions (ignored
for constant models). NQ should be LARGER than:
* max(1.5*(1+NX),2^NX+1) for linear model,
* max(3/4*(NX+2)*(NX+1),2^NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* best results are obtained with quadratic models, worst - with constant
models
* when N is large, NQ and NW must be significantly smaller than N both
to obtain optimal performance and to obtain optimal accuracy. In 2 or
3-dimensional tasks NQ=15 and NW=25 are good values to start with.
* NQ and NW may be greater than N. In such cases they will be
automatically decreased.
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
* this subroutine assumes that point distribution is uniform at the small
scales. If it isn't - for example, points are concentrated along
"lines", but "lines" distribution is uniform at the larger scale - then
you should use IDWBuildModifiedShepardR()
-- ALGLIB PROJECT --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
void idwbuildmodifiedshepard(const ap::real_2d_array& xy,
int n,
int nx,
int d,
int nq,
int nw,
idwinterpolant& z);
/*************************************************************************
IDW interpolant using modified Shepard method for non-uniform datasets.
This type of model uses constant nodal functions and interpolates using
all nodes which are closer than user-specified radius R. It may be used
when points distribution is non-uniform at the small scale, but it is at
the distances as large as R.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
R - radius, R>0
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* if there is less than IDWKMin points within R-ball, algorithm selects
IDWKMin closest ones, so that continuity properties of interpolant are
preserved even far from points.
-- ALGLIB PROJECT --
Copyright 11.04.2010 by Bochkanov Sergey
*************************************************************************/
void idwbuildmodifiedshepardr(const ap::real_2d_array& xy,
int n,
int nx,
double r,
idwinterpolant& z);
/*************************************************************************
IDW model for noisy data.
This subroutine may be used to handle noisy data, i.e. data with noise in
OUTPUT values. It differs from IDWBuildModifiedShepard() in the following
aspects:
* nodal functions are not constrained to pass through nodes: Qi(xi)<>yi,
i.e. we have fitting instead of interpolation.
* weights which are used during least squares fitting stage are all equal
to 1.0 (independently of distance)
* "fast"-linear or constant nodal functions are not supported (either not
robust enough or too rigid)
This problem require far more complex tuning than interpolation problems.
Below you can find some recommendations regarding this problem:
* focus on tuning NQ; it controls noise reduction. As for NW, you can just
make it equal to 2*NQ.
* you can use cross-validation to determine optimal NQ.
* optimal NQ is a result of complex tradeoff between noise level (more
noise = larger NQ required) and underlying function complexity (given
fixed N, larger NQ means smoothing of compex features in the data). For
example, NQ=N will reduce noise to the minimum level possible, but you
will end up with just constant/linear/quadratic (depending on D) least
squares model for the whole dataset.
INPUT PARAMETERS:
XY - X and Y values, array[0..N-1,0..NX].
First NX columns contain X-values, last column contain
Y-values.
N - number of nodes, N>0.
NX - space dimension, NX>=1.
D - nodal function degree, either:
* 1 linear model, least squares fitting. Simpe model for
datasets too small for quadratic models (or for very
noisy problems).
* 2 quadratic model, least squares fitting. Best model
available (if your dataset is large enough).
NQ - number of points used to calculate nodal functions. NQ should
be significantly larger than 1.5 times the number of
coefficients in a nodal function to overcome effects of noise:
* larger than 1.5*(1+NX) for linear model,
* larger than 3/4*(NX+2)*(NX+1) for quadratic model.
Values less than this threshold will be silently increased.
NW - number of points used to calculate weights and to interpolate.
Required: >=2^NX+1, values less than this threshold will be
silently increased.
Recommended value: about 2*NQ or larger
OUTPUT PARAMETERS:
Z - IDW interpolant.
NOTES:
* best results are obtained with quadratic models, linear models are not
recommended to use unless you are pretty sure that it is what you want
* this subroutine is always succeeds (as long as correct parameters are
passed).
* see 'Multivariate Interpolation of Large Sets of Scattered Data' by
Robert J. Renka for more information on this algorithm.
-- ALGLIB PROJECT --
Copyright 02.03.2010 by Bochkanov Sergey
*************************************************************************/
void idwbuildnoisy(const ap::real_2d_array& xy,
int n,
int nx,
int d,
int nq,
int nw,
idwinterpolant& z);
#endif
|