23 #if (AE_COMPILER==AE_MSVC) 24 #pragma warning(disable:4100) 25 #pragma warning(disable:4127) 26 #pragma warning(disable:4702) 27 #pragma warning(disable:4996) 43 _idwinterpolant_owner::_idwinterpolant_owner()
47 throw ap_error(
"ALGLIB: malloc error");
49 throw ap_error(
"ALGLIB: malloc error");
56 throw ap_error(
"ALGLIB: malloc error");
58 throw ap_error(
"ALGLIB: malloc error");
67 throw ap_error(
"ALGLIB: malloc error");
71 _idwinterpolant_owner::~_idwinterpolant_owner()
126 double result =
alglib_impl::idwcalc(const_cast<alglib_impl::idwinterpolant*>(z.
c_ptr()), const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), &_alglib_env_state);
128 return *(
reinterpret_cast<double*
>(&result));
336 throw ap_error(
"ALGLIB: malloc error");
338 throw ap_error(
"ALGLIB: malloc error");
345 throw ap_error(
"ALGLIB: malloc error");
347 throw ap_error(
"ALGLIB: malloc error");
356 throw ap_error(
"ALGLIB: malloc error");
419 return *(
reinterpret_cast<double*
>(&result));
582 alglib_impl::barycentricunpack(const_cast<alglib_impl::barycentricinterpolant*>(b.
c_ptr()), &n, const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), &_alglib_env_state);
615 alglib_impl::barycentricbuildxyw(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::barycentricinterpolant*>(b.
c_ptr()), &_alglib_env_state);
1069 throw ap_error(
"Error while calling 'polynomialbuild': looks like one of arguments has wrong size");
1343 return *(
reinterpret_cast<double*
>(&result));
1387 return *(
reinterpret_cast<double*
>(&result));
1429 return *(
reinterpret_cast<double*
>(&result));
1475 return *(
reinterpret_cast<double*
>(&result));
1517 return *(
reinterpret_cast<double*
>(&result));
1563 return *(
reinterpret_cast<double*
>(&result));
1578 throw ap_error(
"ALGLIB: malloc error");
1580 throw ap_error(
"ALGLIB: malloc error");
1587 throw ap_error(
"ALGLIB: malloc error");
1589 throw ap_error(
"ALGLIB: malloc error");
1598 throw ap_error(
"ALGLIB: malloc error");
1704 throw ap_error(
"Error while calling 'spline1dbuildlinear': looks like one of arguments has wrong size");
1779 alglib_impl::spline1dbuildcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::spline1dinterpolant*>(c.
c_ptr()), &_alglib_env_state);
1851 throw ap_error(
"Error while calling 'spline1dbuildcubic': looks like one of arguments has wrong size");
1860 alglib_impl::spline1dbuildcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::spline1dinterpolant*>(c.
c_ptr()), &_alglib_env_state);
1938 alglib_impl::spline1dgriddiffcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(d.
c_ptr()), &_alglib_env_state);
2018 throw ap_error(
"Error while calling 'spline1dgriddiffcubic': looks like one of arguments has wrong size");
2027 alglib_impl::spline1dgriddiffcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(d.
c_ptr()), &_alglib_env_state);
2106 alglib_impl::spline1dgriddiff2cubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(d1.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), &_alglib_env_state);
2187 throw ap_error(
"Error while calling 'spline1dgriddiff2cubic': looks like one of arguments has wrong size");
2196 alglib_impl::spline1dgriddiff2cubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(d1.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), &_alglib_env_state);
2279 alglib_impl::spline1dconvcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), &_alglib_env_state);
2365 throw ap_error(
"Error while calling 'spline1dconvcubic': looks like one of arguments has wrong size");
2375 alglib_impl::spline1dconvcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), &_alglib_env_state);
2453 void spline1dconvdiffcubic(
const real_1d_array &
x,
const real_1d_array &
y,
const ae_int_t n,
const ae_int_t boundltype,
const double boundl,
const ae_int_t boundrtype,
const double boundr,
const real_1d_array &x2,
const ae_int_t n2,
real_1d_array &y2,
real_1d_array &d2)
2459 alglib_impl::spline1dconvdiffcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), &_alglib_env_state);
2546 throw ap_error(
"Error while calling 'spline1dconvdiffcubic': looks like one of arguments has wrong size");
2556 alglib_impl::spline1dconvdiffcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), &_alglib_env_state);
2636 void spline1dconvdiff2cubic(
const real_1d_array &
x,
const real_1d_array &
y,
const ae_int_t n,
const ae_int_t boundltype,
const double boundl,
const ae_int_t boundrtype,
const double boundr,
const real_1d_array &x2,
const ae_int_t n2,
real_1d_array &y2,
real_1d_array &d2,
real_1d_array &dd2)
2642 alglib_impl::spline1dconvdiff2cubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dd2.
c_ptr()), &_alglib_env_state);
2731 throw ap_error(
"Error while calling 'spline1dconvdiff2cubic': looks like one of arguments has wrong size");
2741 alglib_impl::spline1dconvdiff2cubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, boundltype, boundl, boundrtype, boundr, const_cast<alglib_impl::ae_vector*>(x2.
c_ptr()), n2, const_cast<alglib_impl::ae_vector*>(y2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(d2.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dd2.
c_ptr()), &_alglib_env_state);
2855 throw ap_error(
"Error while calling 'spline1dbuildcatmullrom': looks like one of arguments has wrong size");
2942 throw ap_error(
"Error while calling 'spline1dbuildhermite': looks like one of arguments has wrong size");
3025 throw ap_error(
"Error while calling 'spline1dbuildakima': looks like one of arguments has wrong size");
3062 return *(
reinterpret_cast<double*
>(&result));
3222 return *(
reinterpret_cast<double*
>(&result));
3291 throw ap_error(
"Error while calling 'spline1dbuildmonotone': looks like one of arguments has wrong size");
3319 throw ap_error(
"ALGLIB: malloc error");
3321 throw ap_error(
"ALGLIB: malloc error");
3328 throw ap_error(
"ALGLIB: malloc error");
3330 throw ap_error(
"ALGLIB: malloc error");
3339 throw ap_error(
"ALGLIB: malloc error");
3391 throw ap_error(
"ALGLIB: malloc error");
3393 throw ap_error(
"ALGLIB: malloc error");
3400 throw ap_error(
"ALGLIB: malloc error");
3402 throw ap_error(
"ALGLIB: malloc error");
3411 throw ap_error(
"ALGLIB: malloc error");
3466 throw ap_error(
"ALGLIB: malloc error");
3468 throw ap_error(
"ALGLIB: malloc error");
3475 throw ap_error(
"ALGLIB: malloc error");
3477 throw ap_error(
"ALGLIB: malloc error");
3486 throw ap_error(
"ALGLIB: malloc error");
3562 throw ap_error(
"ALGLIB: malloc error");
3564 throw ap_error(
"ALGLIB: malloc error");
3571 throw ap_error(
"ALGLIB: malloc error");
3573 throw ap_error(
"ALGLIB: malloc error");
3582 throw ap_error(
"ALGLIB: malloc error");
3601 lsfitreport::lsfitreport() :
_lsfitreport_owner() ,
taskrcond(
p_struct->
taskrcond),iterationscount(
p_struct->iterationscount),varidx(
p_struct->varidx),
rmserror(
p_struct->
rmserror),
avgerror(
p_struct->
avgerror),
avgrelerror(
p_struct->
avgrelerror),
maxerror(
p_struct->
maxerror),wrmserror(
p_struct->wrmserror),covpar(&
p_struct->covpar),errpar(&
p_struct->errpar),errcurve(&
p_struct->errcurve),noise(&
p_struct->noise),
r2(
p_struct->
r2)
3605 lsfitreport::lsfitreport(
const lsfitreport &rhs):
_lsfitreport_owner(rhs) ,
taskrcond(
p_struct->
taskrcond),
iterationscount(
p_struct->
iterationscount),
varidx(
p_struct->
varidx),
rmserror(
p_struct->
rmserror),
avgerror(
p_struct->
avgerror),
avgrelerror(
p_struct->
avgrelerror),
maxerror(
p_struct->
maxerror),
wrmserror(
p_struct->
wrmserror),
covpar(&
p_struct->
covpar),
errpar(&
p_struct->
errpar),
errcurve(&
p_struct->
errcurve),
noise(&
p_struct->
noise),
r2(
p_struct->
r2)
3632 throw ap_error(
"ALGLIB: malloc error");
3634 throw ap_error(
"ALGLIB: malloc error");
3641 throw ap_error(
"ALGLIB: malloc error");
3643 throw ap_error(
"ALGLIB: malloc error");
3652 throw ap_error(
"ALGLIB: malloc error");
3738 alglib_impl::polynomialfit(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::barycentricinterpolant*>(p.
c_ptr()), const_cast<alglib_impl::polynomialfitreport*>(rep.
c_ptr()), &_alglib_env_state);
3794 throw ap_error(
"Error while calling 'polynomialfit': looks like one of arguments has wrong size");
3799 alglib_impl::polynomialfit(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::barycentricinterpolant*>(p.
c_ptr()), const_cast<alglib_impl::polynomialfitreport*>(rep.
c_ptr()), &_alglib_env_state);
3889 void polynomialfitwc(
const real_1d_array &
x,
const real_1d_array &
y,
const real_1d_array &
w,
const ae_int_t n,
const real_1d_array &
xc,
const real_1d_array &
yc,
const integer_1d_array &dc,
const ae_int_t k,
const ae_int_t m,
ae_int_t &info,
barycentricinterpolant &p,
polynomialfitreport &rep)
3895 alglib_impl::polynomialfitwc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::barycentricinterpolant*>(p.
c_ptr()), const_cast<alglib_impl::polynomialfitreport*>(rep.
c_ptr()), &_alglib_env_state);
3990 throw ap_error(
"Error while calling 'polynomialfitwc': looks like one of arguments has wrong size");
3992 throw ap_error(
"Error while calling 'polynomialfitwc': looks like one of arguments has wrong size");
3998 alglib_impl::polynomialfitwc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::barycentricinterpolant*>(p.
c_ptr()), const_cast<alglib_impl::polynomialfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4093 void barycentricfitfloaterhormannwc(
const real_1d_array &
x,
const real_1d_array &
y,
const real_1d_array &
w,
const ae_int_t n,
const real_1d_array &
xc,
const real_1d_array &
yc,
const integer_1d_array &dc,
const ae_int_t k,
const ae_int_t m,
ae_int_t &info,
barycentricinterpolant &
b,
barycentricfitreport &rep)
4099 alglib_impl::barycentricfitfloaterhormannwc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::barycentricinterpolant*>(b.
c_ptr()), const_cast<alglib_impl::barycentricfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4201 alglib_impl::spline1dfitpenalized(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, rho, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4251 throw ap_error(
"Error while calling 'spline1dfitpenalized': looks like one of arguments has wrong size");
4256 alglib_impl::spline1dfitpenalized(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, rho, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4339 alglib_impl::spline1dfitpenalizedw(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, m, rho, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4420 throw ap_error(
"Error while calling 'spline1dfitpenalizedw': looks like one of arguments has wrong size");
4425 alglib_impl::spline1dfitpenalizedw(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, m, rho, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4535 void spline1dfitcubicwc(
const real_1d_array &
x,
const real_1d_array &
y,
const real_1d_array &
w,
const ae_int_t n,
const real_1d_array &
xc,
const real_1d_array &
yc,
const integer_1d_array &dc,
const ae_int_t k,
const ae_int_t m,
ae_int_t &info,
spline1dinterpolant &s,
spline1dfitreport &rep)
4541 alglib_impl::spline1dfitcubicwc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4656 throw ap_error(
"Error while calling 'spline1dfitcubicwc': looks like one of arguments has wrong size");
4658 throw ap_error(
"Error while calling 'spline1dfitcubicwc': looks like one of arguments has wrong size");
4664 alglib_impl::spline1dfitcubicwc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4779 void spline1dfithermitewc(
const real_1d_array &
x,
const real_1d_array &
y,
const real_1d_array &
w,
const ae_int_t n,
const real_1d_array &
xc,
const real_1d_array &
yc,
const integer_1d_array &dc,
const ae_int_t k,
const ae_int_t m,
ae_int_t &info,
spline1dinterpolant &s,
spline1dfitreport &rep)
4785 alglib_impl::spline1dfithermitewc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4905 throw ap_error(
"Error while calling 'spline1dfithermitewc': looks like one of arguments has wrong size");
4907 throw ap_error(
"Error while calling 'spline1dfithermitewc': looks like one of arguments has wrong size");
4913 alglib_impl::spline1dfithermitewc(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(xc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(yc.
c_ptr()), const_cast<alglib_impl::ae_vector*>(dc.
c_ptr()), k, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4940 alglib_impl::spline1dfitcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4965 throw ap_error(
"Error while calling 'spline1dfitcubic': looks like one of arguments has wrong size");
4970 alglib_impl::spline1dfitcubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
4998 alglib_impl::spline1dfithermite(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5024 throw ap_error(
"Error while calling 'spline1dfithermite': looks like one of arguments has wrong size");
5029 alglib_impl::spline1dfithermite(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), n, m, &info, const_cast<alglib_impl::spline1dinterpolant*>(s.
c_ptr()), const_cast<alglib_impl::spline1dfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5126 alglib_impl::lsfitlinearw(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), n, m, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5222 throw ap_error(
"Error while calling 'lsfitlinearw': looks like one of arguments has wrong size");
5228 alglib_impl::lsfitlinearw(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), n, m, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5341 alglib_impl::lsfitlinearwc(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(cmatrix.
c_ptr()), n, m, k, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5454 throw ap_error(
"Error while calling 'lsfitlinearwc': looks like one of arguments has wrong size");
5455 if( (fmatrix.
cols()!=cmatrix.
cols()-1))
5456 throw ap_error(
"Error while calling 'lsfitlinearwc': looks like one of arguments has wrong size");
5463 alglib_impl::lsfitlinearwc(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(cmatrix.
c_ptr()), n, m, k, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5555 alglib_impl::lsfitlinear(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), n, m, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5646 throw ap_error(
"Error while calling 'lsfitlinear': looks like one of arguments has wrong size");
5652 alglib_impl::lsfitlinear(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), n, m, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5761 alglib_impl::lsfitlinearc(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(cmatrix.
c_ptr()), n, m, k, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5870 throw ap_error(
"Error while calling 'lsfitlinearc': looks like one of arguments has wrong size");
5871 if( (fmatrix.
cols()!=cmatrix.
cols()-1))
5872 throw ap_error(
"Error while calling 'lsfitlinearc': looks like one of arguments has wrong size");
5879 alglib_impl::lsfitlinearc(const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(fmatrix.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(cmatrix.
c_ptr()), n, m, k, &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
5934 alglib_impl::lsfitcreatewf(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, diffstep, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
5989 throw ap_error(
"Error while calling 'lsfitcreatewf': looks like one of arguments has wrong size");
5996 alglib_impl::lsfitcreatewf(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, diffstep, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6050 alglib_impl::lsfitcreatef(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, diffstep, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6104 throw ap_error(
"Error while calling 'lsfitcreatef': looks like one of arguments has wrong size");
6111 alglib_impl::lsfitcreatef(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, diffstep, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6173 alglib_impl::lsfitcreatewfg(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, cheapfg, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6235 throw ap_error(
"Error while calling 'lsfitcreatewfg': looks like one of arguments has wrong size");
6242 alglib_impl::lsfitcreatewfg(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, cheapfg, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6297 alglib_impl::lsfitcreatefg(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, cheapfg, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6352 throw ap_error(
"Error while calling 'lsfitcreatefg': looks like one of arguments has wrong size");
6359 alglib_impl::lsfitcreatefg(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, cheapfg, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6407 alglib_impl::lsfitcreatewfgh(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6455 throw ap_error(
"Error while calling 'lsfitcreatewfgh': looks like one of arguments has wrong size");
6462 alglib_impl::lsfitcreatewfgh(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(w.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6510 alglib_impl::lsfitcreatefgh(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6558 throw ap_error(
"Error while calling 'lsfitcreatefgh': looks like one of arguments has wrong size");
6565 alglib_impl::lsfitcreatefgh(const_cast<alglib_impl::ae_matrix*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), n, m, k, const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &_alglib_env_state);
6765 alglib_impl::lsfitsetbc(const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), const_cast<alglib_impl::ae_vector*>(bndl.
c_ptr()), const_cast<alglib_impl::ae_vector*>(bndu.
c_ptr()), &_alglib_env_state);
6788 return *(
reinterpret_cast<bool*
>(&result));
6799 void (*rep)(
const real_1d_array &c,
double func,
void *ptr),
6804 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (func is NULL)");
6812 func(state.
c, state.
x, state.
f, ptr);
6818 rep(state.
c, state.
f, ptr);
6821 throw ap_error(
"ALGLIB: error in 'lsfitfit' (some derivatives were not provided?)");
6835 void (*rep)(
const real_1d_array &c,
double func,
void *ptr),
6840 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (func is NULL)");
6842 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (grad is NULL)");
6850 func(state.
c, state.
x, state.
f, ptr);
6855 grad(state.
c, state.
x, state.
f, state.
g, ptr);
6861 rep(state.
c, state.
f, ptr);
6864 throw ap_error(
"ALGLIB: error in 'lsfitfit' (some derivatives were not provided?)");
6879 void (*rep)(
const real_1d_array &c,
double func,
void *ptr),
6884 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (func is NULL)");
6886 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (grad is NULL)");
6888 throw ap_error(
"ALGLIB: error in 'lsfitfit()' (hess is NULL)");
6896 func(state.
c, state.
x, state.
f, ptr);
6901 grad(state.
c, state.
x, state.
f, state.
g, ptr);
6906 hess(state.
c, state.
x, state.
f, state.
g, state.
h, ptr);
6912 rep(state.
c, state.
f, ptr);
6915 throw ap_error(
"ALGLIB: error in 'lsfitfit' (some derivatives were not provided?)");
7007 alglib_impl::lsfitresults(const_cast<alglib_impl::lsfitstate*>(state.
c_ptr()), &info, const_cast<alglib_impl::ae_vector*>(c.
c_ptr()), const_cast<alglib_impl::lsfitreport*>(rep.
c_ptr()), &_alglib_env_state);
7094 throw ap_error(
"ALGLIB: malloc error");
7096 throw ap_error(
"ALGLIB: malloc error");
7103 throw ap_error(
"ALGLIB: malloc error");
7105 throw ap_error(
"ALGLIB: malloc error");
7114 throw ap_error(
"ALGLIB: malloc error");
7164 throw ap_error(
"ALGLIB: malloc error");
7166 throw ap_error(
"ALGLIB: malloc error");
7173 throw ap_error(
"ALGLIB: malloc error");
7175 throw ap_error(
"ALGLIB: malloc error");
7184 throw ap_error(
"ALGLIB: malloc error");
7738 void pspline3diff2(
const pspline3interpolant &p,
const double t,
double &x,
double &
dx,
double &d2x,
double &
y,
double &dy,
double &d2y,
double &
z,
double &dz,
double &d2z)
7744 alglib_impl::pspline3diff2(const_cast<alglib_impl::pspline3interpolant*>(p.
c_ptr()), t, &x, &dx, &d2x, &y, &dy, &d2y, &z, &dz, &d2z, &_alglib_env_state);
7779 return *(
reinterpret_cast<double*
>(&result));
7812 return *(
reinterpret_cast<double*
>(&result));
7830 throw ap_error(
"ALGLIB: malloc error");
7832 throw ap_error(
"ALGLIB: malloc error");
7839 throw ap_error(
"ALGLIB: malloc error");
7841 throw ap_error(
"ALGLIB: malloc error");
7850 throw ap_error(
"ALGLIB: malloc error");
7899 throw ap_error(
"ALGLIB: malloc error");
7901 throw ap_error(
"ALGLIB: malloc error");
7908 throw ap_error(
"ALGLIB: malloc error");
7910 throw ap_error(
"ALGLIB: malloc error");
7919 throw ap_error(
"ALGLIB: malloc error");
7993 s_out.reserve((
size_t)(ssize+1));
7997 if( s_out.length()>(size_t)ssize )
7998 throw ap_error(
"ALGLIB: serialization integrity error");
8723 return *(
reinterpret_cast<double*
>(&result));
8764 return *(
reinterpret_cast<double*
>(&result));
8803 alglib_impl::rbfcalc(const_cast<alglib_impl::rbfmodel*>(s.
c_ptr()), const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), &_alglib_env_state);
8839 alglib_impl::rbfcalcbuf(const_cast<alglib_impl::rbfmodel*>(s.
c_ptr()), const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), &_alglib_env_state);
8879 alglib_impl::rbfgridcalc2(const_cast<alglib_impl::rbfmodel*>(s.
c_ptr()), const_cast<alglib_impl::ae_vector*>(x0.
c_ptr()), n0, const_cast<alglib_impl::ae_vector*>(x1.
c_ptr()), n1, const_cast<alglib_impl::ae_matrix*>(y.
c_ptr()), &_alglib_env_state);
8920 alglib_impl::rbfunpack(const_cast<alglib_impl::rbfmodel*>(s.
c_ptr()), &nx, &ny, const_cast<alglib_impl::ae_matrix*>(xwr.
c_ptr()), &nc, const_cast<alglib_impl::ae_matrix*>(v.
c_ptr()), &_alglib_env_state);
8937 throw ap_error(
"ALGLIB: malloc error");
8939 throw ap_error(
"ALGLIB: malloc error");
8946 throw ap_error(
"ALGLIB: malloc error");
8948 throw ap_error(
"ALGLIB: malloc error");
8957 throw ap_error(
"ALGLIB: malloc error");
9019 return *(
reinterpret_cast<double*
>(&result));
9278 alglib_impl::spline2dbuildbicubicv(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), m, const_cast<alglib_impl::ae_vector*>(f.
c_ptr()), d, const_cast<alglib_impl::spline2dinterpolant*>(c.
c_ptr()), &_alglib_env_state);
9449 alglib_impl::spline2dbuildbicubic(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), const_cast<alglib_impl::ae_matrix*>(f.
c_ptr()), m, n, const_cast<alglib_impl::spline2dinterpolant*>(c.
c_ptr()), &_alglib_env_state);
9491 throw ap_error(
"ALGLIB: malloc error");
9493 throw ap_error(
"ALGLIB: malloc error");
9500 throw ap_error(
"ALGLIB: malloc error");
9502 throw ap_error(
"ALGLIB: malloc error");
9511 throw ap_error(
"ALGLIB: malloc error");
9574 return *(
reinterpret_cast<double*
>(&result));
9731 alglib_impl::spline3dbuildtrilinearv(const_cast<alglib_impl::ae_vector*>(x.
c_ptr()), n, const_cast<alglib_impl::ae_vector*>(y.
c_ptr()), m, const_cast<alglib_impl::ae_vector*>(z.
c_ptr()), l, const_cast<alglib_impl::ae_vector*>(f.
c_ptr()), d, const_cast<alglib_impl::spline3dinterpolant*>(c.
c_ptr()), &_alglib_env_state);
9883 static double idwint_idwqfactor = 1.5;
9884 static ae_int_t idwint_idwkmin = 5;
9896 static void idwint_idwinternalsolver(
ae_vector*
y,
9914 static void spline1d_spline1dgriddiffcubicinternal(
ae_vector* x,
9928 static void spline1d_heapsortpoints(
ae_vector* x,
9932 static void spline1d_heapsortppoints(
ae_vector* x,
9937 static void spline1d_solvetridiagonal(
ae_vector*
a,
9944 static void spline1d_solvecyclictridiagonal(
ae_vector* a,
9951 static double spline1d_diffthreepoint(
double t,
9959 static void spline1d_hermitecalc(
double p0,
9967 static double spline1d_rescaleval(
double a0,
9975 static void lsfit_spline1dfitinternal(
ae_int_t st,
9989 static void lsfit_lsfitlinearinternal(
ae_vector* y,
9998 static void lsfit_lsfitclearrequestfields(
lsfitstate* state,
10004 static void lsfit_internalchebyshevfit(
ae_vector* x,
10017 static void lsfit_barycentricfitwcfixedd(
ae_vector* x,
10032 static void lsfit_estimateerrors(
ae_matrix* f1,
10046 static void pspline_pspline2par(
ae_matrix* xy,
10051 static void pspline_pspline3par(
ae_matrix* xy,
10058 static double rbf_eps = 1.0E-6;
10060 static double rbf_rbffarradius = 6;
10061 static double rbf_rbfnearradius = 2.1;
10062 static double rbf_rbfmlradius = 3;
10063 static ae_int_t rbf_rbffirstversion = 0;
10065 static void rbf_rbfradnn(
rbfmodel* s,
10076 static void rbf_buildrbfmodellsqr(
ae_matrix* x,
10095 static void rbf_buildrbfmlayersmodellsqr(
ae_matrix* x,
10117 static void spline2d_bicubiccalcderivatives(
ae_matrix* a,
10201 if( k<idwint_idwkmin )
10233 for(i=0; i<=k-1; i++)
10253 v1 = (r-
di)/(r-d0);
10255 w =
ae_sqr(v1*v2, _state);
10257 result = result+w*idwint_idwcalcq(z, x, z->
tbuf.
ptr.
p_int[i], _state);
10378 ae_assert(n>0,
"IDWBuildModifiedShepard: N<=0!", _state);
10379 ae_assert(nx>=1,
"IDWBuildModifiedShepard: NX<1!", _state);
10380 ae_assert(d>=-1&&d<=2,
"IDWBuildModifiedShepard: D<>-1 and D<>0 and D<>1 and D<>2!", _state);
10392 nq =
ae_maxint(nq,
ae_iceil(idwint_idwqfactor*(nx+2)*(nx+1)/2, _state)+1, _state);
10402 idwint_idwinit1(n, nx, d, nq, nw, z, _state);
10409 for(i=0; i<=n-1; i++)
10451 for(i=0; i<=n-1; i++)
10486 for(j=0; j<=k-1; j++)
10506 v1 = (r-
di)/(r-d0);
10522 for(j=0; j<=nx-1; j++)
10527 for(j=0; j<=k-1; j++)
10536 for(j2=0; j2<=nx-1; j2++)
10548 for(j2=0; j2<=nx-1; j2++)
10555 for(j=0; j<=nx-1; j++)
10573 for(j=0; j<=k-1; j++)
10575 for(j2=0; j2<=nx-1; j2++)
10590 for(j=0; j<=k-1; j++)
10593 for(j2=0; j2<=nx-1; j2++)
10598 for(j2=0; j2<=nx-1; j2++)
10600 for(j3=j2; j3<=nx-1; j3++)
10608 nc = nx+
ae_round(nx*(nx+1)*0.5, _state);
10610 idwint_idwinternalsolver(&y, &w, &fmatrix, &temp, k, nc, &info, &qsol, &taskrcond, _state);
10623 for(j=0; j<=nc-1; j++)
10636 for(j=0; j<=nc-1; j++)
10693 ae_assert(n>0,
"IDWBuildModifiedShepardR: N<=0!", _state);
10694 ae_assert(nx>=1,
"IDWBuildModifiedShepardR: NX<1!", _state);
10700 idwint_idwinit1(n, nx, 0, 0, n, z, _state);
10708 for(i=0; i<=n-1; i++)
10717 for(i=0; i<=n-1; i++)
10840 ae_assert(n>0,
"IDWBuildNoisy: N<=0!", _state);
10841 ae_assert(nx>=1,
"IDWBuildNoisy: NX<1!", _state);
10842 ae_assert(d>=1&&d<=2,
"IDWBuildNoisy: D<>1 and D<>2!", _state);
10853 nq =
ae_maxint(nq,
ae_iceil(idwint_idwqfactor*(nx+2)*(nx+1)/2, _state)+1, _state);
10862 idwint_idwinit1(n, nx, d, nq, nw, z, _state);
10869 for(i=0; i<=n-1; i++)
10910 for(i=0; i<=n-1; i++)
10935 for(j=0; j<=k-1; j++)
10938 for(j2=0; j2<=nx-1; j2++)
10954 for(j=0; j<=k-1; j++)
10958 for(j2=0; j2<=nx-1; j2++)
10963 for(j2=0; j2<=nx-1; j2++)
10965 for(j3=j2; j3<=nx-1; j3++)
10974 nc = 1+nx+
ae_round(nx*(nx+1)*0.5, _state);
10976 idwint_idwinternalsolver(&y, &w, &fmatrix, &temp, k, nc, &info, &qsol, &taskrcond, _state);
10989 for(j=0; j<=nc-1; j++)
11003 for(j=0; j<=k-1; j++)
11008 for(j=0; j<=nc-2; j++)
11048 for(i=0; i<=nx-1; i++)
11060 for(i=0; i<=nx-1; i++)
11062 for(j=i; j<=nx-1; j++)
11081 static void idwint_idwinit1(
ae_int_t n,
11148 static void idwint_idwinternalsolver(
ae_vector* y,
11181 for(i=0; i<=n-1; i++)
11198 for(i=0; i<=m-1; i++)
11206 for(j=i+1; j<=
m; j++)
11232 for(i=m-2; i>=0; i--)
11245 for(i=0; i<=m-1; i++)
11247 for(j=0; j<=i-1; j++)
11253 rmatrixsolvels(fmatrix, m, m, &b, 10000*ae_machineepsilon, info, &srep, x, _state);
11263 for(i=0; i<=n-1; i++)
11268 *taskrcond = srep.
r2;
11386 result = _state->
v_nan;
11406 for(i=0; i<=b->
n-1; i++)
11422 for(i=0; i<=b->
n-1; i++)
11429 result = b->
sy*s1/s2;
11492 *f = _state->
v_nan;
11493 *df = _state->
v_nan;
11523 for(i=1; i<=b->
n-1; i++)
11538 xscale1 = 1/(xmax-xmin);
11539 xoffs1 = -xmin/(xmax-xmin)+1;
11542 t = t*xscale1+xoffs1;
11543 t = t*xscale2+xoffs2;
11545 xk = xk*xscale1+xoffs1;
11546 xk = xk*xscale2+xoffs2;
11553 for(i=0; i<=b->
n-1; i++)
11556 xi = xi*xscale1+xoffs1;
11557 xi = xi*xscale2+xoffs2;
11562 vv =
ae_sqr(t-xi, _state);
11563 s0 = (t-xk)/(t-xi);
11579 *df = (n1*d0-n0*d1)/
ae_sqr(d0, _state);
11642 *f = _state->
v_nan;
11643 *df = _state->
v_nan;
11644 *d2f = _state->
v_nan;
11677 for(i=1; i<=b->
n-1; i++)
11698 for(i=0; i<=b->
n-1; i++)
11703 vv =
ae_sqr(t-xi, _state);
11704 s0 = (t-xk)/(t-xi);
11706 s2 = -2*(xk-
xi)/(vv*(t-xi));
11724 *df = b->
sy*(n1*d0-n0*d1)/
ae_sqr(d0, _state);
11725 *d2f = b->
sy*((n2*d0-n0*d2)*
ae_sqr(d0, _state)-(n1*d0-n0*d1)*2*d0*d1)/
ae_sqr(
ae_sqr(d0, _state), _state);
11760 for(i=0; i<=b->
n-1; i++)
11772 for(i=0; i<=b->
n-1; i++)
11778 for(i=0; i<=b->
n-1; i++)
11825 for(i=0; i<=b->
n-1; i++)
11830 for(i=0; i<=b->
n-1; i++)
11909 ae_assert(n>0,
"BarycentricBuildXYW: incorrect N!", _state);
11925 ratint_barycentricnormalize(b, _state);
11982 ae_assert(n>0,
"BarycentricFloaterHormann: N<=0!", _state);
11983 ae_assert(d>=0,
"BarycentricFloaterHormann: incorrect D!", _state);
12005 ratint_barycentricnormalize(b, _state);
12024 for(k=1; k<=
d; k++)
12028 for(k=0; k<=n-1; k++)
12038 for(j=i; j<=i+
d; j++)
12058 ratint_barycentricnormalize(b, _state);
12123 for(i=0; i<=b->
n-1; i++)
12133 for(i=0; i<=b->
n-1; i++)
12142 for(i=0; i<=b->
n-2; i++)
12146 tagsort(&b->
x, b->
n, &p1, &p2, _state);
12147 for(j=0; j<=b->
n-1; j++)
12265 ae_assert(p->
n>0,
"PolynomialBar2Cheb: P is not correctly initialized barycentric interpolant!", _state);
12272 for(i=0; i<=p->
n-1; i++)
12283 for(i=0; i<=p->
n-1; i++)
12303 for(i=0; i<=p->
n-1; i++)
12308 for(k=1; k<=p->
n-1; k++)
12320 for(i=0; i<=p->
n-1; i++)
12376 ae_assert(n>=1,
"PolynomialBar2Cheb: N<1", _state);
12377 ae_assert(t->
cnt>=n,
"PolynomialBar2Cheb: Length(T)<N", _state);
12384 for(i=0; i<=n-1; i++)
12394 for(k=1; k<=n-1; k++)
12481 ae_assert(p->
n>0,
"PolynomialBar2Pow: P is not correctly initialized barycentric interpolant!", _state);
12488 for(i=0; i<=p->
n-1; i++)
12499 for(i=0; i<=p->
n-1; i++)
12519 for(i=0; i<=p->
n-1; i++)
12524 for(k=1; k<=p->
n-1; k++)
12536 for(i=0; i<=p->
n-1; i++)
12549 for(i=0; i<=p->
n-1; i++)
12554 for(i=0; i<=p->
n-1; i++)
12556 for(k=i; k<=p->
n-1; k++)
12649 ae_assert(n>=1,
"PolynomialPow2Bar: N<1", _state);
12650 ae_assert(a->
cnt>=n,
"PolynomialPow2Bar: Length(A)<N", _state);
12657 for(i=0; i<=n-1; i++)
12666 for(k=1; k<=n-1; k++)
12728 ae_assert(n>0,
"PolynomialBuild: N<=0!", _state);
12729 ae_assert(x->
cnt>=n,
"PolynomialBuild: Length(X)<N!", _state);
12730 ae_assert(y->
cnt>=n,
"PolynomialBuild: Length(Y)<N!", _state);
12734 ae_assert(
aredistinct(x, n, _state),
"PolynomialBuild: at least two consequent points are too close!", _state);
12743 for(j=0; j<=n-1; j++)
12749 for(k=0; k<=n-1; k++)
12758 for(j=0; j<=n-1; j++)
12819 ae_assert(n>0,
"PolynomialBuildEqDist: N<=0!", _state);
12820 ae_assert(y->
cnt>=n,
"PolynomialBuildEqDist: Length(Y)<N!", _state);
12823 ae_assert(
isfinitevector(y, n, _state),
"PolynomialBuildEqDist: Y contains infinite or NaN values!", _state);
12825 ae_assert(
ae_fp_neq(a+(b-a)/n,a),
"PolynomialBuildEqDist: B is too close to A!", _state);
12847 for(i=0; i<=n-1; i++)
12898 ae_assert(n>0,
"PolynomialBuildCheb1: N<=0!", _state);
12899 ae_assert(y->
cnt>=n,
"PolynomialBuildCheb1: Length(Y)<N!", _state);
12925 for(i=0; i<=n-1; i++)
12975 ae_assert(n>0,
"PolynomialBuildCheb2: N<=0!", _state);
12976 ae_assert(y->
cnt>=n,
"PolynomialBuildCheb2: Length(Y)<N!", _state);
13002 for(i=0; i<=n-1; i++)
13064 ae_assert(n>0,
"PolynomialCalcEqDist: N<=0!", _state);
13065 ae_assert(f->
cnt>=n,
"PolynomialCalcEqDist: Length(F)<N!", _state);
13070 ae_assert(!
ae_isinf(t, _state),
"PolynomialCalcEqDist: T is infinite!", _state);
13077 result = _state->
v_nan;
13097 for(i=1; i<=n-1; i++)
13099 x = a+(double)i/(
double)(n-1)*(b-a);
13128 for(i=0; i<=n-1; i++)
13132 v = s*w/(t-(a+i*h));
13204 ae_assert(n>0,
"PolynomialCalcCheb1: N<=0!", _state);
13205 ae_assert(f->
cnt>=n,
"PolynomialCalcCheb1: Length(F)<N!", _state);
13210 ae_assert(!
ae_isinf(t, _state),
"PolynomialCalcCheb1: T is infinite!", _state);
13217 result = _state->
v_nan;
13249 t = (t-0.5*(a+
b))/(0.5*(b-
a));
13250 a0 =
ae_pi/(2*(n-1)+2);
13251 delta = 2*
ae_pi/(2*(n-1)+2);
13253 beta =
ae_sin(delta, _state);
13259 ca =
ae_cos(a0, _state);
13260 sa =
ae_sin(a0, _state);
13264 for(i=1; i<=n-1; i++)
13270 temps = sa-(alpha*sa-beta*ca);
13271 tempc = ca-(alpha*ca+beta*sa);
13305 ca =
ae_cos(a0, _state);
13306 sa =
ae_sin(a0, _state);
13308 for(i=0; i<=n-1; i++)
13336 temps = sa-(alpha*sa-beta*ca);
13337 tempc = ca-(alpha*ca+beta*sa);
13401 ae_assert(n>0,
"PolynomialCalcCheb2: N<=0!", _state);
13402 ae_assert(f->
cnt>=n,
"PolynomialCalcCheb2: Length(F)<N!", _state);
13407 ae_assert(!
ae_isinf(t, _state),
"PolynomialCalcEqDist: T is infinite!", _state);
13414 result = _state->
v_nan;
13446 t = (t-0.5*(a+
b))/(0.5*(b-
a));
13448 delta =
ae_pi/(n-1);
13450 beta =
ae_sin(delta, _state);
13456 ca =
ae_cos(a0, _state);
13457 sa =
ae_sin(a0, _state);
13461 for(i=1; i<=n-1; i++)
13467 temps = sa-(alpha*sa-beta*ca);
13468 tempc = ca-(alpha*ca+beta*sa);
13502 ca =
ae_cos(a0, _state);
13503 sa =
ae_sin(a0, _state);
13505 for(i=0; i<=n-1; i++)
13540 temps = sa-(alpha*sa-beta*ca);
13541 tempc = ca-(alpha*ca+beta*sa);
13594 ae_assert(n>1,
"Spline1DBuildLinear: N<2!", _state);
13595 ae_assert(x->
cnt>=n,
"Spline1DBuildLinear: Length(X)<N!", _state);
13596 ae_assert(y->
cnt>=n,
"Spline1DBuildLinear: Length(Y)<N!", _state);
13603 spline1d_heapsortpoints(x, y, n, _state);
13604 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildLinear: at least two consequent points are too close!", _state);
13615 for(i=0; i<=n-1; i++)
13619 for(i=0; i<=n-2; i++)
13725 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DBuildCubic: incorrect BoundLType!", _state);
13726 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DBuildCubic: incorrect BoundRType!", _state);
13727 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DBuildCubic: incorrect BoundLType/BoundRType!", _state);
13728 if( boundltype==1||boundltype==2 )
13730 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DBuildCubic: BoundL is infinite or NAN!", _state);
13732 if( boundrtype==1||boundrtype==2 )
13734 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DBuildCubic: BoundR is infinite or NAN!", _state);
13740 ae_assert(n>=2,
"Spline1DBuildCubic: N<2!", _state);
13741 ae_assert(x->
cnt>=n,
"Spline1DBuildCubic: Length(X)<N!", _state);
13742 ae_assert(y->
cnt>=n,
"Spline1DBuildCubic: Length(Y)<N!", _state);
13748 if( boundltype==-1 )
13753 ae_assert(
isfinitevector(y, ylen, _state),
"Spline1DBuildCubic: Y contains infinite or NAN values!", _state);
13754 spline1d_heapsortppoints(x, y, &p, n, _state);
13755 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildCubic: at least two consequent points are too close!", _state);
13762 if( boundltype==-1||boundrtype==-1 )
13766 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, &d, &a1, &a2, &a3, &b, &dt, _state);
13768 c->
periodic = boundltype==-1||boundrtype==-1;
13874 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DGridDiffCubic: incorrect BoundLType!", _state);
13875 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DGridDiffCubic: incorrect BoundRType!", _state);
13876 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DGridDiffCubic: incorrect BoundLType/BoundRType!", _state);
13877 if( boundltype==1||boundltype==2 )
13879 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DGridDiffCubic: BoundL is infinite or NAN!", _state);
13881 if( boundrtype==1||boundrtype==2 )
13883 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DGridDiffCubic: BoundR is infinite or NAN!", _state);
13889 ae_assert(n>=2,
"Spline1DGridDiffCubic: N<2!", _state);
13890 ae_assert(x->
cnt>=n,
"Spline1DGridDiffCubic: Length(X)<N!", _state);
13891 ae_assert(y->
cnt>=n,
"Spline1DGridDiffCubic: Length(Y)<N!", _state);
13897 if( boundltype==-1 )
13901 ae_assert(
isfinitevector(x, n, _state),
"Spline1DGridDiffCubic: X contains infinite or NAN values!", _state);
13902 ae_assert(
isfinitevector(y, ylen, _state),
"Spline1DGridDiffCubic: Y contains infinite or NAN values!", _state);
13903 spline1d_heapsortppoints(x, y, &p, n, _state);
13904 ae_assert(
aredistinct(x, n, _state),
"Spline1DGridDiffCubic: at least two consequent points are too close!", _state);
13910 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, d, &a1, &a2, &a3, &b, &dt, _state);
13920 for(i=0; i<=n-1; i++)
14037 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DGridDiff2Cubic: incorrect BoundLType!", _state);
14038 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DGridDiff2Cubic: incorrect BoundRType!", _state);
14039 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DGridDiff2Cubic: incorrect BoundLType/BoundRType!", _state);
14040 if( boundltype==1||boundltype==2 )
14042 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DGridDiff2Cubic: BoundL is infinite or NAN!", _state);
14044 if( boundrtype==1||boundrtype==2 )
14046 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DGridDiff2Cubic: BoundR is infinite or NAN!", _state);
14052 ae_assert(n>=2,
"Spline1DGridDiff2Cubic: N<2!", _state);
14053 ae_assert(x->
cnt>=n,
"Spline1DGridDiff2Cubic: Length(X)<N!", _state);
14054 ae_assert(y->
cnt>=n,
"Spline1DGridDiff2Cubic: Length(Y)<N!", _state);
14060 if( boundltype==-1 )
14064 ae_assert(
isfinitevector(x, n, _state),
"Spline1DGridDiff2Cubic: X contains infinite or NAN values!", _state);
14065 ae_assert(
isfinitevector(y, ylen, _state),
"Spline1DGridDiff2Cubic: Y contains infinite or NAN values!", _state);
14066 spline1d_heapsortppoints(x, y, &p, n, _state);
14067 ae_assert(
aredistinct(x, n, _state),
"Spline1DGridDiff2Cubic: at least two consequent points are too close!", _state);
14076 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, d1, &a1, &a2, &a3, &b, &dt, _state);
14081 for(i=0; i<=n-2; i++)
14095 delta2 =
ae_sqr(delta, _state);
14096 delta3 = delta*delta2;
14111 for(i=0; i<=n-1; i++)
14116 for(i=0; i<=n-1; i++)
14245 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DConvCubic: incorrect BoundLType!", _state);
14246 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DConvCubic: incorrect BoundRType!", _state);
14247 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DConvCubic: incorrect BoundLType/BoundRType!", _state);
14248 if( boundltype==1||boundltype==2 )
14250 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DConvCubic: BoundL is infinite or NAN!", _state);
14252 if( boundrtype==1||boundrtype==2 )
14254 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DConvCubic: BoundR is infinite or NAN!", _state);
14260 ae_assert(n>=2,
"Spline1DConvCubic: N<2!", _state);
14261 ae_assert(x->
cnt>=n,
"Spline1DConvCubic: Length(X)<N!", _state);
14262 ae_assert(y->
cnt>=n,
"Spline1DConvCubic: Length(Y)<N!", _state);
14263 ae_assert(n2>=2,
"Spline1DConvCubic: N2<2!", _state);
14264 ae_assert(x2->
cnt>=n2,
"Spline1DConvCubic: Length(X2)<N2!", _state);
14270 if( boundltype==-1 )
14277 spline1d_heapsortppoints(x, y, &p, n, _state);
14278 ae_assert(
aredistinct(x, n, _state),
"Spline1DConvCubic: at least two consequent points are too close!", _state);
14291 if( boundrtype==-1&&boundltype==-1 )
14293 for(i=0; i<=n2-1; i++)
14300 spline1d_heapsortppoints(x2, &dt, &p2, n2, _state);
14308 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, &d, &a1, &a2, &a3, &b, &dt, _state);
14309 spline1dconvdiffinternal(x, y, &d, n, x2, n2, y2,
ae_true, &d1,
ae_false, &d2,
ae_false, _state);
14310 ae_assert(dt.
cnt>=n2,
"Spline1DConvCubic: internal error!", _state);
14311 for(i=0; i<=n2-1; i++)
14441 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DConvDiffCubic: incorrect BoundLType!", _state);
14442 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DConvDiffCubic: incorrect BoundRType!", _state);
14443 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DConvDiffCubic: incorrect BoundLType/BoundRType!", _state);
14444 if( boundltype==1||boundltype==2 )
14446 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DConvDiffCubic: BoundL is infinite or NAN!", _state);
14448 if( boundrtype==1||boundrtype==2 )
14450 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DConvDiffCubic: BoundR is infinite or NAN!", _state);
14456 ae_assert(n>=2,
"Spline1DConvDiffCubic: N<2!", _state);
14457 ae_assert(x->
cnt>=n,
"Spline1DConvDiffCubic: Length(X)<N!", _state);
14458 ae_assert(y->
cnt>=n,
"Spline1DConvDiffCubic: Length(Y)<N!", _state);
14459 ae_assert(n2>=2,
"Spline1DConvDiffCubic: N2<2!", _state);
14460 ae_assert(x2->
cnt>=n2,
"Spline1DConvDiffCubic: Length(X2)<N2!", _state);
14466 if( boundltype==-1 )
14470 ae_assert(
isfinitevector(x, n, _state),
"Spline1DConvDiffCubic: X contains infinite or NAN values!", _state);
14471 ae_assert(
isfinitevector(y, ylen, _state),
"Spline1DConvDiffCubic: Y contains infinite or NAN values!", _state);
14472 ae_assert(
isfinitevector(x2, n2, _state),
"Spline1DConvDiffCubic: X2 contains infinite or NAN values!", _state);
14473 spline1d_heapsortppoints(x, y, &p, n, _state);
14474 ae_assert(
aredistinct(x, n, _state),
"Spline1DConvDiffCubic: at least two consequent points are too close!", _state);
14487 if( boundrtype==-1&&boundltype==-1 )
14489 for(i=0; i<=n2-1; i++)
14496 spline1d_heapsortppoints(x2, &dt, &p2, n2, _state);
14504 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, &d, &a1, &a2, &a3, &b, &dt, _state);
14505 spline1dconvdiffinternal(x, y, &d, n, x2, n2, y2,
ae_true, d2,
ae_true, &rt1,
ae_false, _state);
14506 ae_assert(dt.
cnt>=n2,
"Spline1DConvDiffCubic: internal error!", _state);
14507 for(i=0; i<=n2-1; i++)
14512 for(i=0; i<=n2-1; i++)
14644 ae_assert(((boundltype==-1||boundltype==0)||boundltype==1)||boundltype==2,
"Spline1DConvDiff2Cubic: incorrect BoundLType!", _state);
14645 ae_assert(((boundrtype==-1||boundrtype==0)||boundrtype==1)||boundrtype==2,
"Spline1DConvDiff2Cubic: incorrect BoundRType!", _state);
14646 ae_assert((boundrtype==-1&&boundltype==-1)||(boundrtype!=-1&&boundltype!=-1),
"Spline1DConvDiff2Cubic: incorrect BoundLType/BoundRType!", _state);
14647 if( boundltype==1||boundltype==2 )
14649 ae_assert(
ae_isfinite(boundl, _state),
"Spline1DConvDiff2Cubic: BoundL is infinite or NAN!", _state);
14651 if( boundrtype==1||boundrtype==2 )
14653 ae_assert(
ae_isfinite(boundr, _state),
"Spline1DConvDiff2Cubic: BoundR is infinite or NAN!", _state);
14659 ae_assert(n>=2,
"Spline1DConvDiff2Cubic: N<2!", _state);
14660 ae_assert(x->
cnt>=n,
"Spline1DConvDiff2Cubic: Length(X)<N!", _state);
14661 ae_assert(y->
cnt>=n,
"Spline1DConvDiff2Cubic: Length(Y)<N!", _state);
14662 ae_assert(n2>=2,
"Spline1DConvDiff2Cubic: N2<2!", _state);
14663 ae_assert(x2->
cnt>=n2,
"Spline1DConvDiff2Cubic: Length(X2)<N2!", _state);
14669 if( boundltype==-1 )
14673 ae_assert(
isfinitevector(x, n, _state),
"Spline1DConvDiff2Cubic: X contains infinite or NAN values!", _state);
14674 ae_assert(
isfinitevector(y, ylen, _state),
"Spline1DConvDiff2Cubic: Y contains infinite or NAN values!", _state);
14675 ae_assert(
isfinitevector(x2, n2, _state),
"Spline1DConvDiff2Cubic: X2 contains infinite or NAN values!", _state);
14676 spline1d_heapsortppoints(x, y, &p, n, _state);
14677 ae_assert(
aredistinct(x, n, _state),
"Spline1DConvDiff2Cubic: at least two consequent points are too close!", _state);
14690 if( boundrtype==-1&&boundltype==-1 )
14692 for(i=0; i<=n2-1; i++)
14699 spline1d_heapsortppoints(x2, &dt, &p2, n2, _state);
14707 spline1d_spline1dgriddiffcubicinternal(x, y, n, boundltype, boundl, boundrtype, boundr, &d, &a1, &a2, &a3, &b, &dt, _state);
14708 spline1dconvdiffinternal(x, y, &d, n, x2, n2, y2,
ae_true, d2,
ae_true, dd2,
ae_true, _state);
14709 ae_assert(dt.
cnt>=n2,
"Spline1DConvDiff2Cubic: internal error!", _state);
14710 for(i=0; i<=n2-1; i++)
14715 for(i=0; i<=n2-1; i++)
14720 for(i=0; i<=n2-1; i++)
14791 ae_assert(n>=2,
"Spline1DBuildCatmullRom: N<2!", _state);
14792 ae_assert(boundtype==-1||boundtype==0,
"Spline1DBuildCatmullRom: incorrect BoundType!", _state);
14795 ae_assert(x->
cnt>=n,
"Spline1DBuildCatmullRom: Length(X)<N!", _state);
14796 ae_assert(y->
cnt>=n,
"Spline1DBuildCatmullRom: Length(Y)<N!", _state);
14801 ae_assert(
isfinitevector(x, n, _state),
"Spline1DBuildCatmullRom: X contains infinite or NAN values!", _state);
14802 ae_assert(
isfinitevector(y, n, _state),
"Spline1DBuildCatmullRom: Y contains infinite or NAN values!", _state);
14803 spline1d_heapsortpoints(x, y, n, _state);
14804 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildCatmullRom: at least two consequent points are too close!", _state);
14811 if( n==2&&boundtype==0 )
14821 if( n==2&&boundtype==-1 )
14835 if( boundtype==-1 )
14844 for(i=1; i<=n-2; i++)
14863 for(i=1; i<=n-2; i++)
14928 ae_assert(n>=2,
"Spline1DBuildHermite: N<2!", _state);
14929 ae_assert(x->
cnt>=n,
"Spline1DBuildHermite: Length(X)<N!", _state);
14930 ae_assert(y->
cnt>=n,
"Spline1DBuildHermite: Length(Y)<N!", _state);
14931 ae_assert(d->
cnt>=n,
"Spline1DBuildHermite: Length(D)<N!", _state);
14940 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildHermite: at least two consequent points are too close!", _state);
14951 for(i=0; i<=n-1; i++)
14955 for(i=0; i<=n-2; i++)
14958 delta2 =
ae_sqr(delta, _state);
14959 delta3 = delta*delta2;
15018 ae_assert(n>=2,
"Spline1DBuildAkima: N<2!", _state);
15019 ae_assert(x->
cnt>=n,
"Spline1DBuildAkima: Length(X)<N!", _state);
15020 ae_assert(y->
cnt>=n,
"Spline1DBuildAkima: Length(Y)<N!", _state);
15027 spline1d_heapsortpoints(x, y, n, _state);
15028 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildAkima: at least two consequent points are too close!", _state);
15045 for(i=0; i<=n-2; i++)
15049 for(i=1; i<=n-2; i++)
15058 for(i=2; i<=n-3; i++)
15104 ae_assert(c->
k==3,
"Spline1DCalc: internal error", _state);
15112 result = _state->
v_nan;
15183 ae_assert(c->
k==3,
"Spline1DDiff: internal error", _state);
15191 *s = _state->
v_nan;
15192 *ds = _state->
v_nan;
15193 *d2s = _state->
v_nan;
15311 for(i=0; i<=*n-2; i++)
15315 for(j=0; j<=c->
k; j++)
15357 ae_assert(c->
k==3,
"Spline1DLinTransX: internal error", _state);
15374 for(i=0; i<=n-1; i++)
15387 for(i=0; i<=n-1; i++)
15434 ae_assert(c->
k==3,
"Spline1DLinTransX: internal error", _state);
15436 for(i=0; i<=n-2; i++)
15439 for(j=1; j<=3; j++)
15476 double additionalterm;
15499 for(i=0; i<=c->
n-2; i++)
15505 for(j=1; j<=c->
k; j++)
15516 additionalterm = t*intab;
15520 additionalterm = 0;
15545 for(i=0; i<=l-1; i++)
15551 for(j=1; j<=c->
k; j++)
15561 for(j=1; j<=c->
k; j++)
15566 result = result+additionalterm;
15638 if( needy&&y->
cnt<n2 )
15642 if( needd1&&d1->
cnt<n2 )
15646 if( needd2&&d2->
cnt<n2 )
15666 intervalindex = -1;
15674 if( pointindex>=n2 )
15684 if( intervalindex==-1 )
15690 if( intervalindex<n-2 )
15695 if( havetoadvance )
15697 intervalindex = intervalindex+1;
15709 c2 = (3*(fb-fa)-2*da*w-db*w)/w2;
15710 c3 = (2*(fa-fb)+da*w+db*w)/w3;
15720 y->
ptr.
p_double[pointindex] = c0+t*(c1+t*(c2+t*c3));
15724 d1->
ptr.
p_double[pointindex] = c1+2*t*c2+3*t*t*c3;
15730 pointindex = pointindex+1;
15827 ae_assert(c->
k==3,
"Spline1DRootsAndExtrema : incorrect parameter C.K!", _state);
15828 ae_assert(c->
continuity>=0,
"Spline1DRootsAndExtrema : parameter C.Continuity must not be less than 0!", _state);
15858 for(i=0; i<=c->
n-2; i++)
15872 solvecubicpolinom(pl, ml, pr, mr, c->
x.
ptr.
p_double[i], c->
x.
ptr.
p_double[i+1], &x0, &x1, &x2, &ex0, &ex1, &tnr, &tne, &tr, _state);
15873 *dr = *dr||tnr==-1;
15874 *de = *de||tne==-1;
15879 if( tnr==1&&nstep )
16008 for(i=0; i<=*nr-1; i++)
16016 for(i=0; i<=*ne-1; i++)
16041 for(i=0; i<=c->
n-2; i++)
16055 solvecubicpolinom(pl, ml, pr, mr, c->
x.
ptr.
p_double[i], c->
x.
ptr.
p_double[i+1], &x0, &x1, &x2, &ex0, &ex1, &tnr, &tne, &tr, _state);
16092 for(j=0; j<=tnr-1; j++)
16105 for(j=1; j<=tnr-1; j++)
16115 for(j=1; j<=tnr-1; j++)
16128 for(j=0; j<=tnr-1; j++)
16256 for(i=0; i<=tne-1; i++)
16361 for(i=0; i<=*ne-1; i++)
16370 for(i=0; i<=*nr-1; i++)
16403 for(i=0; i<=n-1; i++)
16408 for(i=0; i<=n-1; i++)
16413 for(i=0; i<=n-1; i++)
16476 a = 6*p0+3*m0-6*p1+3*m1;
16477 b = -6*p0-4*m0+6*p1-2*m1;
16529 *x0 = (-b-
ae_sqrt(dd, _state))/(2*a);
16530 *x1 = (-b+
ae_sqrt(dd, _state))/(2*a);
16580 *x0 = (-b-
ae_sqrt(dd, _state))/(2*a);
16581 *x1 = (-b+
ae_sqrt(dd, _state))/(2*a);
16583 exf = a*extr*extr+b*extr+
c;
16623 *x0 = (-b-
ae_sqrt(dd, _state))/(2*a);
16624 *x1 = (-b+
ae_sqrt(dd, _state))/(2*a);
16626 exf = a*extr*extr+b*extr+
c;
16660 exf = a*extr*extr+b*extr+
c;
16672 *x0 = (-b-
ae_sqrt(dd, _state))/(2*a);
16673 *x1 = (-b+
ae_sqrt(dd, _state))/(2*a);
16787 ae_assert(
ae_fp_less(a,b),
"\nSolveCubicPolinom: incorrect borders for [A;B]!\n", _state);
16808 *ex0 = spline1d_rescaleval(0, 1, a, b, *ex0, _state);
16809 *ex1 = spline1d_rescaleval(0, 1, a, b, *ex1, _state);
16817 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, 1, x0, _state);
16820 *x0 = spline1d_rescaleval(0, 1, a, b, *x0, _state);
16833 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, 1, x0, _state);
16836 *x0 = spline1d_rescaleval(0, 1, a, b, *x0, _state);
16844 tex0 = spline1d_rescaleval(a, b, 0, 1, *ex0, _state);
16845 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, tex0, x0, _state)+(*nr);
16848 tempdata->
ptr.
p_double[
i] = spline1d_rescaleval(0, tex0, a, *ex0, *x0, _state);
16851 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, tex0, 1, x0, _state)+(*nr);
16854 *x0 = spline1d_rescaleval(tex0, 1, *ex0, b, *x0, _state);
16898 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, 1, x0, _state);
16901 *x0 = spline1d_rescaleval(0, 1, a, b, *x0, _state);
16909 tex1 = spline1d_rescaleval(a, b, 0, 1, *ex1, _state);
16910 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, tex1, x0, _state)+(*nr);
16913 tempdata->
ptr.
p_double[
i] = spline1d_rescaleval(0, tex1, a, *ex1, *x0, _state);
16916 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, tex1, 1, x0, _state)+(*nr);
16919 *x0 = spline1d_rescaleval(tex1, 1, *ex1, b, *x0, _state);
16944 tex0 = spline1d_rescaleval(a, b, 0, 1, *ex0, _state);
16945 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, tex0, x0, _state)+(*nr);
16948 tempdata->
ptr.
p_double[
i] = spline1d_rescaleval(0, tex0, a, *ex0, *x0, _state);
16951 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, tex0, 1, x0, _state)+(*nr);
16954 *x0 = spline1d_rescaleval(tex0, 1, *ex0, b, *x0, _state);
16992 tex0 = spline1d_rescaleval(a, b, 0, 1, *ex0, _state);
16993 tex1 = spline1d_rescaleval(a, b, 0, 1, *ex1, _state);
16994 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, 0, tex0, x0, _state)+(*nr);
16997 tempdata->
ptr.
p_double[
i] = spline1d_rescaleval(0, tex0, a, *ex0, *x0, _state);
17000 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, tex0, tex1, x0, _state)+(*nr);
17003 *x0 = spline1d_rescaleval(tex0, tex1, *ex0, *ex1, *x0, _state);
17022 *nr =
bisectmethod(pa, tmpma, pb, tmpmb, tex1, 1, x0, _state)+(*nr);
17025 *x0 = spline1d_rescaleval(tex1, 1, *ex1, b, *x0, _state);
17128 spline1d_hermitecalc(pa, ma, pb, mb, a, &lf, &vacuum, _state);
17129 spline1d_hermitecalc(pa, ma, pb, mb, b, &rf, &vacuum, _state);
17165 spline1d_hermitecalc(pa, ma, pb, mb, a0, &lf, &vacuum, _state);
17166 spline1d_hermitecalc(pa, ma, pb, mb, b0, &rf, &vacuum, _state);
17167 spline1d_hermitecalc(pa, ma, pb, mb, m, &mf, &vacuum, _state);
17267 ae_assert(n>=2,
"Spline1DBuildMonotone: N<2", _state);
17268 ae_assert(x->
cnt>=n,
"Spline1DBuildMonotone: Length(X)<N", _state);
17269 ae_assert(y->
cnt>=n,
"Spline1DBuildMonotone: Length(Y)<N", _state);
17276 spline1d_heapsortppoints(x, y, &p, n, _state);
17277 ae_assert(
aredistinct(x, n, _state),
"Spline1DBuildMonotone: at least two consequent points are too close", _state);
17287 for(i=1; i<=n-2; i++)
17316 for(j=i; j<=n-2; j++)
17330 ae_assert(tmpn>=2,
"Spline1DBuildMonotone: internal error", _state);
17337 for(j=i+1; j<=sn-2; j++)
17341 for(j=i; j<=sn-2; j++)
17400 static void spline1d_spline1dgriddiffcubicinternal(
ae_vector* x,
17452 if( (n==2&&boundltype==0)&&boundrtype==0 )
17458 if( (n==2&&boundltype==-1)&&boundrtype==-1 )
17469 if( boundrtype==-1&&boundltype==-1 )
17485 for(i=1; i<=n-2; i++)
17501 spline1d_solvecyclictridiagonal(a1, a2, a3, b, n-1, dt, _state);
17512 if( boundltype==0 )
17519 if( boundltype==1 )
17526 if( boundltype==2 )
17537 for(i=1; i<=n-2; i++)
17548 if( boundrtype==0 )
17555 if( boundrtype==1 )
17562 if( boundrtype==2 )
17573 spline1d_solvetridiagonal(a1, a2, a3, b, n, d, _state);
17581 static void spline1d_heapsortpoints(
ae_vector* x,
17611 static void spline1d_heapsortppoints(
ae_vector* x,
17631 for(i=0; i<=n-1; i++)
17636 for(i=0; i<=n-1; i++)
17657 static void spline1d_solvetridiagonal(
ae_vector* a,
17681 for(k=1; k<=n-1; k++)
17688 for(k=n-2; k>=0; k--)
17707 static void spline1d_solvecyclictridiagonal(
ae_vector* a,
17742 for(k=0; k<=n-1; k++)
17748 spline1d_solvetridiagonal(a, b, c, d, n, &y, _state);
17749 spline1d_solvetridiagonal(a, b, c, &u, n, &z, _state);
17750 for(k=0; k<=n-1; k++)
17761 static double spline1d_diffthreepoint(
double t,
17778 a = (f2-f0-x2/x1*(f1-f0))/(
ae_sqr(x2, _state)-x1*x2);
17779 b = (f1-f0-a*
ae_sqr(x1, _state))/x1;
17803 static void spline1d_hermitecalc(
double p0,
17816 *s = p0*(1+2*t)*(1-t)*(1-t)+m0*t*(1-t)*(1-t)+p1*(3-2*t)*t*t+m1*t*t*(t-1);
17817 *ds = -p0*6*t*(1-t)+m0*(1-t)*(1-3*t)+p1*6*t*(1-t)+m1*t*(3*t-2);
17853 static double spline1d_rescaleval(
double a0,
17885 result = (b1-a1)*(t-a0)/(b0-a0)+a1;
18004 ae_assert(n>0,
"PolynomialFit: N<=0!", _state);
18005 ae_assert(m>0,
"PolynomialFit: M<=0!", _state);
18006 ae_assert(x->
cnt>=n,
"PolynomialFit: Length(X)<N!", _state);
18007 ae_assert(y->
cnt>=n,
"PolynomialFit: Length(Y)<N!", _state);
18011 for(i=0; i<=n-1; i++)
18015 polynomialfitwc(x, y, &w, n, &xc, &yc, &dc, 0, m, info, p, rep, _state);
18165 ae_assert(n>0,
"PolynomialFitWC: N<=0!", _state);
18166 ae_assert(m>0,
"PolynomialFitWC: M<=0!", _state);
18167 ae_assert(k>=0,
"PolynomialFitWC: K<0!", _state);
18168 ae_assert(k<m, "PolynomialFitWC: K>=M!
", _state); 18169 ae_assert(x->cnt>=n, "PolynomialFitWC: Length(X)<N!
", _state); 18170 ae_assert(y->cnt>=n, "PolynomialFitWC: Length(Y)<N!
", _state); 18171 ae_assert(w->cnt>=n, "PolynomialFitWC: Length(W)<N!
", _state); 18172 ae_assert(xc->cnt>=k, "PolynomialFitWC: Length(XC)<
K!
", _state); 18173 ae_assert(yc->cnt>=k, "PolynomialFitWC: Length(YC)<
K!
", _state); 18174 ae_assert(dc->cnt>=k, "PolynomialFitWC: Length(DC)<
K!
", _state); 18175 ae_assert(isfinitevector(x, n, _state), "PolynomialFitWC: X contains infinite
or NaN values!
", _state); 18176 ae_assert(isfinitevector(y, n, _state), "PolynomialFitWC: Y contains infinite
or NaN values!
", _state); 18177 ae_assert(isfinitevector(w, n, _state), "PolynomialFitWC: X contains infinite
or NaN values!
", _state); 18178 ae_assert(isfinitevector(xc, k, _state), "PolynomialFitWC: XC contains infinite
or NaN values!
", _state); 18179 ae_assert(isfinitevector(yc, k, _state), "PolynomialFitWC: YC contains infinite
or NaN values!
", _state); 18180 for(i=0; i<=k-1; i++) 18182 ae_assert(dc->ptr.p_int[i]==0||dc->ptr.p_int[i]==1, "PolynomialFitWC: one of DC[] is not 0
or 1!
", _state); 18186 * Scale X, Y, XC, YC. 18187 * Solve scaled problem using internal Chebyshev fitting function. 18189 lsfitscalexy(x, y, w, n, xc, yc, dc, k, &xa, &xb, &sa, &sb, &xoriginal, &yoriginal, _state); 18190 lsfit_internalchebyshevfit(x, y, w, n, xc, yc, dc, k, m, info, &tmp, &lrep, _state); 18193 ae_frame_leave(_state); 18198 * Generate barycentric model and scale it 18199 * * BX, BY store barycentric model nodes 18200 * * FMatrix is reused (remember - it is at least MxM, what we need) 18202 * Model initialization is done in O(M^2). In principle, it can be 18203 * done in O(M*log(M)), but before it we solved task with O(N*M^2) 18204 * complexity, so it is only a small amount of total time spent. 18206 ae_vector_set_length(&bx, m, _state); 18207 ae_vector_set_length(&by, m, _state); 18208 ae_vector_set_length(&bw, m, _state); 18209 ae_vector_set_length(&tmp2, m, _state); 18211 for(i=0; i<=m-1; i++) 18215 u = ae_cos(ae_pi*i/(m-1), _state); 18222 for(j=0; j<=m-1; j++) 18226 tmp2.ptr.p_double[j] = 1; 18232 tmp2.ptr.p_double[j] = u; 18236 tmp2.ptr.p_double[j] = 2*u*tmp2.ptr.p_double[j-1]-tmp2.ptr.p_double[j-2]; 18239 v = v+tmp.ptr.p_double[j]*tmp2.ptr.p_double[j]; 18241 bx.ptr.p_double[i] = u; 18242 by.ptr.p_double[i] = v; 18243 bw.ptr.p_double[i] = s; 18246 bw.ptr.p_double[i] = 0.5*bw.ptr.p_double[i]; 18250 barycentricbuildxyw(&bx, &by, &bw, m, p, _state); 18251 barycentriclintransx(p, 2/(xb-xa), -(xa+xb)/(xb-xa), _state); 18252 barycentriclintransy(p, sb-sa, sa, _state); 18255 * Scale absolute errors obtained from LSFitLinearW. 18256 * Relative error should be calculated separately 18257 * (because of shifting/scaling of the task) 18259 rep->taskrcond = lrep.taskrcond; 18260 rep->rmserror = lrep.rmserror*(sb-sa); 18261 rep->avgerror = lrep.avgerror*(sb-sa); 18262 rep->maxerror = lrep.maxerror*(sb-sa); 18263 rep->avgrelerror = 0; 18265 for(i=0; i<=n-1; i++) 18267 if( ae_fp_neq(yoriginal.ptr.p_double[i],0) ) 18269 rep->avgrelerror = rep->avgrelerror+ae_fabs(barycentriccalc(p, xoriginal.ptr.p_double[i], _state)-yoriginal.ptr.p_double[i], _state)/ae_fabs(yoriginal.ptr.p_double[i], _state); 18275 rep->avgrelerror = rep->avgrelerror/relcnt; 18277 ae_frame_leave(_state); 18281 /************************************************************************* 18282 Weghted rational least squares fitting using Floater-Hormann rational 18283 functions with optimal D chosen from [0,9], with constraints and 18284 individual weights. 18286 Equidistant grid with M node on [min(x),max(x)] is used to build basis 18287 functions. Different values of D are tried, optimal D (least WEIGHTED root 18288 mean square error) is chosen. Task is linear, so linear least squares 18289 solver is used. Complexity of this computational scheme is O(N*M^2) 18290 (mostly dominated by the least squares solver). 18293 * BarycentricFitFloaterHormann(), "lightweight
" fitting without invididual 18294 weights and constraints. 18297 X - points, array[0..N-1]. 18298 Y - function values, array[0..N-1]. 18299 W - weights, array[0..N-1] 18300 Each summand in square sum of approximation deviations from 18301 given values is multiplied by the square of corresponding 18302 weight. Fill it by 1's if you don't want to solve weighted 18304 N - number of points, N>0. 18305 XC - points where function values/derivatives are constrained, 18307 YC - values of constraints, array[0..K-1] 18308 DC - array[0..K-1], types of constraints: 18309 * DC[i]=0 means that S(XC[i])=YC[i] 18310 * DC[i]=1 means that S'(XC[i])=YC[i] 18311 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 18312 K - number of constraints, 0<=K<M. 18313 K=0 means no constraints (XC/YC/DC are not used in such cases) 18314 M - number of basis functions ( = number_of_nodes), M>=2. 18317 Info- same format as in LSFitLinearWC() subroutine. 18318 * Info>0 task is solved 18319 * Info<=0 an error occurred: 18320 -4 means inconvergence of internal SVD 18321 -3 means inconsistent constraints 18322 -1 means another errors in parameters passed 18323 (N<=0, for example) 18324 B - barycentric interpolant. 18325 Rep - report, same format as in LSFitLinearWC() subroutine. 18326 Following fields are set: 18327 * DBest best value of the D parameter 18328 * RMSError rms error on the (X,Y). 18329 * AvgError average error on the (X,Y). 18330 * AvgRelError average relative error on the non-zero Y 18331 * MaxError maximum error 18332 NON-WEIGHTED ERRORS ARE CALCULATED 18335 this subroutine doesn't calculate task's condition number for K<>0. 18337 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 18339 Setting constraints can lead to undesired results, like ill-conditioned 18340 behavior, or inconsistency being detected. From the other side, it allows 18341 us to improve quality of the fit. Here we summarize our experience with 18342 constrained barycentric interpolants: 18343 * excessive constraints can be inconsistent. Floater-Hormann basis 18344 functions aren't as flexible as splines (although they are very smooth). 18345 * the more evenly constraints are spread across [min(x),max(x)], the more 18346 chances that they will be consistent 18347 * the greater is M (given fixed constraints), the more chances that 18348 constraints will be consistent 18349 * in the general case, consistency of constraints IS NOT GUARANTEED. 18350 * in the several special cases, however, we CAN guarantee consistency. 18351 * one of this cases is constraints on the function VALUES at the interval 18352 boundaries. Note that consustency of the constraints on the function 18353 DERIVATIVES is NOT guaranteed (you can use in such cases cubic splines 18354 which are more flexible). 18355 * another special case is ONE constraint on the function value (OR, but 18356 not AND, derivative) anywhere in the interval 18358 Our final recommendation is to use constraints WHEN AND ONLY WHEN you 18359 can't solve your task without them. Anything beyond special cases given 18360 above is not guaranteed and may result in inconsistency. 18362 -- ALGLIB PROJECT -- 18363 Copyright 18.08.2009 by Bochkanov Sergey 18364 *************************************************************************/ 18365 void barycentricfitfloaterhormannwc(/* Real */ ae_vector* x, 18366 /* Real */ ae_vector* y, 18367 /* Real */ ae_vector* w, 18369 /* Real */ ae_vector* xc, 18370 /* Real */ ae_vector* yc, 18371 /* Integer */ ae_vector* dc, 18375 barycentricinterpolant* b, 18376 barycentricfitreport* rep, 18379 ae_frame _frame_block; 18384 barycentricinterpolant locb; 18385 barycentricfitreport locrep; 18388 ae_frame_make(_state, &_frame_block); 18390 _barycentricinterpolant_clear(b); 18391 _barycentricfitreport_clear(rep); 18392 _barycentricinterpolant_init(&locb, _state, ae_true); 18393 _barycentricfitreport_init(&locrep, _state, ae_true); 18395 ae_assert(n>0, "BarycentricFitFloaterHormannWC: N<=0!
", _state); 18396 ae_assert(m>0, "BarycentricFitFloaterHormannWC: M<=0!
", _state); 18397 ae_assert(k>=0, "BarycentricFitFloaterHormannWC:
K<0!
", _state); 18398 ae_assert(k<m, "BarycentricFitFloaterHormannWC:
K>=M!
", _state); 18399 ae_assert(x->cnt>=n, "BarycentricFitFloaterHormannWC: Length(X)<N!
", _state); 18400 ae_assert(y->cnt>=n, "BarycentricFitFloaterHormannWC: Length(Y)<N!
", _state); 18401 ae_assert(w->cnt>=n, "BarycentricFitFloaterHormannWC: Length(W)<N!
", _state); 18402 ae_assert(xc->cnt>=k, "BarycentricFitFloaterHormannWC: Length(XC)<
K!
", _state); 18403 ae_assert(yc->cnt>=k, "BarycentricFitFloaterHormannWC: Length(YC)<
K!
", _state); 18404 ae_assert(dc->cnt>=k, "BarycentricFitFloaterHormannWC: Length(DC)<
K!
", _state); 18405 ae_assert(isfinitevector(x, n, _state), "BarycentricFitFloaterHormannWC: X contains infinite
or NaN values!
", _state); 18406 ae_assert(isfinitevector(y, n, _state), "BarycentricFitFloaterHormannWC: Y contains infinite
or NaN values!
", _state); 18407 ae_assert(isfinitevector(w, n, _state), "BarycentricFitFloaterHormannWC: X contains infinite
or NaN values!
", _state); 18408 ae_assert(isfinitevector(xc, k, _state), "BarycentricFitFloaterHormannWC: XC contains infinite
or NaN values!
", _state); 18409 ae_assert(isfinitevector(yc, k, _state), "BarycentricFitFloaterHormannWC: YC contains infinite
or NaN values!
", _state); 18410 for(i=0; i<=k-1; i++) 18412 ae_assert(dc->ptr.p_int[i]==0||dc->ptr.p_int[i]==1, "BarycentricFitFloaterHormannWC: one of DC[] is not 0
or 1!
", _state); 18418 * Info is -3 by default (degenerate constraints). 18419 * If LocInfo will always be equal to -3, Info will remain equal to -3. 18420 * If at least once LocInfo will be -4, Info will be -4. 18422 wrmsbest = ae_maxrealnumber; 18425 for(d=0; d<=ae_minint(9, n-1, _state); d++) 18427 lsfit_barycentricfitwcfixedd(x, y, w, n, xc, yc, dc, k, m, d, &locinfo, &locb, &locrep, _state); 18428 ae_assert((locinfo==-4||locinfo==-3)||locinfo>0, "BarycentricFitFloaterHormannWC: unexpected result from BarycentricFitWCFixedD!
", _state); 18433 * Calculate weghted RMS 18436 for(i=0; i<=n-1; i++) 18438 wrmscur = wrmscur+ae_sqr(w->ptr.p_double[i]*(y->ptr.p_double[i]-barycentriccalc(&locb, x->ptr.p_double[i], _state)), _state); 18440 wrmscur = ae_sqrt(wrmscur/n, _state); 18441 if( ae_fp_less(wrmscur,wrmsbest)||rep->dbest<0 ) 18443 barycentriccopy(&locb, b, _state); 18446 rep->rmserror = locrep.rmserror; 18447 rep->avgerror = locrep.avgerror; 18448 rep->avgrelerror = locrep.avgrelerror; 18449 rep->maxerror = locrep.maxerror; 18450 rep->taskrcond = locrep.taskrcond; 18451 wrmsbest = wrmscur; 18456 if( locinfo!=-3&&*info<0 ) 18462 ae_frame_leave(_state); 18466 /************************************************************************* 18467 Rational least squares fitting using Floater-Hormann rational functions 18468 with optimal D chosen from [0,9]. 18470 Equidistant grid with M node on [min(x),max(x)] is used to build basis 18471 functions. Different values of D are tried, optimal D (least root mean 18472 square error) is chosen. Task is linear, so linear least squares solver 18473 is used. Complexity of this computational scheme is O(N*M^2) (mostly 18474 dominated by the least squares solver). 18477 X - points, array[0..N-1]. 18478 Y - function values, array[0..N-1]. 18479 N - number of points, N>0. 18480 M - number of basis functions ( = number_of_nodes), M>=2. 18483 Info- same format as in LSFitLinearWC() subroutine. 18484 * Info>0 task is solved 18485 * Info<=0 an error occurred: 18486 -4 means inconvergence of internal SVD 18487 -3 means inconsistent constraints 18488 B - barycentric interpolant. 18489 Rep - report, same format as in LSFitLinearWC() subroutine. 18490 Following fields are set: 18491 * DBest best value of the D parameter 18492 * RMSError rms error on the (X,Y). 18493 * AvgError average error on the (X,Y). 18494 * AvgRelError average relative error on the non-zero Y 18495 * MaxError maximum error 18496 NON-WEIGHTED ERRORS ARE CALCULATED 18498 -- ALGLIB PROJECT -- 18499 Copyright 18.08.2009 by Bochkanov Sergey 18500 *************************************************************************/ 18501 void barycentricfitfloaterhormann(/* Real */ ae_vector* x, 18502 /* Real */ ae_vector* y, 18506 barycentricinterpolant* b, 18507 barycentricfitreport* rep, 18510 ae_frame _frame_block; 18517 ae_frame_make(_state, &_frame_block); 18519 _barycentricinterpolant_clear(b); 18520 _barycentricfitreport_clear(rep); 18521 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 18522 ae_vector_init(&xc, 0, DT_REAL, _state, ae_true); 18523 ae_vector_init(&yc, 0, DT_REAL, _state, ae_true); 18524 ae_vector_init(&dc, 0, DT_INT, _state, ae_true); 18526 ae_assert(n>0, "BarycentricFitFloaterHormann: N<=0!
", _state); 18527 ae_assert(m>0, "BarycentricFitFloaterHormann: M<=0!
", _state); 18528 ae_assert(x->cnt>=n, "BarycentricFitFloaterHormann: Length(X)<N!
", _state); 18529 ae_assert(y->cnt>=n, "BarycentricFitFloaterHormann: Length(Y)<N!
", _state); 18530 ae_assert(isfinitevector(x, n, _state), "BarycentricFitFloaterHormann: X contains infinite
or NaN values!
", _state); 18531 ae_assert(isfinitevector(y, n, _state), "BarycentricFitFloaterHormann: Y contains infinite
or NaN values!
", _state); 18532 ae_vector_set_length(&w, n, _state); 18533 for(i=0; i<=n-1; i++) 18535 w.ptr.p_double[i] = 1; 18537 barycentricfitfloaterhormannwc(x, y, &w, n, &xc, &yc, &dc, 0, m, info, b, rep, _state); 18538 ae_frame_leave(_state); 18542 /************************************************************************* 18543 Rational least squares fitting using Floater-Hormann rational functions 18544 with optimal D chosen from [0,9]. 18546 Equidistant grid with M node on [min(x),max(x)] is used to build basis 18547 functions. Different values of D are tried, optimal D (least root mean 18548 square error) is chosen. Task is linear, so linear least squares solver 18549 is used. Complexity of this computational scheme is O(N*M^2) (mostly 18550 dominated by the least squares solver). 18553 X - points, array[0..N-1]. 18554 Y - function values, array[0..N-1]. 18555 N - number of points, N>0. 18556 M - number of basis functions ( = number_of_nodes), M>=2. 18559 Info- same format as in LSFitLinearWC() subroutine. 18560 * Info>0 task is solved 18561 * Info<=0 an error occurred: 18562 -4 means inconvergence of internal SVD 18563 -3 means inconsistent constraints 18564 B - barycentric interpolant. 18565 Rep - report, same format as in LSFitLinearWC() subroutine. 18566 Following fields are set: 18567 * DBest best value of the D parameter 18568 * RMSError rms error on the (X,Y). 18569 * AvgError average error on the (X,Y). 18570 * AvgRelError average relative error on the non-zero Y 18571 * MaxError maximum error 18572 NON-WEIGHTED ERRORS ARE CALCULATED 18574 -- ALGLIB PROJECT -- 18575 Copyright 18.08.2009 by Bochkanov Sergey 18576 *************************************************************************/ 18577 void spline1dfitpenalized(/* Real */ ae_vector* x, 18578 /* Real */ ae_vector* y, 18583 spline1dinterpolant* s, 18584 spline1dfitreport* rep, 18587 ae_frame _frame_block; 18593 ae_frame_make(_state, &_frame_block); 18594 ae_vector_init_copy(&_x, x, _state, ae_true); 18596 ae_vector_init_copy(&_y, y, _state, ae_true); 18599 _spline1dinterpolant_clear(s); 18600 _spline1dfitreport_clear(rep); 18601 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 18603 ae_assert(n>=1, "Spline1DFitPenalized: N<1!
", _state); 18604 ae_assert(m>=4, "Spline1DFitPenalized: M<4!
", _state); 18605 ae_assert(x->cnt>=n, "Spline1DFitPenalized: Length(X)<N!
", _state); 18606 ae_assert(y->cnt>=n, "Spline1DFitPenalized: Length(Y)<N!
", _state); 18607 ae_assert(isfinitevector(x, n, _state), "Spline1DFitPenalized: X contains infinite
or NAN values!
", _state); 18608 ae_assert(isfinitevector(y, n, _state), "Spline1DFitPenalized: Y contains infinite
or NAN values!
", _state); 18609 ae_assert(ae_isfinite(rho, _state), "Spline1DFitPenalized: Rho is infinite!
", _state); 18610 ae_vector_set_length(&w, n, _state); 18611 for(i=0; i<=n-1; i++) 18613 w.ptr.p_double[i] = 1; 18615 spline1dfitpenalizedw(x, y, &w, n, m, rho, info, s, rep, _state); 18616 ae_frame_leave(_state); 18620 /************************************************************************* 18621 Weighted fitting by penalized cubic spline. 18623 Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build 18624 basis functions. Basis functions are cubic splines with natural boundary 18625 conditions. Problem is regularized by adding non-linearity penalty to the 18626 usual least squares penalty function: 18628 S(x) = arg min { LS + P }, where 18629 LS = SUM { w[i]^2*(y[i] - S(x[i]))^2 } - least squares penalty 18630 P = C*10^rho*integral{ S''(x)^2*dx } - non-linearity penalty 18631 rho - tunable constant given by user 18632 C - automatically determined scale parameter, 18633 makes penalty invariant with respect to scaling of X, Y, W. 18636 X - points, array[0..N-1]. 18637 Y - function values, array[0..N-1]. 18638 W - weights, array[0..N-1] 18639 Each summand in square sum of approximation deviations from 18640 given values is multiplied by the square of corresponding 18641 weight. Fill it by 1's if you don't want to solve weighted 18643 N - number of points (optional): 18645 * if given, only first N elements of X/Y/W are processed 18646 * if not given, automatically determined from X/Y/W sizes 18647 M - number of basis functions ( = number_of_nodes), M>=4. 18648 Rho - regularization constant passed by user. It penalizes 18649 nonlinearity in the regression spline. It is logarithmically 18650 scaled, i.e. actual value of regularization constant is 18651 calculated as 10^Rho. It is automatically scaled so that: 18652 * Rho=2.0 corresponds to moderate amount of nonlinearity 18653 * generally, it should be somewhere in the [-8.0,+8.0] 18654 If you do not want to penalize nonlineary, 18655 pass small Rho. Values as low as -15 should work. 18658 Info- same format as in LSFitLinearWC() subroutine. 18659 * Info>0 task is solved 18660 * Info<=0 an error occurred: 18661 -4 means inconvergence of internal SVD or 18662 Cholesky decomposition; problem may be 18663 too ill-conditioned (very rare) 18664 S - spline interpolant. 18665 Rep - Following fields are set: 18666 * RMSError rms error on the (X,Y). 18667 * AvgError average error on the (X,Y). 18668 * AvgRelError average relative error on the non-zero Y 18669 * MaxError maximum error 18670 NON-WEIGHTED ERRORS ARE CALCULATED 18673 this subroitine doesn't calculate task's condition number for K<>0. 18675 NOTE 1: additional nodes are added to the spline outside of the fitting 18676 interval to force linearity when x<min(x,xc) or x>max(x,xc). It is done 18677 for consistency - we penalize non-linearity at [min(x,xc),max(x,xc)], so 18678 it is natural to force linearity outside of this interval. 18680 NOTE 2: function automatically sorts points, so caller may pass unsorted 18683 -- ALGLIB PROJECT -- 18684 Copyright 19.10.2010 by Bochkanov Sergey 18685 *************************************************************************/ 18686 void spline1dfitpenalizedw(/* Real */ ae_vector* x, 18687 /* Real */ ae_vector* y, 18688 /* Real */ ae_vector* w, 18693 spline1dinterpolant* s, 18694 spline1dfitreport* rep, 18697 ae_frame _frame_block; 18710 ae_vector xoriginal; 18711 ae_vector yoriginal; 18724 ae_matrix d2matrix; 18737 spline1dinterpolant bs; 18739 ae_vector rightpart; 18740 fblslincgstate cgstate; 18744 ae_frame_make(_state, &_frame_block); 18745 ae_vector_init_copy(&_x, x, _state, ae_true); 18747 ae_vector_init_copy(&_y, y, _state, ae_true); 18749 ae_vector_init_copy(&_w, w, _state, ae_true); 18752 _spline1dinterpolant_clear(s); 18753 _spline1dfitreport_clear(rep); 18754 ae_vector_init(&xoriginal, 0, DT_REAL, _state, ae_true); 18755 ae_vector_init(&yoriginal, 0, DT_REAL, _state, ae_true); 18756 ae_matrix_init(&fmatrix, 0, 0, DT_REAL, _state, ae_true); 18757 ae_vector_init(&fcolumn, 0, DT_REAL, _state, ae_true); 18758 ae_vector_init(&y2, 0, DT_REAL, _state, ae_true); 18759 ae_vector_init(&w2, 0, DT_REAL, _state, ae_true); 18760 ae_vector_init(&xc, 0, DT_REAL, _state, ae_true); 18761 ae_vector_init(&yc, 0, DT_REAL, _state, ae_true); 18762 ae_vector_init(&dc, 0, DT_INT, _state, ae_true); 18763 ae_matrix_init(&amatrix, 0, 0, DT_REAL, _state, ae_true); 18764 ae_matrix_init(&d2matrix, 0, 0, DT_REAL, _state, ae_true); 18765 ae_vector_init(&bx, 0, DT_REAL, _state, ae_true); 18766 ae_vector_init(&by, 0, DT_REAL, _state, ae_true); 18767 ae_vector_init(&bd1, 0, DT_REAL, _state, ae_true); 18768 ae_vector_init(&bd2, 0, DT_REAL, _state, ae_true); 18769 ae_vector_init(&tx, 0, DT_REAL, _state, ae_true); 18770 ae_vector_init(&ty, 0, DT_REAL, _state, ae_true); 18771 ae_vector_init(&td, 0, DT_REAL, _state, ae_true); 18772 _spline1dinterpolant_init(&bs, _state, ae_true); 18773 ae_matrix_init(&nmatrix, 0, 0, DT_REAL, _state, ae_true); 18774 ae_vector_init(&rightpart, 0, DT_REAL, _state, ae_true); 18775 _fblslincgstate_init(&cgstate, _state, ae_true); 18776 ae_vector_init(&c, 0, DT_REAL, _state, ae_true); 18777 ae_vector_init(&tmp0, 0, DT_REAL, _state, ae_true); 18779 ae_assert(n>=1, "Spline1DFitPenalizedW: N<1!
", _state); 18780 ae_assert(m>=4, "Spline1DFitPenalizedW: M<4!
", _state); 18781 ae_assert(x->cnt>=n, "Spline1DFitPenalizedW: Length(X)<N!
", _state); 18782 ae_assert(y->cnt>=n, "Spline1DFitPenalizedW: Length(Y)<N!
", _state); 18783 ae_assert(w->cnt>=n, "Spline1DFitPenalizedW: Length(W)<N!
", _state); 18784 ae_assert(isfinitevector(x, n, _state), "Spline1DFitPenalizedW: X contains infinite
or NAN values!
", _state); 18785 ae_assert(isfinitevector(y, n, _state), "Spline1DFitPenalizedW: Y contains infinite
or NAN values!
", _state); 18786 ae_assert(isfinitevector(w, n, _state), "Spline1DFitPenalizedW: Y contains infinite
or NAN values!
", _state); 18787 ae_assert(ae_isfinite(rho, _state), "Spline1DFitPenalizedW: Rho is infinite!
", _state); 18792 v = -ae_log(ae_machineepsilon, _state)/ae_log(10, _state); 18793 if( ae_fp_less(rho,-v) ) 18797 if( ae_fp_greater(rho,v) ) 18801 lambdav = ae_pow(10, rho, _state); 18806 heapsortdpoints(x, y, w, n, _state); 18809 * Scale X, Y, XC, YC 18811 lsfitscalexy(x, y, w, n, &xc, &yc, &dc, 0, &xa, &xb, &sa, &sb, &xoriginal, &yoriginal, _state); 18816 ae_matrix_set_length(&fmatrix, n, m, _state); 18817 ae_matrix_set_length(&amatrix, m, m, _state); 18818 ae_matrix_set_length(&d2matrix, m, m, _state); 18819 ae_vector_set_length(&bx, m, _state); 18820 ae_vector_set_length(&by, m, _state); 18821 ae_vector_set_length(&fcolumn, n, _state); 18822 ae_matrix_set_length(&nmatrix, m, m, _state); 18823 ae_vector_set_length(&rightpart, m, _state); 18824 ae_vector_set_length(&tmp0, ae_maxint(m, n, _state), _state); 18825 ae_vector_set_length(&c, m, _state); 18829 * * FMatrix by values of basis functions 18830 * * TmpAMatrix by second derivatives of I-th function at J-th point 18831 * * CMatrix by constraints 18834 for(b=0; b<=m-1; b++) 18838 * Prepare I-th basis function 18840 for(j=0; j<=m-1; j++) 18842 bx.ptr.p_double[j] = (double)(2*j)/(double)(m-1)-1; 18843 by.ptr.p_double[j] = 0; 18845 by.ptr.p_double[b] = 1; 18846 spline1dgriddiff2cubic(&bx, &by, m, 2, 0.0, 2, 0.0, &bd1, &bd2, _state); 18847 spline1dbuildcubic(&bx, &by, m, 2, 0.0, 2, 0.0, &bs, _state); 18850 * Calculate B-th column of FMatrix 18851 * Update FDMax (maximum column norm) 18853 spline1dconvcubic(&bx, &by, m, 2, 0.0, 2, 0.0, x, n, &fcolumn, _state); 18854 ae_v_move(&fmatrix.ptr.pp_double[0][b], fmatrix.stride, &fcolumn.ptr.p_double[0], 1, ae_v_len(0,n-1)); 18856 for(i=0; i<=n-1; i++) 18858 v = v+ae_sqr(w->ptr.p_double[i]*fcolumn.ptr.p_double[i], _state); 18860 fdmax = ae_maxreal(fdmax, v, _state); 18863 * Fill temporary with second derivatives of basis function 18865 ae_v_move(&d2matrix.ptr.pp_double[b][0], 1, &bd2.ptr.p_double[0], 1, ae_v_len(0,m-1)); 18869 * * calculate penalty matrix A 18870 * * calculate max of diagonal elements of A 18871 * * calculate PDecay - coefficient before penalty matrix 18873 for(i=0; i<=m-1; i++) 18875 for(j=i; j<=m-1; j++) 18879 * calculate integral(B_i''*B_j'') where B_i and B_j are 18880 * i-th and j-th basis splines. 18881 * B_i and B_j are piecewise linear functions. 18884 for(b=0; b<=m-2; b++) 18886 fa = d2matrix.ptr.pp_double[i][b]; 18887 fb = d2matrix.ptr.pp_double[i][b+1]; 18888 ga = d2matrix.ptr.pp_double[j][b]; 18889 gb = d2matrix.ptr.pp_double[j][b+1]; 18890 v = v+(bx.ptr.p_double[b+1]-bx.ptr.p_double[b])*(fa*ga+(fa*(gb-ga)+ga*(fb-fa))/2+(fb-fa)*(gb-ga)/3); 18892 amatrix.ptr.pp_double[i][j] = v; 18893 amatrix.ptr.pp_double[j][i] = v; 18897 for(i=0; i<=m-1; i++) 18899 admax = ae_maxreal(admax, ae_fabs(amatrix.ptr.pp_double[i][i], _state), _state); 18901 pdecay = lambdav*fdmax/admax; 18904 * Calculate TDecay for Tikhonov regularization 18906 tdecay = fdmax*(1+pdecay)*10*ae_machineepsilon; 18911 * NOTE: FMatrix is spoiled during this process 18913 for(i=0; i<=n-1; i++) 18915 v = w->ptr.p_double[i]; 18916 ae_v_muld(&fmatrix.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 18918 rmatrixgemm(m, m, n, 1.0, &fmatrix, 0, 0, 1, &fmatrix, 0, 0, 0, 0.0, &nmatrix, 0, 0, _state); 18919 for(i=0; i<=m-1; i++) 18921 for(j=0; j<=m-1; j++) 18923 nmatrix.ptr.pp_double[i][j] = nmatrix.ptr.pp_double[i][j]+pdecay*amatrix.ptr.pp_double[i][j]; 18926 for(i=0; i<=m-1; i++) 18928 nmatrix.ptr.pp_double[i][i] = nmatrix.ptr.pp_double[i][i]+tdecay; 18930 for(i=0; i<=m-1; i++) 18932 rightpart.ptr.p_double[i] = 0; 18934 for(i=0; i<=n-1; i++) 18936 v = y->ptr.p_double[i]*w->ptr.p_double[i]; 18937 ae_v_addd(&rightpart.ptr.p_double[0], 1, &fmatrix.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 18943 if( !spdmatrixcholesky(&nmatrix, m, ae_true, _state) ) 18946 ae_frame_leave(_state); 18949 fblscholeskysolve(&nmatrix, 1.0, m, ae_true, &rightpart, &tmp0, _state); 18950 ae_v_move(&c.ptr.p_double[0], 1, &rightpart.ptr.p_double[0], 1, ae_v_len(0,m-1)); 18953 * add nodes to force linearity outside of the fitting interval 18955 spline1dgriddiffcubic(&bx, &c, m, 2, 0.0, 2, 0.0, &bd1, _state); 18956 ae_vector_set_length(&tx, m+2, _state); 18957 ae_vector_set_length(&ty, m+2, _state); 18958 ae_vector_set_length(&td, m+2, _state); 18959 ae_v_move(&tx.ptr.p_double[1], 1, &bx.ptr.p_double[0], 1, ae_v_len(1,m)); 18960 ae_v_move(&ty.ptr.p_double[1], 1, &rightpart.ptr.p_double[0], 1, ae_v_len(1,m)); 18961 ae_v_move(&td.ptr.p_double[1], 1, &bd1.ptr.p_double[0], 1, ae_v_len(1,m)); 18962 tx.ptr.p_double[0] = tx.ptr.p_double[1]-(tx.ptr.p_double[2]-tx.ptr.p_double[1]); 18963 ty.ptr.p_double[0] = ty.ptr.p_double[1]-td.ptr.p_double[1]*(tx.ptr.p_double[2]-tx.ptr.p_double[1]); 18964 td.ptr.p_double[0] = td.ptr.p_double[1]; 18965 tx.ptr.p_double[m+1] = tx.ptr.p_double[m]+(tx.ptr.p_double[m]-tx.ptr.p_double[m-1]); 18966 ty.ptr.p_double[m+1] = ty.ptr.p_double[m]+td.ptr.p_double[m]*(tx.ptr.p_double[m]-tx.ptr.p_double[m-1]); 18967 td.ptr.p_double[m+1] = td.ptr.p_double[m]; 18968 spline1dbuildhermite(&tx, &ty, &td, m+2, s, _state); 18969 spline1dlintransx(s, 2/(xb-xa), -(xa+xb)/(xb-xa), _state); 18970 spline1dlintransy(s, sb-sa, sa, _state); 18978 rep->avgrelerror = 0; 18981 spline1dconvcubic(&bx, &rightpart, m, 2, 0.0, 2, 0.0, x, n, &fcolumn, _state); 18982 for(i=0; i<=n-1; i++) 18984 v = (sb-sa)*fcolumn.ptr.p_double[i]+sa; 18985 rep->rmserror = rep->rmserror+ae_sqr(v-yoriginal.ptr.p_double[i], _state); 18986 rep->avgerror = rep->avgerror+ae_fabs(v-yoriginal.ptr.p_double[i], _state); 18987 if( ae_fp_neq(yoriginal.ptr.p_double[i],0) ) 18989 rep->avgrelerror = rep->avgrelerror+ae_fabs(v-yoriginal.ptr.p_double[i], _state)/ae_fabs(yoriginal.ptr.p_double[i], _state); 18992 rep->maxerror = ae_maxreal(rep->maxerror, ae_fabs(v-yoriginal.ptr.p_double[i], _state), _state); 18994 rep->rmserror = ae_sqrt(rep->rmserror/n, _state); 18995 rep->avgerror = rep->avgerror/n; 18996 if( ae_fp_neq(relcnt,0) ) 18998 rep->avgrelerror = rep->avgrelerror/relcnt; 19000 ae_frame_leave(_state); 19004 /************************************************************************* 19005 Weighted fitting by cubic spline, with constraints on function values or 19008 Equidistant grid with M-2 nodes on [min(x,xc),max(x,xc)] is used to build 19009 basis functions. Basis functions are cubic splines with continuous second 19010 derivatives and non-fixed first derivatives at interval ends. Small 19011 regularizing term is used when solving constrained tasks (to improve 19014 Task is linear, so linear least squares solver is used. Complexity of this 19015 computational scheme is O(N*M^2), mostly dominated by least squares solver 19018 Spline1DFitHermiteWC() - fitting by Hermite splines (more flexible, 19020 Spline1DFitCubic() - "lightweight
" fitting by cubic splines, 19021 without invididual weights and constraints 19024 X - points, array[0..N-1]. 19025 Y - function values, array[0..N-1]. 19026 W - weights, array[0..N-1] 19027 Each summand in square sum of approximation deviations from 19028 given values is multiplied by the square of corresponding 19029 weight. Fill it by 1's if you don't want to solve weighted 19031 N - number of points (optional): 19033 * if given, only first N elements of X/Y/W are processed 19034 * if not given, automatically determined from X/Y/W sizes 19035 XC - points where spline values/derivatives are constrained, 19037 YC - values of constraints, array[0..K-1] 19038 DC - array[0..K-1], types of constraints: 19039 * DC[i]=0 means that S(XC[i])=YC[i] 19040 * DC[i]=1 means that S'(XC[i])=YC[i] 19041 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 19042 K - number of constraints (optional): 19044 * K=0 means no constraints (XC/YC/DC are not used) 19045 * if given, only first K elements of XC/YC/DC are used 19046 * if not given, automatically determined from XC/YC/DC 19047 M - number of basis functions ( = number_of_nodes+2), M>=4. 19050 Info- same format as in LSFitLinearWC() subroutine. 19051 * Info>0 task is solved 19052 * Info<=0 an error occurred: 19053 -4 means inconvergence of internal SVD 19054 -3 means inconsistent constraints 19055 S - spline interpolant. 19056 Rep - report, same format as in LSFitLinearWC() subroutine. 19057 Following fields are set: 19058 * RMSError rms error on the (X,Y). 19059 * AvgError average error on the (X,Y). 19060 * AvgRelError average relative error on the non-zero Y 19061 * MaxError maximum error 19062 NON-WEIGHTED ERRORS ARE CALCULATED 19065 this subroitine doesn't calculate task's condition number for K<>0. 19070 Subroutine automatically sorts points, so caller may pass unsorted array. 19072 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 19074 Setting constraints can lead to undesired results, like ill-conditioned 19075 behavior, or inconsistency being detected. From the other side, it allows 19076 us to improve quality of the fit. Here we summarize our experience with 19077 constrained regression splines: 19078 * excessive constraints can be inconsistent. Splines are piecewise cubic 19079 functions, and it is easy to create an example, where large number of 19080 constraints concentrated in small area will result in inconsistency. 19081 Just because spline is not flexible enough to satisfy all of them. And 19082 same constraints spread across the [min(x),max(x)] will be perfectly 19084 * the more evenly constraints are spread across [min(x),max(x)], the more 19085 chances that they will be consistent 19086 * the greater is M (given fixed constraints), the more chances that 19087 constraints will be consistent 19088 * in the general case, consistency of constraints IS NOT GUARANTEED. 19089 * in the several special cases, however, we CAN guarantee consistency. 19090 * one of this cases is constraints on the function values AND/OR its 19091 derivatives at the interval boundaries. 19092 * another special case is ONE constraint on the function value (OR, but 19093 not AND, derivative) anywhere in the interval 19095 Our final recommendation is to use constraints WHEN AND ONLY WHEN you 19096 can't solve your task without them. Anything beyond special cases given 19097 above is not guaranteed and may result in inconsistency. 19100 -- ALGLIB PROJECT -- 19101 Copyright 18.08.2009 by Bochkanov Sergey 19102 *************************************************************************/ 19103 void spline1dfitcubicwc(/* Real */ ae_vector* x, 19104 /* Real */ ae_vector* y, 19105 /* Real */ ae_vector* w, 19107 /* Real */ ae_vector* xc, 19108 /* Real */ ae_vector* yc, 19109 /* Integer */ ae_vector* dc, 19113 spline1dinterpolant* s, 19114 spline1dfitreport* rep, 19120 _spline1dinterpolant_clear(s); 19121 _spline1dfitreport_clear(rep); 19123 ae_assert(n>=1, "Spline1DFitCubicWC: N<1!
", _state); 19124 ae_assert(m>=4, "Spline1DFitCubicWC: M<4!
", _state); 19125 ae_assert(k>=0, "Spline1DFitCubicWC:
K<0!
", _state); 19126 ae_assert(k<m, "Spline1DFitCubicWC:
K>=M!
", _state); 19127 ae_assert(x->cnt>=n, "Spline1DFitCubicWC: Length(X)<N!
", _state); 19128 ae_assert(y->cnt>=n, "Spline1DFitCubicWC: Length(Y)<N!
", _state); 19129 ae_assert(w->cnt>=n, "Spline1DFitCubicWC: Length(W)<N!
", _state); 19130 ae_assert(xc->cnt>=k, "Spline1DFitCubicWC: Length(XC)<
K!
", _state); 19131 ae_assert(yc->cnt>=k, "Spline1DFitCubicWC: Length(YC)<
K!
", _state); 19132 ae_assert(dc->cnt>=k, "Spline1DFitCubicWC: Length(DC)<
K!
", _state); 19133 ae_assert(isfinitevector(x, n, _state), "Spline1DFitCubicWC: X contains infinite
or NAN values!
", _state); 19134 ae_assert(isfinitevector(y, n, _state), "Spline1DFitCubicWC: Y contains infinite
or NAN values!
", _state); 19135 ae_assert(isfinitevector(w, n, _state), "Spline1DFitCubicWC: Y contains infinite
or NAN values!
", _state); 19136 ae_assert(isfinitevector(xc, k, _state), "Spline1DFitCubicWC: X contains infinite
or NAN values!
", _state); 19137 ae_assert(isfinitevector(yc, k, _state), "Spline1DFitCubicWC: Y contains infinite
or NAN values!
", _state); 19138 for(i=0; i<=k-1; i++) 19140 ae_assert(dc->ptr.p_int[i]==0||dc->ptr.p_int[i]==1, "Spline1DFitCubicWC: DC[i] is neither 0
or 1!
", _state); 19142 lsfit_spline1dfitinternal(0, x, y, w, n, xc, yc, dc, k, m, info, s, rep, _state); 19146 /************************************************************************* 19147 Weighted fitting by Hermite spline, with constraints on function values 19148 or first derivatives. 19150 Equidistant grid with M nodes on [min(x,xc),max(x,xc)] is used to build 19151 basis functions. Basis functions are Hermite splines. Small regularizing 19152 term is used when solving constrained tasks (to improve stability). 19154 Task is linear, so linear least squares solver is used. Complexity of this 19155 computational scheme is O(N*M^2), mostly dominated by least squares solver 19158 Spline1DFitCubicWC() - fitting by Cubic splines (less flexible, 19160 Spline1DFitHermite() - "lightweight
" Hermite fitting, without 19161 invididual weights and constraints 19164 X - points, array[0..N-1]. 19165 Y - function values, array[0..N-1]. 19166 W - weights, array[0..N-1] 19167 Each summand in square sum of approximation deviations from 19168 given values is multiplied by the square of corresponding 19169 weight. Fill it by 1's if you don't want to solve weighted 19171 N - number of points (optional): 19173 * if given, only first N elements of X/Y/W are processed 19174 * if not given, automatically determined from X/Y/W sizes 19175 XC - points where spline values/derivatives are constrained, 19177 YC - values of constraints, array[0..K-1] 19178 DC - array[0..K-1], types of constraints: 19179 * DC[i]=0 means that S(XC[i])=YC[i] 19180 * DC[i]=1 means that S'(XC[i])=YC[i] 19181 SEE BELOW FOR IMPORTANT INFORMATION ON CONSTRAINTS 19182 K - number of constraints (optional): 19184 * K=0 means no constraints (XC/YC/DC are not used) 19185 * if given, only first K elements of XC/YC/DC are used 19186 * if not given, automatically determined from XC/YC/DC 19187 M - number of basis functions (= 2 * number of nodes), 19192 Info- same format as in LSFitLinearW() subroutine: 19193 * Info>0 task is solved 19194 * Info<=0 an error occurred: 19195 -4 means inconvergence of internal SVD 19196 -3 means inconsistent constraints 19197 -2 means odd M was passed (which is not supported) 19198 -1 means another errors in parameters passed 19199 (N<=0, for example) 19200 S - spline interpolant. 19201 Rep - report, same format as in LSFitLinearW() subroutine. 19202 Following fields are set: 19203 * RMSError rms error on the (X,Y). 19204 * AvgError average error on the (X,Y). 19205 * AvgRelError average relative error on the non-zero Y 19206 * MaxError maximum error 19207 NON-WEIGHTED ERRORS ARE CALCULATED 19210 this subroitine doesn't calculate task's condition number for K<>0. 19213 this subroitine supports only even M's 19218 Subroutine automatically sorts points, so caller may pass unsorted array. 19220 SETTING CONSTRAINTS - DANGERS AND OPPORTUNITIES: 19222 Setting constraints can lead to undesired results, like ill-conditioned 19223 behavior, or inconsistency being detected. From the other side, it allows 19224 us to improve quality of the fit. Here we summarize our experience with 19225 constrained regression splines: 19226 * excessive constraints can be inconsistent. Splines are piecewise cubic 19227 functions, and it is easy to create an example, where large number of 19228 constraints concentrated in small area will result in inconsistency. 19229 Just because spline is not flexible enough to satisfy all of them. And 19230 same constraints spread across the [min(x),max(x)] will be perfectly 19232 * the more evenly constraints are spread across [min(x),max(x)], the more 19233 chances that they will be consistent 19234 * the greater is M (given fixed constraints), the more chances that 19235 constraints will be consistent 19236 * in the general case, consistency of constraints is NOT GUARANTEED. 19237 * in the several special cases, however, we can guarantee consistency. 19238 * one of this cases is M>=4 and constraints on the function value 19239 (AND/OR its derivative) at the interval boundaries. 19240 * another special case is M>=4 and ONE constraint on the function value 19241 (OR, BUT NOT AND, derivative) anywhere in [min(x),max(x)] 19243 Our final recommendation is to use constraints WHEN AND ONLY when you 19244 can't solve your task without them. Anything beyond special cases given 19245 above is not guaranteed and may result in inconsistency. 19247 -- ALGLIB PROJECT -- 19248 Copyright 18.08.2009 by Bochkanov Sergey 19249 *************************************************************************/ 19250 void spline1dfithermitewc(/* Real */ ae_vector* x, 19251 /* Real */ ae_vector* y, 19252 /* Real */ ae_vector* w, 19254 /* Real */ ae_vector* xc, 19255 /* Real */ ae_vector* yc, 19256 /* Integer */ ae_vector* dc, 19260 spline1dinterpolant* s, 19261 spline1dfitreport* rep, 19267 _spline1dinterpolant_clear(s); 19268 _spline1dfitreport_clear(rep); 19270 ae_assert(n>=1, "Spline1DFitHermiteWC: N<1!
", _state); 19271 ae_assert(m>=4, "Spline1DFitHermiteWC: M<4!
", _state); 19272 ae_assert(m%2==0, "Spline1DFitHermiteWC: M is odd!
", _state); 19273 ae_assert(k>=0, "Spline1DFitHermiteWC:
K<0!
", _state); 19274 ae_assert(k<m, "Spline1DFitHermiteWC:
K>=M!
", _state); 19275 ae_assert(x->cnt>=n, "Spline1DFitHermiteWC: Length(X)<N!
", _state); 19276 ae_assert(y->cnt>=n, "Spline1DFitHermiteWC: Length(Y)<N!
", _state); 19277 ae_assert(w->cnt>=n, "Spline1DFitHermiteWC: Length(W)<N!
", _state); 19278 ae_assert(xc->cnt>=k, "Spline1DFitHermiteWC: Length(XC)<
K!
", _state); 19279 ae_assert(yc->cnt>=k, "Spline1DFitHermiteWC: Length(YC)<
K!
", _state); 19280 ae_assert(dc->cnt>=k, "Spline1DFitHermiteWC: Length(DC)<
K!
", _state); 19281 ae_assert(isfinitevector(x, n, _state), "Spline1DFitHermiteWC: X contains infinite
or NAN values!
", _state); 19282 ae_assert(isfinitevector(y, n, _state), "Spline1DFitHermiteWC: Y contains infinite
or NAN values!
", _state); 19283 ae_assert(isfinitevector(w, n, _state), "Spline1DFitHermiteWC: Y contains infinite
or NAN values!
", _state); 19284 ae_assert(isfinitevector(xc, k, _state), "Spline1DFitHermiteWC: X contains infinite
or NAN values!
", _state); 19285 ae_assert(isfinitevector(yc, k, _state), "Spline1DFitHermiteWC: Y contains infinite
or NAN values!
", _state); 19286 for(i=0; i<=k-1; i++) 19288 ae_assert(dc->ptr.p_int[i]==0||dc->ptr.p_int[i]==1, "Spline1DFitHermiteWC: DC[i] is neither 0
or 1!
", _state); 19290 lsfit_spline1dfitinternal(1, x, y, w, n, xc, yc, dc, k, m, info, s, rep, _state); 19294 /************************************************************************* 19295 Least squares fitting by cubic spline. 19297 This subroutine is "lightweight
" alternative for more complex and feature- 19298 rich Spline1DFitCubicWC(). See Spline1DFitCubicWC() for more information 19299 about subroutine parameters (we don't duplicate it here because of length) 19301 -- ALGLIB PROJECT -- 19302 Copyright 18.08.2009 by Bochkanov Sergey 19303 *************************************************************************/ 19304 void spline1dfitcubic(/* Real */ ae_vector* x, 19305 /* Real */ ae_vector* y, 19309 spline1dinterpolant* s, 19310 spline1dfitreport* rep, 19313 ae_frame _frame_block; 19320 ae_frame_make(_state, &_frame_block); 19322 _spline1dinterpolant_clear(s); 19323 _spline1dfitreport_clear(rep); 19324 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 19325 ae_vector_init(&xc, 0, DT_REAL, _state, ae_true); 19326 ae_vector_init(&yc, 0, DT_REAL, _state, ae_true); 19327 ae_vector_init(&dc, 0, DT_INT, _state, ae_true); 19329 ae_assert(n>=1, "Spline1DFitCubic: N<1!
", _state); 19330 ae_assert(m>=4, "Spline1DFitCubic: M<4!
", _state); 19331 ae_assert(x->cnt>=n, "Spline1DFitCubic: Length(X)<N!
", _state); 19332 ae_assert(y->cnt>=n, "Spline1DFitCubic: Length(Y)<N!
", _state); 19333 ae_assert(isfinitevector(x, n, _state), "Spline1DFitCubic: X contains infinite
or NAN values!
", _state); 19334 ae_assert(isfinitevector(y, n, _state), "Spline1DFitCubic: Y contains infinite
or NAN values!
", _state); 19335 ae_vector_set_length(&w, n, _state); 19336 for(i=0; i<=n-1; i++) 19338 w.ptr.p_double[i] = 1; 19340 spline1dfitcubicwc(x, y, &w, n, &xc, &yc, &dc, 0, m, info, s, rep, _state); 19341 ae_frame_leave(_state); 19345 /************************************************************************* 19346 Least squares fitting by Hermite spline. 19348 This subroutine is "lightweight
" alternative for more complex and feature- 19349 rich Spline1DFitHermiteWC(). See Spline1DFitHermiteWC() description for 19350 more information about subroutine parameters (we don't duplicate it here 19351 because of length). 19353 -- ALGLIB PROJECT -- 19354 Copyright 18.08.2009 by Bochkanov Sergey 19355 *************************************************************************/ 19356 void spline1dfithermite(/* Real */ ae_vector* x, 19357 /* Real */ ae_vector* y, 19361 spline1dinterpolant* s, 19362 spline1dfitreport* rep, 19365 ae_frame _frame_block; 19372 ae_frame_make(_state, &_frame_block); 19374 _spline1dinterpolant_clear(s); 19375 _spline1dfitreport_clear(rep); 19376 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 19377 ae_vector_init(&xc, 0, DT_REAL, _state, ae_true); 19378 ae_vector_init(&yc, 0, DT_REAL, _state, ae_true); 19379 ae_vector_init(&dc, 0, DT_INT, _state, ae_true); 19381 ae_assert(n>=1, "Spline1DFitHermite: N<1!
", _state); 19382 ae_assert(m>=4, "Spline1DFitHermite: M<4!
", _state); 19383 ae_assert(m%2==0, "Spline1DFitHermite: M is odd!
", _state); 19384 ae_assert(x->cnt>=n, "Spline1DFitHermite: Length(X)<N!
", _state); 19385 ae_assert(y->cnt>=n, "Spline1DFitHermite: Length(Y)<N!
", _state); 19386 ae_assert(isfinitevector(x, n, _state), "Spline1DFitHermite: X contains infinite
or NAN values!
", _state); 19387 ae_assert(isfinitevector(y, n, _state), "Spline1DFitHermite: Y contains infinite
or NAN values!
", _state); 19388 ae_vector_set_length(&w, n, _state); 19389 for(i=0; i<=n-1; i++) 19391 w.ptr.p_double[i] = 1; 19393 spline1dfithermitewc(x, y, &w, n, &xc, &yc, &dc, 0, m, info, s, rep, _state); 19394 ae_frame_leave(_state); 19398 /************************************************************************* 19399 Weighted linear least squares fitting. 19401 QR decomposition is used to reduce task to MxM, then triangular solver or 19402 SVD-based solver is used depending on condition number of the system. It 19403 allows to maximize speed and retain decent accuracy. 19405 IMPORTANT: if you want to perform polynomial fitting, it may be more 19406 convenient to use PolynomialFit() function. This function gives 19407 best results on polynomial problems and solves numerical 19408 stability issues which arise when you fit high-degree 19409 polynomials to your data. 19412 Y - array[0..N-1] Function values in N points. 19413 W - array[0..N-1] Weights corresponding to function values. 19414 Each summand in square sum of approximation deviations 19415 from given values is multiplied by the square of 19416 corresponding weight. 19417 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 19418 FMatrix[I, J] - value of J-th basis function in I-th point. 19419 N - number of points used. N>=1. 19420 M - number of basis functions, M>=1. 19424 * -4 internal SVD decomposition subroutine failed (very 19425 rare and for degenerate systems only) 19426 * -1 incorrect N/M were specified 19428 C - decomposition coefficients, array[0..M-1] 19429 Rep - fitting report. Following fields are set: 19430 * Rep.TaskRCond reciprocal of condition number 19431 * R2 non-adjusted coefficient of determination 19433 * RMSError rms error on the (X,Y). 19434 * AvgError average error on the (X,Y). 19435 * AvgRelError average relative error on the non-zero Y 19436 * MaxError maximum error 19437 NON-WEIGHTED ERRORS ARE CALCULATED 19439 ERRORS IN PARAMETERS 19441 This solver also calculates different kinds of errors in parameters and 19442 fills corresponding fields of report: 19443 * Rep.CovPar covariance matrix for parameters, array[K,K]. 19444 * Rep.ErrPar errors in parameters, array[K], 19445 errpar = sqrt(diag(CovPar)) 19446 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 19447 best-fit curve from "ideal
" best-fit curve built with 19448 infinite number of samples, array[N]. 19449 errcurve = sqrt(diag(F*CovPar*F')), 19450 where F is functions matrix. 19451 * Rep.Noise vector of per-point estimates of noise, array[N] 19453 NOTE: noise in the data is estimated as follows: 19454 * for fitting without user-supplied weights all points are 19455 assumed to have same level of noise, which is estimated from 19457 * for fitting with user-supplied weights we assume that noise 19458 level in I-th point is inversely proportional to Ith weight. 19459 Coefficient of proportionality is estimated from the data. 19461 NOTE: we apply small amount of regularization when we invert squared 19462 Jacobian and calculate covariance matrix. It guarantees that 19463 algorithm won't divide by zero during inversion, but skews 19464 error estimates a bit (fractional error is about 10^-9). 19466 However, we believe that this difference is insignificant for 19467 all practical purposes except for the situation when you want 19468 to compare ALGLIB results with "reference
" implementation up 19469 to the last significant digit. 19471 NOTE: covariance matrix is estimated using correction for degrees 19472 of freedom (covariances are divided by N-M instead of dividing 19476 Copyright 17.08.2009 by Bochkanov Sergey 19477 *************************************************************************/ 19478 void lsfitlinearw(/* Real */ ae_vector* y, 19479 /* Real */ ae_vector* w, 19480 /* Real */ ae_matrix* fmatrix, 19484 /* Real */ ae_vector* c, 19490 ae_vector_clear(c); 19491 _lsfitreport_clear(rep); 19493 ae_assert(n>=1, "LSFitLinearW: N<1!
", _state); 19494 ae_assert(m>=1, "LSFitLinearW: M<1!
", _state); 19495 ae_assert(y->cnt>=n, "LSFitLinearW:
length(Y)<N!
", _state); 19496 ae_assert(isfinitevector(y, n, _state), "LSFitLinearW: Y contains infinite
or NaN values!
", _state); 19497 ae_assert(w->cnt>=n, "LSFitLinearW:
length(W)<N!
", _state); 19498 ae_assert(isfinitevector(w, n, _state), "LSFitLinearW: W contains infinite
or NaN values!
", _state); 19499 ae_assert(fmatrix->rows>=n, "LSFitLinearW: rows(FMatrix)<N!
", _state); 19500 ae_assert(fmatrix->cols>=m, "LSFitLinearW: cols(FMatrix)<M!
", _state); 19501 ae_assert(apservisfinitematrix(fmatrix, n, m, _state), "LSFitLinearW: FMatrix contains infinite
or NaN values!
", _state); 19502 lsfit_lsfitlinearinternal(y, w, fmatrix, n, m, info, c, rep, _state); 19506 /************************************************************************* 19507 Weighted constained linear least squares fitting. 19509 This is variation of LSFitLinearW(), which searchs for min|A*x=b| given 19510 that K additional constraints C*x=bc are satisfied. It reduces original 19511 task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinearW() 19514 IMPORTANT: if you want to perform polynomial fitting, it may be more 19515 convenient to use PolynomialFit() function. This function gives 19516 best results on polynomial problems and solves numerical 19517 stability issues which arise when you fit high-degree 19518 polynomials to your data. 19521 Y - array[0..N-1] Function values in N points. 19522 W - array[0..N-1] Weights corresponding to function values. 19523 Each summand in square sum of approximation deviations 19524 from given values is multiplied by the square of 19525 corresponding weight. 19526 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 19527 FMatrix[I,J] - value of J-th basis function in I-th point. 19528 CMatrix - a table of constraints, array[0..K-1,0..M]. 19529 I-th row of CMatrix corresponds to I-th linear constraint: 19530 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M] 19531 N - number of points used. N>=1. 19532 M - number of basis functions, M>=1. 19533 K - number of constraints, 0 <= K < M 19534 K=0 corresponds to absence of constraints. 19538 * -4 internal SVD decomposition subroutine failed (very 19539 rare and for degenerate systems only) 19540 * -3 either too many constraints (M or more), 19541 degenerate constraints (some constraints are 19542 repetead twice) or inconsistent constraints were 19545 C - decomposition coefficients, array[0..M-1] 19546 Rep - fitting report. Following fields are set: 19547 * R2 non-adjusted coefficient of determination 19549 * RMSError rms error on the (X,Y). 19550 * AvgError average error on the (X,Y). 19551 * AvgRelError average relative error on the non-zero Y 19552 * MaxError maximum error 19553 NON-WEIGHTED ERRORS ARE CALCULATED 19556 this subroitine doesn't calculate task's condition number for K<>0. 19558 ERRORS IN PARAMETERS 19560 This solver also calculates different kinds of errors in parameters and 19561 fills corresponding fields of report: 19562 * Rep.CovPar covariance matrix for parameters, array[K,K]. 19563 * Rep.ErrPar errors in parameters, array[K], 19564 errpar = sqrt(diag(CovPar)) 19565 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 19566 best-fit curve from "ideal
" best-fit curve built with 19567 infinite number of samples, array[N]. 19568 errcurve = sqrt(diag(F*CovPar*F')), 19569 where F is functions matrix. 19570 * Rep.Noise vector of per-point estimates of noise, array[N] 19572 IMPORTANT: errors in parameters are calculated without taking into 19573 account boundary/linear constraints! Presence of constraints 19574 changes distribution of errors, but there is no easy way to 19575 account for constraints when you calculate covariance matrix. 19577 NOTE: noise in the data is estimated as follows: 19578 * for fitting without user-supplied weights all points are 19579 assumed to have same level of noise, which is estimated from 19581 * for fitting with user-supplied weights we assume that noise 19582 level in I-th point is inversely proportional to Ith weight. 19583 Coefficient of proportionality is estimated from the data. 19585 NOTE: we apply small amount of regularization when we invert squared 19586 Jacobian and calculate covariance matrix. It guarantees that 19587 algorithm won't divide by zero during inversion, but skews 19588 error estimates a bit (fractional error is about 10^-9). 19590 However, we believe that this difference is insignificant for 19591 all practical purposes except for the situation when you want 19592 to compare ALGLIB results with "reference
" implementation up 19593 to the last significant digit. 19595 NOTE: covariance matrix is estimated using correction for degrees 19596 of freedom (covariances are divided by N-M instead of dividing 19600 Copyright 07.09.2009 by Bochkanov Sergey 19601 *************************************************************************/ 19602 void lsfitlinearwc(/* Real */ ae_vector* y, 19603 /* Real */ ae_vector* w, 19604 /* Real */ ae_matrix* fmatrix, 19605 /* Real */ ae_matrix* cmatrix, 19610 /* Real */ ae_vector* c, 19614 ae_frame _frame_block; 19616 ae_matrix _cmatrix; 19626 ae_frame_make(_state, &_frame_block); 19627 ae_vector_init_copy(&_y, y, _state, ae_true); 19629 ae_matrix_init_copy(&_cmatrix, cmatrix, _state, ae_true); 19630 cmatrix = &_cmatrix; 19632 ae_vector_clear(c); 19633 _lsfitreport_clear(rep); 19634 ae_vector_init(&tau, 0, DT_REAL, _state, ae_true); 19635 ae_matrix_init(&q, 0, 0, DT_REAL, _state, ae_true); 19636 ae_matrix_init(&f2, 0, 0, DT_REAL, _state, ae_true); 19637 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 19638 ae_vector_init(&c0, 0, DT_REAL, _state, ae_true); 19640 ae_assert(n>=1, "LSFitLinearWC: N<1!
", _state); 19641 ae_assert(m>=1, "LSFitLinearWC: M<1!
", _state); 19642 ae_assert(k>=0, "LSFitLinearWC:
K<0!
", _state); 19643 ae_assert(y->cnt>=n, "LSFitLinearWC:
length(Y)<N!
", _state); 19644 ae_assert(isfinitevector(y, n, _state), "LSFitLinearWC: Y contains infinite
or NaN values!
", _state); 19645 ae_assert(w->cnt>=n, "LSFitLinearWC:
length(W)<N!
", _state); 19646 ae_assert(isfinitevector(w, n, _state), "LSFitLinearWC: W contains infinite
or NaN values!
", _state); 19647 ae_assert(fmatrix->rows>=n, "LSFitLinearWC: rows(FMatrix)<N!
", _state); 19648 ae_assert(fmatrix->cols>=m, "LSFitLinearWC: cols(FMatrix)<M!
", _state); 19649 ae_assert(apservisfinitematrix(fmatrix, n, m, _state), "LSFitLinearWC: FMatrix contains infinite
or NaN values!
", _state); 19650 ae_assert(cmatrix->rows>=k, "LSFitLinearWC: rows(CMatrix)<
K!
", _state); 19651 ae_assert(cmatrix->cols>=m+1||k==0, "LSFitLinearWC: cols(CMatrix)<M+1!
", _state); 19652 ae_assert(apservisfinitematrix(cmatrix, k, m+1, _state), "LSFitLinearWC: CMatrix contains infinite
or NaN values!
", _state); 19656 ae_frame_leave(_state); 19669 lsfit_lsfitlinearinternal(y, w, fmatrix, n, m, info, c, rep, _state); 19675 * First, find general form solution of constraints system: 19676 * * factorize C = L*Q 19678 * * fill upper part of C with zeros (for RCond) 19680 * We got C=C0+Q2'*y where Q2 is lower M-K rows of Q. 19682 rmatrixlq(cmatrix, k, m, &tau, _state); 19683 rmatrixlqunpackq(cmatrix, k, m, &tau, m, &q, _state); 19684 for(i=0; i<=k-1; i++) 19686 for(j=i+1; j<=m-1; j++) 19688 cmatrix->ptr.pp_double[i][j] = 0.0; 19691 if( ae_fp_less(rmatrixlurcondinf(cmatrix, k, _state),1000*ae_machineepsilon) ) 19694 ae_frame_leave(_state); 19697 ae_vector_set_length(&tmp, k, _state); 19698 for(i=0; i<=k-1; i++) 19702 v = ae_v_dotproduct(&cmatrix->ptr.pp_double[i][0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,i-1)); 19708 tmp.ptr.p_double[i] = (cmatrix->ptr.pp_double[i][m]-v)/cmatrix->ptr.pp_double[i][i]; 19710 ae_vector_set_length(&c0, m, _state); 19711 for(i=0; i<=m-1; i++) 19713 c0.ptr.p_double[i] = 0; 19715 for(i=0; i<=k-1; i++) 19717 v = tmp.ptr.p_double[i]; 19718 ae_v_addd(&c0.ptr.p_double[0], 1, &q.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 19722 * Second, prepare modified matrix F2 = F*Q2' and solve modified task 19724 ae_vector_set_length(&tmp, ae_maxint(n, m, _state)+1, _state); 19725 ae_matrix_set_length(&f2, n, m-k, _state); 19726 matrixvectormultiply(fmatrix, 0, n-1, 0, m-1, ae_false, &c0, 0, m-1, -1.0, y, 0, n-1, 1.0, _state); 19727 matrixmatrixmultiply(fmatrix, 0, n-1, 0, m-1, ae_false, &q, k, m-1, 0, m-1, ae_true, 1.0, &f2, 0, n-1, 0, m-k-1, 0.0, &tmp, _state); 19728 lsfit_lsfitlinearinternal(y, w, &f2, n, m-k, info, &tmp, rep, _state); 19729 rep->taskrcond = -1; 19732 ae_frame_leave(_state); 19737 * then, convert back to original answer: C = C0 + Q2'*Y0 19739 ae_vector_set_length(c, m, _state); 19740 ae_v_move(&c->ptr.p_double[0], 1, &c0.ptr.p_double[0], 1, ae_v_len(0,m-1)); 19741 matrixvectormultiply(&q, k, m-1, 0, m-1, ae_true, &tmp, 0, m-k-1, 1.0, c, 0, m-1, 1.0, _state); 19743 ae_frame_leave(_state); 19747 /************************************************************************* 19748 Linear least squares fitting. 19750 QR decomposition is used to reduce task to MxM, then triangular solver or 19751 SVD-based solver is used depending on condition number of the system. It 19752 allows to maximize speed and retain decent accuracy. 19754 IMPORTANT: if you want to perform polynomial fitting, it may be more 19755 convenient to use PolynomialFit() function. This function gives 19756 best results on polynomial problems and solves numerical 19757 stability issues which arise when you fit high-degree 19758 polynomials to your data. 19761 Y - array[0..N-1] Function values in N points. 19762 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 19763 FMatrix[I, J] - value of J-th basis function in I-th point. 19764 N - number of points used. N>=1. 19765 M - number of basis functions, M>=1. 19769 * -4 internal SVD decomposition subroutine failed (very 19770 rare and for degenerate systems only) 19772 C - decomposition coefficients, array[0..M-1] 19773 Rep - fitting report. Following fields are set: 19774 * Rep.TaskRCond reciprocal of condition number 19775 * R2 non-adjusted coefficient of determination 19777 * RMSError rms error on the (X,Y). 19778 * AvgError average error on the (X,Y). 19779 * AvgRelError average relative error on the non-zero Y 19780 * MaxError maximum error 19781 NON-WEIGHTED ERRORS ARE CALCULATED 19783 ERRORS IN PARAMETERS 19785 This solver also calculates different kinds of errors in parameters and 19786 fills corresponding fields of report: 19787 * Rep.CovPar covariance matrix for parameters, array[K,K]. 19788 * Rep.ErrPar errors in parameters, array[K], 19789 errpar = sqrt(diag(CovPar)) 19790 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 19791 best-fit curve from "ideal
" best-fit curve built with 19792 infinite number of samples, array[N]. 19793 errcurve = sqrt(diag(F*CovPar*F')), 19794 where F is functions matrix. 19795 * Rep.Noise vector of per-point estimates of noise, array[N] 19797 NOTE: noise in the data is estimated as follows: 19798 * for fitting without user-supplied weights all points are 19799 assumed to have same level of noise, which is estimated from 19801 * for fitting with user-supplied weights we assume that noise 19802 level in I-th point is inversely proportional to Ith weight. 19803 Coefficient of proportionality is estimated from the data. 19805 NOTE: we apply small amount of regularization when we invert squared 19806 Jacobian and calculate covariance matrix. It guarantees that 19807 algorithm won't divide by zero during inversion, but skews 19808 error estimates a bit (fractional error is about 10^-9). 19810 However, we believe that this difference is insignificant for 19811 all practical purposes except for the situation when you want 19812 to compare ALGLIB results with "reference
" implementation up 19813 to the last significant digit. 19815 NOTE: covariance matrix is estimated using correction for degrees 19816 of freedom (covariances are divided by N-M instead of dividing 19820 Copyright 17.08.2009 by Bochkanov Sergey 19821 *************************************************************************/ 19822 void lsfitlinear(/* Real */ ae_vector* y, 19823 /* Real */ ae_matrix* fmatrix, 19827 /* Real */ ae_vector* c, 19831 ae_frame _frame_block; 19835 ae_frame_make(_state, &_frame_block); 19837 ae_vector_clear(c); 19838 _lsfitreport_clear(rep); 19839 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 19841 ae_assert(n>=1, "LSFitLinear: N<1!
", _state); 19842 ae_assert(m>=1, "LSFitLinear: M<1!
", _state); 19843 ae_assert(y->cnt>=n, "LSFitLinear:
length(Y)<N!
", _state); 19844 ae_assert(isfinitevector(y, n, _state), "LSFitLinear: Y contains infinite
or NaN values!
", _state); 19845 ae_assert(fmatrix->rows>=n, "LSFitLinear: rows(FMatrix)<N!
", _state); 19846 ae_assert(fmatrix->cols>=m, "LSFitLinear: cols(FMatrix)<M!
", _state); 19847 ae_assert(apservisfinitematrix(fmatrix, n, m, _state), "LSFitLinear: FMatrix contains infinite
or NaN values!
", _state); 19848 ae_vector_set_length(&w, n, _state); 19849 for(i=0; i<=n-1; i++) 19851 w.ptr.p_double[i] = 1; 19853 lsfit_lsfitlinearinternal(y, &w, fmatrix, n, m, info, c, rep, _state); 19854 ae_frame_leave(_state); 19858 /************************************************************************* 19859 Constained linear least squares fitting. 19861 This is variation of LSFitLinear(), which searchs for min|A*x=b| given 19862 that K additional constraints C*x=bc are satisfied. It reduces original 19863 task to modified one: min|B*y-d| WITHOUT constraints, then LSFitLinear() 19866 IMPORTANT: if you want to perform polynomial fitting, it may be more 19867 convenient to use PolynomialFit() function. This function gives 19868 best results on polynomial problems and solves numerical 19869 stability issues which arise when you fit high-degree 19870 polynomials to your data. 19873 Y - array[0..N-1] Function values in N points. 19874 FMatrix - a table of basis functions values, array[0..N-1, 0..M-1]. 19875 FMatrix[I,J] - value of J-th basis function in I-th point. 19876 CMatrix - a table of constraints, array[0..K-1,0..M]. 19877 I-th row of CMatrix corresponds to I-th linear constraint: 19878 CMatrix[I,0]*C[0] + ... + CMatrix[I,M-1]*C[M-1] = CMatrix[I,M] 19879 N - number of points used. N>=1. 19880 M - number of basis functions, M>=1. 19881 K - number of constraints, 0 <= K < M 19882 K=0 corresponds to absence of constraints. 19886 * -4 internal SVD decomposition subroutine failed (very 19887 rare and for degenerate systems only) 19888 * -3 either too many constraints (M or more), 19889 degenerate constraints (some constraints are 19890 repetead twice) or inconsistent constraints were 19893 C - decomposition coefficients, array[0..M-1] 19894 Rep - fitting report. Following fields are set: 19895 * R2 non-adjusted coefficient of determination 19897 * RMSError rms error on the (X,Y). 19898 * AvgError average error on the (X,Y). 19899 * AvgRelError average relative error on the non-zero Y 19900 * MaxError maximum error 19901 NON-WEIGHTED ERRORS ARE CALCULATED 19904 this subroitine doesn't calculate task's condition number for K<>0. 19906 ERRORS IN PARAMETERS 19908 This solver also calculates different kinds of errors in parameters and 19909 fills corresponding fields of report: 19910 * Rep.CovPar covariance matrix for parameters, array[K,K]. 19911 * Rep.ErrPar errors in parameters, array[K], 19912 errpar = sqrt(diag(CovPar)) 19913 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 19914 best-fit curve from "ideal
" best-fit curve built with 19915 infinite number of samples, array[N]. 19916 errcurve = sqrt(diag(F*CovPar*F')), 19917 where F is functions matrix. 19918 * Rep.Noise vector of per-point estimates of noise, array[N] 19920 IMPORTANT: errors in parameters are calculated without taking into 19921 account boundary/linear constraints! Presence of constraints 19922 changes distribution of errors, but there is no easy way to 19923 account for constraints when you calculate covariance matrix. 19925 NOTE: noise in the data is estimated as follows: 19926 * for fitting without user-supplied weights all points are 19927 assumed to have same level of noise, which is estimated from 19929 * for fitting with user-supplied weights we assume that noise 19930 level in I-th point is inversely proportional to Ith weight. 19931 Coefficient of proportionality is estimated from the data. 19933 NOTE: we apply small amount of regularization when we invert squared 19934 Jacobian and calculate covariance matrix. It guarantees that 19935 algorithm won't divide by zero during inversion, but skews 19936 error estimates a bit (fractional error is about 10^-9). 19938 However, we believe that this difference is insignificant for 19939 all practical purposes except for the situation when you want 19940 to compare ALGLIB results with "reference
" implementation up 19941 to the last significant digit. 19943 NOTE: covariance matrix is estimated using correction for degrees 19944 of freedom (covariances are divided by N-M instead of dividing 19948 Copyright 07.09.2009 by Bochkanov Sergey 19949 *************************************************************************/ 19950 void lsfitlinearc(/* Real */ ae_vector* y, 19951 /* Real */ ae_matrix* fmatrix, 19952 /* Real */ ae_matrix* cmatrix, 19957 /* Real */ ae_vector* c, 19961 ae_frame _frame_block; 19966 ae_frame_make(_state, &_frame_block); 19967 ae_vector_init_copy(&_y, y, _state, ae_true); 19970 ae_vector_clear(c); 19971 _lsfitreport_clear(rep); 19972 ae_vector_init(&w, 0, DT_REAL, _state, ae_true); 19974 ae_assert(n>=1, "LSFitLinearC: N<1!
", _state); 19975 ae_assert(m>=1, "LSFitLinearC: M<1!
", _state); 19976 ae_assert(k>=0, "LSFitLinearC:
K<0!
", _state); 19977 ae_assert(y->cnt>=n, "LSFitLinearC:
length(Y)<N!
", _state); 19978 ae_assert(isfinitevector(y, n, _state), "LSFitLinearC: Y contains infinite
or NaN values!
", _state); 19979 ae_assert(fmatrix->rows>=n, "LSFitLinearC: rows(FMatrix)<N!
", _state); 19980 ae_assert(fmatrix->cols>=m, "LSFitLinearC: cols(FMatrix)<M!
", _state); 19981 ae_assert(apservisfinitematrix(fmatrix, n, m, _state), "LSFitLinearC: FMatrix contains infinite
or NaN values!
", _state); 19982 ae_assert(cmatrix->rows>=k, "LSFitLinearC: rows(CMatrix)<
K!
", _state); 19983 ae_assert(cmatrix->cols>=m+1||k==0, "LSFitLinearC: cols(CMatrix)<M+1!
", _state); 19984 ae_assert(apservisfinitematrix(cmatrix, k, m+1, _state), "LSFitLinearC: CMatrix contains infinite
or NaN values!
", _state); 19985 ae_vector_set_length(&w, n, _state); 19986 for(i=0; i<=n-1; i++) 19988 w.ptr.p_double[i] = 1; 19990 lsfitlinearwc(y, &w, fmatrix, cmatrix, n, m, k, info, c, rep, _state); 19991 ae_frame_leave(_state); 19995 /************************************************************************* 19996 Weighted nonlinear least squares fitting using function values only. 19998 Combination of numerical differentiation and secant updates is used to 19999 obtain function Jacobian. 20001 Nonlinear task min(F(c)) is solved, where 20003 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 20005 * N is a number of points, 20006 * M is a dimension of a space points belong to, 20007 * K is a dimension of a space of parameters being fitted, 20008 * w is an N-dimensional vector of weight coefficients, 20009 * x is a set of N points, each of them is an M-dimensional vector, 20010 * c is a K-dimensional vector of parameters being fitted 20012 This subroutine uses only f(c,x[i]). 20015 X - array[0..N-1,0..M-1], points (one row = one point) 20016 Y - array[0..N-1], function values. 20017 W - weights, array[0..N-1] 20018 C - array[0..K-1], initial approximation to the solution, 20019 N - number of points, N>1 20020 M - dimension of space 20021 K - number of parameters being fitted 20022 DiffStep- numerical differentiation step; 20023 should not be very small or large; 20024 large = loss of accuracy 20025 small = growth of round-off errors 20028 State - structure which stores algorithm state 20031 Copyright 18.10.2008 by Bochkanov Sergey 20032 *************************************************************************/ 20033 void lsfitcreatewf(/* Real */ ae_matrix* x, 20034 /* Real */ ae_vector* y, 20035 /* Real */ ae_vector* w, 20036 /* Real */ ae_vector* c, 20046 _lsfitstate_clear(state); 20048 ae_assert(n>=1, "LSFitCreateWF: N<1!
", _state); 20049 ae_assert(m>=1, "LSFitCreateWF: M<1!
", _state); 20050 ae_assert(k>=1, "LSFitCreateWF:
K<1!
", _state); 20051 ae_assert(c->cnt>=k, "LSFitCreateWF:
length(C)<
K!
", _state); 20052 ae_assert(isfinitevector(c, k, _state), "LSFitCreateWF: C contains infinite
or NaN values!
", _state); 20053 ae_assert(y->cnt>=n, "LSFitCreateWF:
length(Y)<N!
", _state); 20054 ae_assert(isfinitevector(y, n, _state), "LSFitCreateWF: Y contains infinite
or NaN values!
", _state); 20055 ae_assert(w->cnt>=n, "LSFitCreateWF:
length(W)<N!
", _state); 20056 ae_assert(isfinitevector(w, n, _state), "LSFitCreateWF: W contains infinite
or NaN values!
", _state); 20057 ae_assert(x->rows>=n, "LSFitCreateWF: rows(X)<N!
", _state); 20058 ae_assert(x->cols>=m, "LSFitCreateWF: cols(X)<M!
", _state); 20059 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateWF: X contains infinite
or NaN values!
", _state); 20060 ae_assert(ae_isfinite(diffstep, _state), "LSFitCreateWF: DiffStep is not finite!
", _state); 20061 ae_assert(ae_fp_greater(diffstep,0), "LSFitCreateWF: DiffStep<=0!
", _state); 20062 state->teststep = 0; 20063 state->diffstep = diffstep; 20064 state->npoints = n; 20065 state->nweights = n; 20069 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20070 lsfitsetstpmax(state, 0.0, _state); 20071 lsfitsetxrep(state, ae_false, _state); 20072 ae_matrix_set_length(&state->taskx, n, m, _state); 20073 ae_vector_set_length(&state->tasky, n, _state); 20074 ae_vector_set_length(&state->taskw, n, _state); 20075 ae_vector_set_length(&state->c, k, _state); 20076 ae_vector_set_length(&state->x, m, _state); 20077 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20078 ae_v_move(&state->taskw.ptr.p_double[0], 1, &w->ptr.p_double[0], 1, ae_v_len(0,n-1)); 20079 for(i=0; i<=n-1; i++) 20081 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20082 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20084 ae_vector_set_length(&state->s, k, _state); 20085 ae_vector_set_length(&state->bndl, k, _state); 20086 ae_vector_set_length(&state->bndu, k, _state); 20087 for(i=0; i<=k-1; i++) 20089 state->s.ptr.p_double[i] = 1.0; 20090 state->bndl.ptr.p_double[i] = _state->v_neginf; 20091 state->bndu.ptr.p_double[i] = _state->v_posinf; 20093 state->optalgo = 0; 20094 state->prevnpt = -1; 20095 state->prevalgo = -1; 20096 minlmcreatev(k, n, &state->c, diffstep, &state->optstate, _state); 20097 lsfit_lsfitclearrequestfields(state, _state); 20098 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20099 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20100 state->rstate.stage = -1; 20104 /************************************************************************* 20105 Nonlinear least squares fitting using function values only. 20107 Combination of numerical differentiation and secant updates is used to 20108 obtain function Jacobian. 20110 Nonlinear task min(F(c)) is solved, where 20112 F(c) = (f(c,x[0])-y[0])^2 + ... + (f(c,x[n-1])-y[n-1])^2, 20114 * N is a number of points, 20115 * M is a dimension of a space points belong to, 20116 * K is a dimension of a space of parameters being fitted, 20117 * w is an N-dimensional vector of weight coefficients, 20118 * x is a set of N points, each of them is an M-dimensional vector, 20119 * c is a K-dimensional vector of parameters being fitted 20121 This subroutine uses only f(c,x[i]). 20124 X - array[0..N-1,0..M-1], points (one row = one point) 20125 Y - array[0..N-1], function values. 20126 C - array[0..K-1], initial approximation to the solution, 20127 N - number of points, N>1 20128 M - dimension of space 20129 K - number of parameters being fitted 20130 DiffStep- numerical differentiation step; 20131 should not be very small or large; 20132 large = loss of accuracy 20133 small = growth of round-off errors 20136 State - structure which stores algorithm state 20139 Copyright 18.10.2008 by Bochkanov Sergey 20140 *************************************************************************/ 20141 void lsfitcreatef(/* Real */ ae_matrix* x, 20142 /* Real */ ae_vector* y, 20143 /* Real */ ae_vector* c, 20153 _lsfitstate_clear(state); 20155 ae_assert(n>=1, "LSFitCreateF: N<1!
", _state); 20156 ae_assert(m>=1, "LSFitCreateF: M<1!
", _state); 20157 ae_assert(k>=1, "LSFitCreateF:
K<1!
", _state); 20158 ae_assert(c->cnt>=k, "LSFitCreateF:
length(C)<
K!
", _state); 20159 ae_assert(isfinitevector(c, k, _state), "LSFitCreateF: C contains infinite
or NaN values!
", _state); 20160 ae_assert(y->cnt>=n, "LSFitCreateF:
length(Y)<N!
", _state); 20161 ae_assert(isfinitevector(y, n, _state), "LSFitCreateF: Y contains infinite
or NaN values!
", _state); 20162 ae_assert(x->rows>=n, "LSFitCreateF: rows(X)<N!
", _state); 20163 ae_assert(x->cols>=m, "LSFitCreateF: cols(X)<M!
", _state); 20164 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateF: X contains infinite
or NaN values!
", _state); 20165 ae_assert(x->rows>=n, "LSFitCreateF: rows(X)<N!
", _state); 20166 ae_assert(x->cols>=m, "LSFitCreateF: cols(X)<M!
", _state); 20167 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateF: X contains infinite
or NaN values!
", _state); 20168 ae_assert(ae_isfinite(diffstep, _state), "LSFitCreateF: DiffStep is not finite!
", _state); 20169 ae_assert(ae_fp_greater(diffstep,0), "LSFitCreateF: DiffStep<=0!
", _state); 20170 state->teststep = 0; 20171 state->diffstep = diffstep; 20172 state->npoints = n; 20176 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20177 lsfitsetstpmax(state, 0.0, _state); 20178 lsfitsetxrep(state, ae_false, _state); 20179 ae_matrix_set_length(&state->taskx, n, m, _state); 20180 ae_vector_set_length(&state->tasky, n, _state); 20181 ae_vector_set_length(&state->c, k, _state); 20182 ae_vector_set_length(&state->x, m, _state); 20183 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20184 for(i=0; i<=n-1; i++) 20186 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20187 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20189 ae_vector_set_length(&state->s, k, _state); 20190 ae_vector_set_length(&state->bndl, k, _state); 20191 ae_vector_set_length(&state->bndu, k, _state); 20192 for(i=0; i<=k-1; i++) 20194 state->s.ptr.p_double[i] = 1.0; 20195 state->bndl.ptr.p_double[i] = _state->v_neginf; 20196 state->bndu.ptr.p_double[i] = _state->v_posinf; 20198 state->optalgo = 0; 20199 state->prevnpt = -1; 20200 state->prevalgo = -1; 20201 minlmcreatev(k, n, &state->c, diffstep, &state->optstate, _state); 20202 lsfit_lsfitclearrequestfields(state, _state); 20203 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20204 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20205 state->rstate.stage = -1; 20209 /************************************************************************* 20210 Weighted nonlinear least squares fitting using gradient only. 20212 Nonlinear task min(F(c)) is solved, where 20214 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 20216 * N is a number of points, 20217 * M is a dimension of a space points belong to, 20218 * K is a dimension of a space of parameters being fitted, 20219 * w is an N-dimensional vector of weight coefficients, 20220 * x is a set of N points, each of them is an M-dimensional vector, 20221 * c is a K-dimensional vector of parameters being fitted 20223 This subroutine uses only f(c,x[i]) and its gradient. 20226 X - array[0..N-1,0..M-1], points (one row = one point) 20227 Y - array[0..N-1], function values. 20228 W - weights, array[0..N-1] 20229 C - array[0..K-1], initial approximation to the solution, 20230 N - number of points, N>1 20231 M - dimension of space 20232 K - number of parameters being fitted 20233 CheapFG - boolean flag, which is: 20234 * True if both function and gradient calculation complexity 20235 are less than O(M^2). An improved algorithm can 20236 be used which corresponds to FGJ scheme from 20239 Standard Jacibian-bases Levenberg-Marquardt algo 20240 will be used (FJ scheme). 20243 State - structure which stores algorithm state 20247 LSFitCreateFG (fitting without weights) 20248 LSFitCreateWFGH (fitting using Hessian) 20249 LSFitCreateFGH (fitting using Hessian, without weights) 20252 Copyright 17.08.2009 by Bochkanov Sergey 20253 *************************************************************************/ 20254 void lsfitcreatewfg(/* Real */ ae_matrix* x, 20255 /* Real */ ae_vector* y, 20256 /* Real */ ae_vector* w, 20257 /* Real */ ae_vector* c, 20267 _lsfitstate_clear(state); 20269 ae_assert(n>=1, "LSFitCreateWFG: N<1!
", _state); 20270 ae_assert(m>=1, "LSFitCreateWFG: M<1!
", _state); 20271 ae_assert(k>=1, "LSFitCreateWFG:
K<1!
", _state); 20272 ae_assert(c->cnt>=k, "LSFitCreateWFG:
length(C)<
K!
", _state); 20273 ae_assert(isfinitevector(c, k, _state), "LSFitCreateWFG: C contains infinite
or NaN values!
", _state); 20274 ae_assert(y->cnt>=n, "LSFitCreateWFG:
length(Y)<N!
", _state); 20275 ae_assert(isfinitevector(y, n, _state), "LSFitCreateWFG: Y contains infinite
or NaN values!
", _state); 20276 ae_assert(w->cnt>=n, "LSFitCreateWFG:
length(W)<N!
", _state); 20277 ae_assert(isfinitevector(w, n, _state), "LSFitCreateWFG: W contains infinite
or NaN values!
", _state); 20278 ae_assert(x->rows>=n, "LSFitCreateWFG: rows(X)<N!
", _state); 20279 ae_assert(x->cols>=m, "LSFitCreateWFG: cols(X)<M!
", _state); 20280 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateWFG: X contains infinite
or NaN values!
", _state); 20281 state->teststep = 0; 20282 state->diffstep = 0; 20283 state->npoints = n; 20284 state->nweights = n; 20288 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20289 lsfitsetstpmax(state, 0.0, _state); 20290 lsfitsetxrep(state, ae_false, _state); 20291 ae_matrix_set_length(&state->taskx, n, m, _state); 20292 ae_vector_set_length(&state->tasky, n, _state); 20293 ae_vector_set_length(&state->taskw, n, _state); 20294 ae_vector_set_length(&state->c, k, _state); 20295 ae_vector_set_length(&state->x, m, _state); 20296 ae_vector_set_length(&state->g, k, _state); 20297 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20298 ae_v_move(&state->taskw.ptr.p_double[0], 1, &w->ptr.p_double[0], 1, ae_v_len(0,n-1)); 20299 for(i=0; i<=n-1; i++) 20301 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20302 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20304 ae_vector_set_length(&state->s, k, _state); 20305 ae_vector_set_length(&state->bndl, k, _state); 20306 ae_vector_set_length(&state->bndu, k, _state); 20307 for(i=0; i<=k-1; i++) 20309 state->s.ptr.p_double[i] = 1.0; 20310 state->bndl.ptr.p_double[i] = _state->v_neginf; 20311 state->bndu.ptr.p_double[i] = _state->v_posinf; 20313 state->optalgo = 1; 20314 state->prevnpt = -1; 20315 state->prevalgo = -1; 20318 minlmcreatevgj(k, n, &state->c, &state->optstate, _state); 20322 minlmcreatevj(k, n, &state->c, &state->optstate, _state); 20324 lsfit_lsfitclearrequestfields(state, _state); 20325 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20326 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20327 state->rstate.stage = -1; 20331 /************************************************************************* 20332 Nonlinear least squares fitting using gradient only, without individual 20335 Nonlinear task min(F(c)) is solved, where 20337 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2, 20339 * N is a number of points, 20340 * M is a dimension of a space points belong to, 20341 * K is a dimension of a space of parameters being fitted, 20342 * x is a set of N points, each of them is an M-dimensional vector, 20343 * c is a K-dimensional vector of parameters being fitted 20345 This subroutine uses only f(c,x[i]) and its gradient. 20348 X - array[0..N-1,0..M-1], points (one row = one point) 20349 Y - array[0..N-1], function values. 20350 C - array[0..K-1], initial approximation to the solution, 20351 N - number of points, N>1 20352 M - dimension of space 20353 K - number of parameters being fitted 20354 CheapFG - boolean flag, which is: 20355 * True if both function and gradient calculation complexity 20356 are less than O(M^2). An improved algorithm can 20357 be used which corresponds to FGJ scheme from 20360 Standard Jacibian-bases Levenberg-Marquardt algo 20361 will be used (FJ scheme). 20364 State - structure which stores algorithm state 20367 Copyright 17.08.2009 by Bochkanov Sergey 20368 *************************************************************************/ 20369 void lsfitcreatefg(/* Real */ ae_matrix* x, 20370 /* Real */ ae_vector* y, 20371 /* Real */ ae_vector* c, 20381 _lsfitstate_clear(state); 20383 ae_assert(n>=1, "LSFitCreateFG: N<1!
", _state); 20384 ae_assert(m>=1, "LSFitCreateFG: M<1!
", _state); 20385 ae_assert(k>=1, "LSFitCreateFG:
K<1!
", _state); 20386 ae_assert(c->cnt>=k, "LSFitCreateFG:
length(C)<
K!
", _state); 20387 ae_assert(isfinitevector(c, k, _state), "LSFitCreateFG: C contains infinite
or NaN values!
", _state); 20388 ae_assert(y->cnt>=n, "LSFitCreateFG:
length(Y)<N!
", _state); 20389 ae_assert(isfinitevector(y, n, _state), "LSFitCreateFG: Y contains infinite
or NaN values!
", _state); 20390 ae_assert(x->rows>=n, "LSFitCreateFG: rows(X)<N!
", _state); 20391 ae_assert(x->cols>=m, "LSFitCreateFG: cols(X)<M!
", _state); 20392 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateFG: X contains infinite
or NaN values!
", _state); 20393 ae_assert(x->rows>=n, "LSFitCreateFG: rows(X)<N!
", _state); 20394 ae_assert(x->cols>=m, "LSFitCreateFG: cols(X)<M!
", _state); 20395 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateFG: X contains infinite
or NaN values!
", _state); 20396 state->teststep = 0; 20397 state->diffstep = 0; 20398 state->npoints = n; 20402 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20403 lsfitsetstpmax(state, 0.0, _state); 20404 lsfitsetxrep(state, ae_false, _state); 20405 ae_matrix_set_length(&state->taskx, n, m, _state); 20406 ae_vector_set_length(&state->tasky, n, _state); 20407 ae_vector_set_length(&state->c, k, _state); 20408 ae_vector_set_length(&state->x, m, _state); 20409 ae_vector_set_length(&state->g, k, _state); 20410 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20411 for(i=0; i<=n-1; i++) 20413 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20414 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20416 ae_vector_set_length(&state->s, k, _state); 20417 ae_vector_set_length(&state->bndl, k, _state); 20418 ae_vector_set_length(&state->bndu, k, _state); 20419 for(i=0; i<=k-1; i++) 20421 state->s.ptr.p_double[i] = 1.0; 20422 state->bndl.ptr.p_double[i] = _state->v_neginf; 20423 state->bndu.ptr.p_double[i] = _state->v_posinf; 20425 state->optalgo = 1; 20426 state->prevnpt = -1; 20427 state->prevalgo = -1; 20430 minlmcreatevgj(k, n, &state->c, &state->optstate, _state); 20434 minlmcreatevj(k, n, &state->c, &state->optstate, _state); 20436 lsfit_lsfitclearrequestfields(state, _state); 20437 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20438 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20439 state->rstate.stage = -1; 20443 /************************************************************************* 20444 Weighted nonlinear least squares fitting using gradient/Hessian. 20446 Nonlinear task min(F(c)) is solved, where 20448 F(c) = (w[0]*(f(c,x[0])-y[0]))^2 + ... + (w[n-1]*(f(c,x[n-1])-y[n-1]))^2, 20450 * N is a number of points, 20451 * M is a dimension of a space points belong to, 20452 * K is a dimension of a space of parameters being fitted, 20453 * w is an N-dimensional vector of weight coefficients, 20454 * x is a set of N points, each of them is an M-dimensional vector, 20455 * c is a K-dimensional vector of parameters being fitted 20457 This subroutine uses f(c,x[i]), its gradient and its Hessian. 20460 X - array[0..N-1,0..M-1], points (one row = one point) 20461 Y - array[0..N-1], function values. 20462 W - weights, array[0..N-1] 20463 C - array[0..K-1], initial approximation to the solution, 20464 N - number of points, N>1 20465 M - dimension of space 20466 K - number of parameters being fitted 20469 State - structure which stores algorithm state 20472 Copyright 17.08.2009 by Bochkanov Sergey 20473 *************************************************************************/ 20474 void lsfitcreatewfgh(/* Real */ ae_matrix* x, 20475 /* Real */ ae_vector* y, 20476 /* Real */ ae_vector* w, 20477 /* Real */ ae_vector* c, 20486 _lsfitstate_clear(state); 20488 ae_assert(n>=1, "LSFitCreateWFGH: N<1!
", _state); 20489 ae_assert(m>=1, "LSFitCreateWFGH: M<1!
", _state); 20490 ae_assert(k>=1, "LSFitCreateWFGH:
K<1!
", _state); 20491 ae_assert(c->cnt>=k, "LSFitCreateWFGH:
length(C)<
K!
", _state); 20492 ae_assert(isfinitevector(c, k, _state), "LSFitCreateWFGH: C contains infinite
or NaN values!
", _state); 20493 ae_assert(y->cnt>=n, "LSFitCreateWFGH:
length(Y)<N!
", _state); 20494 ae_assert(isfinitevector(y, n, _state), "LSFitCreateWFGH: Y contains infinite
or NaN values!
", _state); 20495 ae_assert(w->cnt>=n, "LSFitCreateWFGH:
length(W)<N!
", _state); 20496 ae_assert(isfinitevector(w, n, _state), "LSFitCreateWFGH: W contains infinite
or NaN values!
", _state); 20497 ae_assert(x->rows>=n, "LSFitCreateWFGH: rows(X)<N!
", _state); 20498 ae_assert(x->cols>=m, "LSFitCreateWFGH: cols(X)<M!
", _state); 20499 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateWFGH: X contains infinite
or NaN values!
", _state); 20500 state->teststep = 0; 20501 state->diffstep = 0; 20502 state->npoints = n; 20503 state->nweights = n; 20507 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20508 lsfitsetstpmax(state, 0.0, _state); 20509 lsfitsetxrep(state, ae_false, _state); 20510 ae_matrix_set_length(&state->taskx, n, m, _state); 20511 ae_vector_set_length(&state->tasky, n, _state); 20512 ae_vector_set_length(&state->taskw, n, _state); 20513 ae_vector_set_length(&state->c, k, _state); 20514 ae_matrix_set_length(&state->h, k, k, _state); 20515 ae_vector_set_length(&state->x, m, _state); 20516 ae_vector_set_length(&state->g, k, _state); 20517 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20518 ae_v_move(&state->taskw.ptr.p_double[0], 1, &w->ptr.p_double[0], 1, ae_v_len(0,n-1)); 20519 for(i=0; i<=n-1; i++) 20521 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20522 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20524 ae_vector_set_length(&state->s, k, _state); 20525 ae_vector_set_length(&state->bndl, k, _state); 20526 ae_vector_set_length(&state->bndu, k, _state); 20527 for(i=0; i<=k-1; i++) 20529 state->s.ptr.p_double[i] = 1.0; 20530 state->bndl.ptr.p_double[i] = _state->v_neginf; 20531 state->bndu.ptr.p_double[i] = _state->v_posinf; 20533 state->optalgo = 2; 20534 state->prevnpt = -1; 20535 state->prevalgo = -1; 20536 minlmcreatefgh(k, &state->c, &state->optstate, _state); 20537 lsfit_lsfitclearrequestfields(state, _state); 20538 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20539 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20540 state->rstate.stage = -1; 20544 /************************************************************************* 20545 Nonlinear least squares fitting using gradient/Hessian, without individial 20548 Nonlinear task min(F(c)) is solved, where 20550 F(c) = ((f(c,x[0])-y[0]))^2 + ... + ((f(c,x[n-1])-y[n-1]))^2, 20552 * N is a number of points, 20553 * M is a dimension of a space points belong to, 20554 * K is a dimension of a space of parameters being fitted, 20555 * x is a set of N points, each of them is an M-dimensional vector, 20556 * c is a K-dimensional vector of parameters being fitted 20558 This subroutine uses f(c,x[i]), its gradient and its Hessian. 20561 X - array[0..N-1,0..M-1], points (one row = one point) 20562 Y - array[0..N-1], function values. 20563 C - array[0..K-1], initial approximation to the solution, 20564 N - number of points, N>1 20565 M - dimension of space 20566 K - number of parameters being fitted 20569 State - structure which stores algorithm state 20573 Copyright 17.08.2009 by Bochkanov Sergey 20574 *************************************************************************/ 20575 void lsfitcreatefgh(/* Real */ ae_matrix* x, 20576 /* Real */ ae_vector* y, 20577 /* Real */ ae_vector* c, 20586 _lsfitstate_clear(state); 20588 ae_assert(n>=1, "LSFitCreateFGH: N<1!
", _state); 20589 ae_assert(m>=1, "LSFitCreateFGH: M<1!
", _state); 20590 ae_assert(k>=1, "LSFitCreateFGH:
K<1!
", _state); 20591 ae_assert(c->cnt>=k, "LSFitCreateFGH:
length(C)<
K!
", _state); 20592 ae_assert(isfinitevector(c, k, _state), "LSFitCreateFGH: C contains infinite
or NaN values!
", _state); 20593 ae_assert(y->cnt>=n, "LSFitCreateFGH:
length(Y)<N!
", _state); 20594 ae_assert(isfinitevector(y, n, _state), "LSFitCreateFGH: Y contains infinite
or NaN values!
", _state); 20595 ae_assert(x->rows>=n, "LSFitCreateFGH: rows(X)<N!
", _state); 20596 ae_assert(x->cols>=m, "LSFitCreateFGH: cols(X)<M!
", _state); 20597 ae_assert(apservisfinitematrix(x, n, m, _state), "LSFitCreateFGH: X contains infinite
or NaN values!
", _state); 20598 state->teststep = 0; 20599 state->diffstep = 0; 20600 state->npoints = n; 20604 lsfitsetcond(state, 0.0, 0.0, 0, _state); 20605 lsfitsetstpmax(state, 0.0, _state); 20606 lsfitsetxrep(state, ae_false, _state); 20607 ae_matrix_set_length(&state->taskx, n, m, _state); 20608 ae_vector_set_length(&state->tasky, n, _state); 20609 ae_vector_set_length(&state->c, k, _state); 20610 ae_matrix_set_length(&state->h, k, k, _state); 20611 ae_vector_set_length(&state->x, m, _state); 20612 ae_vector_set_length(&state->g, k, _state); 20613 ae_v_move(&state->c.ptr.p_double[0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,k-1)); 20614 for(i=0; i<=n-1; i++) 20616 ae_v_move(&state->taskx.ptr.pp_double[i][0], 1, &x->ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 20617 state->tasky.ptr.p_double[i] = y->ptr.p_double[i]; 20619 ae_vector_set_length(&state->s, k, _state); 20620 ae_vector_set_length(&state->bndl, k, _state); 20621 ae_vector_set_length(&state->bndu, k, _state); 20622 for(i=0; i<=k-1; i++) 20624 state->s.ptr.p_double[i] = 1.0; 20625 state->bndl.ptr.p_double[i] = _state->v_neginf; 20626 state->bndu.ptr.p_double[i] = _state->v_posinf; 20628 state->optalgo = 2; 20629 state->prevnpt = -1; 20630 state->prevalgo = -1; 20631 minlmcreatefgh(k, &state->c, &state->optstate, _state); 20632 lsfit_lsfitclearrequestfields(state, _state); 20633 ae_vector_set_length(&state->rstate.ia, 6+1, _state); 20634 ae_vector_set_length(&state->rstate.ra, 8+1, _state); 20635 state->rstate.stage = -1; 20639 /************************************************************************* 20640 Stopping conditions for nonlinear least squares fitting. 20643 State - structure which stores algorithm state 20644 EpsF - stopping criterion. Algorithm stops if 20645 |F(k+1)-F(k)| <= EpsF*max{|F(k)|, |F(k+1)|, 1} 20647 The subroutine finishes its work if on k+1-th iteration 20648 the condition |v|<=EpsX is fulfilled, where: 20649 * |.| means Euclidian norm 20650 * v - scaled step vector, v[i]=dx[i]/s[i] 20651 * dx - ste pvector, dx=X(k+1)-X(k) 20652 * s - scaling coefficients set by LSFitSetScale() 20653 MaxIts - maximum number of iterations. If MaxIts=0, the number of 20654 iterations is unlimited. Only Levenberg-Marquardt 20655 iterations are counted (L-BFGS/CG iterations are NOT 20656 counted because their cost is very low compared to that of 20661 Passing EpsF=0, EpsX=0 and MaxIts=0 (simultaneously) will lead to automatic 20662 stopping criterion selection (according to the scheme used by MINLM unit). 20666 Copyright 17.08.2009 by Bochkanov Sergey 20667 *************************************************************************/ 20668 void lsfitsetcond(lsfitstate* state, 20676 ae_assert(ae_isfinite(epsf, _state), "LSFitSetCond: EpsF is not finite!
", _state); 20677 ae_assert(ae_fp_greater_eq(epsf,0), "LSFitSetCond: negative EpsF!
", _state); 20678 ae_assert(ae_isfinite(epsx, _state), "LSFitSetCond: EpsX is not finite!
", _state); 20679 ae_assert(ae_fp_greater_eq(epsx,0), "LSFitSetCond: negative EpsX!
", _state); 20680 ae_assert(maxits>=0, "LSFitSetCond: negative MaxIts!
", _state); 20681 state->epsf = epsf; 20682 state->epsx = epsx; 20683 state->maxits = maxits; 20687 /************************************************************************* 20688 This function sets maximum step length 20691 State - structure which stores algorithm state 20692 StpMax - maximum step length, >=0. Set StpMax to 0.0, if you don't 20693 want to limit step length. 20695 Use this subroutine when you optimize target function which contains exp() 20696 or other fast growing functions, and optimization algorithm makes too 20697 large steps which leads to overflow. This function allows us to reject 20698 steps that are too large (and therefore expose us to the possible 20699 overflow) without actually calculating function value at the x+stp*d. 20701 NOTE: non-zero StpMax leads to moderate performance degradation because 20702 intermediate step of preconditioned L-BFGS optimization is incompatible 20703 with limits on step size. 20706 Copyright 02.04.2010 by Bochkanov Sergey 20707 *************************************************************************/ 20708 void lsfitsetstpmax(lsfitstate* state, double stpmax, ae_state *_state) 20712 ae_assert(ae_fp_greater_eq(stpmax,0), "LSFitSetStpMax: StpMax<0!
", _state); 20713 state->stpmax = stpmax; 20717 /************************************************************************* 20718 This function turns on/off reporting. 20721 State - structure which stores algorithm state 20722 NeedXRep- whether iteration reports are needed or not 20724 When reports are needed, State.C (current parameters) and State.F (current 20725 value of fitting function) are reported. 20729 Copyright 15.08.2010 by Bochkanov Sergey 20730 *************************************************************************/ 20731 void lsfitsetxrep(lsfitstate* state, ae_bool needxrep, ae_state *_state) 20735 state->xrep = needxrep; 20739 /************************************************************************* 20740 This function sets scaling coefficients for underlying optimizer. 20742 ALGLIB optimizers use scaling matrices to test stopping conditions (step 20743 size and gradient are scaled before comparison with tolerances). Scale of 20744 the I-th variable is a translation invariant measure of: 20745 a) "how large
" the variable is 20746 b) how large the step should be to make significant changes in the function 20748 Generally, scale is NOT considered to be a form of preconditioner. But LM 20749 optimizer is unique in that it uses scaling matrix both in the stopping 20750 condition tests and as Marquardt damping factor. 20752 Proper scaling is very important for the algorithm performance. It is less 20753 important for the quality of results, but still has some influence (it is 20754 easier to converge when variables are properly scaled, so premature 20755 stopping is possible when very badly scalled variables are combined with 20756 relaxed stopping conditions). 20759 State - structure stores algorithm state 20760 S - array[N], non-zero scaling coefficients 20761 S[i] may be negative, sign doesn't matter. 20764 Copyright 14.01.2011 by Bochkanov Sergey 20765 *************************************************************************/ 20766 void lsfitsetscale(lsfitstate* state, 20767 /* Real */ ae_vector* s, 20773 ae_assert(s->cnt>=state->k, "LSFitSetScale: Length(S)<
K", _state); 20774 for(i=0; i<=state->k-1; i++) 20776 ae_assert(ae_isfinite(s->ptr.p_double[i], _state), "LSFitSetScale: S contains infinite
or NAN elements
", _state); 20777 ae_assert(ae_fp_neq(s->ptr.p_double[i],0), "LSFitSetScale: S contains infinite
or NAN elements
", _state); 20778 state->s.ptr.p_double[i] = ae_fabs(s->ptr.p_double[i], _state); 20783 /************************************************************************* 20784 This function sets boundary constraints for underlying optimizer 20786 Boundary constraints are inactive by default (after initial creation). 20787 They are preserved until explicitly turned off with another SetBC() call. 20790 State - structure stores algorithm state 20791 BndL - lower bounds, array[K]. 20792 If some (all) variables are unbounded, you may specify 20793 very small number or -INF (latter is recommended because 20794 it will allow solver to use better algorithm). 20795 BndU - upper bounds, array[K]. 20796 If some (all) variables are unbounded, you may specify 20797 very large number or +INF (latter is recommended because 20798 it will allow solver to use better algorithm). 20800 NOTE 1: it is possible to specify BndL[i]=BndU[i]. In this case I-th 20801 variable will be "frozen
" at X[i]=BndL[i]=BndU[i]. 20803 NOTE 2: unlike other constrained optimization algorithms, this solver has 20804 following useful properties: 20805 * bound constraints are always satisfied exactly 20806 * function is evaluated only INSIDE area specified by bound constraints 20809 Copyright 14.01.2011 by Bochkanov Sergey 20810 *************************************************************************/ 20811 void lsfitsetbc(lsfitstate* state, 20812 /* Real */ ae_vector* bndl, 20813 /* Real */ ae_vector* bndu, 20821 ae_assert(bndl->cnt>=k, "LSFitSetBC: Length(BndL)<
K", _state); 20822 ae_assert(bndu->cnt>=k, "LSFitSetBC: Length(BndU)<
K", _state); 20823 for(i=0; i<=k-1; i++) 20825 ae_assert(ae_isfinite(bndl->ptr.p_double[i], _state)||ae_isneginf(bndl->ptr.p_double[i], _state), "LSFitSetBC: BndL contains NAN
or +
INF", _state); 20826 ae_assert(ae_isfinite(bndu->ptr.p_double[i], _state)||ae_isposinf(bndu->ptr.p_double[i], _state), "LSFitSetBC: BndU contains NAN
or -
INF", _state); 20827 if( ae_isfinite(bndl->ptr.p_double[i], _state)&&ae_isfinite(bndu->ptr.p_double[i], _state) ) 20829 ae_assert(ae_fp_less_eq(bndl->ptr.p_double[i],bndu->ptr.p_double[i]), "LSFitSetBC: BndL[i]>BndU[i]
", _state); 20831 state->bndl.ptr.p_double[i] = bndl->ptr.p_double[i]; 20832 state->bndu.ptr.p_double[i] = bndu->ptr.p_double[i]; 20837 /************************************************************************* 20840 1. this algorithm is somewhat unusual because it works with parameterized 20841 function f(C,X), where X is a function argument (we have many points 20842 which are characterized by different argument values), and C is a 20845 For example, if we want to do linear fit by f(c0,c1,x) = c0*x+c1, then 20846 x will be argument, and {c0,c1} will be parameters. 20848 It is important to understand that this algorithm finds minimum in the 20849 space of function PARAMETERS (not arguments), so it needs derivatives 20850 of f() with respect to C, not X. 20852 In the example above it will need f=c0*x+c1 and {df/dc0,df/dc1} = {x,1} 20853 instead of {df/dx} = {c0}. 20855 2. Callback functions accept C as the first parameter, and X as the second 20857 3. If state was created with LSFitCreateFG(), algorithm needs just 20858 function and its gradient, but if state was created with 20859 LSFitCreateFGH(), algorithm will need function, gradient and Hessian. 20861 According to the said above, there ase several versions of this 20862 function, which accept different sets of callbacks. 20864 This flexibility opens way to subtle errors - you may create state with 20865 LSFitCreateFGH() (optimization using Hessian), but call function which 20866 does not accept Hessian. So when algorithm will request Hessian, there 20867 will be no callback to call. In this case exception will be thrown. 20869 Be careful to avoid such errors because there is no way to find them at 20870 compile time - you can see them at runtime only. 20873 Copyright 17.08.2009 by Bochkanov Sergey 20874 *************************************************************************/ 20875 ae_bool lsfititeration(lsfitstate* state, ae_state *_state) 20898 * Reverse communication preparations 20899 * I know it looks ugly, but it works the same way 20900 * anywhere from C++ to Python. 20902 * This code initializes locals by: 20903 * * random values determined during code 20904 * generation - on first subroutine call 20905 * * values from previous call - on subsequent calls 20907 if( state->rstate.stage>=0 ) 20909 n = state->rstate.ia.ptr.p_int[0]; 20910 m = state->rstate.ia.ptr.p_int[1]; 20911 k = state->rstate.ia.ptr.p_int[2]; 20912 i = state->rstate.ia.ptr.p_int[3]; 20913 j = state->rstate.ia.ptr.p_int[4]; 20914 j1 = state->rstate.ia.ptr.p_int[5]; 20915 info = state->rstate.ia.ptr.p_int[6]; 20916 lx = state->rstate.ra.ptr.p_double[0]; 20917 lf = state->rstate.ra.ptr.p_double[1]; 20918 ld = state->rstate.ra.ptr.p_double[2]; 20919 rx = state->rstate.ra.ptr.p_double[3]; 20920 rf = state->rstate.ra.ptr.p_double[4]; 20921 rd = state->rstate.ra.ptr.p_double[5]; 20922 v = state->rstate.ra.ptr.p_double[6]; 20923 vv = state->rstate.ra.ptr.p_double[7]; 20924 relcnt = state->rstate.ra.ptr.p_double[8]; 20945 if( state->rstate.stage==0 ) 20949 if( state->rstate.stage==1 ) 20953 if( state->rstate.stage==2 ) 20957 if( state->rstate.stage==3 ) 20961 if( state->rstate.stage==4 ) 20965 if( state->rstate.stage==5 ) 20969 if( state->rstate.stage==6 ) 20973 if( state->rstate.stage==7 ) 20977 if( state->rstate.stage==8 ) 20981 if( state->rstate.stage==9 ) 20985 if( state->rstate.stage==10 ) 20989 if( state->rstate.stage==11 ) 20993 if( state->rstate.stage==12 ) 20997 if( state->rstate.stage==13 ) 21009 if( state->wkind==1 ) 21011 ae_assert(state->npoints==state->nweights, "LSFitFit: number of points is not equal to the number of weights
", _state); 21013 state->repvaridx = -1; 21014 n = state->npoints; 21017 minlmsetcond(&state->optstate, 0.0, state->epsf, state->epsx, state->maxits, _state); 21018 minlmsetstpmax(&state->optstate, state->stpmax, _state); 21019 minlmsetxrep(&state->optstate, state->xrep, _state); 21020 minlmsetscale(&state->optstate, &state->s, _state); 21021 minlmsetbc(&state->optstate, &state->bndl, &state->bndu, _state); 21024 * Check that user-supplied gradient is correct 21026 lsfit_lsfitclearrequestfields(state, _state); 21027 if( !(ae_fp_greater(state->teststep,0)&&state->optalgo==1) ) 21031 for(i=0; i<=k-1; i++) 21033 if( ae_isfinite(state->bndl.ptr.p_double[i], _state) ) 21035 state->c.ptr.p_double[i] = ae_maxreal(state->c.ptr.p_double[i], state->bndl.ptr.p_double[i], _state); 21037 if( ae_isfinite(state->bndu.ptr.p_double[i], _state) ) 21039 state->c.ptr.p_double[i] = ae_minreal(state->c.ptr.p_double[i], state->bndu.ptr.p_double[i], _state); 21042 state->needfg = ae_true; 21049 ae_assert(ae_fp_less_eq(state->bndl.ptr.p_double[i],state->c.ptr.p_double[i])&&ae_fp_less_eq(state->c.ptr.p_double[i],state->bndu.ptr.p_double[i]), "LSFitIteration:
internal error(State.C is out of bounds)
", _state); 21050 v = state->c.ptr.p_double[i]; 21057 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[j][0], 1, ae_v_len(0,m-1)); 21058 state->c.ptr.p_double[i] = v-state->teststep*state->s.ptr.p_double[i]; 21059 if( ae_isfinite(state->bndl.ptr.p_double[i], _state) ) 21061 state->c.ptr.p_double[i] = ae_maxreal(state->c.ptr.p_double[i], state->bndl.ptr.p_double[i], _state); 21063 lx = state->c.ptr.p_double[i]; 21064 state->rstate.stage = 0; 21068 ld = state->g.ptr.p_double[i]; 21069 state->c.ptr.p_double[i] = v+state->teststep*state->s.ptr.p_double[i]; 21070 if( ae_isfinite(state->bndu.ptr.p_double[i], _state) ) 21072 state->c.ptr.p_double[i] = ae_minreal(state->c.ptr.p_double[i], state->bndu.ptr.p_double[i], _state); 21074 rx = state->c.ptr.p_double[i]; 21075 state->rstate.stage = 1; 21079 rd = state->g.ptr.p_double[i]; 21080 state->c.ptr.p_double[i] = (lx+rx)/2; 21081 if( ae_isfinite(state->bndl.ptr.p_double[i], _state) ) 21083 state->c.ptr.p_double[i] = ae_maxreal(state->c.ptr.p_double[i], state->bndl.ptr.p_double[i], _state); 21085 if( ae_isfinite(state->bndu.ptr.p_double[i], _state) ) 21087 state->c.ptr.p_double[i] = ae_minreal(state->c.ptr.p_double[i], state->bndu.ptr.p_double[i], _state); 21089 state->rstate.stage = 2; 21092 state->c.ptr.p_double[i] = v; 21093 if( !derivativecheck(lf, ld, rf, rd, state->f, state->g.ptr.p_double[i], rx-lx, _state) ) 21095 state->repvaridx = i; 21096 state->repterminationtype = -7; 21106 state->needfg = ae_false; 21110 * Fill WCur by weights: 21111 * * for WKind=0 unit weights are chosen 21112 * * for WKind=1 we use user-supplied weights stored in State.TaskW 21114 rvectorsetlengthatleast(&state->wcur, n, _state); 21115 for(i=0; i<=n-1; i++) 21117 state->wcur.ptr.p_double[i] = 1.0; 21118 if( state->wkind==1 ) 21120 state->wcur.ptr.p_double[i] = state->taskw.ptr.p_double[i]; 21128 if( !minlmiteration(&state->optstate, _state) ) 21132 if( !state->optstate.needfi ) 21138 * calculate f[] = wi*(f(xi,c)-yi) 21146 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21147 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21148 state->pointindex = i; 21149 lsfit_lsfitclearrequestfields(state, _state); 21150 state->needf = ae_true; 21151 state->rstate.stage = 3; 21154 state->needf = ae_false; 21155 vv = state->wcur.ptr.p_double[i]; 21156 state->optstate.fi.ptr.p_double[i] = vv*(state->f-state->tasky.ptr.p_double[i]); 21162 if( !state->optstate.needf ) 21168 * calculate F = sum (wi*(f(xi,c)-yi))^2 21170 state->optstate.f = 0; 21177 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21178 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21179 state->pointindex = i; 21180 lsfit_lsfitclearrequestfields(state, _state); 21181 state->needf = ae_true; 21182 state->rstate.stage = 4; 21185 state->needf = ae_false; 21186 vv = state->wcur.ptr.p_double[i]; 21187 state->optstate.f = state->optstate.f+ae_sqr(vv*(state->f-state->tasky.ptr.p_double[i]), _state); 21193 if( !state->optstate.needfg ) 21199 * calculate F/gradF 21201 state->optstate.f = 0; 21202 for(i=0; i<=k-1; i++) 21204 state->optstate.g.ptr.p_double[i] = 0; 21212 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21213 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21214 state->pointindex = i; 21215 lsfit_lsfitclearrequestfields(state, _state); 21216 state->needfg = ae_true; 21217 state->rstate.stage = 5; 21220 state->needfg = ae_false; 21221 vv = state->wcur.ptr.p_double[i]; 21222 state->optstate.f = state->optstate.f+ae_sqr(vv*(state->f-state->tasky.ptr.p_double[i]), _state); 21223 v = ae_sqr(vv, _state)*2*(state->f-state->tasky.ptr.p_double[i]); 21224 ae_v_addd(&state->optstate.g.ptr.p_double[0], 1, &state->g.ptr.p_double[0], 1, ae_v_len(0,k-1), v); 21230 if( !state->optstate.needfij ) 21236 * calculate Fi/jac(Fi) 21244 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21245 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21246 state->pointindex = i; 21247 lsfit_lsfitclearrequestfields(state, _state); 21248 state->needfg = ae_true; 21249 state->rstate.stage = 6; 21252 state->needfg = ae_false; 21253 vv = state->wcur.ptr.p_double[i]; 21254 state->optstate.fi.ptr.p_double[i] = vv*(state->f-state->tasky.ptr.p_double[i]); 21255 ae_v_moved(&state->optstate.j.ptr.pp_double[i][0], 1, &state->g.ptr.p_double[0], 1, ae_v_len(0,k-1), vv); 21261 if( !state->optstate.needfgh ) 21267 * calculate F/grad(F)/hess(F) 21269 state->optstate.f = 0; 21270 for(i=0; i<=k-1; i++) 21272 state->optstate.g.ptr.p_double[i] = 0; 21274 for(i=0; i<=k-1; i++) 21276 for(j=0; j<=k-1; j++) 21278 state->optstate.h.ptr.pp_double[i][j] = 0; 21287 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21288 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21289 state->pointindex = i; 21290 lsfit_lsfitclearrequestfields(state, _state); 21291 state->needfgh = ae_true; 21292 state->rstate.stage = 7; 21295 state->needfgh = ae_false; 21296 vv = state->wcur.ptr.p_double[i]; 21297 state->optstate.f = state->optstate.f+ae_sqr(vv*(state->f-state->tasky.ptr.p_double[i]), _state); 21298 v = ae_sqr(vv, _state)*2*(state->f-state->tasky.ptr.p_double[i]); 21299 ae_v_addd(&state->optstate.g.ptr.p_double[0], 1, &state->g.ptr.p_double[0], 1, ae_v_len(0,k-1), v); 21300 for(j=0; j<=k-1; j++) 21302 v = 2*ae_sqr(vv, _state)*state->g.ptr.p_double[j]; 21303 ae_v_addd(&state->optstate.h.ptr.pp_double[j][0], 1, &state->g.ptr.p_double[0], 1, ae_v_len(0,k-1), v); 21304 v = 2*ae_sqr(vv, _state)*(state->f-state->tasky.ptr.p_double[i]); 21305 ae_v_addd(&state->optstate.h.ptr.pp_double[j][0], 1, &state->h.ptr.pp_double[j][0], 1, ae_v_len(0,k-1), v); 21312 if( !state->optstate.xupdated ) 21318 * Report new iteration 21320 ae_v_move(&state->c.ptr.p_double[0], 1, &state->optstate.x.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21321 state->f = state->optstate.f; 21322 lsfit_lsfitclearrequestfields(state, _state); 21323 state->xupdated = ae_true; 21324 state->rstate.stage = 8; 21327 state->xupdated = ae_false; 21332 minlmresults(&state->optstate, &state->c, &state->optrep, _state); 21333 state->repterminationtype = state->optrep.terminationtype; 21334 state->repiterationscount = state->optrep.iterationscount; 21339 if( state->repterminationtype<=0 ) 21345 * Calculate RMS/Avg/Max/... errors 21347 state->reprmserror = 0; 21348 state->repwrmserror = 0; 21349 state->repavgerror = 0; 21350 state->repavgrelerror = 0; 21351 state->repmaxerror = 0; 21359 ae_v_move(&state->c.ptr.p_double[0], 1, &state->c.ptr.p_double[0], 1, ae_v_len(0,k-1)); 21360 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21361 state->pointindex = i; 21362 lsfit_lsfitclearrequestfields(state, _state); 21363 state->needf = ae_true; 21364 state->rstate.stage = 9; 21367 state->needf = ae_false; 21369 vv = state->wcur.ptr.p_double[i]; 21370 state->reprmserror = state->reprmserror+ae_sqr(v-state->tasky.ptr.p_double[i], _state); 21371 state->repwrmserror = state->repwrmserror+ae_sqr(vv*(v-state->tasky.ptr.p_double[i]), _state); 21372 state->repavgerror = state->repavgerror+ae_fabs(v-state->tasky.ptr.p_double[i], _state); 21373 if( ae_fp_neq(state->tasky.ptr.p_double[i],0) ) 21375 state->repavgrelerror = state->repavgrelerror+ae_fabs(v-state->tasky.ptr.p_double[i], _state)/ae_fabs(state->tasky.ptr.p_double[i], _state); 21378 state->repmaxerror = ae_maxreal(state->repmaxerror, ae_fabs(v-state->tasky.ptr.p_double[i], _state), _state); 21382 state->reprmserror = ae_sqrt(state->reprmserror/n, _state); 21383 state->repwrmserror = ae_sqrt(state->repwrmserror/n, _state); 21384 state->repavgerror = state->repavgerror/n; 21385 if( ae_fp_neq(relcnt,0) ) 21387 state->repavgrelerror = state->repavgrelerror/relcnt; 21391 * Calculate covariance matrix 21393 rmatrixsetlengthatleast(&state->tmpjac, n, k, _state); 21394 rvectorsetlengthatleast(&state->tmpf, n, _state); 21395 rvectorsetlengthatleast(&state->tmp, k, _state); 21396 if( ae_fp_less_eq(state->diffstep,0) ) 21402 * Compute Jacobian by means of numerical differentiation 21404 lsfit_lsfitclearrequestfields(state, _state); 21405 state->needf = ae_true; 21412 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21413 state->pointindex = i; 21414 state->rstate.stage = 10; 21417 state->tmpf.ptr.p_double[i] = state->f; 21424 v = state->c.ptr.p_double[j]; 21425 lx = v-state->diffstep*state->s.ptr.p_double[j]; 21426 state->c.ptr.p_double[j] = lx; 21427 if( ae_isfinite(state->bndl.ptr.p_double[j], _state) ) 21429 state->c.ptr.p_double[j] = ae_maxreal(state->c.ptr.p_double[j], state->bndl.ptr.p_double[j], _state); 21431 state->rstate.stage = 11; 21435 rx = v+state->diffstep*state->s.ptr.p_double[j]; 21436 state->c.ptr.p_double[j] = rx; 21437 if( ae_isfinite(state->bndu.ptr.p_double[j], _state) ) 21439 state->c.ptr.p_double[j] = ae_minreal(state->c.ptr.p_double[j], state->bndu.ptr.p_double[j], _state); 21441 state->rstate.stage = 12; 21445 state->c.ptr.p_double[j] = v; 21446 if( ae_fp_neq(rx,lx) ) 21448 state->tmpjac.ptr.pp_double[i][j] = (rf-lf)/(rx-lx); 21452 state->tmpjac.ptr.pp_double[i][j] = 0; 21460 state->needf = ae_false; 21465 * Jacobian is calculated with user-provided analytic gradient 21467 lsfit_lsfitclearrequestfields(state, _state); 21468 state->needfg = ae_true; 21475 ae_v_move(&state->x.ptr.p_double[0], 1, &state->taskx.ptr.pp_double[i][0], 1, ae_v_len(0,m-1)); 21476 state->pointindex = i; 21477 state->rstate.stage = 13; 21480 state->tmpf.ptr.p_double[i] = state->f; 21481 for(j=0; j<=k-1; j++) 21483 state->tmpjac.ptr.pp_double[i][j] = state->g.ptr.p_double[j]; 21488 state->needfg = ae_false; 21490 for(i=0; i<=k-1; i++) 21492 state->tmp.ptr.p_double[i] = 0.0; 21494 lsfit_estimateerrors(&state->tmpjac, &state->tmpf, &state->tasky, &state->wcur, &state->tmp, &state->s, n, k, &state->rep, &state->tmpjacw, 0, _state); 21504 state->rstate.ia.ptr.p_int[0] = n; 21505 state->rstate.ia.ptr.p_int[1] = m; 21506 state->rstate.ia.ptr.p_int[2] = k; 21507 state->rstate.ia.ptr.p_int[3] = i; 21508 state->rstate.ia.ptr.p_int[4] = j; 21509 state->rstate.ia.ptr.p_int[5] = j1; 21510 state->rstate.ia.ptr.p_int[6] = info; 21511 state->rstate.ra.ptr.p_double[0] = lx; 21512 state->rstate.ra.ptr.p_double[1] = lf; 21513 state->rstate.ra.ptr.p_double[2] = ld; 21514 state->rstate.ra.ptr.p_double[3] = rx; 21515 state->rstate.ra.ptr.p_double[4] = rf; 21516 state->rstate.ra.ptr.p_double[5] = rd; 21517 state->rstate.ra.ptr.p_double[6] = v; 21518 state->rstate.ra.ptr.p_double[7] = vv; 21519 state->rstate.ra.ptr.p_double[8] = relcnt; 21524 /************************************************************************* 21525 Nonlinear least squares fitting results. 21527 Called after return from LSFitFit(). 21530 State - algorithm state 21533 Info - completion code: 21534 * -7 gradient verification failed. 21535 See LSFitSetGradientCheck() for more information. 21536 * 1 relative function improvement is no more than 21538 * 2 relative step is no more than EpsX. 21539 * 4 gradient norm is no more than EpsG 21540 * 5 MaxIts steps was taken 21541 * 7 stopping conditions are too stringent, 21542 further improvement is impossible 21543 C - array[0..K-1], solution 21544 Rep - optimization report. On success following fields are set: 21545 * R2 non-adjusted coefficient of determination 21547 * RMSError rms error on the (X,Y). 21548 * AvgError average error on the (X,Y). 21549 * AvgRelError average relative error on the non-zero Y 21550 * MaxError maximum error 21551 NON-WEIGHTED ERRORS ARE CALCULATED 21552 * WRMSError weighted rms error on the (X,Y). 21554 ERRORS IN PARAMETERS 21556 This solver also calculates different kinds of errors in parameters and 21557 fills corresponding fields of report: 21558 * Rep.CovPar covariance matrix for parameters, array[K,K]. 21559 * Rep.ErrPar errors in parameters, array[K], 21560 errpar = sqrt(diag(CovPar)) 21561 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 21562 best-fit curve from "ideal
" best-fit curve built with 21563 infinite number of samples, array[N]. 21564 errcurve = sqrt(diag(J*CovPar*J')), 21565 where J is Jacobian matrix. 21566 * Rep.Noise vector of per-point estimates of noise, array[N] 21568 IMPORTANT: errors in parameters are calculated without taking into 21569 account boundary/linear constraints! Presence of constraints 21570 changes distribution of errors, but there is no easy way to 21571 account for constraints when you calculate covariance matrix. 21573 NOTE: noise in the data is estimated as follows: 21574 * for fitting without user-supplied weights all points are 21575 assumed to have same level of noise, which is estimated from 21577 * for fitting with user-supplied weights we assume that noise 21578 level in I-th point is inversely proportional to Ith weight. 21579 Coefficient of proportionality is estimated from the data. 21581 NOTE: we apply small amount of regularization when we invert squared 21582 Jacobian and calculate covariance matrix. It guarantees that 21583 algorithm won't divide by zero during inversion, but skews 21584 error estimates a bit (fractional error is about 10^-9). 21586 However, we believe that this difference is insignificant for 21587 all practical purposes except for the situation when you want 21588 to compare ALGLIB results with "reference
" implementation up 21589 to the last significant digit. 21591 NOTE: covariance matrix is estimated using correction for degrees 21592 of freedom (covariances are divided by N-M instead of dividing 21596 Copyright 17.08.2009 by Bochkanov Sergey 21597 *************************************************************************/ 21598 void lsfitresults(lsfitstate* state, 21600 /* Real */ ae_vector* c, 21608 ae_vector_clear(c); 21609 _lsfitreport_clear(rep); 21611 lsfit_clearreport(rep, _state); 21612 *info = state->repterminationtype; 21613 rep->varidx = state->repvaridx; 21616 ae_vector_set_length(c, state->k, _state); 21617 ae_v_move(&c->ptr.p_double[0], 1, &state->c.ptr.p_double[0], 1, ae_v_len(0,state->k-1)); 21618 rep->rmserror = state->reprmserror; 21619 rep->wrmserror = state->repwrmserror; 21620 rep->avgerror = state->repavgerror; 21621 rep->avgrelerror = state->repavgrelerror; 21622 rep->maxerror = state->repmaxerror; 21623 rep->iterationscount = state->repiterationscount; 21624 ae_matrix_set_length(&rep->covpar, state->k, state->k, _state); 21625 ae_vector_set_length(&rep->errpar, state->k, _state); 21626 ae_vector_set_length(&rep->errcurve, state->npoints, _state); 21627 ae_vector_set_length(&rep->noise, state->npoints, _state); 21628 rep->r2 = state->rep.r2; 21629 for(i=0; i<=state->k-1; i++) 21631 for(j=0; j<=state->k-1; j++) 21633 rep->covpar.ptr.pp_double[i][j] = state->rep.covpar.ptr.pp_double[i][j]; 21635 rep->errpar.ptr.p_double[i] = state->rep.errpar.ptr.p_double[i]; 21637 for(i=0; i<=state->npoints-1; i++) 21639 rep->errcurve.ptr.p_double[i] = state->rep.errcurve.ptr.p_double[i]; 21640 rep->noise.ptr.p_double[i] = state->rep.noise.ptr.p_double[i]; 21646 /************************************************************************* 21647 This subroutine turns on verification of the user-supplied analytic 21649 * user calls this subroutine before fitting begins 21650 * LSFitFit() is called 21651 * prior to actual fitting, for each point in data set X_i and each 21652 component of parameters being fited C_j algorithm performs following 21654 * two trial steps are made to C_j-TestStep*S[j] and C_j+TestStep*S[j], 21655 where C_j is j-th parameter and S[j] is a scale of j-th parameter 21656 * if needed, steps are bounded with respect to constraints on C[] 21657 * F(X_i|C) is evaluated at these trial points 21658 * we perform one more evaluation in the middle point of the interval 21659 * we build cubic model using function values and derivatives at trial 21660 points and we compare its prediction with actual value in the middle 21662 * in case difference between prediction and actual value is higher than 21663 some predetermined threshold, algorithm stops with completion code -7; 21664 Rep.VarIdx is set to index of the parameter with incorrect derivative. 21665 * after verification is over, algorithm proceeds to the actual optimization. 21667 NOTE 1: verification needs N*K (points count * parameters count) gradient 21668 evaluations. It is very costly and you should use it only for low 21669 dimensional problems, when you want to be sure that you've 21670 correctly calculated analytic derivatives. You should not use it 21671 in the production code (unless you want to check derivatives 21672 provided by some third party). 21674 NOTE 2: you should carefully choose TestStep. Value which is too large 21675 (so large that function behaviour is significantly non-cubic) will 21676 lead to false alarms. You may use different step for different 21677 parameters by means of setting scale with LSFitSetScale(). 21679 NOTE 3: this function may lead to false positives. In case it reports that 21680 I-th derivative was calculated incorrectly, you may decrease test 21681 step and try one more time - maybe your function changes too 21682 sharply and your step is too large for such rapidly chanding 21685 NOTE 4: this function works only for optimizers created with LSFitCreateWFG() 21686 or LSFitCreateFG() constructors. 21689 State - structure used to store algorithm state 21690 TestStep - verification step: 21691 * TestStep=0 turns verification off 21692 * TestStep>0 activates verification 21695 Copyright 15.06.2012 by Bochkanov Sergey 21696 *************************************************************************/ 21697 void lsfitsetgradientcheck(lsfitstate* state, 21703 ae_assert(ae_isfinite(teststep, _state), "LSFitSetGradientCheck: TestStep contains NaN
or Infinite
", _state); 21704 ae_assert(ae_fp_greater_eq(teststep,0), "LSFitSetGradientCheck: invalid argument TestStep(TestStep<0)
", _state); 21705 state->teststep = teststep; 21709 /************************************************************************* 21710 Internal subroutine: automatic scaling for LLS tasks. 21711 NEVER CALL IT DIRECTLY! 21713 Maps abscissas to [-1,1], standartizes ordinates and correspondingly scales 21714 constraints. It also scales weights so that max(W[i])=1 21716 Transformations performed: 21717 * X, XC [XA,XB] => [-1,+1] 21718 transformation makes min(X)=-1, max(X)=+1 21720 * Y [SA,SB] => [0,1] 21721 transformation makes mean(Y)=0, stddev(Y)=1 21723 * YC transformed accordingly to SA, SB, DC[I] 21725 -- ALGLIB PROJECT -- 21726 Copyright 08.09.2009 by Bochkanov Sergey 21727 *************************************************************************/ 21728 void lsfitscalexy(/* Real */ ae_vector* x, 21729 /* Real */ ae_vector* y, 21730 /* Real */ ae_vector* w, 21732 /* Real */ ae_vector* xc, 21733 /* Real */ ae_vector* yc, 21734 /* Integer */ ae_vector* dc, 21740 /* Real */ ae_vector* xoriginal, 21741 /* Real */ ae_vector* yoriginal, 21753 ae_vector_clear(xoriginal); 21754 ae_vector_clear(yoriginal); 21756 ae_assert(n>=1, "LSFitScaleXY: incorrect N
", _state); 21757 ae_assert(k>=0, "LSFitScaleXY: incorrect
K", _state); 21760 * Calculate xmin/xmax. 21761 * Force xmin<>xmax. 21763 xmin = x->ptr.p_double[0]; 21764 xmax = x->ptr.p_double[0]; 21765 for(i=1; i<=n-1; i++) 21767 xmin = ae_minreal(xmin, x->ptr.p_double[i], _state); 21768 xmax = ae_maxreal(xmax, x->ptr.p_double[i], _state); 21770 for(i=0; i<=k-1; i++) 21772 xmin = ae_minreal(xmin, xc->ptr.p_double[i], _state); 21773 xmax = ae_maxreal(xmax, xc->ptr.p_double[i], _state); 21775 if( ae_fp_eq(xmin,xmax) ) 21777 if( ae_fp_eq(xmin,0) ) 21784 if( ae_fp_greater(xmin,0) ) 21796 * Transform abscissas: map [XA,XB] to [0,1] 21798 * Store old X[] in XOriginal[] (it will be used 21799 * to calculate relative error). 21801 ae_vector_set_length(xoriginal, n, _state); 21802 ae_v_move(&xoriginal->ptr.p_double[0], 1, &x->ptr.p_double[0], 1, ae_v_len(0,n-1)); 21805 for(i=0; i<=n-1; i++) 21807 x->ptr.p_double[i] = 2*(x->ptr.p_double[i]-0.5*(*xa+(*xb)))/(*xb-(*xa)); 21809 for(i=0; i<=k-1; i++) 21811 ae_assert(dc->ptr.p_int[i]>=0, "LSFitScaleXY:
internal error!
", _state); 21812 xc->ptr.p_double[i] = 2*(xc->ptr.p_double[i]-0.5*(*xa+(*xb)))/(*xb-(*xa)); 21813 yc->ptr.p_double[i] = yc->ptr.p_double[i]*ae_pow(0.5*(*xb-(*xa)), dc->ptr.p_int[i], _state); 21817 * Transform function values: map [SA,SB] to [0,1] 21819 * SB = SA+stddev(Y). 21821 * Store old Y[] in YOriginal[] (it will be used 21822 * to calculate relative error). 21824 ae_vector_set_length(yoriginal, n, _state); 21825 ae_v_move(&yoriginal->ptr.p_double[0], 1, &y->ptr.p_double[0], 1, ae_v_len(0,n-1)); 21827 for(i=0; i<=n-1; i++) 21829 *sa = *sa+y->ptr.p_double[i]; 21833 for(i=0; i<=n-1; i++) 21835 *sb = *sb+ae_sqr(y->ptr.p_double[i]-(*sa), _state); 21837 *sb = ae_sqrt(*sb/n, _state)+(*sa); 21838 if( ae_fp_eq(*sb,*sa) ) 21842 if( ae_fp_eq(*sb,*sa) ) 21846 for(i=0; i<=n-1; i++) 21848 y->ptr.p_double[i] = (y->ptr.p_double[i]-(*sa))/(*sb-(*sa)); 21850 for(i=0; i<=k-1; i++) 21852 if( dc->ptr.p_int[i]==0 ) 21854 yc->ptr.p_double[i] = (yc->ptr.p_double[i]-(*sa))/(*sb-(*sa)); 21858 yc->ptr.p_double[i] = yc->ptr.p_double[i]/(*sb-(*sa)); 21866 for(i=0; i<=n-1; i++) 21868 mx = ae_maxreal(mx, ae_fabs(w->ptr.p_double[i], _state), _state); 21870 if( ae_fp_neq(mx,0) ) 21872 for(i=0; i<=n-1; i++) 21874 w->ptr.p_double[i] = w->ptr.p_double[i]/mx; 21880 /************************************************************************* 21881 Internal spline fitting subroutine 21883 -- ALGLIB PROJECT -- 21884 Copyright 08.09.2009 by Bochkanov Sergey 21885 *************************************************************************/ 21886 static void lsfit_spline1dfitinternal(ae_int_t st, 21887 /* Real */ ae_vector* x, 21888 /* Real */ ae_vector* y, 21889 /* Real */ ae_vector* w, 21891 /* Real */ ae_vector* xc, 21892 /* Real */ ae_vector* yc, 21893 /* Integer */ ae_vector* dc, 21897 spline1dinterpolant* s, 21898 spline1dfitreport* rep, 21901 ae_frame _frame_block; 21915 ae_vector xoriginal; 21916 ae_vector yoriginal; 21922 spline1dinterpolant s2; 21934 ae_frame_make(_state, &_frame_block); 21935 ae_vector_init_copy(&_x, x, _state, ae_true); 21937 ae_vector_init_copy(&_y, y, _state, ae_true); 21939 ae_vector_init_copy(&_w, w, _state, ae_true); 21941 ae_vector_init_copy(&_xc, xc, _state, ae_true); 21943 ae_vector_init_copy(&_yc, yc, _state, ae_true); 21946 _spline1dinterpolant_clear(s); 21947 _spline1dfitreport_clear(rep); 21948 ae_matrix_init(&fmatrix, 0, 0, DT_REAL, _state, ae_true); 21949 ae_matrix_init(&cmatrix, 0, 0, DT_REAL, _state, ae_true); 21950 ae_vector_init(&y2, 0, DT_REAL, _state, ae_true); 21951 ae_vector_init(&w2, 0, DT_REAL, _state, ae_true); 21952 ae_vector_init(&sx, 0, DT_REAL, _state, ae_true); 21953 ae_vector_init(&sy, 0, DT_REAL, _state, ae_true); 21954 ae_vector_init(&sd, 0, DT_REAL, _state, ae_true); 21955 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 21956 ae_vector_init(&xoriginal, 0, DT_REAL, _state, ae_true); 21957 ae_vector_init(&yoriginal, 0, DT_REAL, _state, ae_true); 21958 _lsfitreport_init(&lrep, _state, ae_true); 21959 _spline1dinterpolant_init(&s2, _state, ae_true); 21961 ae_assert(st==0||st==1, "Spline1DFit:
internal error!
", _state); 21965 ae_frame_leave(_state); 21971 ae_frame_leave(_state); 21974 if( (n<1||k<0)||k>=m ) 21977 ae_frame_leave(_state); 21980 for(i=0; i<=k-1; i++) 21983 if( dc->ptr.p_int[i]<0 ) 21987 if( dc->ptr.p_int[i]>1 ) 21993 ae_frame_leave(_state); 21997 if( st==1&&m%2!=0 ) 22001 * Hermite fitter must have even number of basis functions 22004 ae_frame_leave(_state); 22009 * weight decay for correct handling of task which becomes 22010 * degenerate after constraints are applied 22012 decay = 10000*ae_machineepsilon; 22015 * Scale X, Y, XC, YC 22017 lsfitscalexy(x, y, w, n, xc, yc, dc, k, &xa, &xb, &sa, &sb, &xoriginal, &yoriginal, _state); 22020 * allocate space, initialize: 22021 * * SX - grid for basis functions 22022 * * SY - values of basis functions at grid points 22023 * * FMatrix- values of basis functions at X[] 22024 * * CMatrix- values (derivatives) of basis functions at XC[] 22026 ae_vector_set_length(&y2, n+m, _state); 22027 ae_vector_set_length(&w2, n+m, _state); 22028 ae_matrix_set_length(&fmatrix, n+m, m, _state); 22031 ae_matrix_set_length(&cmatrix, k, m+1, _state); 22037 * allocate space for cubic spline 22039 ae_vector_set_length(&sx, m-2, _state); 22040 ae_vector_set_length(&sy, m-2, _state); 22041 for(j=0; j<=m-2-1; j++) 22043 sx.ptr.p_double[j] = (double)(2*j)/(double)(m-2-1)-1; 22050 * allocate space for Hermite spline 22052 ae_vector_set_length(&sx, m/2, _state); 22053 ae_vector_set_length(&sy, m/2, _state); 22054 ae_vector_set_length(&sd, m/2, _state); 22055 for(j=0; j<=m/2-1; j++) 22057 sx.ptr.p_double[j] = (double)(2*j)/(double)(m/2-1)-1; 22062 * Prepare design and constraints matrices: 22063 * * fill constraints matrix 22064 * * fill first N rows of design matrix with values 22065 * * fill next M rows of design matrix with regularizing term 22066 * * append M zeros to Y 22067 * * append M elements, mean(abs(W)) each, to W 22069 for(j=0; j<=m-1; j++) 22073 * prepare Jth basis function 22079 * cubic spline basis 22081 for(i=0; i<=m-2-1; i++) 22083 sy.ptr.p_double[i] = 0; 22089 sy.ptr.p_double[j] = 1; 22099 spline1dbuildcubic(&sx, &sy, m-2, 1, bl, 1, br, &s2, _state); 22107 for(i=0; i<=m/2-1; i++) 22109 sy.ptr.p_double[i] = 0; 22110 sd.ptr.p_double[i] = 0; 22114 sy.ptr.p_double[j/2] = 1; 22118 sd.ptr.p_double[j/2] = 1; 22120 spline1dbuildhermite(&sx, &sy, &sd, m/2, &s2, _state); 22124 * values at X[], XC[] 22126 for(i=0; i<=n-1; i++) 22128 fmatrix.ptr.pp_double[i][j] = spline1dcalc(&s2, x->ptr.p_double[i], _state); 22130 for(i=0; i<=k-1; i++) 22132 ae_assert(dc->ptr.p_int[i]>=0&&dc->ptr.p_int[i]<=2, "Spline1DFit:
internal error!
", _state); 22133 spline1ddiff(&s2, xc->ptr.p_double[i], &v0, &v1, &v2, _state); 22134 if( dc->ptr.p_int[i]==0 ) 22136 cmatrix.ptr.pp_double[i][j] = v0; 22138 if( dc->ptr.p_int[i]==1 ) 22140 cmatrix.ptr.pp_double[i][j] = v1; 22142 if( dc->ptr.p_int[i]==2 ) 22144 cmatrix.ptr.pp_double[i][j] = v2; 22148 for(i=0; i<=k-1; i++) 22150 cmatrix.ptr.pp_double[i][m] = yc->ptr.p_double[i]; 22152 for(i=0; i<=m-1; i++) 22154 for(j=0; j<=m-1; j++) 22158 fmatrix.ptr.pp_double[n+i][j] = decay; 22162 fmatrix.ptr.pp_double[n+i][j] = 0; 22166 ae_vector_set_length(&y2, n+m, _state); 22167 ae_vector_set_length(&w2, n+m, _state); 22168 ae_v_move(&y2.ptr.p_double[0], 1, &y->ptr.p_double[0], 1, ae_v_len(0,n-1)); 22169 ae_v_move(&w2.ptr.p_double[0], 1, &w->ptr.p_double[0], 1, ae_v_len(0,n-1)); 22171 for(i=0; i<=n-1; i++) 22173 mx = mx+ae_fabs(w->ptr.p_double[i], _state); 22176 for(i=0; i<=m-1; i++) 22178 y2.ptr.p_double[n+i] = 0; 22179 w2.ptr.p_double[n+i] = mx; 22183 * Solve constrained task 22189 * solve using regularization 22191 lsfitlinearwc(&y2, &w2, &fmatrix, &cmatrix, n+m, m, k, info, &tmp, &lrep, _state); 22197 * no constraints, no regularization needed 22199 lsfitlinearwc(y, w, &fmatrix, &cmatrix, n, m, k, info, &tmp, &lrep, _state); 22203 ae_frame_leave(_state); 22208 * Generate spline and scale it 22214 * cubic spline basis 22216 ae_v_move(&sy.ptr.p_double[0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,m-2-1)); 22217 spline1dbuildcubic(&sx, &sy, m-2, 1, tmp.ptr.p_double[m-2], 1, tmp.ptr.p_double[m-1], s, _state); 22225 for(i=0; i<=m/2-1; i++) 22227 sy.ptr.p_double[i] = tmp.ptr.p_double[2*i]; 22228 sd.ptr.p_double[i] = tmp.ptr.p_double[2*i+1]; 22230 spline1dbuildhermite(&sx, &sy, &sd, m/2, s, _state); 22232 spline1dlintransx(s, 2/(xb-xa), -(xa+xb)/(xb-xa), _state); 22233 spline1dlintransy(s, sb-sa, sa, _state); 22236 * Scale absolute errors obtained from LSFitLinearW. 22237 * Relative error should be calculated separately 22238 * (because of shifting/scaling of the task) 22240 rep->taskrcond = lrep.taskrcond; 22241 rep->rmserror = lrep.rmserror*(sb-sa); 22242 rep->avgerror = lrep.avgerror*(sb-sa); 22243 rep->maxerror = lrep.maxerror*(sb-sa); 22244 rep->avgrelerror = 0; 22246 for(i=0; i<=n-1; i++) 22248 if( ae_fp_neq(yoriginal.ptr.p_double[i],0) ) 22250 rep->avgrelerror = rep->avgrelerror+ae_fabs(spline1dcalc(s, xoriginal.ptr.p_double[i], _state)-yoriginal.ptr.p_double[i], _state)/ae_fabs(yoriginal.ptr.p_double[i], _state); 22256 rep->avgrelerror = rep->avgrelerror/relcnt; 22258 ae_frame_leave(_state); 22262 /************************************************************************* 22263 Internal fitting subroutine 22264 *************************************************************************/ 22265 static void lsfit_lsfitlinearinternal(/* Real */ ae_vector* y, 22266 /* Real */ ae_vector* w, 22267 /* Real */ ae_matrix* fmatrix, 22271 /* Real */ ae_vector* c, 22275 ae_frame _frame_block; 22297 ae_frame_make(_state, &_frame_block); 22299 ae_vector_clear(c); 22300 _lsfitreport_clear(rep); 22301 ae_matrix_init(&ft, 0, 0, DT_REAL, _state, ae_true); 22302 ae_matrix_init(&q, 0, 0, DT_REAL, _state, ae_true); 22303 ae_matrix_init(&l, 0, 0, DT_REAL, _state, ae_true); 22304 ae_matrix_init(&r, 0, 0, DT_REAL, _state, ae_true); 22305 ae_vector_init(&b, 0, DT_REAL, _state, ae_true); 22306 ae_vector_init(&wmod, 0, DT_REAL, _state, ae_true); 22307 ae_vector_init(&tau, 0, DT_REAL, _state, ae_true); 22308 ae_vector_init(&nzeros, 0, DT_REAL, _state, ae_true); 22309 ae_vector_init(&s, 0, DT_REAL, _state, ae_true); 22310 ae_vector_init(&sv, 0, DT_REAL, _state, ae_true); 22311 ae_matrix_init(&u, 0, 0, DT_REAL, _state, ae_true); 22312 ae_matrix_init(&vt, 0, 0, DT_REAL, _state, ae_true); 22313 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 22314 ae_vector_init(&utb, 0, DT_REAL, _state, ae_true); 22315 ae_vector_init(&sutb, 0, DT_REAL, _state, ae_true); 22317 lsfit_clearreport(rep, _state); 22321 ae_frame_leave(_state); 22325 threshold = ae_sqrt(ae_machineepsilon, _state); 22328 * Degenerate case, needs special handling 22334 * Create design matrix. 22336 ae_matrix_set_length(&ft, n, m, _state); 22337 ae_vector_set_length(&b, n, _state); 22338 ae_vector_set_length(&wmod, n, _state); 22339 for(j=0; j<=n-1; j++) 22341 v = w->ptr.p_double[j]; 22342 ae_v_moved(&ft.ptr.pp_double[j][0], 1, &fmatrix->ptr.pp_double[j][0], 1, ae_v_len(0,m-1), v); 22343 b.ptr.p_double[j] = w->ptr.p_double[j]*y->ptr.p_double[j]; 22344 wmod.ptr.p_double[j] = 1; 22348 * LQ decomposition and reduction to M=N 22350 ae_vector_set_length(c, m, _state); 22351 for(i=0; i<=m-1; i++) 22353 c->ptr.p_double[i] = 0; 22355 rep->taskrcond = 0; 22356 rmatrixlq(&ft, n, m, &tau, _state); 22357 rmatrixlqunpackq(&ft, n, m, &tau, n, &q, _state); 22358 rmatrixlqunpackl(&ft, n, m, &l, _state); 22359 lsfit_lsfitlinearinternal(&b, &wmod, &l, n, n, info, &tmp, rep, _state); 22362 ae_frame_leave(_state); 22365 for(i=0; i<=n-1; i++) 22367 v = tmp.ptr.p_double[i]; 22368 ae_v_addd(&c->ptr.p_double[0], 1, &q.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 22370 ae_frame_leave(_state); 22375 * N>=M. Generate design matrix and reduce to N=M using 22376 * QR decomposition. 22378 ae_matrix_set_length(&ft, n, m, _state); 22379 ae_vector_set_length(&b, n, _state); 22380 for(j=0; j<=n-1; j++) 22382 v = w->ptr.p_double[j]; 22383 ae_v_moved(&ft.ptr.pp_double[j][0], 1, &fmatrix->ptr.pp_double[j][0], 1, ae_v_len(0,m-1), v); 22384 b.ptr.p_double[j] = w->ptr.p_double[j]*y->ptr.p_double[j]; 22386 rmatrixqr(&ft, n, m, &tau, _state); 22387 rmatrixqrunpackq(&ft, n, m, &tau, m, &q, _state); 22388 rmatrixqrunpackr(&ft, n, m, &r, _state); 22389 ae_vector_set_length(&tmp, m, _state); 22390 for(i=0; i<=m-1; i++) 22392 tmp.ptr.p_double[i] = 0; 22394 for(i=0; i<=n-1; i++) 22396 v = b.ptr.p_double[i]; 22397 ae_v_addd(&tmp.ptr.p_double[0], 1, &q.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 22399 ae_vector_set_length(&b, m, _state); 22400 ae_v_move(&b.ptr.p_double[0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,m-1)); 22403 * R contains reduced MxM design upper triangular matrix, 22404 * B contains reduced Mx1 right part. 22406 * Determine system condition number and decide 22407 * should we use triangular solver (faster) or 22408 * SVD-based solver (more stable). 22410 * We can use LU-based RCond estimator for this task. 22412 rep->taskrcond = rmatrixlurcondinf(&r, m, _state); 22413 if( ae_fp_greater(rep->taskrcond,threshold) ) 22417 * use QR-based solver 22419 ae_vector_set_length(c, m, _state); 22420 c->ptr.p_double[m-1] = b.ptr.p_double[m-1]/r.ptr.pp_double[m-1][m-1]; 22421 for(i=m-2; i>=0; i--) 22423 v = ae_v_dotproduct(&r.ptr.pp_double[i][i+1], 1, &c->ptr.p_double[i+1], 1, ae_v_len(i+1,m-1)); 22424 c->ptr.p_double[i] = (b.ptr.p_double[i]-v)/r.ptr.pp_double[i][i]; 22431 * use SVD-based solver 22433 if( !rmatrixsvd(&r, m, m, 1, 1, 2, &sv, &u, &vt, _state) ) 22436 ae_frame_leave(_state); 22439 ae_vector_set_length(&utb, m, _state); 22440 ae_vector_set_length(&sutb, m, _state); 22441 for(i=0; i<=m-1; i++) 22443 utb.ptr.p_double[i] = 0; 22445 for(i=0; i<=m-1; i++) 22447 v = b.ptr.p_double[i]; 22448 ae_v_addd(&utb.ptr.p_double[0], 1, &u.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 22450 if( ae_fp_greater(sv.ptr.p_double[0],0) ) 22452 rep->taskrcond = sv.ptr.p_double[m-1]/sv.ptr.p_double[0]; 22453 for(i=0; i<=m-1; i++) 22455 if( ae_fp_greater(sv.ptr.p_double[i],threshold*sv.ptr.p_double[0]) ) 22457 sutb.ptr.p_double[i] = utb.ptr.p_double[i]/sv.ptr.p_double[i]; 22461 sutb.ptr.p_double[i] = 0; 22467 rep->taskrcond = 0; 22468 for(i=0; i<=m-1; i++) 22470 sutb.ptr.p_double[i] = 0; 22473 ae_vector_set_length(c, m, _state); 22474 for(i=0; i<=m-1; i++) 22476 c->ptr.p_double[i] = 0; 22478 for(i=0; i<=m-1; i++) 22480 v = sutb.ptr.p_double[i]; 22481 ae_v_addd(&c->ptr.p_double[0], 1, &vt.ptr.pp_double[i][0], 1, ae_v_len(0,m-1), v); 22490 rep->avgrelerror = 0; 22493 for(i=0; i<=n-1; i++) 22495 v = ae_v_dotproduct(&fmatrix->ptr.pp_double[i][0], 1, &c->ptr.p_double[0], 1, ae_v_len(0,m-1)); 22496 rep->rmserror = rep->rmserror+ae_sqr(v-y->ptr.p_double[i], _state); 22497 rep->avgerror = rep->avgerror+ae_fabs(v-y->ptr.p_double[i], _state); 22498 if( ae_fp_neq(y->ptr.p_double[i],0) ) 22500 rep->avgrelerror = rep->avgrelerror+ae_fabs(v-y->ptr.p_double[i], _state)/ae_fabs(y->ptr.p_double[i], _state); 22503 rep->maxerror = ae_maxreal(rep->maxerror, ae_fabs(v-y->ptr.p_double[i], _state), _state); 22505 rep->rmserror = ae_sqrt(rep->rmserror/n, _state); 22506 rep->avgerror = rep->avgerror/n; 22509 rep->avgrelerror = rep->avgrelerror/relcnt; 22511 ae_vector_set_length(&nzeros, n, _state); 22512 ae_vector_set_length(&s, m, _state); 22513 for(i=0; i<=m-1; i++) 22515 s.ptr.p_double[i] = 0; 22517 for(i=0; i<=n-1; i++) 22519 for(j=0; j<=m-1; j++) 22521 s.ptr.p_double[j] = s.ptr.p_double[j]+ae_sqr(fmatrix->ptr.pp_double[i][j], _state); 22523 nzeros.ptr.p_double[i] = 0; 22525 for(i=0; i<=m-1; i++) 22527 if( ae_fp_neq(s.ptr.p_double[i],0) ) 22529 s.ptr.p_double[i] = ae_sqrt(1/s.ptr.p_double[i], _state); 22533 s.ptr.p_double[i] = 1; 22536 lsfit_estimateerrors(fmatrix, &nzeros, y, w, c, &s, n, m, rep, &r, 1, _state); 22537 ae_frame_leave(_state); 22541 /************************************************************************* 22542 Internal subroutine 22543 *************************************************************************/ 22544 static void lsfit_lsfitclearrequestfields(lsfitstate* state, 22549 state->needf = ae_false; 22550 state->needfg = ae_false; 22551 state->needfgh = ae_false; 22552 state->xupdated = ae_false; 22556 /************************************************************************* 22557 Internal subroutine, calculates barycentric basis functions. 22558 Used for efficient simultaneous calculation of N basis functions. 22561 Copyright 17.08.2009 by Bochkanov Sergey 22562 *************************************************************************/ 22563 static void lsfit_barycentriccalcbasis(barycentricinterpolant* b, 22565 /* Real */ ae_vector* y, 22577 * special case: N=1 22581 y->ptr.p_double[0] = 1; 22586 * Here we assume that task is normalized, i.e.: 22589 * 3. X[] is ordered 22591 * First, we decide: should we use "safe
" formula (guarded 22592 * against overflow) or fast one? 22594 s = ae_fabs(t-b->x.ptr.p_double[0], _state); 22595 for(i=0; i<=b->n-1; i++) 22597 v = b->x.ptr.p_double[i]; 22598 if( ae_fp_eq(v,t) ) 22600 for(j=0; j<=b->n-1; j++) 22602 y->ptr.p_double[j] = 0; 22604 y->ptr.p_double[i] = 1; 22607 v = ae_fabs(t-v, _state); 22608 if( ae_fp_less(v,s) ) 22614 for(i=0; i<=b->n-1; i++) 22616 v = s/(t-b->x.ptr.p_double[i]); 22617 v = v*b->w.ptr.p_double[i]; 22618 y->ptr.p_double[i] = v; 22622 ae_v_muld(&y->ptr.p_double[0], 1, ae_v_len(0,b->n-1), v); 22626 /************************************************************************* 22627 This is internal function for Chebyshev fitting. 22629 It assumes that input data are normalized: 22630 * X/XC belong to [-1,+1], 22631 * mean(Y)=0, stddev(Y)=1. 22633 It does not checks inputs for errors. 22635 This function is used to fit general (shifted) Chebyshev models, power 22636 basis models or barycentric models. 22639 X - points, array[0..N-1]. 22640 Y - function values, array[0..N-1]. 22641 W - weights, array[0..N-1] 22642 N - number of points, N>0. 22643 XC - points where polynomial values/derivatives are constrained, 22645 YC - values of constraints, array[0..K-1] 22646 DC - array[0..K-1], types of constraints: 22647 * DC[i]=0 means that P(XC[i])=YC[i] 22648 * DC[i]=1 means that P'(XC[i])=YC[i] 22649 K - number of constraints, 0<=K<M. 22650 K=0 means no constraints (XC/YC/DC are not used in such cases) 22651 M - number of basis functions (= polynomial_degree + 1), M>=1 22654 Info- same format as in LSFitLinearW() subroutine: 22655 * Info>0 task is solved 22656 * Info<=0 an error occurred: 22657 -4 means inconvergence of internal SVD 22658 -3 means inconsistent constraints 22659 C - interpolant in Chebyshev form; [-1,+1] is used as base interval 22660 Rep - report, same format as in LSFitLinearW() subroutine. 22661 Following fields are set: 22662 * RMSError rms error on the (X,Y). 22663 * AvgError average error on the (X,Y). 22664 * AvgRelError average relative error on the non-zero Y 22665 * MaxError maximum error 22666 NON-WEIGHTED ERRORS ARE CALCULATED 22669 this subroitine doesn't calculate task's condition number for K<>0. 22671 -- ALGLIB PROJECT -- 22672 Copyright 10.12.2009 by Bochkanov Sergey 22673 *************************************************************************/ 22674 static void lsfit_internalchebyshevfit(/* Real */ ae_vector* x, 22675 /* Real */ ae_vector* y, 22676 /* Real */ ae_vector* w, 22678 /* Real */ ae_vector* xc, 22679 /* Real */ ae_vector* yc, 22680 /* Integer */ ae_vector* dc, 22684 /* Real */ ae_vector* c, 22688 ae_frame _frame_block; 22706 ae_frame_make(_state, &_frame_block); 22707 ae_vector_init_copy(&_xc, xc, _state, ae_true); 22709 ae_vector_init_copy(&_yc, yc, _state, ae_true); 22712 ae_vector_clear(c); 22713 _lsfitreport_clear(rep); 22714 ae_vector_init(&y2, 0, DT_REAL, _state, ae_true); 22715 ae_vector_init(&w2, 0, DT_REAL, _state, ae_true); 22716 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 22717 ae_vector_init(&tmp2, 0, DT_REAL, _state, ae_true); 22718 ae_vector_init(&tmpdiff, 0, DT_REAL, _state, ae_true); 22719 ae_vector_init(&bx, 0, DT_REAL, _state, ae_true); 22720 ae_vector_init(&by, 0, DT_REAL, _state, ae_true); 22721 ae_vector_init(&bw, 0, DT_REAL, _state, ae_true); 22722 ae_matrix_init(&fmatrix, 0, 0, DT_REAL, _state, ae_true); 22723 ae_matrix_init(&cmatrix, 0, 0, DT_REAL, _state, ae_true); 22725 lsfit_clearreport(rep, _state); 22728 * weight decay for correct handling of task which becomes 22729 * degenerate after constraints are applied 22731 decay = 10000*ae_machineepsilon; 22734 * allocate space, initialize/fill: 22735 * * FMatrix- values of basis functions at X[] 22736 * * CMatrix- values (derivatives) of basis functions at XC[] 22737 * * fill constraints matrix 22738 * * fill first N rows of design matrix with values 22739 * * fill next M rows of design matrix with regularizing term 22740 * * append M zeros to Y 22741 * * append M elements, mean(abs(W)) each, to W 22743 ae_vector_set_length(&y2, n+m, _state); 22744 ae_vector_set_length(&w2, n+m, _state); 22745 ae_vector_set_length(&tmp, m, _state); 22746 ae_vector_set_length(&tmpdiff, m, _state); 22747 ae_matrix_set_length(&fmatrix, n+m, m, _state); 22750 ae_matrix_set_length(&cmatrix, k, m+1, _state); 22754 * Fill design matrix, Y2, W2: 22755 * * first N rows with basis functions for original points 22756 * * next M rows with decay terms 22758 for(i=0; i<=n-1; i++) 22763 * use Tmp for calculations to avoid multidimensional arrays overhead 22765 for(j=0; j<=m-1; j++) 22769 tmp.ptr.p_double[j] = 1; 22775 tmp.ptr.p_double[j] = x->ptr.p_double[i]; 22779 tmp.ptr.p_double[j] = 2*x->ptr.p_double[i]*tmp.ptr.p_double[j-1]-tmp.ptr.p_double[j-2]; 22783 ae_v_move(&fmatrix.ptr.pp_double[i][0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,m-1)); 22785 for(i=0; i<=m-1; i++) 22787 for(j=0; j<=m-1; j++) 22791 fmatrix.ptr.pp_double[n+i][j] = decay; 22795 fmatrix.ptr.pp_double[n+i][j] = 0; 22799 ae_v_move(&y2.ptr.p_double[0], 1, &y->ptr.p_double[0], 1, ae_v_len(0,n-1)); 22800 ae_v_move(&w2.ptr.p_double[0], 1, &w->ptr.p_double[0], 1, ae_v_len(0,n-1)); 22802 for(i=0; i<=n-1; i++) 22804 mx = mx+ae_fabs(w->ptr.p_double[i], _state); 22807 for(i=0; i<=m-1; i++) 22809 y2.ptr.p_double[n+i] = 0; 22810 w2.ptr.p_double[n+i] = mx; 22814 * fill constraints matrix 22816 for(i=0; i<=k-1; i++) 22821 * use Tmp for basis function values, 22822 * TmpDiff for basos function derivatives 22824 for(j=0; j<=m-1; j++) 22828 tmp.ptr.p_double[j] = 1; 22829 tmpdiff.ptr.p_double[j] = 0; 22835 tmp.ptr.p_double[j] = xc->ptr.p_double[i]; 22836 tmpdiff.ptr.p_double[j] = 1; 22840 tmp.ptr.p_double[j] = 2*xc->ptr.p_double[i]*tmp.ptr.p_double[j-1]-tmp.ptr.p_double[j-2]; 22841 tmpdiff.ptr.p_double[j] = 2*(tmp.ptr.p_double[j-1]+xc->ptr.p_double[i]*tmpdiff.ptr.p_double[j-1])-tmpdiff.ptr.p_double[j-2]; 22845 if( dc->ptr.p_int[i]==0 ) 22847 ae_v_move(&cmatrix.ptr.pp_double[i][0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,m-1)); 22849 if( dc->ptr.p_int[i]==1 ) 22851 ae_v_move(&cmatrix.ptr.pp_double[i][0], 1, &tmpdiff.ptr.p_double[0], 1, ae_v_len(0,m-1)); 22853 cmatrix.ptr.pp_double[i][m] = yc->ptr.p_double[i]; 22857 * Solve constrained task 22863 * solve using regularization 22865 lsfitlinearwc(&y2, &w2, &fmatrix, &cmatrix, n+m, m, k, info, c, rep, _state); 22871 * no constraints, no regularization needed 22873 lsfitlinearwc(y, w, &fmatrix, &cmatrix, n, m, 0, info, c, rep, _state); 22877 ae_frame_leave(_state); 22880 ae_frame_leave(_state); 22884 /************************************************************************* 22885 Internal Floater-Hormann fitting subroutine for fixed D 22886 *************************************************************************/ 22887 static void lsfit_barycentricfitwcfixedd(/* Real */ ae_vector* x, 22888 /* Real */ ae_vector* y, 22889 /* Real */ ae_vector* w, 22891 /* Real */ ae_vector* xc, 22892 /* Real */ ae_vector* yc, 22893 /* Integer */ ae_vector* dc, 22898 barycentricinterpolant* b, 22899 barycentricfitreport* rep, 22902 ae_frame _frame_block; 22915 ae_vector xoriginal; 22916 ae_vector yoriginal; 22922 barycentricinterpolant b2; 22932 ae_frame_make(_state, &_frame_block); 22933 ae_vector_init_copy(&_x, x, _state, ae_true); 22935 ae_vector_init_copy(&_y, y, _state, ae_true); 22937 ae_vector_init_copy(&_w, w, _state, ae_true); 22939 ae_vector_init_copy(&_xc, xc, _state, ae_true); 22941 ae_vector_init_copy(&_yc, yc, _state, ae_true); 22944 _barycentricinterpolant_clear(b); 22945 _barycentricfitreport_clear(rep); 22946 ae_matrix_init(&fmatrix, 0, 0, DT_REAL, _state, ae_true); 22947 ae_matrix_init(&cmatrix, 0, 0, DT_REAL, _state, ae_true); 22948 ae_vector_init(&y2, 0, DT_REAL, _state, ae_true); 22949 ae_vector_init(&w2, 0, DT_REAL, _state, ae_true); 22950 ae_vector_init(&sx, 0, DT_REAL, _state, ae_true); 22951 ae_vector_init(&sy, 0, DT_REAL, _state, ae_true); 22952 ae_vector_init(&sbf, 0, DT_REAL, _state, ae_true); 22953 ae_vector_init(&xoriginal, 0, DT_REAL, _state, ae_true); 22954 ae_vector_init(&yoriginal, 0, DT_REAL, _state, ae_true); 22955 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 22956 _lsfitreport_init(&lrep, _state, ae_true); 22957 _barycentricinterpolant_init(&b2, _state, ae_true); 22959 if( ((n<1||m<2)||k<0)||k>=m ) 22962 ae_frame_leave(_state); 22965 for(i=0; i<=k-1; i++) 22968 if( dc->ptr.p_int[i]<0 ) 22972 if( dc->ptr.p_int[i]>1 ) 22978 ae_frame_leave(_state); 22984 * weight decay for correct handling of task which becomes 22985 * degenerate after constraints are applied 22987 decay = 10000*ae_machineepsilon; 22990 * Scale X, Y, XC, YC 22992 lsfitscalexy(x, y, w, n, xc, yc, dc, k, &xa, &xb, &sa, &sb, &xoriginal, &yoriginal, _state); 22995 * allocate space, initialize: 22996 * * FMatrix- values of basis functions at X[] 22997 * * CMatrix- values (derivatives) of basis functions at XC[] 22999 ae_vector_set_length(&y2, n+m, _state); 23000 ae_vector_set_length(&w2, n+m, _state); 23001 ae_matrix_set_length(&fmatrix, n+m, m, _state); 23004 ae_matrix_set_length(&cmatrix, k, m+1, _state); 23006 ae_vector_set_length(&y2, n+m, _state); 23007 ae_vector_set_length(&w2, n+m, _state); 23010 * Prepare design and constraints matrices: 23011 * * fill constraints matrix 23012 * * fill first N rows of design matrix with values 23013 * * fill next M rows of design matrix with regularizing term 23014 * * append M zeros to Y 23015 * * append M elements, mean(abs(W)) each, to W 23017 ae_vector_set_length(&sx, m, _state); 23018 ae_vector_set_length(&sy, m, _state); 23019 ae_vector_set_length(&sbf, m, _state); 23020 for(j=0; j<=m-1; j++) 23022 sx.ptr.p_double[j] = (double)(2*j)/(double)(m-1)-1; 23024 for(i=0; i<=m-1; i++) 23026 sy.ptr.p_double[i] = 1; 23028 barycentricbuildfloaterhormann(&sx, &sy, m, d, &b2, _state); 23030 for(i=0; i<=n-1; i++) 23032 lsfit_barycentriccalcbasis(&b2, x->ptr.p_double[i], &sbf, _state); 23033 ae_v_move(&fmatrix.ptr.pp_double[i][0], 1, &sbf.ptr.p_double[0], 1, ae_v_len(0,m-1)); 23034 y2.ptr.p_double[i] = y->ptr.p_double[i]; 23035 w2.ptr.p_double[i] = w->ptr.p_double[i]; 23036 mx = mx+ae_fabs(w->ptr.p_double[i], _state)/n; 23038 for(i=0; i<=m-1; i++) 23040 for(j=0; j<=m-1; j++) 23044 fmatrix.ptr.pp_double[n+i][j] = decay; 23048 fmatrix.ptr.pp_double[n+i][j] = 0; 23051 y2.ptr.p_double[n+i] = 0; 23052 w2.ptr.p_double[n+i] = mx; 23056 for(j=0; j<=m-1; j++) 23058 for(i=0; i<=m-1; i++) 23060 sy.ptr.p_double[i] = 0; 23062 sy.ptr.p_double[j] = 1; 23063 barycentricbuildfloaterhormann(&sx, &sy, m, d, &b2, _state); 23064 for(i=0; i<=k-1; i++) 23066 ae_assert(dc->ptr.p_int[i]>=0&&dc->ptr.p_int[i]<=1, "BarycentricFit:
internal error!
", _state); 23067 barycentricdiff1(&b2, xc->ptr.p_double[i], &v0, &v1, _state); 23068 if( dc->ptr.p_int[i]==0 ) 23070 cmatrix.ptr.pp_double[i][j] = v0; 23072 if( dc->ptr.p_int[i]==1 ) 23074 cmatrix.ptr.pp_double[i][j] = v1; 23078 for(i=0; i<=k-1; i++) 23080 cmatrix.ptr.pp_double[i][m] = yc->ptr.p_double[i]; 23085 * Solve constrained task 23091 * solve using regularization 23093 lsfitlinearwc(&y2, &w2, &fmatrix, &cmatrix, n+m, m, k, info, &tmp, &lrep, _state); 23099 * no constraints, no regularization needed 23101 lsfitlinearwc(y, w, &fmatrix, &cmatrix, n, m, k, info, &tmp, &lrep, _state); 23105 ae_frame_leave(_state); 23110 * Generate interpolant and scale it 23112 ae_v_move(&sy.ptr.p_double[0], 1, &tmp.ptr.p_double[0], 1, ae_v_len(0,m-1)); 23113 barycentricbuildfloaterhormann(&sx, &sy, m, d, b, _state); 23114 barycentriclintransx(b, 2/(xb-xa), -(xa+xb)/(xb-xa), _state); 23115 barycentriclintransy(b, sb-sa, sa, _state); 23118 * Scale absolute errors obtained from LSFitLinearW. 23119 * Relative error should be calculated separately 23120 * (because of shifting/scaling of the task) 23122 rep->taskrcond = lrep.taskrcond; 23123 rep->rmserror = lrep.rmserror*(sb-sa); 23124 rep->avgerror = lrep.avgerror*(sb-sa); 23125 rep->maxerror = lrep.maxerror*(sb-sa); 23126 rep->avgrelerror = 0; 23128 for(i=0; i<=n-1; i++) 23130 if( ae_fp_neq(yoriginal.ptr.p_double[i],0) ) 23132 rep->avgrelerror = rep->avgrelerror+ae_fabs(barycentriccalc(b, xoriginal.ptr.p_double[i], _state)-yoriginal.ptr.p_double[i], _state)/ae_fabs(yoriginal.ptr.p_double[i], _state); 23138 rep->avgrelerror = rep->avgrelerror/relcnt; 23140 ae_frame_leave(_state); 23144 static void lsfit_clearreport(lsfitreport* rep, ae_state *_state) 23148 rep->taskrcond = 0; 23149 rep->iterationscount = 0; 23153 rep->avgrelerror = 0; 23155 rep->wrmserror = 0; 23157 ae_matrix_set_length(&rep->covpar, 0, 0, _state); 23158 ae_vector_set_length(&rep->errpar, 0, _state); 23159 ae_vector_set_length(&rep->errcurve, 0, _state); 23160 ae_vector_set_length(&rep->noise, 0, _state); 23164 /************************************************************************* 23165 This internal function estimates covariance matrix and other error-related 23166 information for linear/nonlinear least squares model. 23168 It has a bit awkward interface, but it can be used for both linear and 23169 nonlinear problems. 23172 F1 - array[0..N-1,0..K-1]: 23173 * for linear problems - matrix of function values 23174 * for nonlinear problems - Jacobian matrix 23175 F0 - array[0..N-1]: 23176 * for linear problems - must be filled with zeros 23177 * for nonlinear problems - must store values of function being 23180 * for linear and nonlinear problems - must store target values 23181 W - weights, array[0..N-1]: 23182 * for linear and nonlinear problems - weights 23184 * for linear and nonlinear problems - current solution 23186 * its components should be strictly positive 23187 * squared inverse of this diagonal matrix is used as damping 23188 factor for covariance matrix (linear and nonlinear problems) 23189 * for nonlinear problems, when scale of the variables is usually 23190 explicitly given by user, you may use scale vector for this 23192 * for linear problems you may set this parameter to 23193 S=sqrt(1/diag(F'*F)) 23194 * this parameter is automatically rescaled by this function, 23195 only relative magnitudes of its components (with respect to 23196 each other) matter. 23197 N - number of points, N>0. 23198 K - number of dimensions 23199 Rep - structure which is used to store results 23200 Z - additional matrix which, depending on ZKind, may contain some 23201 information used to accelerate calculations - or just can be 23203 * for ZKind=0 Z contains no information, just temporary 23204 buffer which can be resized and used as needed 23205 * for ZKind=1 Z contains triangular matrix from QR 23206 decomposition of W*F1. This matrix can be used 23207 to speedup calculation of covariance matrix. 23208 It should not be changed by algorithm. 23209 ZKind- contents of Z 23213 * Rep.CovPar covariance matrix for parameters, array[K,K]. 23214 * Rep.ErrPar errors in parameters, array[K], 23215 errpar = sqrt(diag(CovPar)) 23216 * Rep.ErrCurve vector of fit errors - standard deviations of empirical 23217 best-fit curve from "ideal
" best-fit curve built with 23218 infinite number of samples, array[N]. 23219 errcurve = sqrt(diag(J*CovPar*J')), 23220 where J is Jacobian matrix. 23221 * Rep.Noise vector of per-point estimates of noise, array[N] 23222 * Rep.R2 coefficient of determination (non-weighted) 23224 Other fields of Rep are not changed. 23226 IMPORTANT: errors in parameters are calculated without taking into 23227 account boundary/linear constraints! Presence of constraints 23228 changes distribution of errors, but there is no easy way to 23229 account for constraints when you calculate covariance matrix. 23231 NOTE: noise in the data is estimated as follows: 23232 * for fitting without user-supplied weights all points are 23233 assumed to have same level of noise, which is estimated from 23235 * for fitting with user-supplied weights we assume that noise 23236 level in I-th point is inversely proportional to Ith weight. 23237 Coefficient of proportionality is estimated from the data. 23239 NOTE: we apply small amount of regularization when we invert squared 23240 Jacobian and calculate covariance matrix. It guarantees that 23241 algorithm won't divide by zero during inversion, but skews 23242 error estimates a bit (fractional error is about 10^-9). 23244 However, we believe that this difference is insignificant for 23245 all practical purposes except for the situation when you want 23246 to compare ALGLIB results with "reference
" implementation up 23247 to the last significant digit. 23249 -- ALGLIB PROJECT -- 23250 Copyright 10.12.2009 by Bochkanov Sergey 23251 *************************************************************************/ 23252 static void lsfit_estimateerrors(/* Real */ ae_matrix* f1, 23253 /* Real */ ae_vector* f0, 23254 /* Real */ ae_vector* y, 23255 /* Real */ ae_vector* w, 23256 /* Real */ ae_vector* x, 23257 /* Real */ ae_vector* s, 23261 /* Real */ ae_matrix* z, 23265 ae_frame _frame_block; 23273 matinvreport invrep; 23281 ae_frame_make(_state, &_frame_block); 23282 ae_vector_init_copy(&_s, s, _state, ae_true); 23284 _matinvreport_init(&invrep, _state, ae_true); 23288 * Compute NZCnt - count of non-zero weights 23291 for(i=0; i<=n-1; i++) 23293 if( ae_fp_neq(w->ptr.p_double[i],0) ) 23305 for(i=0; i<=n-1; i++) 23307 if( ae_fp_neq(w->ptr.p_double[i],0) ) 23309 avg = avg+y->ptr.p_double[i]; 23315 for(i=0; i<=n-1; i++) 23317 if( ae_fp_neq(w->ptr.p_double[i],0) ) 23319 v = ae_v_dotproduct(&f1->ptr.pp_double[i][0], 1, &x->ptr.p_double[0], 1, ae_v_len(0,k-1)); 23320 v = v+f0->ptr.p_double[i]; 23321 rss = rss+ae_sqr(v-y->ptr.p_double[i], _state); 23322 tss = tss+ae_sqr(y->ptr.p_double[i]-avg, _state); 23325 if( ae_fp_neq(tss,0) ) 23327 rep->r2 = ae_maxreal(1.0-rss/tss, 0.0, _state); 23340 * Compute estimate of proportionality between noise in the data and weights: 23341 * NoiseC = mean(per-point-noise*per-point-weight) 23342 * Noise level (standard deviation) at each point is equal to NoiseC/W[I]. 23347 for(i=0; i<=n-1; i++) 23349 if( ae_fp_neq(w->ptr.p_double[i],0) ) 23351 v = ae_v_dotproduct(&f1->ptr.pp_double[i][0], 1, &x->ptr.p_double[0], 1, ae_v_len(0,k-1)); 23352 v = v+f0->ptr.p_double[i]; 23353 noisec = noisec+ae_sqr((v-y->ptr.p_double[i])*w->ptr.p_double[i], _state); 23356 noisec = ae_sqrt(noisec/(nzcnt-k), _state); 23364 * Two branches on noise level: 23365 * * NoiseC>0 normal situation 23366 * * NoiseC=0 degenerate case CovPar is filled by zeros 23368 rmatrixsetlengthatleast(&rep->covpar, k, k, _state); 23369 if( ae_fp_greater(noisec,0) ) 23373 * Normal situation: non-zero noise level 23375 ae_assert(zkind==0||zkind==1, "LSFit:
internal error in EstimateErrors()
function", _state); 23380 * Z contains no additional information which can be used to speed up 23381 * calculations. We have to calculate covariance matrix on our own: 23382 * * Compute scaled Jacobian N*J, where N[i,i]=WCur[I]/NoiseC, store in Z 23383 * * Compute Z'*Z, store in CovPar 23384 * * Apply moderate regularization to CovPar and compute matrix inverse. 23385 * In case inverse failed, increase regularization parameter and try 23388 rmatrixsetlengthatleast(z, n, k, _state); 23389 for(i=0; i<=n-1; i++) 23391 v = w->ptr.p_double[i]/noisec; 23392 ae_v_moved(&z->ptr.pp_double[i][0], 1, &f1->ptr.pp_double[i][0], 1, ae_v_len(0,k-1), v); 23396 * Convert S to automatically scaled damped matrix: 23397 * * calculate SZ - sum of diagonal elements of Z'*Z 23398 * * calculate SS - sum of diagonal elements of S^(-2) 23399 * * overwrite S by (SZ/SS)*S^(-2) 23400 * * now S has approximately same magnitude as giagonal of Z'*Z 23403 for(i=0; i<=n-1; i++) 23405 for(j=0; j<=k-1; j++) 23407 sz = sz+z->ptr.pp_double[i][j]*z->ptr.pp_double[i][j]; 23410 if( ae_fp_eq(sz,0) ) 23415 for(j=0; j<=k-1; j++) 23417 ss = ss+1/ae_sqr(s->ptr.p_double[j], _state); 23419 for(j=0; j<=k-1; j++) 23421 s->ptr.p_double[j] = sz/ss/ae_sqr(s->ptr.p_double[j], _state); 23425 * Calculate damped inverse inv(Z'*Z+S). 23426 * We increase damping factor V until Z'*Z become well-conditioned. 23428 v = 1.0E3*ae_machineepsilon; 23431 rmatrixsyrk(k, n, 1.0, z, 0, 0, 2, 0.0, &rep->covpar, 0, 0, ae_true, _state); 23432 for(i=0; i<=k-1; i++) 23434 rep->covpar.ptr.pp_double[i][i] = rep->covpar.ptr.pp_double[i][i]+v*s->ptr.p_double[i]; 23436 spdmatrixinverse(&rep->covpar, k, ae_true, &info, &invrep, _state); 23440 for(i=0; i<=k-1; i++) 23442 for(j=i+1; j<=k-1; j++) 23444 rep->covpar.ptr.pp_double[j][i] = rep->covpar.ptr.pp_double[i][j]; 23452 * We can reuse additional information: 23453 * * Z contains R matrix from QR decomposition of W*F1 23454 * * After multiplication by 1/NoiseC we get Z_mod = N*F1, where diag(N)=w[i]/NoiseC 23455 * * Such triangular Z_mod is a Cholesky factor from decomposition of J'*N'*N*J. 23456 * Thus, we can calculate covariance matrix as inverse of the matrix given by 23457 * its Cholesky decomposition. It allow us to avoid time-consuming calculation 23458 * of J'*N'*N*J in CovPar - complexity is reduced from O(N*K^2) to O(K^3), which 23459 * is quite good because K is usually orders of magnitude smaller than N. 23461 * First, convert S to automatically scaled damped matrix: 23462 * * calculate SZ - sum of magnitudes of diagonal elements of Z/NoiseC 23463 * * calculate SS - sum of diagonal elements of S^(-1) 23464 * * overwrite S by (SZ/SS)*S^(-1) 23465 * * now S has approximately same magnitude as giagonal of Z'*Z 23468 for(j=0; j<=k-1; j++) 23470 sz = sz+ae_fabs(z->ptr.pp_double[j][j]/noisec, _state); 23472 if( ae_fp_eq(sz,0) ) 23477 for(j=0; j<=k-1; j++) 23479 ss = ss+1/s->ptr.p_double[j]; 23481 for(j=0; j<=k-1; j++) 23483 s->ptr.p_double[j] = sz/ss/s->ptr.p_double[j]; 23487 * Calculate damped inverse of inv((Z+v*S)'*(Z+v*S)) 23488 * We increase damping factor V until matrix become well-conditioned. 23490 v = 1.0E3*ae_machineepsilon; 23493 for(i=0; i<=k-1; i++) 23495 for(j=i; j<=k-1; j++) 23497 rep->covpar.ptr.pp_double[i][j] = z->ptr.pp_double[i][j]/noisec; 23499 rep->covpar.ptr.pp_double[i][i] = rep->covpar.ptr.pp_double[i][i]+v*s->ptr.p_double[i]; 23501 spdmatrixcholeskyinverse(&rep->covpar, k, ae_true, &info, &invrep, _state); 23505 for(i=0; i<=k-1; i++) 23507 for(j=i+1; j<=k-1; j++) 23509 rep->covpar.ptr.pp_double[j][i] = rep->covpar.ptr.pp_double[i][j]; 23518 * Degenerate situation: zero noise level, covariance matrix is zero. 23520 for(i=0; i<=k-1; i++) 23522 for(j=0; j<=k-1; j++) 23524 rep->covpar.ptr.pp_double[j][i] = 0; 23530 * Estimate erorrs in parameters, curve and per-point noise 23532 rvectorsetlengthatleast(&rep->errpar, k, _state); 23533 rvectorsetlengthatleast(&rep->errcurve, n, _state); 23534 rvectorsetlengthatleast(&rep->noise, n, _state); 23535 for(i=0; i<=k-1; i++) 23537 rep->errpar.ptr.p_double[i] = ae_sqrt(rep->covpar.ptr.pp_double[i][i], _state); 23539 for(i=0; i<=n-1; i++) 23543 * ErrCurve[I] is sqrt(P[i,i]) where P=J*CovPar*J' 23546 for(j=0; j<=k-1; j++) 23548 for(j1=0; j1<=k-1; j1++) 23550 v = v+f1->ptr.pp_double[i][j]*rep->covpar.ptr.pp_double[j][j1]*f1->ptr.pp_double[i][j1]; 23553 rep->errcurve.ptr.p_double[i] = ae_sqrt(v, _state); 23556 * Noise[i] is filled using weights and current estimate of noise level 23558 if( ae_fp_neq(w->ptr.p_double[i],0) ) 23560 rep->noise.ptr.p_double[i] = noisec/w->ptr.p_double[i]; 23564 rep->noise.ptr.p_double[i] = 0; 23567 ae_frame_leave(_state); 23571 ae_bool _polynomialfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic) 23573 polynomialfitreport *p = (polynomialfitreport*)_p; 23574 ae_touch_ptr((void*)p); 23579 ae_bool _polynomialfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 23581 polynomialfitreport *dst = (polynomialfitreport*)_dst; 23582 polynomialfitreport *src = (polynomialfitreport*)_src; 23583 dst->taskrcond = src->taskrcond; 23584 dst->rmserror = src->rmserror; 23585 dst->avgerror = src->avgerror; 23586 dst->avgrelerror = src->avgrelerror; 23587 dst->maxerror = src->maxerror; 23592 void _polynomialfitreport_clear(void* _p) 23594 polynomialfitreport *p = (polynomialfitreport*)_p; 23595 ae_touch_ptr((void*)p); 23599 void _polynomialfitreport_destroy(void* _p) 23601 polynomialfitreport *p = (polynomialfitreport*)_p; 23602 ae_touch_ptr((void*)p); 23606 ae_bool _barycentricfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic) 23608 barycentricfitreport *p = (barycentricfitreport*)_p; 23609 ae_touch_ptr((void*)p); 23614 ae_bool _barycentricfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 23616 barycentricfitreport *dst = (barycentricfitreport*)_dst; 23617 barycentricfitreport *src = (barycentricfitreport*)_src; 23618 dst->taskrcond = src->taskrcond; 23619 dst->dbest = src->dbest; 23620 dst->rmserror = src->rmserror; 23621 dst->avgerror = src->avgerror; 23622 dst->avgrelerror = src->avgrelerror; 23623 dst->maxerror = src->maxerror; 23628 void _barycentricfitreport_clear(void* _p) 23630 barycentricfitreport *p = (barycentricfitreport*)_p; 23631 ae_touch_ptr((void*)p); 23635 void _barycentricfitreport_destroy(void* _p) 23637 barycentricfitreport *p = (barycentricfitreport*)_p; 23638 ae_touch_ptr((void*)p); 23642 ae_bool _spline1dfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic) 23644 spline1dfitreport *p = (spline1dfitreport*)_p; 23645 ae_touch_ptr((void*)p); 23650 ae_bool _spline1dfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 23652 spline1dfitreport *dst = (spline1dfitreport*)_dst; 23653 spline1dfitreport *src = (spline1dfitreport*)_src; 23654 dst->taskrcond = src->taskrcond; 23655 dst->rmserror = src->rmserror; 23656 dst->avgerror = src->avgerror; 23657 dst->avgrelerror = src->avgrelerror; 23658 dst->maxerror = src->maxerror; 23663 void _spline1dfitreport_clear(void* _p) 23665 spline1dfitreport *p = (spline1dfitreport*)_p; 23666 ae_touch_ptr((void*)p); 23670 void _spline1dfitreport_destroy(void* _p) 23672 spline1dfitreport *p = (spline1dfitreport*)_p; 23673 ae_touch_ptr((void*)p); 23677 ae_bool _lsfitreport_init(void* _p, ae_state *_state, ae_bool make_automatic) 23679 lsfitreport *p = (lsfitreport*)_p; 23680 ae_touch_ptr((void*)p); 23681 if( !ae_matrix_init(&p->covpar, 0, 0, DT_REAL, _state, make_automatic) ) 23683 if( !ae_vector_init(&p->errpar, 0, DT_REAL, _state, make_automatic) ) 23685 if( !ae_vector_init(&p->errcurve, 0, DT_REAL, _state, make_automatic) ) 23687 if( !ae_vector_init(&p->noise, 0, DT_REAL, _state, make_automatic) ) 23693 ae_bool _lsfitreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 23695 lsfitreport *dst = (lsfitreport*)_dst; 23696 lsfitreport *src = (lsfitreport*)_src; 23697 dst->taskrcond = src->taskrcond; 23698 dst->iterationscount = src->iterationscount; 23699 dst->varidx = src->varidx; 23700 dst->rmserror = src->rmserror; 23701 dst->avgerror = src->avgerror; 23702 dst->avgrelerror = src->avgrelerror; 23703 dst->maxerror = src->maxerror; 23704 dst->wrmserror = src->wrmserror; 23705 if( !ae_matrix_init_copy(&dst->covpar, &src->covpar, _state, make_automatic) ) 23707 if( !ae_vector_init_copy(&dst->errpar, &src->errpar, _state, make_automatic) ) 23709 if( !ae_vector_init_copy(&dst->errcurve, &src->errcurve, _state, make_automatic) ) 23711 if( !ae_vector_init_copy(&dst->noise, &src->noise, _state, make_automatic) ) 23718 void _lsfitreport_clear(void* _p) 23720 lsfitreport *p = (lsfitreport*)_p; 23721 ae_touch_ptr((void*)p); 23722 ae_matrix_clear(&p->covpar); 23723 ae_vector_clear(&p->errpar); 23724 ae_vector_clear(&p->errcurve); 23725 ae_vector_clear(&p->noise); 23729 void _lsfitreport_destroy(void* _p) 23731 lsfitreport *p = (lsfitreport*)_p; 23732 ae_touch_ptr((void*)p); 23733 ae_matrix_destroy(&p->covpar); 23734 ae_vector_destroy(&p->errpar); 23735 ae_vector_destroy(&p->errcurve); 23736 ae_vector_destroy(&p->noise); 23740 ae_bool _lsfitstate_init(void* _p, ae_state *_state, ae_bool make_automatic) 23742 lsfitstate *p = (lsfitstate*)_p; 23743 ae_touch_ptr((void*)p); 23744 if( !ae_vector_init(&p->s, 0, DT_REAL, _state, make_automatic) ) 23746 if( !ae_vector_init(&p->bndl, 0, DT_REAL, _state, make_automatic) ) 23748 if( !ae_vector_init(&p->bndu, 0, DT_REAL, _state, make_automatic) ) 23750 if( !ae_matrix_init(&p->taskx, 0, 0, DT_REAL, _state, make_automatic) ) 23752 if( !ae_vector_init(&p->tasky, 0, DT_REAL, _state, make_automatic) ) 23754 if( !ae_vector_init(&p->taskw, 0, DT_REAL, _state, make_automatic) ) 23756 if( !ae_vector_init(&p->x, 0, DT_REAL, _state, make_automatic) ) 23758 if( !ae_vector_init(&p->c, 0, DT_REAL, _state, make_automatic) ) 23760 if( !ae_vector_init(&p->g, 0, DT_REAL, _state, make_automatic) ) 23762 if( !ae_matrix_init(&p->h, 0, 0, DT_REAL, _state, make_automatic) ) 23764 if( !ae_vector_init(&p->wcur, 0, DT_REAL, _state, make_automatic) ) 23766 if( !ae_vector_init(&p->tmp, 0, DT_REAL, _state, make_automatic) ) 23768 if( !ae_vector_init(&p->tmpf, 0, DT_REAL, _state, make_automatic) ) 23770 if( !ae_matrix_init(&p->tmpjac, 0, 0, DT_REAL, _state, make_automatic) ) 23772 if( !ae_matrix_init(&p->tmpjacw, 0, 0, DT_REAL, _state, make_automatic) ) 23774 if( !_matinvreport_init(&p->invrep, _state, make_automatic) ) 23776 if( !_lsfitreport_init(&p->rep, _state, make_automatic) ) 23778 if( !_minlmstate_init(&p->optstate, _state, make_automatic) ) 23780 if( !_minlmreport_init(&p->optrep, _state, make_automatic) ) 23782 if( !_rcommstate_init(&p->rstate, _state, make_automatic) ) 23788 ae_bool _lsfitstate_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 23790 lsfitstate *dst = (lsfitstate*)_dst; 23791 lsfitstate *src = (lsfitstate*)_src; 23792 dst->optalgo = src->optalgo; 23795 dst->epsf = src->epsf; 23796 dst->epsx = src->epsx; 23797 dst->maxits = src->maxits; 23798 dst->stpmax = src->stpmax; 23799 dst->xrep = src->xrep; 23800 if( !ae_vector_init_copy(&dst->s, &src->s, _state, make_automatic) ) 23802 if( !ae_vector_init_copy(&dst->bndl, &src->bndl, _state, make_automatic) ) 23804 if( !ae_vector_init_copy(&dst->bndu, &src->bndu, _state, make_automatic) ) 23806 if( !ae_matrix_init_copy(&dst->taskx, &src->taskx, _state, make_automatic) ) 23808 if( !ae_vector_init_copy(&dst->tasky, &src->tasky, _state, make_automatic) ) 23810 dst->npoints = src->npoints; 23811 if( !ae_vector_init_copy(&dst->taskw, &src->taskw, _state, make_automatic) ) 23813 dst->nweights = src->nweights; 23814 dst->wkind = src->wkind; 23815 dst->wits = src->wits; 23816 dst->diffstep = src->diffstep; 23817 dst->teststep = src->teststep; 23818 dst->xupdated = src->xupdated; 23819 dst->needf = src->needf; 23820 dst->needfg = src->needfg; 23821 dst->needfgh = src->needfgh; 23822 dst->pointindex = src->pointindex; 23823 if( !ae_vector_init_copy(&dst->x, &src->x, _state, make_automatic) ) 23825 if( !ae_vector_init_copy(&dst->c, &src->c, _state, make_automatic) ) 23828 if( !ae_vector_init_copy(&dst->g, &src->g, _state, make_automatic) ) 23830 if( !ae_matrix_init_copy(&dst->h, &src->h, _state, make_automatic) ) 23832 if( !ae_vector_init_copy(&dst->wcur, &src->wcur, _state, make_automatic) ) 23834 if( !ae_vector_init_copy(&dst->tmp, &src->tmp, _state, make_automatic) ) 23836 if( !ae_vector_init_copy(&dst->tmpf, &src->tmpf, _state, make_automatic) ) 23838 if( !ae_matrix_init_copy(&dst->tmpjac, &src->tmpjac, _state, make_automatic) ) 23840 if( !ae_matrix_init_copy(&dst->tmpjacw, &src->tmpjacw, _state, make_automatic) ) 23842 dst->tmpnoise = src->tmpnoise; 23843 if( !_matinvreport_init_copy(&dst->invrep, &src->invrep, _state, make_automatic) ) 23845 dst->repiterationscount = src->repiterationscount; 23846 dst->repterminationtype = src->repterminationtype; 23847 dst->repvaridx = src->repvaridx; 23848 dst->reprmserror = src->reprmserror; 23849 dst->repavgerror = src->repavgerror; 23850 dst->repavgrelerror = src->repavgrelerror; 23851 dst->repmaxerror = src->repmaxerror; 23852 dst->repwrmserror = src->repwrmserror; 23853 if( !_lsfitreport_init_copy(&dst->rep, &src->rep, _state, make_automatic) ) 23855 if( !_minlmstate_init_copy(&dst->optstate, &src->optstate, _state, make_automatic) ) 23857 if( !_minlmreport_init_copy(&dst->optrep, &src->optrep, _state, make_automatic) ) 23859 dst->prevnpt = src->prevnpt; 23860 dst->prevalgo = src->prevalgo; 23861 if( !_rcommstate_init_copy(&dst->rstate, &src->rstate, _state, make_automatic) ) 23867 void _lsfitstate_clear(void* _p) 23869 lsfitstate *p = (lsfitstate*)_p; 23870 ae_touch_ptr((void*)p); 23871 ae_vector_clear(&p->s); 23872 ae_vector_clear(&p->bndl); 23873 ae_vector_clear(&p->bndu); 23874 ae_matrix_clear(&p->taskx); 23875 ae_vector_clear(&p->tasky); 23876 ae_vector_clear(&p->taskw); 23877 ae_vector_clear(&p->x); 23878 ae_vector_clear(&p->c); 23879 ae_vector_clear(&p->g); 23880 ae_matrix_clear(&p->h); 23881 ae_vector_clear(&p->wcur); 23882 ae_vector_clear(&p->tmp); 23883 ae_vector_clear(&p->tmpf); 23884 ae_matrix_clear(&p->tmpjac); 23885 ae_matrix_clear(&p->tmpjacw); 23886 _matinvreport_clear(&p->invrep); 23887 _lsfitreport_clear(&p->rep); 23888 _minlmstate_clear(&p->optstate); 23889 _minlmreport_clear(&p->optrep); 23890 _rcommstate_clear(&p->rstate); 23894 void _lsfitstate_destroy(void* _p) 23896 lsfitstate *p = (lsfitstate*)_p; 23897 ae_touch_ptr((void*)p); 23898 ae_vector_destroy(&p->s); 23899 ae_vector_destroy(&p->bndl); 23900 ae_vector_destroy(&p->bndu); 23901 ae_matrix_destroy(&p->taskx); 23902 ae_vector_destroy(&p->tasky); 23903 ae_vector_destroy(&p->taskw); 23904 ae_vector_destroy(&p->x); 23905 ae_vector_destroy(&p->c); 23906 ae_vector_destroy(&p->g); 23907 ae_matrix_destroy(&p->h); 23908 ae_vector_destroy(&p->wcur); 23909 ae_vector_destroy(&p->tmp); 23910 ae_vector_destroy(&p->tmpf); 23911 ae_matrix_destroy(&p->tmpjac); 23912 ae_matrix_destroy(&p->tmpjacw); 23913 _matinvreport_destroy(&p->invrep); 23914 _lsfitreport_destroy(&p->rep); 23915 _minlmstate_destroy(&p->optstate); 23916 _minlmreport_destroy(&p->optrep); 23917 _rcommstate_destroy(&p->rstate); 23923 /************************************************************************* 23924 This function builds non-periodic 2-dimensional parametric spline which 23925 starts at (X[0],Y[0]) and ends at (X[N-1],Y[N-1]). 23928 XY - points, array[0..N-1,0..1]. 23929 XY[I,0:1] corresponds to the Ith point. 23930 Order of points is important! 23931 N - points count, N>=5 for Akima splines, N>=2 for other types of 23935 * 1 parabolically terminated Catmull-Rom spline (Tension=0) 23936 * 2 parabolically terminated cubic spline 23937 PT - parameterization type: 23943 P - parametric spline interpolant 23947 * this function assumes that there all consequent points are distinct. 23948 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on. 23949 However, non-consequent points may coincide, i.e. we can have (x0,y0)= 23952 -- ALGLIB PROJECT -- 23953 Copyright 28.05.2010 by Bochkanov Sergey 23954 *************************************************************************/ 23955 void pspline2build(/* Real */ ae_matrix* xy, 23959 pspline2interpolant* p, 23962 ae_frame _frame_block; 23966 ae_frame_make(_state, &_frame_block); 23967 ae_matrix_init_copy(&_xy, xy, _state, ae_true); 23969 _pspline2interpolant_clear(p); 23970 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 23972 ae_assert(st>=0&&st<=2, "PSpline2Build: incorrect spline
type!
", _state); 23973 ae_assert(pt>=0&&pt<=2, "PSpline2Build: incorrect parameterization
type!
", _state); 23976 ae_assert(n>=5, "PSpline2Build: N<5 (minimum value
for Akima splines)!
", _state); 23980 ae_assert(n>=2, "PSpline2Build: N<2!
", _state); 23987 p->periodic = ae_false; 23988 ae_vector_set_length(&tmp, n, _state); 23991 * Build parameterization, check that all parameters are distinct 23993 pspline_pspline2par(xy, n, pt, &p->p, _state); 23994 ae_assert(aredistinct(&p->p, n, _state), "PSpline2Build: consequent points are too close!
", _state); 24001 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24002 spline1dbuildakima(&p->p, &tmp, n, &p->x, _state); 24003 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24004 spline1dbuildakima(&p->p, &tmp, n, &p->y, _state); 24008 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24009 spline1dbuildcatmullrom(&p->p, &tmp, n, 0, 0.0, &p->x, _state); 24010 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24011 spline1dbuildcatmullrom(&p->p, &tmp, n, 0, 0.0, &p->y, _state); 24015 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24016 spline1dbuildcubic(&p->p, &tmp, n, 0, 0.0, 0, 0.0, &p->x, _state); 24017 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24018 spline1dbuildcubic(&p->p, &tmp, n, 0, 0.0, 0, 0.0, &p->y, _state); 24020 ae_frame_leave(_state); 24024 /************************************************************************* 24025 This function builds non-periodic 3-dimensional parametric spline which 24026 starts at (X[0],Y[0],Z[0]) and ends at (X[N-1],Y[N-1],Z[N-1]). 24028 Same as PSpline2Build() function, but for 3D, so we won't duplicate its 24031 -- ALGLIB PROJECT -- 24032 Copyright 28.05.2010 by Bochkanov Sergey 24033 *************************************************************************/ 24034 void pspline3build(/* Real */ ae_matrix* xy, 24038 pspline3interpolant* p, 24041 ae_frame _frame_block; 24045 ae_frame_make(_state, &_frame_block); 24046 ae_matrix_init_copy(&_xy, xy, _state, ae_true); 24048 _pspline3interpolant_clear(p); 24049 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 24051 ae_assert(st>=0&&st<=2, "PSpline3Build: incorrect spline
type!
", _state); 24052 ae_assert(pt>=0&&pt<=2, "PSpline3Build: incorrect parameterization
type!
", _state); 24055 ae_assert(n>=5, "PSpline3Build: N<5 (minimum value
for Akima splines)!
", _state); 24059 ae_assert(n>=2, "PSpline3Build: N<2!
", _state); 24066 p->periodic = ae_false; 24067 ae_vector_set_length(&tmp, n, _state); 24070 * Build parameterization, check that all parameters are distinct 24072 pspline_pspline3par(xy, n, pt, &p->p, _state); 24073 ae_assert(aredistinct(&p->p, n, _state), "PSpline3Build: consequent points are too close!
", _state); 24080 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24081 spline1dbuildakima(&p->p, &tmp, n, &p->x, _state); 24082 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24083 spline1dbuildakima(&p->p, &tmp, n, &p->y, _state); 24084 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][2], xy->stride, ae_v_len(0,n-1)); 24085 spline1dbuildakima(&p->p, &tmp, n, &p->z, _state); 24089 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24090 spline1dbuildcatmullrom(&p->p, &tmp, n, 0, 0.0, &p->x, _state); 24091 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24092 spline1dbuildcatmullrom(&p->p, &tmp, n, 0, 0.0, &p->y, _state); 24093 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][2], xy->stride, ae_v_len(0,n-1)); 24094 spline1dbuildcatmullrom(&p->p, &tmp, n, 0, 0.0, &p->z, _state); 24098 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24099 spline1dbuildcubic(&p->p, &tmp, n, 0, 0.0, 0, 0.0, &p->x, _state); 24100 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24101 spline1dbuildcubic(&p->p, &tmp, n, 0, 0.0, 0, 0.0, &p->y, _state); 24102 ae_v_move(&tmp.ptr.p_double[0], 1, &xy->ptr.pp_double[0][2], xy->stride, ae_v_len(0,n-1)); 24103 spline1dbuildcubic(&p->p, &tmp, n, 0, 0.0, 0, 0.0, &p->z, _state); 24105 ae_frame_leave(_state); 24109 /************************************************************************* 24110 This function builds periodic 2-dimensional parametric spline which 24111 starts at (X[0],Y[0]), goes through all points to (X[N-1],Y[N-1]) and then 24112 back to (X[0],Y[0]). 24115 XY - points, array[0..N-1,0..1]. 24116 XY[I,0:1] corresponds to the Ith point. 24117 XY[N-1,0:1] must be different from XY[0,0:1]. 24118 Order of points is important! 24119 N - points count, N>=3 for other types of splines. 24121 * 1 Catmull-Rom spline (Tension=0) with cyclic boundary conditions 24122 * 2 cubic spline with cyclic boundary conditions 24123 PT - parameterization type: 24129 P - parametric spline interpolant 24133 * this function assumes that there all consequent points are distinct. 24134 I.e. (x0,y0)<>(x1,y1), (x1,y1)<>(x2,y2), (x2,y2)<>(x3,y3) and so on. 24135 However, non-consequent points may coincide, i.e. we can have (x0,y0)= 24137 * last point of sequence is NOT equal to the first point. You shouldn't 24138 make curve "explicitly periodic
" by making them equal. 24140 -- ALGLIB PROJECT -- 24141 Copyright 28.05.2010 by Bochkanov Sergey 24142 *************************************************************************/ 24143 void pspline2buildperiodic(/* Real */ ae_matrix* xy, 24147 pspline2interpolant* p, 24150 ae_frame _frame_block; 24155 ae_frame_make(_state, &_frame_block); 24156 ae_matrix_init_copy(&_xy, xy, _state, ae_true); 24158 _pspline2interpolant_clear(p); 24159 ae_matrix_init(&xyp, 0, 0, DT_REAL, _state, ae_true); 24160 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 24162 ae_assert(st>=1&&st<=2, "PSpline2BuildPeriodic: incorrect spline
type!
", _state); 24163 ae_assert(pt>=0&&pt<=2, "PSpline2BuildPeriodic: incorrect parameterization
type!
", _state); 24164 ae_assert(n>=3, "PSpline2BuildPeriodic: N<3!
", _state); 24170 p->periodic = ae_true; 24171 ae_vector_set_length(&tmp, n+1, _state); 24172 ae_matrix_set_length(&xyp, n+1, 2, _state); 24173 ae_v_move(&xyp.ptr.pp_double[0][0], xyp.stride, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24174 ae_v_move(&xyp.ptr.pp_double[0][1], xyp.stride, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24175 ae_v_move(&xyp.ptr.pp_double[n][0], 1, &xy->ptr.pp_double[0][0], 1, ae_v_len(0,1)); 24178 * Build parameterization, check that all parameters are distinct 24180 pspline_pspline2par(&xyp, n+1, pt, &p->p, _state); 24181 ae_assert(aredistinct(&p->p, n+1, _state), "PSpline2BuildPeriodic: consequent (
or first and last) points are too close!
", _state); 24188 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][0], xyp.stride, ae_v_len(0,n)); 24189 spline1dbuildcatmullrom(&p->p, &tmp, n+1, -1, 0.0, &p->x, _state); 24190 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][1], xyp.stride, ae_v_len(0,n)); 24191 spline1dbuildcatmullrom(&p->p, &tmp, n+1, -1, 0.0, &p->y, _state); 24195 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][0], xyp.stride, ae_v_len(0,n)); 24196 spline1dbuildcubic(&p->p, &tmp, n+1, -1, 0.0, -1, 0.0, &p->x, _state); 24197 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][1], xyp.stride, ae_v_len(0,n)); 24198 spline1dbuildcubic(&p->p, &tmp, n+1, -1, 0.0, -1, 0.0, &p->y, _state); 24200 ae_frame_leave(_state); 24204 /************************************************************************* 24205 This function builds periodic 3-dimensional parametric spline which 24206 starts at (X[0],Y[0],Z[0]), goes through all points to (X[N-1],Y[N-1],Z[N-1]) 24207 and then back to (X[0],Y[0],Z[0]). 24209 Same as PSpline2Build() function, but for 3D, so we won't duplicate its 24212 -- ALGLIB PROJECT -- 24213 Copyright 28.05.2010 by Bochkanov Sergey 24214 *************************************************************************/ 24215 void pspline3buildperiodic(/* Real */ ae_matrix* xy, 24219 pspline3interpolant* p, 24222 ae_frame _frame_block; 24227 ae_frame_make(_state, &_frame_block); 24228 ae_matrix_init_copy(&_xy, xy, _state, ae_true); 24230 _pspline3interpolant_clear(p); 24231 ae_matrix_init(&xyp, 0, 0, DT_REAL, _state, ae_true); 24232 ae_vector_init(&tmp, 0, DT_REAL, _state, ae_true); 24234 ae_assert(st>=1&&st<=2, "PSpline3BuildPeriodic: incorrect spline
type!
", _state); 24235 ae_assert(pt>=0&&pt<=2, "PSpline3BuildPeriodic: incorrect parameterization
type!
", _state); 24236 ae_assert(n>=3, "PSpline3BuildPeriodic: N<3!
", _state); 24242 p->periodic = ae_true; 24243 ae_vector_set_length(&tmp, n+1, _state); 24244 ae_matrix_set_length(&xyp, n+1, 3, _state); 24245 ae_v_move(&xyp.ptr.pp_double[0][0], xyp.stride, &xy->ptr.pp_double[0][0], xy->stride, ae_v_len(0,n-1)); 24246 ae_v_move(&xyp.ptr.pp_double[0][1], xyp.stride, &xy->ptr.pp_double[0][1], xy->stride, ae_v_len(0,n-1)); 24247 ae_v_move(&xyp.ptr.pp_double[0][2], xyp.stride, &xy->ptr.pp_double[0][2], xy->stride, ae_v_len(0,n-1)); 24248 ae_v_move(&xyp.ptr.pp_double[n][0], 1, &xy->ptr.pp_double[0][0], 1, ae_v_len(0,2)); 24251 * Build parameterization, check that all parameters are distinct 24253 pspline_pspline3par(&xyp, n+1, pt, &p->p, _state); 24254 ae_assert(aredistinct(&p->p, n+1, _state), "PSplineBuild2Periodic: consequent (
or first and last) points are too close!
", _state); 24261 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][0], xyp.stride, ae_v_len(0,n)); 24262 spline1dbuildcatmullrom(&p->p, &tmp, n+1, -1, 0.0, &p->x, _state); 24263 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][1], xyp.stride, ae_v_len(0,n)); 24264 spline1dbuildcatmullrom(&p->p, &tmp, n+1, -1, 0.0, &p->y, _state); 24265 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][2], xyp.stride, ae_v_len(0,n)); 24266 spline1dbuildcatmullrom(&p->p, &tmp, n+1, -1, 0.0, &p->z, _state); 24270 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][0], xyp.stride, ae_v_len(0,n)); 24271 spline1dbuildcubic(&p->p, &tmp, n+1, -1, 0.0, -1, 0.0, &p->x, _state); 24272 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][1], xyp.stride, ae_v_len(0,n)); 24273 spline1dbuildcubic(&p->p, &tmp, n+1, -1, 0.0, -1, 0.0, &p->y, _state); 24274 ae_v_move(&tmp.ptr.p_double[0], 1, &xyp.ptr.pp_double[0][2], xyp.stride, ae_v_len(0,n)); 24275 spline1dbuildcubic(&p->p, &tmp, n+1, -1, 0.0, -1, 0.0, &p->z, _state); 24277 ae_frame_leave(_state); 24281 /************************************************************************* 24282 This function returns vector of parameter values correspoding to points. 24284 I.e. for P created from (X[0],Y[0])...(X[N-1],Y[N-1]) and U=TValues(P) we 24286 (X[0],Y[0]) = PSpline2Calc(P,U[0]), 24287 (X[1],Y[1]) = PSpline2Calc(P,U[1]), 24288 (X[2],Y[2]) = PSpline2Calc(P,U[2]), 24292 P - parametric spline interpolant 24300 * for non-periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]=1 24301 * for periodic splines U[0]=0, U[0]<U[1]<...<U[N-1], U[N-1]<1 24303 -- ALGLIB PROJECT -- 24304 Copyright 28.05.2010 by Bochkanov Sergey 24305 *************************************************************************/ 24306 void pspline2parametervalues(pspline2interpolant* p, 24308 /* Real */ ae_vector* t, 24313 ae_vector_clear(t); 24315 ae_assert(p->n>=2, "PSpline2ParameterValues:
internal error!
", _state); 24317 ae_vector_set_length(t, *n, _state); 24318 ae_v_move(&t->ptr.p_double[0], 1, &p->p.ptr.p_double[0], 1, ae_v_len(0,*n-1)); 24319 t->ptr.p_double[0] = 0; 24322 t->ptr.p_double[*n-1] = 1; 24327 /************************************************************************* 24328 This function returns vector of parameter values correspoding to points. 24330 Same as PSpline2ParameterValues(), but for 3D. 24332 -- ALGLIB PROJECT -- 24333 Copyright 28.05.2010 by Bochkanov Sergey 24334 *************************************************************************/ 24335 void pspline3parametervalues(pspline3interpolant* p, 24337 /* Real */ ae_vector* t, 24342 ae_vector_clear(t); 24344 ae_assert(p->n>=2, "PSpline3ParameterValues:
internal error!
", _state); 24346 ae_vector_set_length(t, *n, _state); 24347 ae_v_move(&t->ptr.p_double[0], 1, &p->p.ptr.p_double[0], 1, ae_v_len(0,*n-1)); 24348 t->ptr.p_double[0] = 0; 24351 t->ptr.p_double[*n-1] = 1; 24356 /************************************************************************* 24357 This function calculates the value of the parametric spline for a given 24358 value of parameter T 24361 P - parametric spline interpolant 24363 * T in [0,1] corresponds to interval spanned by points 24364 * for non-periodic splines T<0 (or T>1) correspond to parts of 24365 the curve before the first (after the last) point 24366 * for periodic splines T<0 (or T>1) are projected into [0,1] 24367 by making T=T-floor(T). 24374 -- ALGLIB PROJECT -- 24375 Copyright 28.05.2010 by Bochkanov Sergey 24376 *************************************************************************/ 24377 void pspline2calc(pspline2interpolant* p, 24389 t = t-ae_ifloor(t, _state); 24391 *x = spline1dcalc(&p->x, t, _state); 24392 *y = spline1dcalc(&p->y, t, _state); 24396 /************************************************************************* 24397 This function calculates the value of the parametric spline for a given 24398 value of parameter T. 24401 P - parametric spline interpolant 24403 * T in [0,1] corresponds to interval spanned by points 24404 * for non-periodic splines T<0 (or T>1) correspond to parts of 24405 the curve before the first (after the last) point 24406 * for periodic splines T<0 (or T>1) are projected into [0,1] 24407 by making T=T-floor(T). 24415 -- ALGLIB PROJECT -- 24416 Copyright 28.05.2010 by Bochkanov Sergey 24417 *************************************************************************/ 24418 void pspline3calc(pspline3interpolant* p, 24432 t = t-ae_ifloor(t, _state); 24434 *x = spline1dcalc(&p->x, t, _state); 24435 *y = spline1dcalc(&p->y, t, _state); 24436 *z = spline1dcalc(&p->z, t, _state); 24440 /************************************************************************* 24441 This function calculates tangent vector for a given value of parameter T 24444 P - parametric spline interpolant 24446 * T in [0,1] corresponds to interval spanned by points 24447 * for non-periodic splines T<0 (or T>1) correspond to parts of 24448 the curve before the first (after the last) point 24449 * for periodic splines T<0 (or T>1) are projected into [0,1] 24450 by making T=T-floor(T). 24453 X - X-component of tangent vector (normalized) 24454 Y - Y-component of tangent vector (normalized) 24457 X^2+Y^2 is either 1 (for non-zero tangent vector) or 0. 24460 -- ALGLIB PROJECT -- 24461 Copyright 28.05.2010 by Bochkanov Sergey 24462 *************************************************************************/ 24463 void pspline2tangent(pspline2interpolant* p, 24478 t = t-ae_ifloor(t, _state); 24480 pspline2diff(p, t, &v0, x, &v1, y, _state); 24481 if( ae_fp_neq(*x,0)||ae_fp_neq(*y,0) ) 24485 * this code is a bit more complex than X^2+Y^2 to avoid 24486 * overflow for large values of X and Y. 24488 v = safepythag2(*x, *y, _state); 24495 /************************************************************************* 24496 This function calculates tangent vector for a given value of parameter T 24499 P - parametric spline interpolant 24501 * T in [0,1] corresponds to interval spanned by points 24502 * for non-periodic splines T<0 (or T>1) correspond to parts of 24503 the curve before the first (after the last) point 24504 * for periodic splines T<0 (or T>1) are projected into [0,1] 24505 by making T=T-floor(T). 24508 X - X-component of tangent vector (normalized) 24509 Y - Y-component of tangent vector (normalized) 24510 Z - Z-component of tangent vector (normalized) 24513 X^2+Y^2+Z^2 is either 1 (for non-zero tangent vector) or 0. 24516 -- ALGLIB PROJECT -- 24517 Copyright 28.05.2010 by Bochkanov Sergey 24518 *************************************************************************/ 24519 void pspline3tangent(pspline3interpolant* p, 24537 t = t-ae_ifloor(t, _state); 24539 pspline3diff(p, t, &v0, x, &v1, y, &v2, z, _state); 24540 if( (ae_fp_neq(*x,0)||ae_fp_neq(*y,0))||ae_fp_neq(*z,0) ) 24542 v = safepythag3(*x, *y, *z, _state); 24550 /************************************************************************* 24551 This function calculates derivative, i.e. it returns (dX/dT,dY/dT). 24554 P - parametric spline interpolant 24556 * T in [0,1] corresponds to interval spanned by points 24557 * for non-periodic splines T<0 (or T>1) correspond to parts of 24558 the curve before the first (after the last) point 24559 * for periodic splines T<0 (or T>1) are projected into [0,1] 24560 by making T=T-floor(T). 24569 -- ALGLIB PROJECT -- 24570 Copyright 28.05.2010 by Bochkanov Sergey 24571 *************************************************************************/ 24572 void pspline2diff(pspline2interpolant* p, 24589 t = t-ae_ifloor(t, _state); 24591 spline1ddiff(&p->x, t, x, dx, &d2s, _state); 24592 spline1ddiff(&p->y, t, y, dy, &d2s, _state); 24596 /************************************************************************* 24597 This function calculates derivative, i.e. it returns (dX/dT,dY/dT,dZ/dT). 24600 P - parametric spline interpolant 24602 * T in [0,1] corresponds to interval spanned by points 24603 * for non-periodic splines T<0 (or T>1) correspond to parts of 24604 the curve before the first (after the last) point 24605 * for periodic splines T<0 (or T>1) are projected into [0,1] 24606 by making T=T-floor(T). 24617 -- ALGLIB PROJECT -- 24618 Copyright 28.05.2010 by Bochkanov Sergey 24619 *************************************************************************/ 24620 void pspline3diff(pspline3interpolant* p, 24641 t = t-ae_ifloor(t, _state); 24643 spline1ddiff(&p->x, t, x, dx, &d2s, _state); 24644 spline1ddiff(&p->y, t, y, dy, &d2s, _state); 24645 spline1ddiff(&p->z, t, z, dz, &d2s, _state); 24649 /************************************************************************* 24650 This function calculates first and second derivative with respect to T. 24653 P - parametric spline interpolant 24655 * T in [0,1] corresponds to interval spanned by points 24656 * for non-periodic splines T<0 (or T>1) correspond to parts of 24657 the curve before the first (after the last) point 24658 * for periodic splines T<0 (or T>1) are projected into [0,1] 24659 by making T=T-floor(T). 24664 D2X - second derivative 24667 D2Y - second derivative 24670 -- ALGLIB PROJECT -- 24671 Copyright 28.05.2010 by Bochkanov Sergey 24672 *************************************************************************/ 24673 void pspline2diff2(pspline2interpolant* p, 24693 t = t-ae_ifloor(t, _state); 24695 spline1ddiff(&p->x, t, x, dx, d2x, _state); 24696 spline1ddiff(&p->y, t, y, dy, d2y, _state); 24700 /************************************************************************* 24701 This function calculates first and second derivative with respect to T. 24704 P - parametric spline interpolant 24706 * T in [0,1] corresponds to interval spanned by points 24707 * for non-periodic splines T<0 (or T>1) correspond to parts of 24708 the curve before the first (after the last) point 24709 * for periodic splines T<0 (or T>1) are projected into [0,1] 24710 by making T=T-floor(T). 24715 D2X - second derivative 24718 D2Y - second derivative 24721 D2Z - second derivative 24724 -- ALGLIB PROJECT -- 24725 Copyright 28.05.2010 by Bochkanov Sergey 24726 *************************************************************************/ 24727 void pspline3diff2(pspline3interpolant* p, 24753 t = t-ae_ifloor(t, _state); 24755 spline1ddiff(&p->x, t, x, dx, d2x, _state); 24756 spline1ddiff(&p->y, t, y, dy, d2y, _state); 24757 spline1ddiff(&p->z, t, z, dz, d2z, _state); 24761 /************************************************************************* 24762 This function calculates arc length, i.e. length of curve between t=a 24766 P - parametric spline interpolant 24767 A,B - parameter values corresponding to arc ends: 24768 * B>A will result in positive length returned 24769 * B<A will result in negative length returned 24772 length of arc starting at T=A and ending at T=B. 24775 -- ALGLIB PROJECT -- 24776 Copyright 30.05.2010 by Bochkanov Sergey 24777 *************************************************************************/ 24778 double pspline2arclength(pspline2interpolant* p, 24783 ae_frame _frame_block; 24794 ae_frame_make(_state, &_frame_block); 24795 _autogkstate_init(&state, _state, ae_true); 24796 _autogkreport_init(&rep, _state, ae_true); 24798 autogksmooth(a, b, &state, _state); 24799 while(autogkiteration(&state, _state)) 24801 spline1ddiff(&p->x, state.x, &sx, &dsx, &d2sx, _state); 24802 spline1ddiff(&p->y, state.x, &sy, &dsy, &d2sy, _state); 24803 state.f = safepythag2(dsx, dsy, _state); 24805 autogkresults(&state, &result, &rep, _state); 24806 ae_assert(rep.terminationtype>0, "PSpline2ArcLength:
internal error!
", _state); 24807 ae_frame_leave(_state); 24812 /************************************************************************* 24813 This function calculates arc length, i.e. length of curve between t=a 24817 P - parametric spline interpolant 24818 A,B - parameter values corresponding to arc ends: 24819 * B>A will result in positive length returned 24820 * B<A will result in negative length returned 24823 length of arc starting at T=A and ending at T=B. 24826 -- ALGLIB PROJECT -- 24827 Copyright 30.05.2010 by Bochkanov Sergey 24828 *************************************************************************/ 24829 double pspline3arclength(pspline3interpolant* p, 24834 ae_frame _frame_block; 24848 ae_frame_make(_state, &_frame_block); 24849 _autogkstate_init(&state, _state, ae_true); 24850 _autogkreport_init(&rep, _state, ae_true); 24852 autogksmooth(a, b, &state, _state); 24853 while(autogkiteration(&state, _state)) 24855 spline1ddiff(&p->x, state.x, &sx, &dsx, &d2sx, _state); 24856 spline1ddiff(&p->y, state.x, &sy, &dsy, &d2sy, _state); 24857 spline1ddiff(&p->z, state.x, &sz, &dsz, &d2sz, _state); 24858 state.f = safepythag3(dsx, dsy, dsz, _state); 24860 autogkresults(&state, &result, &rep, _state); 24861 ae_assert(rep.terminationtype>0, "PSpline3ArcLength:
internal error!
", _state); 24862 ae_frame_leave(_state); 24867 /************************************************************************* 24868 Builds non-periodic parameterization for 2-dimensional spline 24869 *************************************************************************/ 24870 static void pspline_pspline2par(/* Real */ ae_matrix* xy, 24873 /* Real */ ae_vector* p, 24879 ae_vector_clear(p); 24881 ae_assert(pt>=0&&pt<=2, "PSpline2Par:
internal error!
", _state); 24884 * Build parameterization: 24885 * * fill by non-normalized values 24886 * * normalize them so we have P[0]=0, P[N-1]=1. 24888 ae_vector_set_length(p, n, _state); 24891 for(i=0; i<=n-1; i++) 24893 p->ptr.p_double[i] = i; 24898 p->ptr.p_double[0] = 0; 24899 for(i=1; i<=n-1; i++) 24901 p->ptr.p_double[i] = p->ptr.p_double[i-1]+safepythag2(xy->ptr.pp_double[i][0]-xy->ptr.pp_double[i-1][0], xy->ptr.pp_double[i][1]-xy->ptr.pp_double[i-1][1], _state); 24906 p->ptr.p_double[0] = 0; 24907 for(i=1; i<=n-1; i++) 24909 p->ptr.p_double[i] = p->ptr.p_double[i-1]+ae_sqrt(safepythag2(xy->ptr.pp_double[i][0]-xy->ptr.pp_double[i-1][0], xy->ptr.pp_double[i][1]-xy->ptr.pp_double[i-1][1], _state), _state); 24912 v = 1/p->ptr.p_double[n-1]; 24913 ae_v_muld(&p->ptr.p_double[0], 1, ae_v_len(0,n-1), v); 24917 /************************************************************************* 24918 Builds non-periodic parameterization for 3-dimensional spline 24919 *************************************************************************/ 24920 static void pspline_pspline3par(/* Real */ ae_matrix* xy, 24923 /* Real */ ae_vector* p, 24929 ae_vector_clear(p); 24931 ae_assert(pt>=0&&pt<=2, "PSpline3Par:
internal error!
", _state); 24934 * Build parameterization: 24935 * * fill by non-normalized values 24936 * * normalize them so we have P[0]=0, P[N-1]=1. 24938 ae_vector_set_length(p, n, _state); 24941 for(i=0; i<=n-1; i++) 24943 p->ptr.p_double[i] = i; 24948 p->ptr.p_double[0] = 0; 24949 for(i=1; i<=n-1; i++) 24951 p->ptr.p_double[i] = p->ptr.p_double[i-1]+safepythag3(xy->ptr.pp_double[i][0]-xy->ptr.pp_double[i-1][0], xy->ptr.pp_double[i][1]-xy->ptr.pp_double[i-1][1], xy->ptr.pp_double[i][2]-xy->ptr.pp_double[i-1][2], _state); 24956 p->ptr.p_double[0] = 0; 24957 for(i=1; i<=n-1; i++) 24959 p->ptr.p_double[i] = p->ptr.p_double[i-1]+ae_sqrt(safepythag3(xy->ptr.pp_double[i][0]-xy->ptr.pp_double[i-1][0], xy->ptr.pp_double[i][1]-xy->ptr.pp_double[i-1][1], xy->ptr.pp_double[i][2]-xy->ptr.pp_double[i-1][2], _state), _state); 24962 v = 1/p->ptr.p_double[n-1]; 24963 ae_v_muld(&p->ptr.p_double[0], 1, ae_v_len(0,n-1), v); 24967 ae_bool _pspline2interpolant_init(void* _p, ae_state *_state, ae_bool make_automatic) 24969 pspline2interpolant *p = (pspline2interpolant*)_p; 24970 ae_touch_ptr((void*)p); 24971 if( !ae_vector_init(&p->p, 0, DT_REAL, _state, make_automatic) ) 24973 if( !_spline1dinterpolant_init(&p->x, _state, make_automatic) ) 24975 if( !_spline1dinterpolant_init(&p->y, _state, make_automatic) ) 24981 ae_bool _pspline2interpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 24983 pspline2interpolant *dst = (pspline2interpolant*)_dst; 24984 pspline2interpolant *src = (pspline2interpolant*)_src; 24986 dst->periodic = src->periodic; 24987 if( !ae_vector_init_copy(&dst->p, &src->p, _state, make_automatic) ) 24989 if( !_spline1dinterpolant_init_copy(&dst->x, &src->x, _state, make_automatic) ) 24991 if( !_spline1dinterpolant_init_copy(&dst->y, &src->y, _state, make_automatic) ) 24997 void _pspline2interpolant_clear(void* _p) 24999 pspline2interpolant *p = (pspline2interpolant*)_p; 25000 ae_touch_ptr((void*)p); 25001 ae_vector_clear(&p->p); 25002 _spline1dinterpolant_clear(&p->x); 25003 _spline1dinterpolant_clear(&p->y); 25007 void _pspline2interpolant_destroy(void* _p) 25009 pspline2interpolant *p = (pspline2interpolant*)_p; 25010 ae_touch_ptr((void*)p); 25011 ae_vector_destroy(&p->p); 25012 _spline1dinterpolant_destroy(&p->x); 25013 _spline1dinterpolant_destroy(&p->y); 25017 ae_bool _pspline3interpolant_init(void* _p, ae_state *_state, ae_bool make_automatic) 25019 pspline3interpolant *p = (pspline3interpolant*)_p; 25020 ae_touch_ptr((void*)p); 25021 if( !ae_vector_init(&p->p, 0, DT_REAL, _state, make_automatic) ) 25023 if( !_spline1dinterpolant_init(&p->x, _state, make_automatic) ) 25025 if( !_spline1dinterpolant_init(&p->y, _state, make_automatic) ) 25027 if( !_spline1dinterpolant_init(&p->z, _state, make_automatic) ) 25033 ae_bool _pspline3interpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 25035 pspline3interpolant *dst = (pspline3interpolant*)_dst; 25036 pspline3interpolant *src = (pspline3interpolant*)_src; 25038 dst->periodic = src->periodic; 25039 if( !ae_vector_init_copy(&dst->p, &src->p, _state, make_automatic) ) 25041 if( !_spline1dinterpolant_init_copy(&dst->x, &src->x, _state, make_automatic) ) 25043 if( !_spline1dinterpolant_init_copy(&dst->y, &src->y, _state, make_automatic) ) 25045 if( !_spline1dinterpolant_init_copy(&dst->z, &src->z, _state, make_automatic) ) 25051 void _pspline3interpolant_clear(void* _p) 25053 pspline3interpolant *p = (pspline3interpolant*)_p; 25054 ae_touch_ptr((void*)p); 25055 ae_vector_clear(&p->p); 25056 _spline1dinterpolant_clear(&p->x); 25057 _spline1dinterpolant_clear(&p->y); 25058 _spline1dinterpolant_clear(&p->z); 25062 void _pspline3interpolant_destroy(void* _p) 25064 pspline3interpolant *p = (pspline3interpolant*)_p; 25065 ae_touch_ptr((void*)p); 25066 ae_vector_destroy(&p->p); 25067 _spline1dinterpolant_destroy(&p->x); 25068 _spline1dinterpolant_destroy(&p->y); 25069 _spline1dinterpolant_destroy(&p->z); 25075 /************************************************************************* 25076 This function creates RBF model for a scalar (NY=1) or vector (NY>1) 25077 function in a NX-dimensional space (NX=2 or NX=3). 25079 Newly created model is empty. It can be used for interpolation right after 25080 creation, but it just returns zeros. You have to add points to the model, 25081 tune interpolation settings, and then call model construction function 25082 RBFBuildModel() which will update model according to your specification. 25085 1. User creates model with RBFCreate() 25086 2. User adds dataset with RBFSetPoints() (points do NOT have to be on a 25088 3. (OPTIONAL) User chooses polynomial term by calling: 25089 * RBFLinTerm() to set linear term 25090 * RBFConstTerm() to set constant term 25091 * RBFZeroTerm() to set zero term 25092 By default, linear term is used. 25093 4. User chooses specific RBF algorithm to use: either QNN (RBFSetAlgoQNN) 25094 or ML (RBFSetAlgoMultiLayer). 25095 5. User calls RBFBuildModel() function which rebuilds model according to 25097 6. User may call RBFCalc() to calculate model value at the specified point, 25098 RBFGridCalc() to calculate model values at the points of the regular 25099 grid. User may extract model coefficients with RBFUnpack() call. 25102 NX - dimension of the space, NX=2 or NX=3 25103 NY - function dimension, NY>=1 25106 S - RBF model (initially equals to zero) 25108 NOTE 1: memory requirements. RBF models require amount of memory which is 25109 proportional to the number of data points. Memory is allocated 25110 during model construction, but most of this memory is freed after 25111 model coefficients are calculated. 25113 Some approximate estimates for N centers with default settings are 25115 * about 250*N*(sizeof(double)+2*sizeof(int)) bytes of memory is 25116 needed during model construction stage. 25117 * about 15*N*sizeof(double) bytes is needed after model is built. 25118 For example, for N=100000 we may need 0.6 GB of memory to build 25119 model, but just about 0.012 GB to store it. 25122 Copyright 13.12.2011 by Bochkanov Sergey 25123 *************************************************************************/ 25124 void rbfcreate(ae_int_t nx, ae_int_t ny, rbfmodel* s, ae_state *_state) 25129 _rbfmodel_clear(s); 25131 ae_assert(nx==2||nx==3, "RBFCreate: NX<>2 and NX<>3
", _state); 25132 ae_assert(ny>=1, "RBFCreate: NY<1
", _state); 25137 ae_matrix_set_length(&s->v, ny, rbf_mxnx+1, _state); 25138 for(i=0; i<=ny-1; i++) 25140 for(j=0; j<=rbf_mxnx; j++) 25142 s->v.ptr.pp_double[i][j] = 0; 25148 s->fixrad = ae_false; 25152 s->algorithmtype = 1; 25155 * stopping criteria 25157 s->epsort = rbf_eps; 25158 s->epserr = rbf_eps; 25163 /************************************************************************* 25164 This function adds dataset. 25166 This function overrides results of the previous calls, i.e. multiple calls 25167 of this function will result in only the last set being added. 25170 S - RBF model, initialized by RBFCreate() call. 25171 XY - points, array[N,NX+NY]. One row corresponds to one point 25172 in the dataset. First NX elements are coordinates, next 25173 NY elements are function values. Array may be larger than 25174 specific, in this case only leading [N,NX+NY] elements 25176 N - number of points in the dataset 25178 After you've added dataset and (optionally) tuned algorithm settings you 25179 should call RBFBuildModel() in order to build a model for you. 25181 NOTE: this function has some serialization-related subtleties. We 25182 recommend you to study serialization examples from ALGLIB Reference 25183 Manual if you want to perform serialization of your models. 25187 Copyright 13.12.2011 by Bochkanov Sergey 25188 *************************************************************************/ 25189 void rbfsetpoints(rbfmodel* s, 25190 /* Real */ ae_matrix* xy, 25198 ae_assert(n>0, "RBFSetPoints: N<0
", _state); 25199 ae_assert(xy->rows>=n, "RBFSetPoints: Rows(XY)<N
", _state); 25200 ae_assert(xy->cols>=s->nx+s->ny, "RBFSetPoints: Cols(XY)<NX+NY
", _state); 25202 ae_matrix_set_length(&s->x, s->n, rbf_mxnx, _state); 25203 ae_matrix_set_length(&s->y, s->n, s->ny, _state); 25204 for(i=0; i<=s->n-1; i++) 25206 for(j=0; j<=rbf_mxnx-1; j++) 25208 s->x.ptr.pp_double[i][j] = 0; 25210 for(j=0; j<=s->nx-1; j++) 25212 s->x.ptr.pp_double[i][j] = xy->ptr.pp_double[i][j]; 25214 for(j=0; j<=s->ny-1; j++) 25216 s->y.ptr.pp_double[i][j] = xy->ptr.pp_double[i][j+s->nx]; 25222 /************************************************************************* 25223 This function sets RBF interpolation algorithm. ALGLIB supports several 25224 RBF algorithms with different properties. 25226 This algorithm is called RBF-QNN and it is good for point sets with 25227 following properties: 25228 a) all points are distinct 25229 b) all points are well separated. 25230 c) points distribution is approximately uniform. There is no "contour
25231 lines
", clusters of points, or other small-scale structures. 25233 Algorithm description: 25234 1) interpolation centers are allocated to data points 25235 2) interpolation radii are calculated as distances to the nearest centers 25236 times Q coefficient (where Q is a value from [0.75,1.50]). 25237 3) after performing (2) radii are transformed in order to avoid situation 25238 when single outlier has very large radius and influences many points 25239 across all dataset. Transformation has following form: 25240 new_r[i] = min(r[i],Z*median(r[])) 25241 where r[i] is I-th radius, median() is a median radius across entire 25242 dataset, Z is user-specified value which controls amount of deviation 25243 from median radius. 25245 When (a) is violated, we will be unable to build RBF model. When (b) or 25246 (c) are violated, model will be built, but interpolation quality will be 25247 low. See http://www.alglib.net/interpolation/ for more information on this 25250 This algorithm is used by default. 25252 Additional Q parameter controls smoothness properties of the RBF basis: 25253 * Q<0.75 will give perfectly conditioned basis, but terrible smoothness 25254 properties (RBF interpolant will have sharp peaks around function values) 25255 * Q around 1.0 gives good balance between smoothness and condition number 25256 * Q>1.5 will lead to badly conditioned systems and slow convergence of the 25257 underlying linear solver (although smoothness will be very good) 25258 * Q>2.0 will effectively make optimizer useless because it won't converge 25259 within reasonable amount of iterations. It is possible to set such large 25260 Q, but it is advised not to do so. 25263 S - RBF model, initialized by RBFCreate() call 25264 Q - Q parameter, Q>0, recommended value - 1.0 25265 Z - Z parameter, Z>0, recommended value - 5.0 25267 NOTE: this function has some serialization-related subtleties. We 25268 recommend you to study serialization examples from ALGLIB Reference 25269 Manual if you want to perform serialization of your models. 25273 Copyright 13.12.2011 by Bochkanov Sergey 25274 *************************************************************************/ 25275 void rbfsetalgoqnn(rbfmodel* s, double q, double z, ae_state *_state) 25279 ae_assert(ae_isfinite(q, _state), "RBFSetAlgoQNN: Q is infinite
or NAN
", _state); 25280 ae_assert(ae_fp_greater(q,0), "RBFSetAlgoQNN: Q<=0
", _state); 25281 rbf_rbfgridpoints(s, _state); 25282 rbf_rbfradnn(s, q, z, _state); 25283 s->algorithmtype = 1; 25287 /************************************************************************* 25288 This function sets RBF interpolation algorithm. ALGLIB supports several 25289 RBF algorithms with different properties. 25291 This algorithm is called RBF-ML. It builds multilayer RBF model, i.e. 25292 model with subsequently decreasing radii, which allows us to combine 25293 smoothness (due to large radii of the first layers) with exactness (due 25294 to small radii of the last layers) and fast convergence. 25296 Internally RBF-ML uses many different means of acceleration, from sparse 25297 matrices to KD-trees, which results in algorithm whose working time is 25298 roughly proportional to N*log(N)*Density*RBase^2*NLayers, where N is a 25299 number of points, Density is an average density if points per unit of the 25300 interpolation space, RBase is an initial radius, NLayers is a number of 25303 RBF-ML is good for following kinds of interpolation problems: 25304 1. "exact
" problems (perfect fit) with well separated points 25305 2. least squares problems with arbitrary distribution of points (algorithm 25306 gives perfect fit where it is possible, and resorts to least squares 25307 fit in the hard areas). 25308 3. noisy problems where we want to apply some controlled amount of 25312 S - RBF model, initialized by RBFCreate() call 25313 RBase - RBase parameter, RBase>0 25314 NLayers - NLayers parameter, NLayers>0, recommended value to start 25316 LambdaV - regularization value, can be useful when solving problem 25317 in the least squares sense. Optimal lambda is problem- 25318 dependent and require trial and error. In our experience, 25319 good lambda can be as large as 0.1, and you can use 0.001 25321 Default value - 0.01, which is used when LambdaV is not 25322 given. You can specify zero value, but it is not 25323 recommended to do so. 25327 In order to use this algorithm you have to choose three parameters: 25328 * initial radius RBase 25329 * number of layers in the model NLayers 25330 * regularization coefficient LambdaV 25332 Initial radius is easy to choose - you can pick any number several times 25333 larger than the average distance between points. Algorithm won't break 25334 down if you choose radius which is too large (model construction time will 25335 increase, but model will be built correctly). 25337 Choose such number of layers that RLast=RBase/2^(NLayers-1) (radius used 25338 by the last layer) will be smaller than the typical distance between 25339 points. In case model error is too large, you can increase number of 25340 layers. Having more layers will make model construction and evaluation 25341 proportionally slower, but it will allow you to have model which precisely 25342 fits your data. From the other side, if you want to suppress noise, you 25343 can DECREASE number of layers to make your model less flexible. 25345 Regularization coefficient LambdaV controls smoothness of the individual 25346 models built for each layer. We recommend you to use default value in case 25347 you don't want to tune this parameter, because having non-zero LambdaV 25348 accelerates and stabilizes internal iterative algorithm. In case you want 25349 to suppress noise you can use LambdaV as additional parameter (larger 25350 value = more smoothness) to tune. 25354 1. Using initial radius which is too large. Memory requirements of the 25355 RBF-ML are roughly proportional to N*Density*RBase^2 (where Density is 25356 an average density of points per unit of the interpolation space). In 25357 the extreme case of the very large RBase we will need O(N^2) units of 25358 memory - and many layers in order to decrease radius to some reasonably 25361 2. Using too small number of layers - RBF models with large radius are not 25362 flexible enough to reproduce small variations in the target function. 25363 You need many layers with different radii, from large to small, in 25364 order to have good model. 25366 3. Using initial radius which is too small. You will get model with 25367 "holes
" in the areas which are too far away from interpolation centers. 25368 However, algorithm will work correctly (and quickly) in this case. 25370 4. Using too many layers - you will get too large and too slow model. This 25371 model will perfectly reproduce your function, but maybe you will be 25372 able to achieve similar results with less layers (and less memory). 25375 Copyright 02.03.2012 by Bochkanov Sergey 25376 *************************************************************************/ 25377 void rbfsetalgomultilayer(rbfmodel* s, 25385 ae_assert(ae_isfinite(rbase, _state), "RBFSetAlgoMultiLayer: RBase is infinite
or NaN
", _state); 25386 ae_assert(ae_fp_greater(rbase,0), "RBFSetAlgoMultiLayer: RBase<=0
", _state); 25387 ae_assert(nlayers>=0, "RBFSetAlgoMultiLayer: NLayers<0
", _state); 25388 ae_assert(ae_isfinite(lambdav, _state), "RBFSetAlgoMultiLayer: LambdaV is infinite
or NAN
", _state); 25389 ae_assert(ae_fp_greater_eq(lambdav,0), "RBFSetAlgoMultiLayer: LambdaV<0
", _state); 25390 s->radvalue = rbase; 25391 s->nlayers = nlayers; 25392 s->algorithmtype = 2; 25393 s->lambdav = lambdav; 25397 /************************************************************************* 25398 This function sets linear term (model is a sum of radial basis functions 25399 plus linear polynomial). This function won't have effect until next call 25400 to RBFBuildModel(). 25403 S - RBF model, initialized by RBFCreate() call 25405 NOTE: this function has some serialization-related subtleties. We 25406 recommend you to study serialization examples from ALGLIB Reference 25407 Manual if you want to perform serialization of your models. 25410 Copyright 13.12.2011 by Bochkanov Sergey 25411 *************************************************************************/ 25412 void rbfsetlinterm(rbfmodel* s, ae_state *_state) 25420 /************************************************************************* 25421 This function sets constant term (model is a sum of radial basis functions 25422 plus constant). This function won't have effect until next call to 25426 S - RBF model, initialized by RBFCreate() call 25428 NOTE: this function has some serialization-related subtleties. We 25429 recommend you to study serialization examples from ALGLIB Reference 25430 Manual if you want to perform serialization of your models. 25433 Copyright 13.12.2011 by Bochkanov Sergey 25434 *************************************************************************/ 25435 void rbfsetconstterm(rbfmodel* s, ae_state *_state) 25443 /************************************************************************* 25444 This function sets zero term (model is a sum of radial basis functions 25445 without polynomial term). This function won't have effect until next call 25446 to RBFBuildModel(). 25449 S - RBF model, initialized by RBFCreate() call 25451 NOTE: this function has some serialization-related subtleties. We 25452 recommend you to study serialization examples from ALGLIB Reference 25453 Manual if you want to perform serialization of your models. 25456 Copyright 13.12.2011 by Bochkanov Sergey 25457 *************************************************************************/ 25458 void rbfsetzeroterm(rbfmodel* s, ae_state *_state) 25466 /************************************************************************* 25467 This function sets stopping criteria of the underlying linear solver. 25470 S - RBF model, initialized by RBFCreate() call 25471 EpsOrt - orthogonality stopping criterion, EpsOrt>=0. Algorithm will 25472 stop when ||A'*r||<=EpsOrt where A' is a transpose of the 25473 system matrix, r is a residual vector. 25474 Recommended value of EpsOrt is equal to 1E-6. 25475 This criterion will stop algorithm when we have "bad fit
" 25476 situation, i.e. when we should stop in a point with large, 25478 EpsErr - residual stopping criterion. Algorithm will stop when 25479 ||r||<=EpsErr*||b||, where r is a residual vector, b is a 25480 right part of the system (function values). 25481 Recommended value of EpsErr is equal to 1E-3 or 1E-6. 25482 This criterion will stop algorithm in a "good fit
" 25483 situation when we have near-zero residual near the desired 25485 MaxIts - this criterion will stop algorithm after MaxIts iterations. 25486 It should be used for debugging purposes only! 25487 Zero MaxIts means that no limit is placed on the number of 25490 We recommend to set moderate non-zero values EpsOrt and EpsErr 25491 simultaneously. Values equal to 10E-6 are good to start with. In case you 25492 need high performance and do not need high precision , you may decrease 25493 EpsErr down to 0.001. However, we do not recommend decreasing EpsOrt. 25495 As for MaxIts, we recommend to leave it zero unless you know what you do. 25497 NOTE: this function has some serialization-related subtleties. We 25498 recommend you to study serialization examples from ALGLIB Reference 25499 Manual if you want to perform serialization of your models. 25502 Copyright 13.12.2011 by Bochkanov Sergey 25503 *************************************************************************/ 25504 void rbfsetcond(rbfmodel* s, 25512 ae_assert(ae_isfinite(epsort, _state)&&ae_fp_greater_eq(epsort,0), "RBFSetCond: EpsOrt is negative,
INF or NAN
", _state); 25513 ae_assert(ae_isfinite(epserr, _state)&&ae_fp_greater_eq(epserr,0), "RBFSetCond: EpsB is negative,
INF or NAN
", _state); 25514 ae_assert(maxits>=0, "RBFSetCond: MaxIts is negative
", _state); 25515 if( (ae_fp_eq(epsort,0)&&ae_fp_eq(epserr,0))&&maxits==0 ) 25517 s->epsort = rbf_eps; 25518 s->epserr = rbf_eps; 25523 s->epsort = epsort; 25524 s->epserr = epserr; 25525 s->maxits = maxits; 25530 /************************************************************************* 25531 This function builds RBF model and returns report (contains some 25532 information which can be used for evaluation of the algorithm properties). 25534 Call to this function modifies RBF model by calculating its centers/radii/ 25535 weights and saving them into RBFModel structure. Initially RBFModel 25536 contain zero coefficients, but after call to this function we will have 25537 coefficients which were calculated in order to fit our dataset. 25539 After you called this function you can call RBFCalc(), RBFGridCalc() and 25540 other model calculation functions. 25543 S - RBF model, initialized by RBFCreate() call 25545 * Rep.TerminationType: 25546 * -5 - non-distinct basis function centers were detected, 25547 interpolation aborted 25548 * -4 - nonconvergence of the internal SVD solver 25549 * 1 - successful termination 25550 Fields are used for debugging purposes: 25551 * Rep.IterationsCount - iterations count of the LSQR solver 25552 * Rep.NMV - number of matrix-vector products 25553 * Rep.ARows - rows count for the system matrix 25554 * Rep.ACols - columns count for the system matrix 25555 * Rep.ANNZ - number of significantly non-zero elements 25556 (elements above some algorithm-determined threshold) 25558 NOTE: failure to build model will leave current state of the structure 25562 Copyright 13.12.2011 by Bochkanov Sergey 25563 *************************************************************************/ 25564 void rbfbuildmodel(rbfmodel* s, rbfreport* rep, ae_state *_state) 25566 ae_frame _frame_block; 25575 ae_matrix residualy; 25593 ae_int_t layerscnt; 25595 ae_frame_make(_state, &_frame_block); 25596 _rbfreport_clear(rep); 25597 _kdtree_init(&tree, _state, ae_true); 25598 _kdtree_init(&ctree, _state, ae_true); 25599 ae_vector_init(&dist, 0, DT_REAL, _state, ae_true); 25600 ae_vector_init(&xcx, 0, DT_REAL, _state, ae_true); 25601 ae_matrix_init(&a, 0, 0, DT_REAL, _state, ae_true); 25602 ae_matrix_init(&v, 0, 0, DT_REAL, _state, ae_true); 25603 ae_matrix_init(&omega, 0, 0, DT_REAL, _state, ae_true); 25604 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 25605 ae_matrix_init(&residualy, 0, 0, DT_REAL, _state, ae_true); 25606 ae_vector_init(&radius, 0, DT_REAL, _state, ae_true); 25607 ae_matrix_init(&xc, 0, 0, DT_REAL, _state, ae_true); 25608 ae_vector_init(&mnx, 0, DT_REAL, _state, ae_true); 25609 ae_vector_init(&mxx, 0, DT_REAL, _state, ae_true); 25610 ae_vector_init(&edge, 0, DT_REAL, _state, ae_true); 25611 ae_vector_init(&mxsteps, 0, DT_INT, _state, ae_true); 25612 ae_vector_init(&tags, 0, DT_INT, _state, ae_true); 25613 ae_vector_init(&ctags, 0, DT_INT, _state, ae_true); 25614 ae_vector_init(&tmp0, 0, DT_REAL, _state, ae_true); 25615 ae_vector_init(&tmp1, 0, DT_REAL, _state, ae_true); 25617 ae_assert(s->nx==2||s->nx==3, "RBFBuildModel: S.NX<>2
or S.NX<>3!
", _state); 25620 * Quick exit when we have no points 25624 rep->terminationtype = 1; 25625 rep->iterationscount = 0; 25629 kdtreebuildtagged(&s->xc, &tags, 0, rbf_mxnx, 0, 2, &s->tree, _state); 25630 ae_matrix_set_length(&s->xc, 0, 0, _state); 25631 ae_matrix_set_length(&s->wr, 0, 0, _state); 25634 ae_matrix_set_length(&s->v, s->ny, rbf_mxnx+1, _state); 25635 for(i=0; i<=s->ny-1; i++) 25637 for(j=0; j<=rbf_mxnx; j++) 25639 s->v.ptr.pp_double[i][j] = 0; 25642 ae_frame_leave(_state); 25647 * General case, N>0 25650 rep->iterationscount = 0; 25652 ae_vector_set_length(&xcx, rbf_mxnx, _state); 25655 * First model in a sequence - linear model. 25656 * Residuals from linear regression are stored in the ResidualY variable 25657 * (used later to build RBF models). 25659 ae_matrix_set_length(&residualy, s->n, s->ny, _state); 25660 for(i=0; i<=s->n-1; i++) 25662 for(j=0; j<=s->ny-1; j++) 25664 residualy.ptr.pp_double[i][j] = s->y.ptr.pp_double[i][j]; 25667 if( !rbf_buildlinearmodel(&s->x, &residualy, s->n, s->ny, s->aterm, &v, _state) ) 25669 rep->terminationtype = -5; 25670 ae_frame_leave(_state); 25675 * Handle special case: multilayer model with NLayers=0. 25678 if( s->algorithmtype==2&&s->nlayers==0 ) 25680 rep->terminationtype = 1; 25681 rep->iterationscount = 0; 25685 kdtreebuildtagged(&s->xc, &tags, 0, rbf_mxnx, 0, 2, &s->tree, _state); 25686 ae_matrix_set_length(&s->xc, 0, 0, _state); 25687 ae_matrix_set_length(&s->wr, 0, 0, _state); 25690 ae_matrix_set_length(&s->v, s->ny, rbf_mxnx+1, _state); 25691 for(i=0; i<=s->ny-1; i++) 25693 for(j=0; j<=rbf_mxnx; j++) 25695 s->v.ptr.pp_double[i][j] = v.ptr.pp_double[i][j]; 25698 ae_frame_leave(_state); 25703 * Second model in a sequence - RBF term. 25705 * NOTE: assignments below are not necessary, but without them 25706 * MSVC complains about unitialized variables. 25711 if( s->algorithmtype==1 ) 25716 * This model uses local KD-trees to speed-up nearest neighbor searches. 25718 if( s->gridtype==1 ) 25720 ae_vector_set_length(&mxx, s->nx, _state); 25721 ae_vector_set_length(&mnx, s->nx, _state); 25722 ae_vector_set_length(&mxsteps, s->nx, _state); 25723 ae_vector_set_length(&edge, s->nx, _state); 25724 for(i=0; i<=s->nx-1; i++) 25726 mxx.ptr.p_double[i] = s->x.ptr.pp_double[0][i]; 25727 mnx.ptr.p_double[i] = s->x.ptr.pp_double[0][i]; 25729 for(i=0; i<=s->n-1; i++) 25731 for(j=0; j<=s->nx-1; j++) 25733 if( ae_fp_less(mxx.ptr.p_double[j],s->x.ptr.pp_double[i][j]) ) 25735 mxx.ptr.p_double[j] = s->x.ptr.pp_double[i][j]; 25737 if( ae_fp_greater(mnx.ptr.p_double[j],s->x.ptr.pp_double[i][j]) ) 25739 mnx.ptr.p_double[j] = s->x.ptr.pp_double[i][j]; 25743 for(i=0; i<=s->nx-1; i++) 25745 mxsteps.ptr.p_int[i] = ae_trunc((mxx.ptr.p_double[i]-mnx.ptr.p_double[i])/(2*s->h), _state)+1; 25746 edge.ptr.p_double[i] = (mxx.ptr.p_double[i]+mnx.ptr.p_double[i])/2-s->h*mxsteps.ptr.p_int[i]; 25749 for(i=0; i<=s->nx-1; i++) 25751 mxsteps.ptr.p_int[i] = 2*mxsteps.ptr.p_int[i]+1; 25752 nc = nc*mxsteps.ptr.p_int[i]; 25754 ae_matrix_set_length(&xc, nc, rbf_mxnx, _state); 25757 for(i=0; i<=mxsteps.ptr.p_int[0]-1; i++) 25759 for(j=0; j<=mxsteps.ptr.p_int[1]-1; j++) 25761 for(k2=0; k2<=rbf_mxnx-1; k2++) 25763 xc.ptr.pp_double[i*mxsteps.ptr.p_int[1]+j][k2] = 0; 25765 xc.ptr.pp_double[i*mxsteps.ptr.p_int[1]+j][0] = edge.ptr.p_double[0]+s->h*i; 25766 xc.ptr.pp_double[i*mxsteps.ptr.p_int[1]+j][1] = edge.ptr.p_double[1]+s->h*j; 25772 for(i=0; i<=mxsteps.ptr.p_int[0]-1; i++) 25774 for(j=0; j<=mxsteps.ptr.p_int[1]-1; j++) 25776 for(k=0; k<=mxsteps.ptr.p_int[2]-1; k++) 25778 for(k2=0; k2<=rbf_mxnx-1; k2++) 25780 xc.ptr.pp_double[i*mxsteps.ptr.p_int[1]+j][k2] = 0; 25782 xc.ptr.pp_double[(i*mxsteps.ptr.p_int[1]+j)*mxsteps.ptr.p_int[2]+k][0] = edge.ptr.p_double[0]+s->h*i; 25783 xc.ptr.pp_double[(i*mxsteps.ptr.p_int[1]+j)*mxsteps.ptr.p_int[2]+k][1] = edge.ptr.p_double[1]+s->h*j; 25784 xc.ptr.pp_double[(i*mxsteps.ptr.p_int[1]+j)*mxsteps.ptr.p_int[2]+k][2] = edge.ptr.p_double[2]+s->h*k; 25792 if( s->gridtype==2 ) 25795 ae_matrix_set_length(&xc, nc, rbf_mxnx, _state); 25796 for(i=0; i<=nc-1; i++) 25798 for(j=0; j<=rbf_mxnx-1; j++) 25800 xc.ptr.pp_double[i][j] = s->x.ptr.pp_double[i][j]; 25806 if( s->gridtype==3 ) 25809 ae_matrix_set_length(&xc, nc, rbf_mxnx, _state); 25810 for(i=0; i<=nc-1; i++) 25812 for(j=0; j<=rbf_mxnx-1; j++) 25814 xc.ptr.pp_double[i][j] = s->xc.ptr.pp_double[i][j]; 25820 ae_assert(ae_false, "RBFBuildModel: either S.GridType<1
or S.GridType>3!
", _state); 25825 ae_vector_set_length(&radius, nc, _state); 25826 ae_vector_set_length(&ctags, nc, _state); 25827 for(i=0; i<=nc-1; i++) 25829 ctags.ptr.p_int[i] = i; 25831 kdtreebuildtagged(&xc, &ctags, nc, rbf_mxnx, 0, 2, &ctree, _state); 25838 for(i=0; i<=nc-1; i++) 25840 radius.ptr.p_double[i] = s->radvalue; 25842 rmax = radius.ptr.p_double[0]; 25858 radius.ptr.p_double[0] = s->radvalue; 25859 rmax = radius.ptr.p_double[0]; 25865 * NC>1, calculate radii using distances to nearest neigbors 25867 for(i=0; i<=nc-1; i++) 25869 for(j=0; j<=rbf_mxnx-1; j++) 25871 xcx.ptr.p_double[j] = xc.ptr.pp_double[i][j]; 25873 if( kdtreequeryknn(&ctree, &xcx, 1, ae_false, _state)>0 ) 25875 kdtreequeryresultsdistances(&ctree, &dist, _state); 25876 radius.ptr.p_double[i] = s->radvalue*dist.ptr.p_double[0]; 25882 * No neighbors found (it will happen when we have only one center). 25883 * Initialize radius with default value. 25885 radius.ptr.p_double[i] = 1.0; 25892 rvectorsetlengthatleast(&tmp0, nc, _state); 25893 for(i=0; i<=nc-1; i++) 25895 tmp0.ptr.p_double[i] = radius.ptr.p_double[i]; 25897 tagsortfast(&tmp0, &tmp1, nc, _state); 25898 for(i=0; i<=nc-1; i++) 25900 radius.ptr.p_double[i] = ae_minreal(radius.ptr.p_double[i], s->radzvalue*tmp0.ptr.p_double[nc/2], _state); 25904 * Calculate RMax, check that all radii are non-zero 25906 for(i=0; i<=nc-1; i++) 25908 rmax = ae_maxreal(rmax, radius.ptr.p_double[i], _state); 25910 for(i=0; i<=nc-1; i++) 25912 if( ae_fp_eq(radius.ptr.p_double[i],0) ) 25914 rep->terminationtype = -5; 25915 ae_frame_leave(_state); 25922 ivectorsetlengthatleast(&tags, s->n, _state); 25923 for(i=0; i<=s->n-1; i++) 25925 tags.ptr.p_int[i] = i; 25927 kdtreebuildtagged(&s->x, &tags, s->n, rbf_mxnx, 0, 2, &tree, _state); 25928 rbf_buildrbfmodellsqr(&s->x, &residualy, &xc, &radius, s->n, nc, s->ny, &tree, &ctree, s->epsort, s->epserr, s->maxits, &rep->annz, &snnz, &omega, &rep->terminationtype, &rep->iterationscount, &rep->nmv, _state); 25933 if( s->algorithmtype==2 ) 25935 rmax = s->radvalue; 25936 rbf_buildrbfmlayersmodellsqr(&s->x, &residualy, &xc, s->radvalue, &radius, s->n, &nc, s->ny, s->nlayers, &ctree, 1.0E-6, 1.0E-6, 50, s->lambdav, &rep->annz, &omega, &rep->terminationtype, &rep->iterationscount, &rep->nmv, _state); 25937 layerscnt = s->nlayers; 25941 ae_assert(ae_false, "RBFBuildModel:
internal error(AlgorithmType neither 1 nor 2)
", _state); 25944 if( rep->terminationtype<=0 ) 25946 ae_frame_leave(_state); 25953 s->nc = nc/layerscnt; 25956 ae_matrix_set_length(&s->xc, s->nc, rbf_mxnx, _state); 25957 ae_matrix_set_length(&s->wr, s->nc, 1+s->nl*s->ny, _state); 25958 ae_matrix_set_length(&s->v, s->ny, rbf_mxnx+1, _state); 25959 for(i=0; i<=s->nc-1; i++) 25961 for(j=0; j<=rbf_mxnx-1; j++) 25963 s->xc.ptr.pp_double[i][j] = xc.ptr.pp_double[i][j]; 25966 ivectorsetlengthatleast(&tags, s->nc, _state); 25967 for(i=0; i<=s->nc-1; i++) 25969 tags.ptr.p_int[i] = i; 25971 kdtreebuildtagged(&s->xc, &tags, s->nc, rbf_mxnx, 0, 2, &s->tree, _state); 25972 for(i=0; i<=s->nc-1; i++) 25974 s->wr.ptr.pp_double[i][0] = radius.ptr.p_double[i]; 25975 for(k=0; k<=layerscnt-1; k++) 25977 for(j=0; j<=s->ny-1; j++) 25979 s->wr.ptr.pp_double[i][1+k*s->ny+j] = omega.ptr.pp_double[k*s->nc+i][j]; 25983 for(i=0; i<=s->ny-1; i++) 25985 for(j=0; j<=rbf_mxnx; j++) 25987 s->v.ptr.pp_double[i][j] = v.ptr.pp_double[i][j]; 25990 rep->terminationtype = 1; 25992 rep->acols = s->nc; 25993 ae_frame_leave(_state); 25997 /************************************************************************* 25998 This function calculates values of the RBF model in the given point. 26000 This function should be used when we have NY=1 (scalar function) and NX=2 26001 (2-dimensional space). If you have 3-dimensional space, use RBFCalc3(). If 26002 you have general situation (NX-dimensional space, NY-dimensional function) 26003 you should use general, less efficient implementation RBFCalc(). 26005 If you want to calculate function values many times, consider using 26006 RBFGridCalc2(), which is far more efficient than many subsequent calls to 26009 This function returns 0.0 when: 26010 * model is not initialized 26016 X0 - first coordinate, finite number 26017 X1 - second coordinate, finite number 26020 value of the model or 0.0 (as defined above) 26023 Copyright 13.12.2011 by Bochkanov Sergey 26024 *************************************************************************/ 26025 double rbfcalc2(rbfmodel* s, double x0, double x1, ae_state *_state) 26038 ae_assert(ae_isfinite(x0, _state), "RBFCalc2: invalid value
for X0 (X0 is Inf)!
", _state); 26039 ae_assert(ae_isfinite(x1, _state), "RBFCalc2: invalid value
for X1 (X1 is Inf)!
", _state); 26040 if( s->ny!=1||s->nx!=2 ) 26045 result = s->v.ptr.pp_double[0][0]*x0+s->v.ptr.pp_double[0][1]*x1+s->v.ptr.pp_double[0][rbf_mxnx]; 26050 rvectorsetlengthatleast(&s->calcbufxcx, rbf_mxnx, _state); 26051 for(i=0; i<=rbf_mxnx-1; i++) 26053 s->calcbufxcx.ptr.p_double[i] = 0.0; 26055 s->calcbufxcx.ptr.p_double[0] = x0; 26056 s->calcbufxcx.ptr.p_double[1] = x1; 26057 lx = kdtreequeryrnn(&s->tree, &s->calcbufxcx, s->rmax*rbf_rbffarradius, ae_true, _state); 26058 kdtreequeryresultsx(&s->tree, &s->calcbufx, _state); 26059 kdtreequeryresultstags(&s->tree, &s->calcbuftags, _state); 26060 for(i=0; i<=lx-1; i++) 26062 tg = s->calcbuftags.ptr.p_int[i]; 26063 d2 = ae_sqr(x0-s->calcbufx.ptr.pp_double[i][0], _state)+ae_sqr(x1-s->calcbufx.ptr.pp_double[i][1], _state); 26064 rcur = s->wr.ptr.pp_double[tg][0]; 26065 bfcur = ae_exp(-d2/(rcur*rcur), _state); 26066 for(j=0; j<=s->nl-1; j++) 26068 result = result+bfcur*s->wr.ptr.pp_double[tg][1+j]; 26078 /************************************************************************* 26079 This function calculates values of the RBF model in the given point. 26081 This function should be used when we have NY=1 (scalar function) and NX=3 26082 (3-dimensional space). If you have 2-dimensional space, use RBFCalc2(). If 26083 you have general situation (NX-dimensional space, NY-dimensional function) 26084 you should use general, less efficient implementation RBFCalc(). 26086 This function returns 0.0 when: 26087 * model is not initialized 26093 X0 - first coordinate, finite number 26094 X1 - second coordinate, finite number 26095 X2 - third coordinate, finite number 26098 value of the model or 0.0 (as defined above) 26101 Copyright 13.12.2011 by Bochkanov Sergey 26102 *************************************************************************/ 26103 double rbfcalc3(rbfmodel* s, 26119 ae_assert(ae_isfinite(x0, _state), "RBFCalc3: invalid value
for X0 (X0 is Inf
or NaN)!
", _state); 26120 ae_assert(ae_isfinite(x1, _state), "RBFCalc3: invalid value
for X1 (X1 is Inf
or NaN)!
", _state); 26121 ae_assert(ae_isfinite(x2, _state), "RBFCalc3: invalid value
for X2 (X2 is Inf
or NaN)!
", _state); 26122 if( s->ny!=1||s->nx!=3 ) 26127 result = s->v.ptr.pp_double[0][0]*x0+s->v.ptr.pp_double[0][1]*x1+s->v.ptr.pp_double[0][2]*x2+s->v.ptr.pp_double[0][rbf_mxnx]; 26134 * calculating value for F(X) 26136 rvectorsetlengthatleast(&s->calcbufxcx, rbf_mxnx, _state); 26137 for(i=0; i<=rbf_mxnx-1; i++) 26139 s->calcbufxcx.ptr.p_double[i] = 0.0; 26141 s->calcbufxcx.ptr.p_double[0] = x0; 26142 s->calcbufxcx.ptr.p_double[1] = x1; 26143 s->calcbufxcx.ptr.p_double[2] = x2; 26144 lx = kdtreequeryrnn(&s->tree, &s->calcbufxcx, s->rmax*rbf_rbffarradius, ae_true, _state); 26145 kdtreequeryresultsx(&s->tree, &s->calcbufx, _state); 26146 kdtreequeryresultstags(&s->tree, &s->calcbuftags, _state); 26147 for(i=0; i<=lx-1; i++) 26149 tg = s->calcbuftags.ptr.p_int[i]; 26150 rcur = s->wr.ptr.pp_double[tg][0]; 26151 bf = ae_exp(-(ae_sqr(x0-s->calcbufx.ptr.pp_double[i][0], _state)+ae_sqr(x1-s->calcbufx.ptr.pp_double[i][1], _state)+ae_sqr(x2-s->calcbufx.ptr.pp_double[i][2], _state))/ae_sqr(rcur, _state), _state); 26152 for(j=0; j<=s->nl-1; j++) 26154 result = result+bf*s->wr.ptr.pp_double[tg][1+j]; 26163 /************************************************************************* 26164 This function calculates values of the RBF model at the given point. 26166 This is general function which can be used for arbitrary NX (dimension of 26167 the space of arguments) and NY (dimension of the function itself). However 26168 when you have NY=1 you may find more convenient to use RBFCalc2() or 26171 This function returns 0.0 when model is not initialized. 26175 X - coordinates, array[NX]. 26176 X may have more than NX elements, in this case only 26177 leading NX will be used. 26180 Y - function value, array[NY]. Y is out-parameter and 26181 reallocated after call to this function. In case you want 26182 to reuse previously allocated Y, you may use RBFCalcBuf(), 26183 which reallocates Y only when it is too small. 26186 Copyright 13.12.2011 by Bochkanov Sergey 26187 *************************************************************************/ 26188 void rbfcalc(rbfmodel* s, 26189 /* Real */ ae_vector* x, 26190 /* Real */ ae_vector* y, 26194 ae_vector_clear(y); 26196 ae_assert(x->cnt>=s->nx, "RBFCalc: Length(X)<NX
", _state); 26197 ae_assert(isfinitevector(x, s->nx, _state), "RBFCalc: X contains infinite
or NaN values
", _state); 26198 rbfcalcbuf(s, x, y, _state); 26202 /************************************************************************* 26203 This function calculates values of the RBF model at the given point. 26205 Same as RBFCalc(), but does not reallocate Y when in is large enough to 26206 store function values. 26210 X - coordinates, array[NX]. 26211 X may have more than NX elements, in this case only 26212 leading NX will be used. 26213 Y - possibly preallocated array 26216 Y - function value, array[NY]. Y is not reallocated when it 26220 Copyright 13.12.2011 by Bochkanov Sergey 26221 *************************************************************************/ 26222 void rbfcalcbuf(rbfmodel* s, 26223 /* Real */ ae_vector* x, 26224 /* Real */ ae_vector* y, 26237 ae_assert(x->cnt>=s->nx, "RBFCalcBuf: Length(X)<NX
", _state); 26238 ae_assert(isfinitevector(x, s->nx, _state), "RBFCalcBuf: X contains infinite
or NaN values
", _state); 26241 ae_vector_set_length(y, s->ny, _state); 26243 for(i=0; i<=s->ny-1; i++) 26245 y->ptr.p_double[i] = s->v.ptr.pp_double[i][rbf_mxnx]; 26246 for(j=0; j<=s->nx-1; j++) 26248 y->ptr.p_double[i] = y->ptr.p_double[i]+s->v.ptr.pp_double[i][j]*x->ptr.p_double[j]; 26255 rvectorsetlengthatleast(&s->calcbufxcx, rbf_mxnx, _state); 26256 for(i=0; i<=rbf_mxnx-1; i++) 26258 s->calcbufxcx.ptr.p_double[i] = 0.0; 26260 for(i=0; i<=s->nx-1; i++) 26262 s->calcbufxcx.ptr.p_double[i] = x->ptr.p_double[i]; 26264 lx = kdtreequeryrnn(&s->tree, &s->calcbufxcx, s->rmax*rbf_rbffarradius, ae_true, _state); 26265 kdtreequeryresultsx(&s->tree, &s->calcbufx, _state); 26266 kdtreequeryresultstags(&s->tree, &s->calcbuftags, _state); 26267 for(i=0; i<=s->ny-1; i++) 26269 for(j=0; j<=lx-1; j++) 26271 tg = s->calcbuftags.ptr.p_int[j]; 26272 rcur = s->wr.ptr.pp_double[tg][0]; 26273 bf = ae_exp(-(ae_sqr(s->calcbufxcx.ptr.p_double[0]-s->calcbufx.ptr.pp_double[j][0], _state)+ae_sqr(s->calcbufxcx.ptr.p_double[1]-s->calcbufx.ptr.pp_double[j][1], _state)+ae_sqr(s->calcbufxcx.ptr.p_double[2]-s->calcbufx.ptr.pp_double[j][2], _state))/ae_sqr(rcur, _state), _state); 26274 for(k=0; k<=s->nl-1; k++) 26276 y->ptr.p_double[i] = y->ptr.p_double[i]+bf*s->wr.ptr.pp_double[tg][1+k*s->ny+i]; 26285 /************************************************************************* 26286 This function calculates values of the RBF model at the regular grid. 26288 Grid have N0*N1 points, with Point[I,J] = (X0[I], X1[J]) 26290 This function returns 0.0 when: 26291 * model is not initialized 26297 X0 - array of grid nodes, first coordinates, array[N0] 26298 N0 - grid size (number of nodes) in the first dimension 26299 X1 - array of grid nodes, second coordinates, array[N1] 26300 N1 - grid size (number of nodes) in the second dimension 26303 Y - function values, array[N0,N1]. Y is out-variable and 26304 is reallocated by this function. 26307 Copyright 13.12.2011 by Bochkanov Sergey 26308 *************************************************************************/ 26309 void rbfgridcalc2(rbfmodel* s, 26310 /* Real */ ae_vector* x0, 26312 /* Real */ ae_vector* x1, 26314 /* Real */ ae_matrix* y, 26317 ae_frame _frame_block; 26340 ae_frame_make(_state, &_frame_block); 26341 ae_matrix_clear(y); 26342 ae_vector_init(&cpx0, 0, DT_REAL, _state, ae_true); 26343 ae_vector_init(&cpx1, 0, DT_REAL, _state, ae_true); 26344 ae_vector_init(&p01, 0, DT_INT, _state, ae_true); 26345 ae_vector_init(&p11, 0, DT_INT, _state, ae_true); 26346 ae_vector_init(&p2, 0, DT_INT, _state, ae_true); 26348 ae_assert(n0>0, "RBFGridCalc2: invalid value
for N0 (N0<=0)!
", _state); 26349 ae_assert(n1>0, "RBFGridCalc2: invalid value
for N1 (N1<=0)!
", _state); 26350 ae_assert(x0->cnt>=n0, "RBFGridCalc2: Length(X0)<N0
", _state); 26351 ae_assert(x1->cnt>=n1, "RBFGridCalc2: Length(X1)<N1
", _state); 26352 ae_assert(isfinitevector(x0, n0, _state), "RBFGridCalc2: X0 contains infinite
or NaN values!
", _state); 26353 ae_assert(isfinitevector(x1, n1, _state), "RBFGridCalc2: X1 contains infinite
or NaN values!
", _state); 26354 ae_matrix_set_length(y, n0, n1, _state); 26355 for(i=0; i<=n0-1; i++) 26357 for(j=0; j<=n1-1; j++) 26359 y->ptr.pp_double[i][j] = 0; 26362 if( (s->ny!=1||s->nx!=2)||s->nc==0 ) 26364 ae_frame_leave(_state); 26369 *create and sort arrays 26371 ae_vector_set_length(&cpx0, n0, _state); 26372 for(i=0; i<=n0-1; i++) 26374 cpx0.ptr.p_double[i] = x0->ptr.p_double[i]; 26376 tagsort(&cpx0, n0, &p01, &p2, _state); 26377 ae_vector_set_length(&cpx1, n1, _state); 26378 for(i=0; i<=n1-1; i++) 26380 cpx1.ptr.p_double[i] = x1->ptr.p_double[i]; 26382 tagsort(&cpx1, n1, &p11, &p2, _state); 26385 *calculate function's value 26387 for(i=0; i<=s->nc-1; i++) 26389 radius = s->wr.ptr.pp_double[i][0]; 26390 for(d=0; d<=s->nl-1; d++) 26392 omega = s->wr.ptr.pp_double[i][1+d]; 26393 rlimit = radius*rbf_rbffarradius; 26396 *search lower and upper indexes 26398 i00 = lowerbound(&cpx0, n0, s->xc.ptr.pp_double[i][0]-rlimit, _state); 26399 i01 = upperbound(&cpx0, n0, s->xc.ptr.pp_double[i][0]+rlimit, _state); 26400 i10 = lowerbound(&cpx1, n1, s->xc.ptr.pp_double[i][1]-rlimit, _state); 26401 i11 = upperbound(&cpx1, n1, s->xc.ptr.pp_double[i][1]+rlimit, _state); 26402 xc0 = s->xc.ptr.pp_double[i][0]; 26403 xc1 = s->xc.ptr.pp_double[i][1]; 26404 for(j=i00; j<=i01-1; j++) 26406 hcpx0 = cpx0.ptr.p_double[j]; 26407 hp01 = p01.ptr.p_int[j]; 26408 for(k=i10; k<=i11-1; k++) 26410 xcnorm2 = ae_sqr(hcpx0-xc0, _state)+ae_sqr(cpx1.ptr.p_double[k]-xc1, _state); 26411 if( ae_fp_less_eq(xcnorm2,rlimit*rlimit) ) 26413 y->ptr.pp_double[hp01][p11.ptr.p_int[k]] = y->ptr.pp_double[hp01][p11.ptr.p_int[k]]+ae_exp(-xcnorm2/ae_sqr(radius, _state), _state)*omega; 26417 radius = 0.5*radius; 26424 for(i=0; i<=n0-1; i++) 26426 for(j=0; j<=n1-1; j++) 26428 y->ptr.pp_double[i][j] = y->ptr.pp_double[i][j]+s->v.ptr.pp_double[0][0]*x0->ptr.p_double[i]+s->v.ptr.pp_double[0][1]*x1->ptr.p_double[j]+s->v.ptr.pp_double[0][rbf_mxnx]; 26431 ae_frame_leave(_state); 26435 /************************************************************************* 26436 This function "unpacks
" RBF model by extracting its coefficients. 26442 NX - dimensionality of argument 26443 NY - dimensionality of the target function 26444 XWR - model information, array[NC,NX+NY+1]. 26445 One row of the array corresponds to one basis function: 26446 * first NX columns - coordinates of the center 26447 * next NY columns - weights, one per dimension of the 26448 function being modelled 26449 * last column - radius, same for all dimensions of 26450 the function being modelled 26451 NC - number of the centers 26452 V - polynomial term , array[NY,NX+1]. One row per one 26453 dimension of the function being modelled. First NX 26454 elements are linear coefficients, V[NX] is equal to the 26458 Copyright 13.12.2011 by Bochkanov Sergey 26459 *************************************************************************/ 26460 void rbfunpack(rbfmodel* s, 26463 /* Real */ ae_matrix* xwr, 26465 /* Real */ ae_matrix* v, 26474 ae_matrix_clear(xwr); 26476 ae_matrix_clear(v); 26485 ae_matrix_set_length(v, s->ny, s->nx+1, _state); 26486 for(i=0; i<=s->ny-1; i++) 26488 ae_v_move(&v->ptr.pp_double[i][0], 1, &s->v.ptr.pp_double[i][0], 1, ae_v_len(0,s->nx-1)); 26489 v->ptr.pp_double[i][s->nx] = s->v.ptr.pp_double[i][rbf_mxnx]; 26497 ae_matrix_set_length(xwr, s->nc*s->nl, s->nx+s->ny+1, _state); 26498 for(i=0; i<=s->nc-1; i++) 26500 rcur = s->wr.ptr.pp_double[i][0]; 26501 for(j=0; j<=s->nl-1; j++) 26503 ae_v_move(&xwr->ptr.pp_double[i*s->nl+j][0], 1, &s->xc.ptr.pp_double[i][0], 1, ae_v_len(0,s->nx-1)); 26504 ae_v_move(&xwr->ptr.pp_double[i*s->nl+j][s->nx], 1, &s->wr.ptr.pp_double[i][1+j*s->ny], 1, ae_v_len(s->nx,s->nx+s->ny-1)); 26505 xwr->ptr.pp_double[i*s->nl+j][s->nx+s->ny] = rcur; 26513 /************************************************************************* 26514 Serializer: allocation 26517 Copyright 02.02.2012 by Bochkanov Sergey 26518 *************************************************************************/ 26519 void rbfalloc(ae_serializer* s, rbfmodel* model, ae_state *_state) 26527 ae_serializer_alloc_entry(s); 26528 ae_serializer_alloc_entry(s); 26533 ae_serializer_alloc_entry(s); 26534 ae_serializer_alloc_entry(s); 26535 ae_serializer_alloc_entry(s); 26536 ae_serializer_alloc_entry(s); 26537 kdtreealloc(s, &model->tree, _state); 26538 allocrealmatrix(s, &model->xc, -1, -1, _state); 26539 allocrealmatrix(s, &model->wr, -1, -1, _state); 26540 ae_serializer_alloc_entry(s); 26541 allocrealmatrix(s, &model->v, -1, -1, _state); 26545 /************************************************************************* 26546 Serializer: serialization 26549 Copyright 02.02.2012 by Bochkanov Sergey 26550 *************************************************************************/ 26551 void rbfserialize(ae_serializer* s, rbfmodel* model, ae_state *_state) 26559 ae_serializer_serialize_int(s, getrbfserializationcode(_state), _state); 26560 ae_serializer_serialize_int(s, rbf_rbffirstversion, _state); 26565 ae_serializer_serialize_int(s, model->nx, _state); 26566 ae_serializer_serialize_int(s, model->ny, _state); 26567 ae_serializer_serialize_int(s, model->nc, _state); 26568 ae_serializer_serialize_int(s, model->nl, _state); 26569 kdtreeserialize(s, &model->tree, _state); 26570 serializerealmatrix(s, &model->xc, -1, -1, _state); 26571 serializerealmatrix(s, &model->wr, -1, -1, _state); 26572 ae_serializer_serialize_double(s, model->rmax, _state); 26573 serializerealmatrix(s, &model->v, -1, -1, _state); 26577 /************************************************************************* 26578 Serializer: unserialization 26581 Copyright 02.02.2012 by Bochkanov Sergey 26582 *************************************************************************/ 26583 void rbfunserialize(ae_serializer* s, rbfmodel* model, ae_state *_state) 26590 _rbfmodel_clear(model); 26596 ae_serializer_unserialize_int(s, &i0, _state); 26597 ae_assert(i0==getrbfserializationcode(_state), "RBFUnserialize: stream header corrupted
", _state); 26598 ae_serializer_unserialize_int(s, &i1, _state); 26599 ae_assert(i1==rbf_rbffirstversion, "RBFUnserialize: stream header corrupted
", _state); 26602 * Unserialize primary model parameters, initialize model. 26604 * It is necessary to call RBFCreate() because some internal fields 26605 * which are NOT unserialized will need initialization. 26607 ae_serializer_unserialize_int(s, &nx, _state); 26608 ae_serializer_unserialize_int(s, &ny, _state); 26609 rbfcreate(nx, ny, model, _state); 26610 ae_serializer_unserialize_int(s, &model->nc, _state); 26611 ae_serializer_unserialize_int(s, &model->nl, _state); 26612 kdtreeunserialize(s, &model->tree, _state); 26613 unserializerealmatrix(s, &model->xc, _state); 26614 unserializerealmatrix(s, &model->wr, _state); 26615 ae_serializer_unserialize_double(s, &model->rmax, _state); 26616 unserializerealmatrix(s, &model->v, _state); 26620 /************************************************************************* 26621 This function changes centers allocation algorithm to one which allocates 26622 centers exactly at the dataset points (one input point = one center). This 26623 function won't have effect until next call to RBFBuildModel(). 26626 S - RBF model, initialized by RBFCreate() call 26628 NOTE: this function has some serialization-related subtleties. We 26629 recommend you to study serialization examples from ALGLIB Reference 26630 Manual if you want to perform serialization of your models. 26633 Copyright 13.12.2011 by Bochkanov Sergey 26634 *************************************************************************/ 26635 static void rbf_rbfgridpoints(rbfmodel* s, ae_state *_state) 26643 /************************************************************************* 26644 This function changes radii calculation algorithm to one which makes 26645 radius for I-th node equal to R[i]=DistNN[i]*Q, where: 26646 * R[i] is a radius calculated by the algorithm 26647 * DistNN[i] is distance from I-th center to its nearest neighbor center 26648 * Q is a scale parameter, which should be within [0.75,1.50], with 26649 recommended value equal to 1.0 26650 * after performing radii calculation, radii are transformed in order to 26651 avoid situation when single outlier has very large radius and influences 26652 many points across entire dataset. Transformation has following form: 26653 new_r[i] = min(r[i],Z*median(r[])) 26654 where r[i] is I-th radius, median() is a median radius across entire 26655 dataset, Z is user-specified value which controls amount of deviation 26656 from median radius. 26658 This function won't have effect until next call to RBFBuildModel(). 26660 The idea behind this algorithm is to choose radii corresponding to basis 26661 functions is such way that I-th radius is approximately equal to distance 26662 from I-th center to its nearest neighbor. In this case interactions with 26663 distant points will be insignificant, and we will get well conditioned 26666 Properties of this basis depend on the value of Q: 26667 * Q<0.75 will give perfectly conditioned basis, but terrible smoothness 26668 properties (RBF interpolant will have sharp peaks around function values) 26669 * Q>1.5 will lead to badly conditioned systems and slow convergence of the 26670 underlying linear solver (although smoothness will be very good) 26671 * Q around 1.0 gives good balance between smoothness and condition number 26675 S - RBF model, initialized by RBFCreate() call 26676 Q - radius coefficient, Q>0 26677 Z - z-parameter, Z>0 26679 Default value of Q is equal to 1.0 26680 Default value of Z is equal to 5.0 26682 NOTE: this function has some serialization-related subtleties. We 26683 recommend you to study serialization examples from ALGLIB Reference 26684 Manual if you want to perform serialization of your models. 26687 Copyright 13.12.2011 by Bochkanov Sergey 26688 *************************************************************************/ 26689 static void rbf_rbfradnn(rbfmodel* s, 26696 ae_assert(ae_isfinite(q, _state)&&ae_fp_greater(q,0), "RBFRadNN: Q<=0, infinite
or NAN
", _state); 26697 ae_assert(ae_isfinite(z, _state)&&ae_fp_greater(z,0), "RBFRadNN: Z<=0, infinite
or NAN
", _state); 26698 s->fixrad = ae_false; 26704 static ae_bool rbf_buildlinearmodel(/* Real */ ae_matrix* x, 26705 /* Real */ ae_matrix* y, 26708 ae_int_t modeltype, 26709 /* Real */ ae_matrix* v, 26712 ae_frame _frame_block; 26716 ae_vector shifting; 26727 ae_frame_make(_state, &_frame_block); 26728 ae_matrix_clear(v); 26729 ae_vector_init(&tmpy, 0, DT_REAL, _state, ae_true); 26730 ae_matrix_init(&a, 0, 0, DT_REAL, _state, ae_true); 26731 ae_vector_init(&shifting, 0, DT_REAL, _state, ae_true); 26732 ae_vector_init(&c, 0, DT_REAL, _state, ae_true); 26733 _lsfitreport_init(&rep, _state, ae_true); 26735 ae_assert(n>=0, "BuildLinearModel: N<0
", _state); 26736 ae_assert(ny>0, "BuildLinearModel: NY<=0
", _state); 26739 * Handle degenerate case (N=0) 26742 ae_matrix_set_length(v, ny, rbf_mxnx+1, _state); 26745 for(j=0; j<=rbf_mxnx; j++) 26747 for(i=0; i<=ny-1; i++) 26749 v->ptr.pp_double[i][j] = 0; 26752 ae_frame_leave(_state); 26757 * Allocate temporaries 26759 ae_vector_set_length(&tmpy, n, _state); 26762 * General linear model. 26768 * Calculate scaling/shifting, transform variables, prepare LLS problem 26770 ae_matrix_set_length(&a, n, rbf_mxnx+1, _state); 26771 ae_vector_set_length(&shifting, rbf_mxnx, _state); 26773 for(i=0; i<=rbf_mxnx-1; i++) 26775 mn = x->ptr.pp_double[0][i]; 26777 for(j=1; j<=n-1; j++) 26779 if( ae_fp_greater(mn,x->ptr.pp_double[j][i]) ) 26781 mn = x->ptr.pp_double[j][i]; 26783 if( ae_fp_less(mx,x->ptr.pp_double[j][i]) ) 26785 mx = x->ptr.pp_double[j][i]; 26788 scaling = ae_maxreal(scaling, mx-mn, _state); 26789 shifting.ptr.p_double[i] = 0.5*(mx+mn); 26791 if( ae_fp_eq(scaling,0) ) 26797 scaling = 0.5*scaling; 26799 for(i=0; i<=n-1; i++) 26801 for(j=0; j<=rbf_mxnx-1; j++) 26803 a.ptr.pp_double[i][j] = (x->ptr.pp_double[i][j]-shifting.ptr.p_double[j])/scaling; 26806 for(i=0; i<=n-1; i++) 26808 a.ptr.pp_double[i][rbf_mxnx] = 1; 26812 * Solve linear system in transformed variables, make backward 26814 for(i=0; i<=ny-1; i++) 26816 for(j=0; j<=n-1; j++) 26818 tmpy.ptr.p_double[j] = y->ptr.pp_double[j][i]; 26820 lsfitlinear(&tmpy, &a, n, rbf_mxnx+1, &info, &c, &rep, _state); 26824 ae_frame_leave(_state); 26827 for(j=0; j<=rbf_mxnx-1; j++) 26829 v->ptr.pp_double[i][j] = c.ptr.p_double[j]/scaling; 26831 v->ptr.pp_double[i][rbf_mxnx] = c.ptr.p_double[rbf_mxnx]; 26832 for(j=0; j<=rbf_mxnx-1; j++) 26834 v->ptr.pp_double[i][rbf_mxnx] = v->ptr.pp_double[i][rbf_mxnx]-shifting.ptr.p_double[j]*v->ptr.pp_double[i][j]; 26836 for(j=0; j<=n-1; j++) 26838 for(k=0; k<=rbf_mxnx-1; k++) 26840 y->ptr.pp_double[j][i] = y->ptr.pp_double[j][i]-x->ptr.pp_double[j][k]*v->ptr.pp_double[i][k]; 26842 y->ptr.pp_double[j][i] = y->ptr.pp_double[j][i]-v->ptr.pp_double[i][rbf_mxnx]; 26845 ae_frame_leave(_state); 26850 * Constant model, very simple 26854 for(i=0; i<=ny-1; i++) 26856 for(j=0; j<=rbf_mxnx; j++) 26858 v->ptr.pp_double[i][j] = 0; 26860 for(j=0; j<=n-1; j++) 26862 v->ptr.pp_double[i][rbf_mxnx] = v->ptr.pp_double[i][rbf_mxnx]+y->ptr.pp_double[j][i]; 26866 v->ptr.pp_double[i][rbf_mxnx] = v->ptr.pp_double[i][rbf_mxnx]/n; 26868 for(j=0; j<=n-1; j++) 26870 y->ptr.pp_double[j][i] = y->ptr.pp_double[j][i]-v->ptr.pp_double[i][rbf_mxnx]; 26873 ae_frame_leave(_state); 26880 ae_assert(modeltype==3, "BuildLinearModel: unknown model
type", _state); 26881 for(i=0; i<=ny-1; i++) 26883 for(j=0; j<=rbf_mxnx; j++) 26885 v->ptr.pp_double[i][j] = 0; 26888 ae_frame_leave(_state); 26893 static void rbf_buildrbfmodellsqr(/* Real */ ae_matrix* x, 26894 /* Real */ ae_matrix* y, 26895 /* Real */ ae_matrix* xc, 26896 /* Real */ ae_vector* r, 26900 kdtree* pointstree, 26901 kdtree* centerstree, 26907 /* Real */ ae_matrix* w, 26909 ae_int_t* iterationscount, 26913 ae_frame _frame_block; 26914 linlsqrstate state; 26915 linlsqrreport lsqrrep; 26918 ae_vector nearcenterscnt; 26919 ae_vector nearpointscnt; 26920 ae_vector skipnearpointscnt; 26921 ae_vector farpointscnt; 26922 ae_int_t maxnearcenterscnt; 26923 ae_int_t maxnearpointscnt; 26924 ae_int_t maxfarpointscnt; 26925 ae_int_t sumnearcenterscnt; 26926 ae_int_t sumnearpointscnt; 26927 ae_int_t sumfarpointscnt; 26929 ae_vector pointstags; 26930 ae_vector centerstags; 26931 ae_matrix nearpoints; 26932 ae_matrix nearcenters; 26933 ae_matrix farpoints; 26935 ae_int_t pointscnt; 26936 ae_int_t centerscnt; 26961 ae_frame_make(_state, &_frame_block); 26964 ae_matrix_clear(w); 26966 *iterationscount = 0; 26968 _linlsqrstate_init(&state, _state, ae_true); 26969 _linlsqrreport_init(&lsqrrep, _state, ae_true); 26970 _sparsematrix_init(&spg, _state, ae_true); 26971 _sparsematrix_init(&sps, _state, ae_true); 26972 ae_vector_init(&nearcenterscnt, 0, DT_INT, _state, ae_true); 26973 ae_vector_init(&nearpointscnt, 0, DT_INT, _state, ae_true); 26974 ae_vector_init(&skipnearpointscnt, 0, DT_INT, _state, ae_true); 26975 ae_vector_init(&farpointscnt, 0, DT_INT, _state, ae_true); 26976 ae_vector_init(&pointstags, 0, DT_INT, _state, ae_true); 26977 ae_vector_init(¢erstags, 0, DT_INT, _state, ae_true); 26978 ae_matrix_init(&nearpoints, 0, 0, DT_REAL, _state, ae_true); 26979 ae_matrix_init(&nearcenters, 0, 0, DT_REAL, _state, ae_true); 26980 ae_matrix_init(&farpoints, 0, 0, DT_REAL, _state, ae_true); 26981 ae_vector_init(&xcx, 0, DT_REAL, _state, ae_true); 26982 ae_vector_init(&tmpy, 0, DT_REAL, _state, ae_true); 26983 ae_vector_init(&tc, 0, DT_REAL, _state, ae_true); 26984 ae_vector_init(&g, 0, DT_REAL, _state, ae_true); 26985 ae_vector_init(&c, 0, DT_REAL, _state, ae_true); 26986 ae_matrix_init(&a, 0, 0, DT_REAL, _state, ae_true); 26987 ae_vector_init(&tmp0, 0, DT_REAL, _state, ae_true); 26988 ae_vector_init(&tmp1, 0, DT_REAL, _state, ae_true); 26989 ae_vector_init(&tmp2, 0, DT_REAL, _state, ae_true); 26990 ae_matrix_init(&xx, 0, 0, DT_REAL, _state, ae_true); 26991 ae_matrix_init(&cx, 0, 0, DT_REAL, _state, ae_true); 26995 * Handle special cases: NC=0 27000 *iterationscount = 0; 27002 ae_frame_leave(_state); 27007 * Prepare for general case, NC>0 27009 ae_vector_set_length(&xcx, rbf_mxnx, _state); 27010 ae_vector_set_length(&pointstags, n, _state); 27011 ae_vector_set_length(¢erstags, nc, _state); 27013 *iterationscount = 0; 27017 * This block prepares quantities used to compute approximate cardinal basis functions (ACBFs): 27018 * * NearCentersCnt[] - array[NC], whose elements store number of near centers used to build ACBF 27019 * * NearPointsCnt[] - array[NC], number of near points used to build ACBF 27020 * * FarPointsCnt[] - array[NC], number of far points (ones where ACBF is nonzero) 27021 * * MaxNearCentersCnt - max(NearCentersCnt) 27022 * * MaxNearPointsCnt - max(NearPointsCnt) 27023 * * SumNearCentersCnt - sum(NearCentersCnt) 27024 * * SumNearPointsCnt - sum(NearPointsCnt) 27025 * * SumFarPointsCnt - sum(FarPointsCnt) 27027 ae_vector_set_length(&nearcenterscnt, nc, _state); 27028 ae_vector_set_length(&nearpointscnt, nc, _state); 27029 ae_vector_set_length(&skipnearpointscnt, nc, _state); 27030 ae_vector_set_length(&farpointscnt, nc, _state); 27031 maxnearcenterscnt = 0; 27032 maxnearpointscnt = 0; 27033 maxfarpointscnt = 0; 27034 sumnearcenterscnt = 0; 27035 sumnearpointscnt = 0; 27036 sumfarpointscnt = 0; 27037 for(i=0; i<=nc-1; i++) 27039 for(j=0; j<=rbf_mxnx-1; j++) 27041 xcx.ptr.p_double[j] = xc->ptr.pp_double[i][j]; 27045 * Determine number of near centers and maximum radius of near centers 27047 nearcenterscnt.ptr.p_int[i] = kdtreequeryrnn(centerstree, &xcx, r->ptr.p_double[i]*rbf_rbfnearradius, ae_true, _state); 27048 kdtreequeryresultstags(centerstree, ¢erstags, _state); 27050 for(j=0; j<=nearcenterscnt.ptr.p_int[i]-1; j++) 27052 maxrad = ae_maxreal(maxrad, ae_fabs(r->ptr.p_double[centerstags.ptr.p_int[j]], _state), _state); 27056 * Determine number of near points (ones which used to build ACBF) 27057 * and skipped points (the most near points which are NOT used to build ACBF 27058 * and are NOT included in the near points count 27060 skipnearpointscnt.ptr.p_int[i] = kdtreequeryrnn(pointstree, &xcx, 0.1*r->ptr.p_double[i], ae_true, _state); 27061 nearpointscnt.ptr.p_int[i] = kdtreequeryrnn(pointstree, &xcx, (r->ptr.p_double[i]+maxrad)*rbf_rbfnearradius, ae_true, _state)-skipnearpointscnt.ptr.p_int[i]; 27062 ae_assert(nearpointscnt.ptr.p_int[i]>=0, "BuildRBFModelLSQR:
internal error", _state); 27065 * Determine number of far points 27067 farpointscnt.ptr.p_int[i] = kdtreequeryrnn(pointstree, &xcx, ae_maxreal(r->ptr.p_double[i]*rbf_rbfnearradius+maxrad*rbf_rbffarradius, r->ptr.p_double[i]*rbf_rbffarradius, _state), ae_true, _state); 27070 * calculate sum and max, make some basic checks 27072 ae_assert(nearcenterscnt.ptr.p_int[i]>0, "BuildRBFModelLSQR:
internal error", _state); 27073 maxnearcenterscnt = ae_maxint(maxnearcenterscnt, nearcenterscnt.ptr.p_int[i], _state); 27074 maxnearpointscnt = ae_maxint(maxnearpointscnt, nearpointscnt.ptr.p_int[i], _state); 27075 maxfarpointscnt = ae_maxint(maxfarpointscnt, farpointscnt.ptr.p_int[i], _state); 27076 sumnearcenterscnt = sumnearcenterscnt+nearcenterscnt.ptr.p_int[i]; 27077 sumnearpointscnt = sumnearpointscnt+nearpointscnt.ptr.p_int[i]; 27078 sumfarpointscnt = sumfarpointscnt+farpointscnt.ptr.p_int[i]; 27080 *snnz = sumnearcenterscnt; 27081 *gnnz = sumfarpointscnt; 27082 ae_assert(maxnearcenterscnt>0, "BuildRBFModelLSQR:
internal error", _state); 27085 * Allocate temporaries. 27087 * NOTE: we want to avoid allocation of zero-size arrays, so we 27088 * use max(desired_size,1) instead of desired_size when performing 27089 * memory allocation. 27091 ae_matrix_set_length(&a, maxnearpointscnt+maxnearcenterscnt, maxnearcenterscnt, _state); 27092 ae_vector_set_length(&tmpy, maxnearpointscnt+maxnearcenterscnt, _state); 27093 ae_vector_set_length(&g, maxnearcenterscnt, _state); 27094 ae_vector_set_length(&c, maxnearcenterscnt, _state); 27095 ae_matrix_set_length(&nearcenters, maxnearcenterscnt, rbf_mxnx, _state); 27096 ae_matrix_set_length(&nearpoints, ae_maxint(maxnearpointscnt, 1, _state), rbf_mxnx, _state); 27097 ae_matrix_set_length(&farpoints, ae_maxint(maxfarpointscnt, 1, _state), rbf_mxnx, _state); 27102 sparsecreate(n, nc, *gnnz, &spg, _state); 27103 sparsecreate(nc, nc, *snnz, &sps, _state); 27104 for(i=0; i<=nc-1; i++) 27106 centerscnt = nearcenterscnt.ptr.p_int[i]; 27111 for(j=0; j<=rbf_mxnx-1; j++) 27113 xcx.ptr.p_double[j] = xc->ptr.pp_double[i][j]; 27119 tmpi = kdtreequeryknn(centerstree, &xcx, centerscnt, ae_true, _state); 27120 ae_assert(tmpi==centerscnt, "BuildRBFModelLSQR:
internal error", _state); 27121 kdtreequeryresultsx(centerstree, &cx, _state); 27122 kdtreequeryresultstags(centerstree, ¢erstags, _state); 27128 for(j=0; j<=centerscnt-1; j++) 27130 mrad = ae_maxreal(mrad, r->ptr.p_double[centerstags.ptr.p_int[j]], _state); 27134 * we need to be sure that 'CTree' contains 27135 * at least one side center 27137 sparseset(&sps, i, i, 1, _state); 27138 c.ptr.p_double[0] = 1.0; 27139 for(j=1; j<=centerscnt-1; j++) 27141 c.ptr.p_double[j] = 0.0; 27143 if( centerscnt>1&&nearpointscnt.ptr.p_int[i]>0 ) 27147 * first KDTree request for points 27149 pointscnt = nearpointscnt.ptr.p_int[i]; 27150 tmpi = kdtreequeryknn(pointstree, &xcx, skipnearpointscnt.ptr.p_int[i]+nearpointscnt.ptr.p_int[i], ae_true, _state); 27151 ae_assert(tmpi==skipnearpointscnt.ptr.p_int[i]+nearpointscnt.ptr.p_int[i], "BuildRBFModelLSQR:
internal error", _state); 27152 kdtreequeryresultsx(pointstree, &xx, _state); 27153 sind = skipnearpointscnt.ptr.p_int[i]; 27154 for(j=0; j<=pointscnt-1; j++) 27156 vx = xx.ptr.pp_double[sind+j][0]; 27157 vy = xx.ptr.pp_double[sind+j][1]; 27158 vz = xx.ptr.pp_double[sind+j][2]; 27159 for(k=0; k<=centerscnt-1; k++) 27162 vv = vx-cx.ptr.pp_double[k][0]; 27164 vv = vy-cx.ptr.pp_double[k][1]; 27166 vv = vz-cx.ptr.pp_double[k][2]; 27168 vv = r->ptr.p_double[centerstags.ptr.p_int[k]]; 27169 a.ptr.pp_double[j][k] = ae_exp(-vr/(vv*vv), _state); 27172 for(j=0; j<=centerscnt-1; j++) 27174 g.ptr.p_double[j] = ae_exp(-(ae_sqr(xcx.ptr.p_double[0]-cx.ptr.pp_double[j][0], _state)+ae_sqr(xcx.ptr.p_double[1]-cx.ptr.pp_double[j][1], _state)+ae_sqr(xcx.ptr.p_double[2]-cx.ptr.pp_double[j][2], _state))/ae_sqr(r->ptr.p_double[centerstags.ptr.p_int[j]], _state), _state); 27178 * calculate the problem 27180 gnorm2 = ae_v_dotproduct(&g.ptr.p_double[0], 1, &g.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1)); 27181 for(j=0; j<=pointscnt-1; j++) 27183 vv = ae_v_dotproduct(&a.ptr.pp_double[j][0], 1, &g.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1)); 27185 tmpy.ptr.p_double[j] = -vv; 27186 ae_v_subd(&a.ptr.pp_double[j][0], 1, &g.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1), vv); 27188 for(j=pointscnt; j<=pointscnt+centerscnt-1; j++) 27190 for(k=0; k<=centerscnt-1; k++) 27192 a.ptr.pp_double[j][k] = 0.0; 27194 a.ptr.pp_double[j][j-pointscnt] = 1.0E-6; 27195 tmpy.ptr.p_double[j] = 0.0; 27197 fblssolvels(&a, &tmpy, pointscnt+centerscnt, centerscnt, &tmp0, &tmp1, &tmp2, _state); 27198 ae_v_move(&c.ptr.p_double[0], 1, &tmpy.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1)); 27199 vv = ae_v_dotproduct(&g.ptr.p_double[0], 1, &c.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1)); 27201 ae_v_subd(&c.ptr.p_double[0], 1, &g.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1), vv); 27203 ae_v_addd(&c.ptr.p_double[0], 1, &g.ptr.p_double[0], 1, ae_v_len(0,centerscnt-1), vv); 27204 for(j=0; j<=centerscnt-1; j++) 27206 sparseset(&sps, i, centerstags.ptr.p_int[j], c.ptr.p_double[j], _state); 27211 * second KDTree request for points 27213 pointscnt = farpointscnt.ptr.p_int[i]; 27214 tmpi = kdtreequeryknn(pointstree, &xcx, pointscnt, ae_true, _state); 27215 ae_assert(tmpi==pointscnt, "BuildRBFModelLSQR:
internal error", _state); 27216 kdtreequeryresultsx(pointstree, &xx, _state); 27217 kdtreequeryresultstags(pointstree, &pointstags, _state); 27222 for(j=0; j<=pointscnt-1; j++) 27225 vx = xx.ptr.pp_double[j][0]; 27226 vy = xx.ptr.pp_double[j][1]; 27227 vz = xx.ptr.pp_double[j][2]; 27228 for(k=0; k<=centerscnt-1; k++) 27231 vv = vx-cx.ptr.pp_double[k][0]; 27233 vv = vy-cx.ptr.pp_double[k][1]; 27235 vv = vz-cx.ptr.pp_double[k][2]; 27237 vv = r->ptr.p_double[centerstags.ptr.p_int[k]]; 27239 fx = fx+c.ptr.p_double[k]*ae_exp(-vr/vv, _state); 27241 sparseset(&spg, pointstags.ptr.p_int[j], i, fx, _state); 27244 sparseconverttocrs(&spg, _state); 27245 sparseconverttocrs(&sps, _state); 27248 * solve by LSQR method 27250 ae_vector_set_length(&tmpy, n, _state); 27251 ae_vector_set_length(&tc, nc, _state); 27252 ae_matrix_set_length(w, nc, ny, _state); 27253 linlsqrcreate(n, nc, &state, _state); 27254 linlsqrsetcond(&state, epsort, epserr, maxits, _state); 27255 for(i=0; i<=ny-1; i++) 27257 for(j=0; j<=n-1; j++) 27259 tmpy.ptr.p_double[j] = y->ptr.pp_double[j][i]; 27261 linlsqrsolvesparse(&state, &spg, &tmpy, _state); 27262 linlsqrresults(&state, &c, &lsqrrep, _state); 27263 if( lsqrrep.terminationtype<=0 ) 27266 ae_frame_leave(_state); 27269 sparsemtv(&sps, &c, &tc, _state); 27270 for(j=0; j<=nc-1; j++) 27272 w->ptr.pp_double[j][i] = tc.ptr.p_double[j]; 27274 *iterationscount = *iterationscount+lsqrrep.iterationscount; 27275 *nmv = *nmv+lsqrrep.nmv; 27278 ae_frame_leave(_state); 27282 static void rbf_buildrbfmlayersmodellsqr(/* Real */ ae_matrix* x, 27283 /* Real */ ae_matrix* y, 27284 /* Real */ ae_matrix* xc, 27286 /* Real */ ae_vector* r, 27291 kdtree* centerstree, 27297 /* Real */ ae_matrix* w, 27299 ae_int_t* iterationscount, 27303 ae_frame _frame_block; 27304 linlsqrstate state; 27305 linlsqrreport lsqrrep; 27314 ae_vector centerstags; 27323 ae_frame_make(_state, &_frame_block); 27324 ae_matrix_clear(xc); 27325 ae_vector_clear(r); 27328 ae_matrix_clear(w); 27330 *iterationscount = 0; 27332 _linlsqrstate_init(&state, _state, ae_true); 27333 _linlsqrreport_init(&lsqrrep, _state, ae_true); 27334 _sparsematrix_init(&spa, _state, ae_true); 27335 ae_vector_init(&omega, 0, DT_REAL, _state, ae_true); 27336 ae_vector_init(&xx, 0, DT_REAL, _state, ae_true); 27337 ae_vector_init(&tmpy, 0, DT_REAL, _state, ae_true); 27338 ae_matrix_init(&cx, 0, 0, DT_REAL, _state, ae_true); 27339 ae_vector_init(¢erstags, 0, DT_INT, _state, ae_true); 27341 ae_assert(nlayers>=0, "BuildRBFMLayersModelLSQR: invalid argument(NLayers<0)
", _state); 27342 ae_assert(n>=0, "BuildRBFMLayersModelLSQR: invalid argument(N<0)
", _state); 27343 ae_assert(rbf_mxnx>0&&rbf_mxnx<=3, "BuildRBFMLayersModelLSQR:
internal error(invalid global
const MxNX: either MxNX<=0 or MxNX>3)
", _state); 27345 if( n==0||nlayers==0 ) 27348 *iterationscount = 0; 27350 ae_frame_leave(_state); 27354 ae_vector_set_length(&xx, rbf_mxnx, _state); 27355 ae_vector_set_length(¢erstags, n, _state); 27356 ae_matrix_set_length(xc, *nc, rbf_mxnx, _state); 27357 ae_vector_set_length(r, *nc, _state); 27358 for(i=0; i<=*nc-1; i++) 27360 for(j=0; j<=rbf_mxnx-1; j++) 27362 xc->ptr.pp_double[i][j] = x->ptr.pp_double[i%n][j]; 27365 for(i=0; i<=*nc-1; i++) 27367 r->ptr.p_double[i] = rval/ae_pow(2, i/n, _state); 27369 for(i=0; i<=n-1; i++) 27371 centerstags.ptr.p_int[i] = i; 27373 kdtreebuildtagged(xc, ¢erstags, n, rbf_mxnx, 0, 2, centerstree, _state); 27374 ae_vector_set_length(&omega, n, _state); 27375 ae_vector_set_length(&tmpy, n, _state); 27376 ae_matrix_set_length(w, *nc, ny, _state); 27378 *iterationscount = 0; 27380 linlsqrcreate(n, n, &state, _state); 27381 linlsqrsetcond(&state, epsort, epserr, maxits, _state); 27382 linlsqrsetlambdai(&state, 1.0E-6, _state); 27385 * calculate number of non-zero elements for sparse matrix 27387 for(i=0; i<=n-1; i++) 27389 for(j=0; j<=rbf_mxnx-1; j++) 27391 xx.ptr.p_double[j] = x->ptr.pp_double[i][j]; 27393 *annz = *annz+kdtreequeryrnn(centerstree, &xx, r->ptr.p_double[0]*rbf_rbfmlradius, ae_true, _state); 27395 for(layer=0; layer<=nlayers-1; layer++) 27399 * Fill sparse matrix, calculate norm(A) 27402 sparsecreate(n, n, *annz, &spa, _state); 27403 for(i=0; i<=n-1; i++) 27405 for(j=0; j<=rbf_mxnx-1; j++) 27407 xx.ptr.p_double[j] = x->ptr.pp_double[i][j]; 27409 nec = kdtreequeryrnn(centerstree, &xx, r->ptr.p_double[layer*n]*rbf_rbfmlradius, ae_true, _state); 27410 kdtreequeryresultsx(centerstree, &cx, _state); 27411 kdtreequeryresultstags(centerstree, ¢erstags, _state); 27412 for(j=0; j<=nec-1; j++) 27414 v = ae_exp(-(ae_sqr(xx.ptr.p_double[0]-cx.ptr.pp_double[j][0], _state)+ae_sqr(xx.ptr.p_double[1]-cx.ptr.pp_double[j][1], _state)+ae_sqr(xx.ptr.p_double[2]-cx.ptr.pp_double[j][2], _state))/ae_sqr(r->ptr.p_double[layer*n+centerstags.ptr.p_int[j]], _state), _state); 27415 sparseset(&spa, i, centerstags.ptr.p_int[j], v, _state); 27416 anorm = anorm+ae_sqr(v, _state); 27419 anorm = ae_sqrt(anorm, _state); 27420 sparseconverttocrs(&spa, _state); 27423 * Calculate maximum residual before adding new layer. 27424 * This value is not used by algorithm, the only purpose is to make debugging easier. 27427 for(j=0; j<=n-1; j++) 27429 for(i=0; i<=ny-1; i++) 27431 rmaxbefore = ae_maxreal(rmaxbefore, ae_fabs(y->ptr.pp_double[j][i], _state), _state); 27436 * Process NY dimensions of the target function 27438 for(i=0; i<=ny-1; i++) 27440 for(j=0; j<=n-1; j++) 27442 tmpy.ptr.p_double[j] = y->ptr.pp_double[j][i]; 27446 * calculate Omega for current layer 27448 linlsqrsetlambdai(&state, lambdav*anorm/n, _state); 27449 linlsqrsolvesparse(&state, &spa, &tmpy, _state); 27450 linlsqrresults(&state, &omega, &lsqrrep, _state); 27451 if( lsqrrep.terminationtype<=0 ) 27454 ae_frame_leave(_state); 27459 * calculate error for current layer 27461 for(j=0; j<=n-1; j++) 27464 for(k=0; k<=rbf_mxnx-1; k++) 27466 xx.ptr.p_double[k] = x->ptr.pp_double[j][k]; 27468 nec = kdtreequeryrnn(centerstree, &xx, r->ptr.p_double[layer*n]*rbf_rbffarradius, ae_true, _state); 27469 kdtreequeryresultsx(centerstree, &cx, _state); 27470 kdtreequeryresultstags(centerstree, ¢erstags, _state); 27471 for(k=0; k<=nec-1; k++) 27473 yval = yval+omega.ptr.p_double[centerstags.ptr.p_int[k]]*ae_exp(-(ae_sqr(xx.ptr.p_double[0]-cx.ptr.pp_double[k][0], _state)+ae_sqr(xx.ptr.p_double[1]-cx.ptr.pp_double[k][1], _state)+ae_sqr(xx.ptr.p_double[2]-cx.ptr.pp_double[k][2], _state))/ae_sqr(r->ptr.p_double[layer*n+centerstags.ptr.p_int[k]], _state), _state); 27475 y->ptr.pp_double[j][i] = y->ptr.pp_double[j][i]-yval; 27479 * write Omega in out parameter W 27481 for(j=0; j<=n-1; j++) 27483 w->ptr.pp_double[layer*n+j][i] = omega.ptr.p_double[j]; 27485 *iterationscount = *iterationscount+lsqrrep.iterationscount; 27486 *nmv = *nmv+lsqrrep.nmv; 27490 * Calculate maximum residual before adding new layer. 27491 * This value is not used by algorithm, the only purpose is to make debugging easier. 27494 for(j=0; j<=n-1; j++) 27496 for(i=0; i<=ny-1; i++) 27498 rmaxafter = ae_maxreal(rmaxafter, ae_fabs(y->ptr.pp_double[j][i], _state), _state); 27503 ae_frame_leave(_state); 27507 ae_bool _rbfmodel_init(void* _p, ae_state *_state, ae_bool make_automatic) 27509 rbfmodel *p = (rbfmodel*)_p; 27510 ae_touch_ptr((void*)p); 27511 if( !_kdtree_init(&p->tree, _state, make_automatic) ) 27513 if( !ae_matrix_init(&p->xc, 0, 0, DT_REAL, _state, make_automatic) ) 27515 if( !ae_matrix_init(&p->wr, 0, 0, DT_REAL, _state, make_automatic) ) 27517 if( !ae_matrix_init(&p->v, 0, 0, DT_REAL, _state, make_automatic) ) 27519 if( !ae_matrix_init(&p->x, 0, 0, DT_REAL, _state, make_automatic) ) 27521 if( !ae_matrix_init(&p->y, 0, 0, DT_REAL, _state, make_automatic) ) 27523 if( !ae_vector_init(&p->calcbufxcx, 0, DT_REAL, _state, make_automatic) ) 27525 if( !ae_matrix_init(&p->calcbufx, 0, 0, DT_REAL, _state, make_automatic) ) 27527 if( !ae_vector_init(&p->calcbuftags, 0, DT_INT, _state, make_automatic) ) 27533 ae_bool _rbfmodel_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 27535 rbfmodel *dst = (rbfmodel*)_dst; 27536 rbfmodel *src = (rbfmodel*)_src; 27541 if( !_kdtree_init_copy(&dst->tree, &src->tree, _state, make_automatic) ) 27543 if( !ae_matrix_init_copy(&dst->xc, &src->xc, _state, make_automatic) ) 27545 if( !ae_matrix_init_copy(&dst->wr, &src->wr, _state, make_automatic) ) 27547 dst->rmax = src->rmax; 27548 if( !ae_matrix_init_copy(&dst->v, &src->v, _state, make_automatic) ) 27550 dst->gridtype = src->gridtype; 27551 dst->fixrad = src->fixrad; 27552 dst->lambdav = src->lambdav; 27553 dst->radvalue = src->radvalue; 27554 dst->radzvalue = src->radzvalue; 27555 dst->nlayers = src->nlayers; 27556 dst->aterm = src->aterm; 27557 dst->algorithmtype = src->algorithmtype; 27558 dst->epsort = src->epsort; 27559 dst->epserr = src->epserr; 27560 dst->maxits = src->maxits; 27563 if( !ae_matrix_init_copy(&dst->x, &src->x, _state, make_automatic) ) 27565 if( !ae_matrix_init_copy(&dst->y, &src->y, _state, make_automatic) ) 27567 if( !ae_vector_init_copy(&dst->calcbufxcx, &src->calcbufxcx, _state, make_automatic) ) 27569 if( !ae_matrix_init_copy(&dst->calcbufx, &src->calcbufx, _state, make_automatic) ) 27571 if( !ae_vector_init_copy(&dst->calcbuftags, &src->calcbuftags, _state, make_automatic) ) 27577 void _rbfmodel_clear(void* _p) 27579 rbfmodel *p = (rbfmodel*)_p; 27580 ae_touch_ptr((void*)p); 27581 _kdtree_clear(&p->tree); 27582 ae_matrix_clear(&p->xc); 27583 ae_matrix_clear(&p->wr); 27584 ae_matrix_clear(&p->v); 27585 ae_matrix_clear(&p->x); 27586 ae_matrix_clear(&p->y); 27587 ae_vector_clear(&p->calcbufxcx); 27588 ae_matrix_clear(&p->calcbufx); 27589 ae_vector_clear(&p->calcbuftags); 27593 void _rbfmodel_destroy(void* _p) 27595 rbfmodel *p = (rbfmodel*)_p; 27596 ae_touch_ptr((void*)p); 27597 _kdtree_destroy(&p->tree); 27598 ae_matrix_destroy(&p->xc); 27599 ae_matrix_destroy(&p->wr); 27600 ae_matrix_destroy(&p->v); 27601 ae_matrix_destroy(&p->x); 27602 ae_matrix_destroy(&p->y); 27603 ae_vector_destroy(&p->calcbufxcx); 27604 ae_matrix_destroy(&p->calcbufx); 27605 ae_vector_destroy(&p->calcbuftags); 27609 ae_bool _rbfreport_init(void* _p, ae_state *_state, ae_bool make_automatic) 27611 rbfreport *p = (rbfreport*)_p; 27612 ae_touch_ptr((void*)p); 27617 ae_bool _rbfreport_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 27619 rbfreport *dst = (rbfreport*)_dst; 27620 rbfreport *src = (rbfreport*)_src; 27621 dst->arows = src->arows; 27622 dst->acols = src->acols; 27623 dst->annz = src->annz; 27624 dst->iterationscount = src->iterationscount; 27625 dst->nmv = src->nmv; 27626 dst->terminationtype = src->terminationtype; 27631 void _rbfreport_clear(void* _p) 27633 rbfreport *p = (rbfreport*)_p; 27634 ae_touch_ptr((void*)p); 27638 void _rbfreport_destroy(void* _p) 27640 rbfreport *p = (rbfreport*)_p; 27641 ae_touch_ptr((void*)p); 27647 /************************************************************************* 27648 This subroutine calculates the value of the bilinear or bicubic spline at 27652 C - coefficients table. 27653 Built by BuildBilinearSpline or BuildBicubicSpline. 27659 -- ALGLIB PROJECT -- 27660 Copyright 05.07.2007 by Bochkanov Sergey 27661 *************************************************************************/ 27662 double spline2dcalc(spline2dinterpolant* c, 27674 ae_assert(c->stype==-1||c->stype==-3, "Spline2DCalc: incorrect C (incorrect parameter C.SType)
", _state); 27675 ae_assert(ae_isfinite(x, _state)&&ae_isfinite(y, _state), "Spline2DCalc: X
or Y contains NaN
or Infinite value
", _state); 27681 spline2ddiff(c, x, y, &v, &vx, &vy, &vxy, _state); 27687 /************************************************************************* 27688 This subroutine calculates the value of the bilinear or bicubic spline at 27689 the given point X and its derivatives. 27692 C - spline interpolant. 27699 FXY - d2S(x,y)/dXdY 27701 -- ALGLIB PROJECT -- 27702 Copyright 05.07.2007 by Bochkanov Sergey 27703 *************************************************************************/ 27704 void spline2ddiff(spline2dinterpolant* c, 27748 ae_assert(c->stype==-1||c->stype==-3, "Spline2DDiff: incorrect C (incorrect parameter C.SType)
", _state); 27749 ae_assert(ae_isfinite(x, _state)&&ae_isfinite(y, _state), "Spline2DDiff: X
or Y contains NaN
or Infinite value
", _state); 27752 * Prepare F, dF/dX, dF/dY, d2F/dXdY 27764 * Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included) 27771 if( ae_fp_greater_eq(c->x.ptr.p_double[h],x) ) 27780 t = (x-c->x.ptr.p_double[l])/(c->x.ptr.p_double[l+1]-c->x.ptr.p_double[l]); 27781 dt = 1.0/(c->x.ptr.p_double[l+1]-c->x.ptr.p_double[l]); 27785 * Binary search in the [ y[0], ..., y[m-2] ] (y[m-1] is not included) 27792 if( ae_fp_greater_eq(c->y.ptr.p_double[h],y) ) 27801 u = (y-c->y.ptr.p_double[l])/(c->y.ptr.p_double[l+1]-c->y.ptr.p_double[l]); 27802 du = 1.0/(c->y.ptr.p_double[l+1]-c->y.ptr.p_double[l]); 27806 * Bilinear interpolation 27810 y1 = c->f.ptr.p_double[c->n*iy+ix]; 27811 y2 = c->f.ptr.p_double[c->n*iy+(ix+1)]; 27812 y3 = c->f.ptr.p_double[c->n*(iy+1)+(ix+1)]; 27813 y4 = c->f.ptr.p_double[c->n*(iy+1)+ix]; 27814 *f = (1-t)*(1-u)*y1+t*(1-u)*y2+t*u*y3+(1-t)*u*y4; 27815 *fx = (-(1-u)*y1+(1-u)*y2+u*y3-u*y4)*dt; 27816 *fy = (-(1-t)*y1-t*y2+t*y3+(1-t)*y4)*du; 27817 *fxy = (y1-y2+y3-y4)*du*dt; 27822 * Bicubic interpolation 27832 t2 = ae_sqr(t, _state); 27836 u2 = ae_sqr(u, _state); 27840 sfxy = 3*c->n*c->m; 27842 s2 = c->n*iy+(ix+1); 27843 s3 = c->n*(iy+1)+(ix+1); 27844 s4 = c->n*(iy+1)+ix; 27849 v = c->f.ptr.p_double[s1]; 27851 v = c->f.ptr.p_double[sfy+s1]/du; 27853 *fy = *fy+v*t0*u0*du; 27854 v = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s4]-2*c->f.ptr.p_double[sfy+s1]/du-c->f.ptr.p_double[sfy+s4]/du; 27856 *fy = *fy+2*v*t0*u1*du; 27857 v = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s4]+c->f.ptr.p_double[sfy+s1]/du+c->f.ptr.p_double[sfy+s4]/du; 27859 *fy = *fy+3*v*t0*u2*du; 27860 v = c->f.ptr.p_double[sfx+s1]/dt; 27862 *fx = *fx+v*t0*u0*dt; 27863 v = c->f.ptr.p_double[sfxy+s1]/(dt*du); 27865 *fx = *fx+v*t0*u1*dt; 27866 *fy = *fy+v*t1*u0*du; 27867 *fxy = *fxy+v*t0*u0*dt*du; 27868 v = -3*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 27870 *fx = *fx+v*t0*u2*dt; 27871 *fy = *fy+2*v*t1*u1*du; 27872 *fxy = *fxy+2*v*t0*u1*dt*du; 27873 v = 2*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 27875 *fx = *fx+v*t0*u3*dt; 27876 *fy = *fy+3*v*t1*u2*du; 27877 *fxy = *fxy+3*v*t0*u2*dt*du; 27878 v = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s2]-2*c->f.ptr.p_double[sfx+s1]/dt-c->f.ptr.p_double[sfx+s2]/dt; 27880 *fx = *fx+2*v*t1*u0*dt; 27881 v = -3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du); 27883 *fx = *fx+2*v*t1*u1*dt; 27884 *fy = *fy+v*t2*u0*du; 27885 *fxy = *fxy+2*v*t1*u0*dt*du; 27886 v = 9*c->f.ptr.p_double[s1]-9*c->f.ptr.p_double[s2]+9*c->f.ptr.p_double[s3]-9*c->f.ptr.p_double[s4]+6*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s2]/dt-3*c->f.ptr.p_double[sfx+s3]/dt-6*c->f.ptr.p_double[sfx+s4]/dt+6*c->f.ptr.p_double[sfy+s1]/du-6*c->f.ptr.p_double[sfy+s2]/du-3*c->f.ptr.p_double[sfy+s3]/du+3*c->f.ptr.p_double[sfy+s4]/du+4*c->f.ptr.p_double[sfxy+s1]/(dt*du)+2*c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 27888 *fx = *fx+2*v*t1*u2*dt; 27889 *fy = *fy+2*v*t2*u1*du; 27890 *fxy = *fxy+4*v*t1*u1*dt*du; 27891 v = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-4*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s2]/dt+2*c->f.ptr.p_double[sfx+s3]/dt+4*c->f.ptr.p_double[sfx+s4]/dt-3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du+3*c->f.ptr.p_double[sfy+s3]/du-3*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 27893 *fx = *fx+2*v*t1*u3*dt; 27894 *fy = *fy+3*v*t2*u2*du; 27895 *fxy = *fxy+6*v*t1*u2*dt*du; 27896 v = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s2]+c->f.ptr.p_double[sfx+s1]/dt+c->f.ptr.p_double[sfx+s2]/dt; 27898 *fx = *fx+3*v*t2*u0*dt; 27899 v = 2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du); 27901 *fx = *fx+3*v*t2*u1*dt; 27902 *fy = *fy+v*t3*u0*du; 27903 *fxy = *fxy+3*v*t2*u0*dt*du; 27904 v = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-3*c->f.ptr.p_double[sfx+s1]/dt-3*c->f.ptr.p_double[sfx+s2]/dt+3*c->f.ptr.p_double[sfx+s3]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-4*c->f.ptr.p_double[sfy+s1]/du+4*c->f.ptr.p_double[sfy+s2]/du+2*c->f.ptr.p_double[sfy+s3]/du-2*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-2*c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 27906 *fx = *fx+3*v*t2*u2*dt; 27907 *fy = *fy+2*v*t3*u1*du; 27908 *fxy = *fxy+6*v*t2*u1*dt*du; 27909 v = 4*c->f.ptr.p_double[s1]-4*c->f.ptr.p_double[s2]+4*c->f.ptr.p_double[s3]-4*c->f.ptr.p_double[s4]+2*c->f.ptr.p_double[sfx+s1]/dt+2*c->f.ptr.p_double[sfx+s2]/dt-2*c->f.ptr.p_double[sfx+s3]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfy+s3]/du+2*c->f.ptr.p_double[sfy+s4]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 27911 *fx = *fx+3*v*t2*u3*dt; 27912 *fy = *fy+3*v*t3*u2*du; 27913 *fxy = *fxy+9*v*t2*u2*dt*du; 27919 /************************************************************************* 27920 This subroutine performs linear transformation of the spline argument. 27923 C - spline interpolant 27924 AX, BX - transformation coefficients: x = A*t + B 27925 AY, BY - transformation coefficients: y = A*u + B 27927 C - transformed spline 27929 -- ALGLIB PROJECT -- 27930 Copyright 30.06.2007 by Bochkanov Sergey 27931 *************************************************************************/ 27932 void spline2dlintransxy(spline2dinterpolant* c, 27939 ae_frame _frame_block; 27948 ae_frame_make(_state, &_frame_block); 27949 ae_vector_init(&x, 0, DT_REAL, _state, ae_true); 27950 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 27951 ae_vector_init(&f, 0, DT_REAL, _state, ae_true); 27952 ae_vector_init(&v, 0, DT_REAL, _state, ae_true); 27954 ae_assert(c->stype==-3||c->stype==-1, "Spline2DLinTransXY: incorrect C (incorrect parameter C.SType)
", _state); 27955 ae_assert(ae_isfinite(ax, _state), "Spline2DLinTransXY: AX is infinite
or NaN
", _state); 27956 ae_assert(ae_isfinite(bx, _state), "Spline2DLinTransXY: BX is infinite
or NaN
", _state); 27957 ae_assert(ae_isfinite(ay, _state), "Spline2DLinTransXY: AY is infinite
or NaN
", _state); 27958 ae_assert(ae_isfinite(by, _state), "Spline2DLinTransXY: BY is infinite
or NaN
", _state); 27959 ae_vector_set_length(&x, c->n, _state); 27960 ae_vector_set_length(&y, c->m, _state); 27961 ae_vector_set_length(&f, c->m*c->n*c->d, _state); 27962 for(j=0; j<=c->n-1; j++) 27964 x.ptr.p_double[j] = c->x.ptr.p_double[j]; 27966 for(i=0; i<=c->m-1; i++) 27968 y.ptr.p_double[i] = c->y.ptr.p_double[i]; 27970 for(i=0; i<=c->m-1; i++) 27972 for(j=0; j<=c->n-1; j++) 27974 for(k=0; k<=c->d-1; k++) 27976 f.ptr.p_double[c->d*(i*c->n+j)+k] = c->f.ptr.p_double[c->d*(i*c->n+j)+k]; 27982 * Handle different combinations of AX/AY 27984 if( ae_fp_eq(ax,0)&&ae_fp_neq(ay,0) ) 27986 for(i=0; i<=c->m-1; i++) 27988 spline2dcalcvbuf(c, bx, y.ptr.p_double[i], &v, _state); 27989 y.ptr.p_double[i] = (y.ptr.p_double[i]-by)/ay; 27990 for(j=0; j<=c->n-1; j++) 27992 for(k=0; k<=c->d-1; k++) 27994 f.ptr.p_double[c->d*(i*c->n+j)+k] = v.ptr.p_double[k]; 27999 if( ae_fp_neq(ax,0)&&ae_fp_eq(ay,0) ) 28001 for(j=0; j<=c->n-1; j++) 28003 spline2dcalcvbuf(c, x.ptr.p_double[j], by, &v, _state); 28004 x.ptr.p_double[j] = (x.ptr.p_double[j]-bx)/ax; 28005 for(i=0; i<=c->m-1; i++) 28007 for(k=0; k<=c->d-1; k++) 28009 f.ptr.p_double[c->d*(i*c->n+j)+k] = v.ptr.p_double[k]; 28014 if( ae_fp_neq(ax,0)&&ae_fp_neq(ay,0) ) 28016 for(j=0; j<=c->n-1; j++) 28018 x.ptr.p_double[j] = (x.ptr.p_double[j]-bx)/ax; 28020 for(i=0; i<=c->m-1; i++) 28022 y.ptr.p_double[i] = (y.ptr.p_double[i]-by)/ay; 28025 if( ae_fp_eq(ax,0)&&ae_fp_eq(ay,0) ) 28027 spline2dcalcvbuf(c, bx, by, &v, _state); 28028 for(i=0; i<=c->m-1; i++) 28030 for(j=0; j<=c->n-1; j++) 28032 for(k=0; k<=c->d-1; k++) 28034 f.ptr.p_double[c->d*(i*c->n+j)+k] = v.ptr.p_double[k]; 28045 spline2dbuildbicubicv(&x, c->n, &y, c->m, &f, c->d, c, _state); 28049 spline2dbuildbilinearv(&x, c->n, &y, c->m, &f, c->d, c, _state); 28051 ae_frame_leave(_state); 28055 /************************************************************************* 28056 This subroutine performs linear transformation of the spline. 28059 C - spline interpolant. 28060 A, B- transformation coefficients: S2(x,y) = A*S(x,y) + B 28063 C - transformed spline 28065 -- ALGLIB PROJECT -- 28066 Copyright 30.06.2007 by Bochkanov Sergey 28067 *************************************************************************/ 28068 void spline2dlintransf(spline2dinterpolant* c, 28073 ae_frame _frame_block; 28080 ae_frame_make(_state, &_frame_block); 28081 ae_vector_init(&x, 0, DT_REAL, _state, ae_true); 28082 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 28083 ae_vector_init(&f, 0, DT_REAL, _state, ae_true); 28085 ae_assert(c->stype==-3||c->stype==-1, "Spline2DLinTransF: incorrect C (incorrect parameter C.SType)
", _state); 28086 ae_vector_set_length(&x, c->n, _state); 28087 ae_vector_set_length(&y, c->m, _state); 28088 ae_vector_set_length(&f, c->m*c->n*c->d, _state); 28089 for(j=0; j<=c->n-1; j++) 28091 x.ptr.p_double[j] = c->x.ptr.p_double[j]; 28093 for(i=0; i<=c->m-1; i++) 28095 y.ptr.p_double[i] = c->y.ptr.p_double[i]; 28097 for(i=0; i<=c->m*c->n*c->d-1; i++) 28099 f.ptr.p_double[i] = a*c->f.ptr.p_double[i]+b; 28103 spline2dbuildbicubicv(&x, c->n, &y, c->m, &f, c->d, c, _state); 28107 spline2dbuildbilinearv(&x, c->n, &y, c->m, &f, c->d, c, _state); 28109 ae_frame_leave(_state); 28113 /************************************************************************* 28114 This subroutine makes the copy of the spline model. 28117 C - spline interpolant 28122 -- ALGLIB PROJECT -- 28123 Copyright 29.06.2007 by Bochkanov Sergey 28124 *************************************************************************/ 28125 void spline2dcopy(spline2dinterpolant* c, 28126 spline2dinterpolant* cc, 28131 _spline2dinterpolant_clear(cc); 28133 ae_assert(c->k==1||c->k==3, "Spline2DCopy: incorrect C (incorrect parameter C.K)
", _state); 28138 cc->stype = c->stype; 28142 tblsize = 4*c->n*c->m*c->d; 28146 tblsize = c->n*c->m*c->d; 28148 ae_assert(tblsize>0, "Spline2DCopy:
internal error", _state); 28149 ae_vector_set_length(&cc->x, cc->n, _state); 28150 ae_vector_set_length(&cc->y, cc->m, _state); 28151 ae_vector_set_length(&cc->f, tblsize, _state); 28152 ae_v_move(&cc->x.ptr.p_double[0], 1, &c->x.ptr.p_double[0], 1, ae_v_len(0,cc->n-1)); 28153 ae_v_move(&cc->y.ptr.p_double[0], 1, &c->y.ptr.p_double[0], 1, ae_v_len(0,cc->m-1)); 28154 ae_v_move(&cc->f.ptr.p_double[0], 1, &c->f.ptr.p_double[0], 1, ae_v_len(0,tblsize-1)); 28158 /************************************************************************* 28159 Bicubic spline resampling 28162 A - function values at the old grid, 28163 array[0..OldHeight-1, 0..OldWidth-1] 28164 OldHeight - old grid height, OldHeight>1 28165 OldWidth - old grid width, OldWidth>1 28166 NewHeight - new grid height, NewHeight>1 28167 NewWidth - new grid width, NewWidth>1 28170 B - function values at the new grid, 28171 array[0..NewHeight-1, 0..NewWidth-1] 28173 -- ALGLIB routine -- 28175 Copyright by Bochkanov Sergey 28176 *************************************************************************/ 28177 void spline2dresamplebicubic(/* Real */ ae_matrix* a, 28178 ae_int_t oldheight, 28180 /* Real */ ae_matrix* b, 28181 ae_int_t newheight, 28185 ae_frame _frame_block; 28189 spline1dinterpolant c; 28195 ae_frame_make(_state, &_frame_block); 28196 ae_matrix_clear(b); 28197 ae_matrix_init(&buf, 0, 0, DT_REAL, _state, ae_true); 28198 ae_vector_init(&x, 0, DT_REAL, _state, ae_true); 28199 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 28200 _spline1dinterpolant_init(&c, _state, ae_true); 28202 ae_assert(oldwidth>1&&oldheight>1, "Spline2DResampleBicubic: width/height less than 1
", _state); 28203 ae_assert(newwidth>1&&newheight>1, "Spline2DResampleBicubic: width/height less than 1
", _state); 28208 mw = ae_maxint(oldwidth, newwidth, _state); 28209 mh = ae_maxint(oldheight, newheight, _state); 28210 ae_matrix_set_length(b, newheight, newwidth, _state); 28211 ae_matrix_set_length(&buf, oldheight, newwidth, _state); 28212 ae_vector_set_length(&x, ae_maxint(mw, mh, _state), _state); 28213 ae_vector_set_length(&y, ae_maxint(mw, mh, _state), _state); 28216 * Horizontal interpolation 28218 for(i=0; i<=oldheight-1; i++) 28224 for(j=0; j<=oldwidth-1; j++) 28226 x.ptr.p_double[j] = (double)j/(double)(oldwidth-1); 28227 y.ptr.p_double[j] = a->ptr.pp_double[i][j]; 28231 * Interpolate and place result into temporary matrix 28233 spline1dbuildcubic(&x, &y, oldwidth, 0, 0.0, 0, 0.0, &c, _state); 28234 for(j=0; j<=newwidth-1; j++) 28236 buf.ptr.pp_double[i][j] = spline1dcalc(&c, (double)j/(double)(newwidth-1), _state); 28241 * Vertical interpolation 28243 for(j=0; j<=newwidth-1; j++) 28249 for(i=0; i<=oldheight-1; i++) 28251 x.ptr.p_double[i] = (double)i/(double)(oldheight-1); 28252 y.ptr.p_double[i] = buf.ptr.pp_double[i][j]; 28256 * Interpolate and place result into B 28258 spline1dbuildcubic(&x, &y, oldheight, 0, 0.0, 0, 0.0, &c, _state); 28259 for(i=0; i<=newheight-1; i++) 28261 b->ptr.pp_double[i][j] = spline1dcalc(&c, (double)i/(double)(newheight-1), _state); 28264 ae_frame_leave(_state); 28268 /************************************************************************* 28269 Bilinear spline resampling 28272 A - function values at the old grid, 28273 array[0..OldHeight-1, 0..OldWidth-1] 28274 OldHeight - old grid height, OldHeight>1 28275 OldWidth - old grid width, OldWidth>1 28276 NewHeight - new grid height, NewHeight>1 28277 NewWidth - new grid width, NewWidth>1 28280 B - function values at the new grid, 28281 array[0..NewHeight-1, 0..NewWidth-1] 28283 -- ALGLIB routine -- 28285 Copyright by Bochkanov Sergey 28286 *************************************************************************/ 28287 void spline2dresamplebilinear(/* Real */ ae_matrix* a, 28288 ae_int_t oldheight, 28290 /* Real */ ae_matrix* b, 28291 ae_int_t newheight, 28302 ae_matrix_clear(b); 28304 ae_assert(oldwidth>1&&oldheight>1, "Spline2DResampleBilinear: width/height less than 1
", _state); 28305 ae_assert(newwidth>1&&newheight>1, "Spline2DResampleBilinear: width/height less than 1
", _state); 28306 ae_matrix_set_length(b, newheight, newwidth, _state); 28307 for(i=0; i<=newheight-1; i++) 28309 for(j=0; j<=newwidth-1; j++) 28311 l = i*(oldheight-1)/(newheight-1); 28312 if( l==oldheight-1 ) 28316 u = (double)i/(double)(newheight-1)*(oldheight-1)-l; 28317 c = j*(oldwidth-1)/(newwidth-1); 28318 if( c==oldwidth-1 ) 28322 t = (double)(j*(oldwidth-1))/(double)(newwidth-1)-c; 28323 b->ptr.pp_double[i][j] = (1-t)*(1-u)*a->ptr.pp_double[l][c]+t*(1-u)*a->ptr.pp_double[l][c+1]+t*u*a->ptr.pp_double[l+1][c+1]+(1-t)*u*a->ptr.pp_double[l+1][c]; 28329 /************************************************************************* 28330 This subroutine builds bilinear vector-valued spline. 28333 X - spline abscissas, array[0..N-1] 28334 Y - spline ordinates, array[0..M-1] 28335 F - function values, array[0..M*N*D-1]: 28336 * first D elements store D values at (X[0],Y[0]) 28337 * next D elements store D values at (X[1],Y[0]) 28338 * general form - D function values at (X[i],Y[j]) are stored 28339 at F[D*(J*N+I)...D*(J*N+I)+D-1]. 28340 M,N - grid size, M>=2, N>=2 28341 D - vector dimension, D>=1 28344 C - spline interpolant 28346 -- ALGLIB PROJECT -- 28347 Copyright 16.04.2012 by Bochkanov Sergey 28348 *************************************************************************/ 28349 void spline2dbuildbilinearv(/* Real */ ae_vector* x, 28351 /* Real */ ae_vector* y, 28353 /* Real */ ae_vector* f, 28355 spline2dinterpolant* c, 28364 _spline2dinterpolant_clear(c); 28366 ae_assert(n>=2, "Spline2DBuildBilinearV: N is less then 2
", _state); 28367 ae_assert(m>=2, "Spline2DBuildBilinearV: M is less then 2
", _state); 28368 ae_assert(d>=1, "Spline2DBuildBilinearV: invalid argument D (D<1)
", _state); 28369 ae_assert(x->cnt>=n&&y->cnt>=m, "Spline2DBuildBilinearV:
length of X
or Y is too
short (Length(X/Y)<N/M)
", _state); 28370 ae_assert(isfinitevector(x, n, _state)&&isfinitevector(y, m, _state), "Spline2DBuildBilinearV: X
or Y contains NaN
or Infinite value
", _state); 28372 ae_assert(f->cnt>=k, "Spline2DBuildBilinearV:
length of F is too
short (Length(F)<N*M*D)
", _state); 28373 ae_assert(isfinitevector(f, k, _state), "Spline2DBuildBilinearV: F contains NaN
or Infinite value
", _state); 28383 ae_vector_set_length(&c->x, c->n, _state); 28384 ae_vector_set_length(&c->y, c->m, _state); 28385 ae_vector_set_length(&c->f, k, _state); 28386 for(i=0; i<=c->n-1; i++) 28388 c->x.ptr.p_double[i] = x->ptr.p_double[i]; 28390 for(i=0; i<=c->m-1; i++) 28392 c->y.ptr.p_double[i] = y->ptr.p_double[i]; 28394 for(i=0; i<=k-1; i++) 28396 c->f.ptr.p_double[i] = f->ptr.p_double[i]; 28402 for(j=0; j<=c->n-1; j++) 28405 for(i=j+1; i<=c->n-1; i++) 28407 if( ae_fp_less(c->x.ptr.p_double[i],c->x.ptr.p_double[k]) ) 28414 for(i=0; i<=c->m-1; i++) 28416 for(i0=0; i0<=c->d-1; i0++) 28418 t = c->f.ptr.p_double[c->d*(i*c->n+j)+i0]; 28419 c->f.ptr.p_double[c->d*(i*c->n+j)+i0] = c->f.ptr.p_double[c->d*(i*c->n+k)+i0]; 28420 c->f.ptr.p_double[c->d*(i*c->n+k)+i0] = t; 28423 t = c->x.ptr.p_double[j]; 28424 c->x.ptr.p_double[j] = c->x.ptr.p_double[k]; 28425 c->x.ptr.p_double[k] = t; 28428 for(i=0; i<=c->m-1; i++) 28431 for(j=i+1; j<=c->m-1; j++) 28433 if( ae_fp_less(c->y.ptr.p_double[j],c->y.ptr.p_double[k]) ) 28440 for(j=0; j<=c->n-1; j++) 28442 for(i0=0; i0<=c->d-1; i0++) 28444 t = c->f.ptr.p_double[c->d*(i*c->n+j)+i0]; 28445 c->f.ptr.p_double[c->d*(i*c->n+j)+i0] = c->f.ptr.p_double[c->d*(k*c->n+j)+i0]; 28446 c->f.ptr.p_double[c->d*(k*c->n+j)+i0] = t; 28449 t = c->y.ptr.p_double[i]; 28450 c->y.ptr.p_double[i] = c->y.ptr.p_double[k]; 28451 c->y.ptr.p_double[k] = t; 28457 /************************************************************************* 28458 This subroutine builds bicubic vector-valued spline. 28461 X - spline abscissas, array[0..N-1] 28462 Y - spline ordinates, array[0..M-1] 28463 F - function values, array[0..M*N*D-1]: 28464 * first D elements store D values at (X[0],Y[0]) 28465 * next D elements store D values at (X[1],Y[0]) 28466 * general form - D function values at (X[i],Y[j]) are stored 28467 at F[D*(J*N+I)...D*(J*N+I)+D-1]. 28468 M,N - grid size, M>=2, N>=2 28469 D - vector dimension, D>=1 28472 C - spline interpolant 28474 -- ALGLIB PROJECT -- 28475 Copyright 16.04.2012 by Bochkanov Sergey 28476 *************************************************************************/ 28477 void spline2dbuildbicubicv(/* Real */ ae_vector* x, 28479 /* Real */ ae_vector* y, 28481 /* Real */ ae_vector* f, 28483 spline2dinterpolant* c, 28486 ae_frame _frame_block; 28498 ae_frame_make(_state, &_frame_block); 28499 ae_vector_init_copy(&_f, f, _state, ae_true); 28501 _spline2dinterpolant_clear(c); 28502 ae_matrix_init(&tf, 0, 0, DT_REAL, _state, ae_true); 28503 ae_matrix_init(&dx, 0, 0, DT_REAL, _state, ae_true); 28504 ae_matrix_init(&dy, 0, 0, DT_REAL, _state, ae_true); 28505 ae_matrix_init(&dxy, 0, 0, DT_REAL, _state, ae_true); 28507 ae_assert(n>=2, "Spline2DBuildBicubicV: N is less than 2
", _state); 28508 ae_assert(m>=2, "Spline2DBuildBicubicV: M is less than 2
", _state); 28509 ae_assert(d>=1, "Spline2DBuildBicubicV: invalid argument D (D<1)
", _state); 28510 ae_assert(x->cnt>=n&&y->cnt>=m, "Spline2DBuildBicubicV:
length of X
or Y is too
short (Length(X/Y)<N/M)
", _state); 28511 ae_assert(isfinitevector(x, n, _state)&&isfinitevector(y, m, _state), "Spline2DBuildBicubicV: X
or Y contains NaN
or Infinite value
", _state); 28513 ae_assert(f->cnt>=k, "Spline2DBuildBicubicV:
length of F is too
short (Length(F)<N*M*D)
", _state); 28514 ae_assert(isfinitevector(f, k, _state), "Spline2DBuildBicubicV: F contains NaN
or Infinite value
", _state); 28517 * Fill interpolant: 28518 * F[0]...F[N*M*D-1]: 28519 * f(i,j) table. f(0,0), f(0, 1), f(0,2) and so on... 28520 * F[N*M*D]...F[2*N*M*D-1]: 28521 * df(i,j)/dx table. 28522 * F[2*N*M*D]...F[3*N*M*D-1]: 28523 * df(i,j)/dy table. 28524 * F[3*N*M*D]...F[4*N*M*D-1]: 28525 * d2f(i,j)/dxdy table. 28533 ae_vector_set_length(&c->x, c->n, _state); 28534 ae_vector_set_length(&c->y, c->m, _state); 28535 ae_vector_set_length(&c->f, k, _state); 28536 ae_matrix_set_length(&tf, c->m, c->n, _state); 28537 for(i=0; i<=c->n-1; i++) 28539 c->x.ptr.p_double[i] = x->ptr.p_double[i]; 28541 for(i=0; i<=c->m-1; i++) 28543 c->y.ptr.p_double[i] = y->ptr.p_double[i]; 28549 for(j=0; j<=c->n-1; j++) 28552 for(i=j+1; i<=c->n-1; i++) 28554 if( ae_fp_less(c->x.ptr.p_double[i],c->x.ptr.p_double[k]) ) 28561 for(i=0; i<=c->m-1; i++) 28563 for(di=0; di<=c->d-1; di++) 28565 t = f->ptr.p_double[c->d*(i*c->n+j)+di]; 28566 f->ptr.p_double[c->d*(i*c->n+j)+di] = f->ptr.p_double[c->d*(i*c->n+k)+di]; 28567 f->ptr.p_double[c->d*(i*c->n+k)+di] = t; 28570 t = c->x.ptr.p_double[j]; 28571 c->x.ptr.p_double[j] = c->x.ptr.p_double[k]; 28572 c->x.ptr.p_double[k] = t; 28575 for(i=0; i<=c->m-1; i++) 28578 for(j=i+1; j<=c->m-1; j++) 28580 if( ae_fp_less(c->y.ptr.p_double[j],c->y.ptr.p_double[k]) ) 28587 for(j=0; j<=c->n-1; j++) 28589 for(di=0; di<=c->d-1; di++) 28591 t = f->ptr.p_double[c->d*(i*c->n+j)+di]; 28592 f->ptr.p_double[c->d*(i*c->n+j)+di] = f->ptr.p_double[c->d*(k*c->n+j)+di]; 28593 f->ptr.p_double[c->d*(k*c->n+j)+di] = t; 28596 t = c->y.ptr.p_double[i]; 28597 c->y.ptr.p_double[i] = c->y.ptr.p_double[k]; 28598 c->y.ptr.p_double[k] = t; 28601 for(di=0; di<=c->d-1; di++) 28603 for(i=0; i<=c->m-1; i++) 28605 for(j=0; j<=c->n-1; j++) 28607 tf.ptr.pp_double[i][j] = f->ptr.p_double[c->d*(i*c->n+j)+di]; 28610 spline2d_bicubiccalcderivatives(&tf, &c->x, &c->y, c->m, c->n, &dx, &dy, &dxy, _state); 28611 for(i=0; i<=c->m-1; i++) 28613 for(j=0; j<=c->n-1; j++) 28615 k = c->d*(i*c->n+j)+di; 28616 c->f.ptr.p_double[k] = tf.ptr.pp_double[i][j]; 28617 c->f.ptr.p_double[c->n*c->m*c->d+k] = dx.ptr.pp_double[i][j]; 28618 c->f.ptr.p_double[2*c->n*c->m*c->d+k] = dy.ptr.pp_double[i][j]; 28619 c->f.ptr.p_double[3*c->n*c->m*c->d+k] = dxy.ptr.pp_double[i][j]; 28623 ae_frame_leave(_state); 28627 /************************************************************************* 28628 This subroutine calculates bilinear or bicubic vector-valued spline at the 28632 C - spline interpolant. 28634 F - output buffer, possibly preallocated array. In case array size 28635 is large enough to store result, it is not reallocated. Array 28636 which is too short will be reallocated 28639 F - array[D] (or larger) which stores function values 28641 -- ALGLIB PROJECT -- 28642 Copyright 16.04.2012 by Bochkanov Sergey 28643 *************************************************************************/ 28644 void spline2dcalcvbuf(spline2dinterpolant* c, 28647 /* Real */ ae_vector* f, 28682 ae_assert(c->stype==-1||c->stype==-3, "Spline2DCalcVBuf: incorrect C (incorrect parameter C.SType)
", _state); 28683 ae_assert(ae_isfinite(x, _state)&&ae_isfinite(y, _state), "Spline2DCalcVBuf: either X=NaN/Infinite
or Y=NaN/Infinite
", _state); 28684 rvectorsetlengthatleast(f, c->d, _state); 28687 * Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included) 28694 if( ae_fp_greater_eq(c->x.ptr.p_double[h],x) ) 28703 t = (x-c->x.ptr.p_double[l])/(c->x.ptr.p_double[l+1]-c->x.ptr.p_double[l]); 28704 dt = 1.0/(c->x.ptr.p_double[l+1]-c->x.ptr.p_double[l]); 28708 * Binary search in the [ y[0], ..., y[m-2] ] (y[m-1] is not included) 28715 if( ae_fp_greater_eq(c->y.ptr.p_double[h],y) ) 28724 u = (y-c->y.ptr.p_double[l])/(c->y.ptr.p_double[l+1]-c->y.ptr.p_double[l]); 28725 du = 1.0/(c->y.ptr.p_double[l+1]-c->y.ptr.p_double[l]); 28729 * Bilinear interpolation 28733 for(i=0; i<=c->d-1; i++) 28735 y1 = c->f.ptr.p_double[c->d*(c->n*iy+ix)+i]; 28736 y2 = c->f.ptr.p_double[c->d*(c->n*iy+(ix+1))+i]; 28737 y3 = c->f.ptr.p_double[c->d*(c->n*(iy+1)+(ix+1))+i]; 28738 y4 = c->f.ptr.p_double[c->d*(c->n*(iy+1)+ix)+i]; 28739 f->ptr.p_double[i] = (1-t)*(1-u)*y1+t*(1-u)*y2+t*u*y3+(1-t)*u*y4; 28745 * Bicubic interpolation 28755 t2 = ae_sqr(t, _state); 28759 u2 = ae_sqr(u, _state); 28761 sfx = c->n*c->m*c->d; 28762 sfy = 2*c->n*c->m*c->d; 28763 sfxy = 3*c->n*c->m*c->d; 28764 for(i=0; i<=c->d-1; i++) 28768 * Prepare F, dF/dX, dF/dY, d2F/dXdY 28770 f->ptr.p_double[i] = 0; 28771 s1 = c->d*(c->n*iy+ix)+i; 28772 s2 = c->d*(c->n*iy+(ix+1))+i; 28773 s3 = c->d*(c->n*(iy+1)+(ix+1))+i; 28774 s4 = c->d*(c->n*(iy+1)+ix)+i; 28779 v = c->f.ptr.p_double[s1]; 28780 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t0*u0; 28781 v = c->f.ptr.p_double[sfy+s1]/du; 28782 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t0*u1; 28783 v = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s4]-2*c->f.ptr.p_double[sfy+s1]/du-c->f.ptr.p_double[sfy+s4]/du; 28784 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t0*u2; 28785 v = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s4]+c->f.ptr.p_double[sfy+s1]/du+c->f.ptr.p_double[sfy+s4]/du; 28786 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t0*u3; 28787 v = c->f.ptr.p_double[sfx+s1]/dt; 28788 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t1*u0; 28789 v = c->f.ptr.p_double[sfxy+s1]/(dt*du); 28790 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t1*u1; 28791 v = -3*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 28792 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t1*u2; 28793 v = 2*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 28794 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t1*u3; 28795 v = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s2]-2*c->f.ptr.p_double[sfx+s1]/dt-c->f.ptr.p_double[sfx+s2]/dt; 28796 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t2*u0; 28797 v = -3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du); 28798 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t2*u1; 28799 v = 9*c->f.ptr.p_double[s1]-9*c->f.ptr.p_double[s2]+9*c->f.ptr.p_double[s3]-9*c->f.ptr.p_double[s4]+6*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s2]/dt-3*c->f.ptr.p_double[sfx+s3]/dt-6*c->f.ptr.p_double[sfx+s4]/dt+6*c->f.ptr.p_double[sfy+s1]/du-6*c->f.ptr.p_double[sfy+s2]/du-3*c->f.ptr.p_double[sfy+s3]/du+3*c->f.ptr.p_double[sfy+s4]/du+4*c->f.ptr.p_double[sfxy+s1]/(dt*du)+2*c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 28800 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t2*u2; 28801 v = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-4*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s2]/dt+2*c->f.ptr.p_double[sfx+s3]/dt+4*c->f.ptr.p_double[sfx+s4]/dt-3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du+3*c->f.ptr.p_double[sfy+s3]/du-3*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 28802 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t2*u3; 28803 v = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s2]+c->f.ptr.p_double[sfx+s1]/dt+c->f.ptr.p_double[sfx+s2]/dt; 28804 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t3*u0; 28805 v = 2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du); 28806 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t3*u1; 28807 v = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-3*c->f.ptr.p_double[sfx+s1]/dt-3*c->f.ptr.p_double[sfx+s2]/dt+3*c->f.ptr.p_double[sfx+s3]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-4*c->f.ptr.p_double[sfy+s1]/du+4*c->f.ptr.p_double[sfy+s2]/du+2*c->f.ptr.p_double[sfy+s3]/du-2*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-2*c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 28808 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t3*u2; 28809 v = 4*c->f.ptr.p_double[s1]-4*c->f.ptr.p_double[s2]+4*c->f.ptr.p_double[s3]-4*c->f.ptr.p_double[s4]+2*c->f.ptr.p_double[sfx+s1]/dt+2*c->f.ptr.p_double[sfx+s2]/dt-2*c->f.ptr.p_double[sfx+s3]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfy+s3]/du+2*c->f.ptr.p_double[sfy+s4]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 28810 f->ptr.p_double[i] = f->ptr.p_double[i]+v*t3*u3; 28817 /************************************************************************* 28818 This subroutine calculates bilinear or bicubic vector-valued spline at the 28822 C - spline interpolant. 28826 F - array[D] which stores function values. F is out-parameter and 28827 it is reallocated after call to this function. In case you 28828 want to reuse previously allocated F, you may use 28829 Spline2DCalcVBuf(), which reallocates F only when it is too 28832 -- ALGLIB PROJECT -- 28833 Copyright 16.04.2012 by Bochkanov Sergey 28834 *************************************************************************/ 28835 void spline2dcalcv(spline2dinterpolant* c, 28838 /* Real */ ae_vector* f, 28842 ae_vector_clear(f); 28844 ae_assert(c->stype==-1||c->stype==-3, "Spline2DCalcV: incorrect C (incorrect parameter C.SType)
", _state); 28845 ae_assert(ae_isfinite(x, _state)&&ae_isfinite(y, _state), "Spline2DCalcV: either X=NaN/Infinite
or Y=NaN/Infinite
", _state); 28846 ae_vector_set_length(f, c->d, _state); 28847 spline2dcalcvbuf(c, x, y, f, _state); 28851 /************************************************************************* 28852 This subroutine unpacks two-dimensional spline into the coefficients table 28855 C - spline interpolant. 28858 M, N- grid size (x-axis and y-axis) 28859 D - number of components 28860 Tbl - coefficients table, unpacked format, 28861 D - components: [0..(N-1)*(M-1)*D-1, 0..19]. 28862 For T=0..D-1 (component index), I = 0...N-2 (x index), 28863 J=0..M-2 (y index): 28864 K := T + I*D + J*D*(N-1) 28866 K-th row stores decomposition for T-th component of the 28867 vector-valued function 28881 On each grid square spline is equals to: 28882 S(x) = SUM(c[i,j]*(t^i)*(u^j), i=0..3, j=0..3) 28886 -- ALGLIB PROJECT -- 28887 Copyright 16.04.2012 by Bochkanov Sergey 28888 *************************************************************************/ 28889 void spline2dunpackv(spline2dinterpolant* c, 28893 /* Real */ ae_matrix* tbl, 28920 ae_matrix_clear(tbl); 28922 ae_assert(c->stype==-3||c->stype==-1, "Spline2DUnpackV: incorrect C (incorrect parameter C.SType)
", _state); 28926 ae_matrix_set_length(tbl, (*n-1)*(*m-1)*(*d), 20, _state); 28927 sfx = *n*(*m)*(*d); 28928 sfy = 2*(*n)*(*m)*(*d); 28929 sfxy = 3*(*n)*(*m)*(*d); 28930 for(i=0; i<=*m-2; i++) 28932 for(j=0; j<=*n-2; j++) 28934 for(k=0; k<=*d-1; k++) 28936 p = *d*(i*(*n-1)+j)+k; 28937 tbl->ptr.pp_double[p][0] = c->x.ptr.p_double[j]; 28938 tbl->ptr.pp_double[p][1] = c->x.ptr.p_double[j+1]; 28939 tbl->ptr.pp_double[p][2] = c->y.ptr.p_double[i]; 28940 tbl->ptr.pp_double[p][3] = c->y.ptr.p_double[i+1]; 28941 dt = 1/(tbl->ptr.pp_double[p][1]-tbl->ptr.pp_double[p][0]); 28942 du = 1/(tbl->ptr.pp_double[p][3]-tbl->ptr.pp_double[p][2]); 28945 * Bilinear interpolation 28949 for(k0=4; k0<=19; k0++) 28951 tbl->ptr.pp_double[p][k0] = 0; 28953 y1 = c->f.ptr.p_double[*d*(*n*i+j)+k]; 28954 y2 = c->f.ptr.p_double[*d*(*n*i+(j+1))+k]; 28955 y3 = c->f.ptr.p_double[*d*(*n*(i+1)+(j+1))+k]; 28956 y4 = c->f.ptr.p_double[*d*(*n*(i+1)+j)+k]; 28957 tbl->ptr.pp_double[p][4] = y1; 28958 tbl->ptr.pp_double[p][4+1*4+0] = y2-y1; 28959 tbl->ptr.pp_double[p][4+0*4+1] = y4-y1; 28960 tbl->ptr.pp_double[p][4+1*4+1] = y3-y2-y4+y1; 28964 * Bicubic interpolation 28968 s1 = *d*(*n*i+j)+k; 28969 s2 = *d*(*n*i+(j+1))+k; 28970 s3 = *d*(*n*(i+1)+(j+1))+k; 28971 s4 = *d*(*n*(i+1)+j)+k; 28972 tbl->ptr.pp_double[p][4+0*4+0] = c->f.ptr.p_double[s1]; 28973 tbl->ptr.pp_double[p][4+0*4+1] = c->f.ptr.p_double[sfy+s1]/du; 28974 tbl->ptr.pp_double[p][4+0*4+2] = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s4]-2*c->f.ptr.p_double[sfy+s1]/du-c->f.ptr.p_double[sfy+s4]/du; 28975 tbl->ptr.pp_double[p][4+0*4+3] = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s4]+c->f.ptr.p_double[sfy+s1]/du+c->f.ptr.p_double[sfy+s4]/du; 28976 tbl->ptr.pp_double[p][4+1*4+0] = c->f.ptr.p_double[sfx+s1]/dt; 28977 tbl->ptr.pp_double[p][4+1*4+1] = c->f.ptr.p_double[sfxy+s1]/(dt*du); 28978 tbl->ptr.pp_double[p][4+1*4+2] = -3*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 28979 tbl->ptr.pp_double[p][4+1*4+3] = 2*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 28980 tbl->ptr.pp_double[p][4+2*4+0] = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s2]-2*c->f.ptr.p_double[sfx+s1]/dt-c->f.ptr.p_double[sfx+s2]/dt; 28981 tbl->ptr.pp_double[p][4+2*4+1] = -3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du); 28982 tbl->ptr.pp_double[p][4+2*4+2] = 9*c->f.ptr.p_double[s1]-9*c->f.ptr.p_double[s2]+9*c->f.ptr.p_double[s3]-9*c->f.ptr.p_double[s4]+6*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s2]/dt-3*c->f.ptr.p_double[sfx+s3]/dt-6*c->f.ptr.p_double[sfx+s4]/dt+6*c->f.ptr.p_double[sfy+s1]/du-6*c->f.ptr.p_double[sfy+s2]/du-3*c->f.ptr.p_double[sfy+s3]/du+3*c->f.ptr.p_double[sfy+s4]/du+4*c->f.ptr.p_double[sfxy+s1]/(dt*du)+2*c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 28983 tbl->ptr.pp_double[p][4+2*4+3] = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-4*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s2]/dt+2*c->f.ptr.p_double[sfx+s3]/dt+4*c->f.ptr.p_double[sfx+s4]/dt-3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du+3*c->f.ptr.p_double[sfy+s3]/du-3*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 28984 tbl->ptr.pp_double[p][4+3*4+0] = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s2]+c->f.ptr.p_double[sfx+s1]/dt+c->f.ptr.p_double[sfx+s2]/dt; 28985 tbl->ptr.pp_double[p][4+3*4+1] = 2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du); 28986 tbl->ptr.pp_double[p][4+3*4+2] = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-3*c->f.ptr.p_double[sfx+s1]/dt-3*c->f.ptr.p_double[sfx+s2]/dt+3*c->f.ptr.p_double[sfx+s3]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-4*c->f.ptr.p_double[sfy+s1]/du+4*c->f.ptr.p_double[sfy+s2]/du+2*c->f.ptr.p_double[sfy+s3]/du-2*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-2*c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 28987 tbl->ptr.pp_double[p][4+3*4+3] = 4*c->f.ptr.p_double[s1]-4*c->f.ptr.p_double[s2]+4*c->f.ptr.p_double[s3]-4*c->f.ptr.p_double[s4]+2*c->f.ptr.p_double[sfx+s1]/dt+2*c->f.ptr.p_double[sfx+s2]/dt-2*c->f.ptr.p_double[sfx+s3]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfy+s3]/du+2*c->f.ptr.p_double[sfy+s4]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 28993 for(ci=0; ci<=3; ci++) 28995 for(cj=0; cj<=3; cj++) 28997 tbl->ptr.pp_double[p][4+ci*4+cj] = tbl->ptr.pp_double[p][4+ci*4+cj]*ae_pow(dt, ci, _state)*ae_pow(du, cj, _state); 29006 /************************************************************************* 29007 This subroutine was deprecated in ALGLIB 3.6.0 29009 We recommend you to switch to Spline2DBuildBilinearV(), which is more 29010 flexible and accepts its arguments in more convenient order. 29012 -- ALGLIB PROJECT -- 29013 Copyright 05.07.2007 by Bochkanov Sergey 29014 *************************************************************************/ 29015 void spline2dbuildbilinear(/* Real */ ae_vector* x, 29016 /* Real */ ae_vector* y, 29017 /* Real */ ae_matrix* f, 29020 spline2dinterpolant* c, 29028 _spline2dinterpolant_clear(c); 29030 ae_assert(n>=2, "Spline2DBuildBilinear: N<2
", _state); 29031 ae_assert(m>=2, "Spline2DBuildBilinear: M<2
", _state); 29032 ae_assert(x->cnt>=n&&y->cnt>=m, "Spline2DBuildBilinear:
length of X
or Y is too short (Length(X/Y)<N/M)
", _state); 29033 ae_assert(isfinitevector(x, n, _state)&&isfinitevector(y, m, _state), "Spline2DBuildBilinear: X
or Y contains NaN
or Infinite value
", _state); 29034 ae_assert(f->rows>=m&&f->cols>=n, "Spline2DBuildBilinear: size of F is too small (rows(F)<M
or cols(F)<N)
", _state); 29035 ae_assert(apservisfinitematrix(f, m, n, _state), "Spline2DBuildBilinear: F contains NaN
or Infinite value
", _state); 29045 ae_vector_set_length(&c->x, c->n, _state); 29046 ae_vector_set_length(&c->y, c->m, _state); 29047 ae_vector_set_length(&c->f, c->n*c->m, _state); 29048 for(i=0; i<=c->n-1; i++) 29050 c->x.ptr.p_double[i] = x->ptr.p_double[i]; 29052 for(i=0; i<=c->m-1; i++) 29054 c->y.ptr.p_double[i] = y->ptr.p_double[i]; 29056 for(i=0; i<=c->m-1; i++) 29058 for(j=0; j<=c->n-1; j++) 29060 c->f.ptr.p_double[i*c->n+j] = f->ptr.pp_double[i][j]; 29067 for(j=0; j<=c->n-1; j++) 29070 for(i=j+1; i<=c->n-1; i++) 29072 if( ae_fp_less(c->x.ptr.p_double[i],c->x.ptr.p_double[k]) ) 29079 for(i=0; i<=c->m-1; i++) 29081 t = c->f.ptr.p_double[i*c->n+j]; 29082 c->f.ptr.p_double[i*c->n+j] = c->f.ptr.p_double[i*c->n+k]; 29083 c->f.ptr.p_double[i*c->n+k] = t; 29085 t = c->x.ptr.p_double[j]; 29086 c->x.ptr.p_double[j] = c->x.ptr.p_double[k]; 29087 c->x.ptr.p_double[k] = t; 29090 for(i=0; i<=c->m-1; i++) 29093 for(j=i+1; j<=c->m-1; j++) 29095 if( ae_fp_less(c->y.ptr.p_double[j],c->y.ptr.p_double[k]) ) 29102 for(j=0; j<=c->n-1; j++) 29104 t = c->f.ptr.p_double[i*c->n+j]; 29105 c->f.ptr.p_double[i*c->n+j] = c->f.ptr.p_double[k*c->n+j]; 29106 c->f.ptr.p_double[k*c->n+j] = t; 29108 t = c->y.ptr.p_double[i]; 29109 c->y.ptr.p_double[i] = c->y.ptr.p_double[k]; 29110 c->y.ptr.p_double[k] = t; 29116 /************************************************************************* 29117 This subroutine was deprecated in ALGLIB 3.6.0 29119 We recommend you to switch to Spline2DBuildBicubicV(), which is more 29120 flexible and accepts its arguments in more convenient order. 29122 -- ALGLIB PROJECT -- 29123 Copyright 05.07.2007 by Bochkanov Sergey 29124 *************************************************************************/ 29125 void spline2dbuildbicubic(/* Real */ ae_vector* x, 29126 /* Real */ ae_vector* y, 29127 /* Real */ ae_matrix* f, 29130 spline2dinterpolant* c, 29133 ae_frame _frame_block; 29146 ae_frame_make(_state, &_frame_block); 29147 ae_matrix_init_copy(&_f, f, _state, ae_true); 29149 _spline2dinterpolant_clear(c); 29150 ae_matrix_init(&dx, 0, 0, DT_REAL, _state, ae_true); 29151 ae_matrix_init(&dy, 0, 0, DT_REAL, _state, ae_true); 29152 ae_matrix_init(&dxy, 0, 0, DT_REAL, _state, ae_true); 29154 ae_assert(n>=2, "Spline2DBuildBicubicSpline: N<2
", _state); 29155 ae_assert(m>=2, "Spline2DBuildBicubicSpline: M<2
", _state); 29156 ae_assert(x->cnt>=n&&y->cnt>=m, "Spline2DBuildBicubic:
length of X
or Y is too
short (Length(X/Y)<N/M)
", _state); 29157 ae_assert(isfinitevector(x, n, _state)&&isfinitevector(y, m, _state), "Spline2DBuildBicubic: X
or Y contains NaN
or Infinite value
", _state); 29158 ae_assert(f->rows>=m&&f->cols>=n, "Spline2DBuildBicubic: size of F is too small (rows(F)<M
or cols(F)<N)
", _state); 29159 ae_assert(apservisfinitematrix(f, m, n, _state), "Spline2DBuildBicubic: F contains NaN
or Infinite value
", _state); 29162 * Fill interpolant: 29164 * f(i,j) table. f(0,0), f(0, 1), f(0,2) and so on... 29165 * F[N*M]...F[2*N*M-1]: 29166 * df(i,j)/dx table. 29167 * F[2*N*M]...F[3*N*M-1]: 29168 * df(i,j)/dy table. 29169 * F[3*N*M]...F[4*N*M-1]: 29170 * d2f(i,j)/dxdy table. 29179 sfxy = 3*c->n*c->m; 29180 ae_vector_set_length(&c->x, c->n, _state); 29181 ae_vector_set_length(&c->y, c->m, _state); 29182 ae_vector_set_length(&c->f, 4*c->n*c->m, _state); 29183 for(i=0; i<=c->n-1; i++) 29185 c->x.ptr.p_double[i] = x->ptr.p_double[i]; 29187 for(i=0; i<=c->m-1; i++) 29189 c->y.ptr.p_double[i] = y->ptr.p_double[i]; 29195 for(j=0; j<=c->n-1; j++) 29198 for(i=j+1; i<=c->n-1; i++) 29200 if( ae_fp_less(c->x.ptr.p_double[i],c->x.ptr.p_double[k]) ) 29207 for(i=0; i<=c->m-1; i++) 29209 t = f->ptr.pp_double[i][j]; 29210 f->ptr.pp_double[i][j] = f->ptr.pp_double[i][k]; 29211 f->ptr.pp_double[i][k] = t; 29213 t = c->x.ptr.p_double[j]; 29214 c->x.ptr.p_double[j] = c->x.ptr.p_double[k]; 29215 c->x.ptr.p_double[k] = t; 29218 for(i=0; i<=c->m-1; i++) 29221 for(j=i+1; j<=c->m-1; j++) 29223 if( ae_fp_less(c->y.ptr.p_double[j],c->y.ptr.p_double[k]) ) 29230 for(j=0; j<=c->n-1; j++) 29232 t = f->ptr.pp_double[i][j]; 29233 f->ptr.pp_double[i][j] = f->ptr.pp_double[k][j]; 29234 f->ptr.pp_double[k][j] = t; 29236 t = c->y.ptr.p_double[i]; 29237 c->y.ptr.p_double[i] = c->y.ptr.p_double[k]; 29238 c->y.ptr.p_double[k] = t; 29241 spline2d_bicubiccalcderivatives(f, &c->x, &c->y, c->m, c->n, &dx, &dy, &dxy, _state); 29242 for(i=0; i<=c->m-1; i++) 29244 for(j=0; j<=c->n-1; j++) 29247 c->f.ptr.p_double[k] = f->ptr.pp_double[i][j]; 29248 c->f.ptr.p_double[sfx+k] = dx.ptr.pp_double[i][j]; 29249 c->f.ptr.p_double[sfy+k] = dy.ptr.pp_double[i][j]; 29250 c->f.ptr.p_double[sfxy+k] = dxy.ptr.pp_double[i][j]; 29253 ae_frame_leave(_state); 29257 /************************************************************************* 29258 This subroutine was deprecated in ALGLIB 3.6.0 29260 We recommend you to switch to Spline2DUnpackV(), which is more flexible 29261 and accepts its arguments in more convenient order. 29263 -- ALGLIB PROJECT -- 29264 Copyright 29.06.2007 by Bochkanov Sergey 29265 *************************************************************************/ 29266 void spline2dunpack(spline2dinterpolant* c, 29269 /* Real */ ae_matrix* tbl, 29294 ae_matrix_clear(tbl); 29296 ae_assert(c->stype==-3||c->stype==-1, "Spline2DUnpack: incorrect C (incorrect parameter C.SType)
", _state); 29305 ae_matrix_set_length(tbl, (*n-1)*(*m-1), 20, _state); 29308 sfxy = 3*(*n)*(*m); 29313 for(i=0; i<=*m-2; i++) 29315 for(j=0; j<=*n-2; j++) 29318 tbl->ptr.pp_double[p][0] = c->x.ptr.p_double[j]; 29319 tbl->ptr.pp_double[p][1] = c->x.ptr.p_double[j+1]; 29320 tbl->ptr.pp_double[p][2] = c->y.ptr.p_double[i]; 29321 tbl->ptr.pp_double[p][3] = c->y.ptr.p_double[i+1]; 29322 dt = 1/(tbl->ptr.pp_double[p][1]-tbl->ptr.pp_double[p][0]); 29323 du = 1/(tbl->ptr.pp_double[p][3]-tbl->ptr.pp_double[p][2]); 29326 * Bilinear interpolation 29330 for(k=4; k<=19; k++) 29332 tbl->ptr.pp_double[p][k] = 0; 29334 y1 = c->f.ptr.p_double[*n*i+j]; 29335 y2 = c->f.ptr.p_double[*n*i+(j+1)]; 29336 y3 = c->f.ptr.p_double[*n*(i+1)+(j+1)]; 29337 y4 = c->f.ptr.p_double[*n*(i+1)+j]; 29338 tbl->ptr.pp_double[p][4] = y1; 29339 tbl->ptr.pp_double[p][4+1*4+0] = y2-y1; 29340 tbl->ptr.pp_double[p][4+0*4+1] = y4-y1; 29341 tbl->ptr.pp_double[p][4+1*4+1] = y3-y2-y4+y1; 29345 * Bicubic interpolation 29351 s3 = *n*(i+1)+(j+1); 29353 tbl->ptr.pp_double[p][4+0*4+0] = c->f.ptr.p_double[s1]; 29354 tbl->ptr.pp_double[p][4+0*4+1] = c->f.ptr.p_double[sfy+s1]/du; 29355 tbl->ptr.pp_double[p][4+0*4+2] = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s4]-2*c->f.ptr.p_double[sfy+s1]/du-c->f.ptr.p_double[sfy+s4]/du; 29356 tbl->ptr.pp_double[p][4+0*4+3] = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s4]+c->f.ptr.p_double[sfy+s1]/du+c->f.ptr.p_double[sfy+s4]/du; 29357 tbl->ptr.pp_double[p][4+1*4+0] = c->f.ptr.p_double[sfx+s1]/dt; 29358 tbl->ptr.pp_double[p][4+1*4+1] = c->f.ptr.p_double[sfxy+s1]/(dt*du); 29359 tbl->ptr.pp_double[p][4+1*4+2] = -3*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 29360 tbl->ptr.pp_double[p][4+1*4+3] = 2*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 29361 tbl->ptr.pp_double[p][4+2*4+0] = -3*c->f.ptr.p_double[s1]+3*c->f.ptr.p_double[s2]-2*c->f.ptr.p_double[sfx+s1]/dt-c->f.ptr.p_double[sfx+s2]/dt; 29362 tbl->ptr.pp_double[p][4+2*4+1] = -3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du); 29363 tbl->ptr.pp_double[p][4+2*4+2] = 9*c->f.ptr.p_double[s1]-9*c->f.ptr.p_double[s2]+9*c->f.ptr.p_double[s3]-9*c->f.ptr.p_double[s4]+6*c->f.ptr.p_double[sfx+s1]/dt+3*c->f.ptr.p_double[sfx+s2]/dt-3*c->f.ptr.p_double[sfx+s3]/dt-6*c->f.ptr.p_double[sfx+s4]/dt+6*c->f.ptr.p_double[sfy+s1]/du-6*c->f.ptr.p_double[sfy+s2]/du-3*c->f.ptr.p_double[sfy+s3]/du+3*c->f.ptr.p_double[sfy+s4]/du+4*c->f.ptr.p_double[sfxy+s1]/(dt*du)+2*c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 29364 tbl->ptr.pp_double[p][4+2*4+3] = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-4*c->f.ptr.p_double[sfx+s1]/dt-2*c->f.ptr.p_double[sfx+s2]/dt+2*c->f.ptr.p_double[sfx+s3]/dt+4*c->f.ptr.p_double[sfx+s4]/dt-3*c->f.ptr.p_double[sfy+s1]/du+3*c->f.ptr.p_double[sfy+s2]/du+3*c->f.ptr.p_double[sfy+s3]/du-3*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-2*c->f.ptr.p_double[sfxy+s4]/(dt*du); 29365 tbl->ptr.pp_double[p][4+3*4+0] = 2*c->f.ptr.p_double[s1]-2*c->f.ptr.p_double[s2]+c->f.ptr.p_double[sfx+s1]/dt+c->f.ptr.p_double[sfx+s2]/dt; 29366 tbl->ptr.pp_double[p][4+3*4+1] = 2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du); 29367 tbl->ptr.pp_double[p][4+3*4+2] = -6*c->f.ptr.p_double[s1]+6*c->f.ptr.p_double[s2]-6*c->f.ptr.p_double[s3]+6*c->f.ptr.p_double[s4]-3*c->f.ptr.p_double[sfx+s1]/dt-3*c->f.ptr.p_double[sfx+s2]/dt+3*c->f.ptr.p_double[sfx+s3]/dt+3*c->f.ptr.p_double[sfx+s4]/dt-4*c->f.ptr.p_double[sfy+s1]/du+4*c->f.ptr.p_double[sfy+s2]/du+2*c->f.ptr.p_double[sfy+s3]/du-2*c->f.ptr.p_double[sfy+s4]/du-2*c->f.ptr.p_double[sfxy+s1]/(dt*du)-2*c->f.ptr.p_double[sfxy+s2]/(dt*du)-c->f.ptr.p_double[sfxy+s3]/(dt*du)-c->f.ptr.p_double[sfxy+s4]/(dt*du); 29368 tbl->ptr.pp_double[p][4+3*4+3] = 4*c->f.ptr.p_double[s1]-4*c->f.ptr.p_double[s2]+4*c->f.ptr.p_double[s3]-4*c->f.ptr.p_double[s4]+2*c->f.ptr.p_double[sfx+s1]/dt+2*c->f.ptr.p_double[sfx+s2]/dt-2*c->f.ptr.p_double[sfx+s3]/dt-2*c->f.ptr.p_double[sfx+s4]/dt+2*c->f.ptr.p_double[sfy+s1]/du-2*c->f.ptr.p_double[sfy+s2]/du-2*c->f.ptr.p_double[sfy+s3]/du+2*c->f.ptr.p_double[sfy+s4]/du+c->f.ptr.p_double[sfxy+s1]/(dt*du)+c->f.ptr.p_double[sfxy+s2]/(dt*du)+c->f.ptr.p_double[sfxy+s3]/(dt*du)+c->f.ptr.p_double[sfxy+s4]/(dt*du); 29374 for(ci=0; ci<=3; ci++) 29376 for(cj=0; cj<=3; cj++) 29378 tbl->ptr.pp_double[p][4+ci*4+cj] = tbl->ptr.pp_double[p][4+ci*4+cj]*ae_pow(dt, ci, _state)*ae_pow(du, cj, _state); 29386 /************************************************************************* 29387 Internal subroutine. 29388 Calculation of the first derivatives and the cross-derivative. 29389 *************************************************************************/ 29390 static void spline2d_bicubiccalcderivatives(/* Real */ ae_matrix* a, 29391 /* Real */ ae_vector* x, 29392 /* Real */ ae_vector* y, 29395 /* Real */ ae_matrix* dx, 29396 /* Real */ ae_matrix* dy, 29397 /* Real */ ae_matrix* dxy, 29400 ae_frame _frame_block; 29408 spline1dinterpolant c; 29410 ae_frame_make(_state, &_frame_block); 29411 ae_matrix_clear(dx); 29412 ae_matrix_clear(dy); 29413 ae_matrix_clear(dxy); 29414 ae_vector_init(&xt, 0, DT_REAL, _state, ae_true); 29415 ae_vector_init(&ft, 0, DT_REAL, _state, ae_true); 29416 _spline1dinterpolant_init(&c, _state, ae_true); 29418 ae_matrix_set_length(dx, m, n, _state); 29419 ae_matrix_set_length(dy, m, n, _state); 29420 ae_matrix_set_length(dxy, m, n, _state); 29425 ae_vector_set_length(&xt, n, _state); 29426 ae_vector_set_length(&ft, n, _state); 29427 for(i=0; i<=m-1; i++) 29429 for(j=0; j<=n-1; j++) 29431 xt.ptr.p_double[j] = x->ptr.p_double[j]; 29432 ft.ptr.p_double[j] = a->ptr.pp_double[i][j]; 29434 spline1dbuildcubic(&xt, &ft, n, 0, 0.0, 0, 0.0, &c, _state); 29435 for(j=0; j<=n-1; j++) 29437 spline1ddiff(&c, x->ptr.p_double[j], &s, &ds, &d2s, _state); 29438 dx->ptr.pp_double[i][j] = ds; 29445 ae_vector_set_length(&xt, m, _state); 29446 ae_vector_set_length(&ft, m, _state); 29447 for(j=0; j<=n-1; j++) 29449 for(i=0; i<=m-1; i++) 29451 xt.ptr.p_double[i] = y->ptr.p_double[i]; 29452 ft.ptr.p_double[i] = a->ptr.pp_double[i][j]; 29454 spline1dbuildcubic(&xt, &ft, m, 0, 0.0, 0, 0.0, &c, _state); 29455 for(i=0; i<=m-1; i++) 29457 spline1ddiff(&c, y->ptr.p_double[i], &s, &ds, &d2s, _state); 29458 dy->ptr.pp_double[i][j] = ds; 29465 ae_vector_set_length(&xt, n, _state); 29466 ae_vector_set_length(&ft, n, _state); 29467 for(i=0; i<=m-1; i++) 29469 for(j=0; j<=n-1; j++) 29471 xt.ptr.p_double[j] = x->ptr.p_double[j]; 29472 ft.ptr.p_double[j] = dy->ptr.pp_double[i][j]; 29474 spline1dbuildcubic(&xt, &ft, n, 0, 0.0, 0, 0.0, &c, _state); 29475 for(j=0; j<=n-1; j++) 29477 spline1ddiff(&c, x->ptr.p_double[j], &s, &ds, &d2s, _state); 29478 dxy->ptr.pp_double[i][j] = ds; 29481 ae_frame_leave(_state); 29485 ae_bool _spline2dinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic) 29487 spline2dinterpolant *p = (spline2dinterpolant*)_p; 29488 ae_touch_ptr((void*)p); 29489 if( !ae_vector_init(&p->x, 0, DT_REAL, _state, make_automatic) ) 29491 if( !ae_vector_init(&p->y, 0, DT_REAL, _state, make_automatic) ) 29493 if( !ae_vector_init(&p->f, 0, DT_REAL, _state, make_automatic) ) 29499 ae_bool _spline2dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 29501 spline2dinterpolant *dst = (spline2dinterpolant*)_dst; 29502 spline2dinterpolant *src = (spline2dinterpolant*)_src; 29504 dst->stype = src->stype; 29508 if( !ae_vector_init_copy(&dst->x, &src->x, _state, make_automatic) ) 29510 if( !ae_vector_init_copy(&dst->y, &src->y, _state, make_automatic) ) 29512 if( !ae_vector_init_copy(&dst->f, &src->f, _state, make_automatic) ) 29518 void _spline2dinterpolant_clear(void* _p) 29520 spline2dinterpolant *p = (spline2dinterpolant*)_p; 29521 ae_touch_ptr((void*)p); 29522 ae_vector_clear(&p->x); 29523 ae_vector_clear(&p->y); 29524 ae_vector_clear(&p->f); 29528 void _spline2dinterpolant_destroy(void* _p) 29530 spline2dinterpolant *p = (spline2dinterpolant*)_p; 29531 ae_touch_ptr((void*)p); 29532 ae_vector_destroy(&p->x); 29533 ae_vector_destroy(&p->y); 29534 ae_vector_destroy(&p->f); 29540 /************************************************************************* 29541 This subroutine calculates the value of the trilinear or tricubic spline at 29542 the given point (X,Y,Z). 29545 C - coefficients table. 29546 Built by BuildBilinearSpline or BuildBicubicSpline. 29553 -- ALGLIB PROJECT -- 29554 Copyright 26.04.2012 by Bochkanov Sergey 29555 *************************************************************************/ 29556 double spline3dcalc(spline3dinterpolant* c, 29569 ae_assert(c->stype==-1||c->stype==-3, "Spline3DCalc: incorrect C (incorrect parameter C.SType)
", _state); 29570 ae_assert((ae_isfinite(x, _state)&&ae_isfinite(y, _state))&&ae_isfinite(z, _state), "Spline3DCalc: X=NaN/Infinite, Y=NaN/Infinite
or Z=NaN/Infinite
", _state); 29576 spline3d_spline3ddiff(c, x, y, z, &v, &vx, &vy, &vxy, _state); 29582 /************************************************************************* 29583 This subroutine performs linear transformation of the spline argument. 29586 C - spline interpolant 29587 AX, BX - transformation coefficients: x = A*u + B 29588 AY, BY - transformation coefficients: y = A*v + B 29589 AZ, BZ - transformation coefficients: z = A*w + B 29592 C - transformed spline 29594 -- ALGLIB PROJECT -- 29595 Copyright 26.04.2012 by Bochkanov Sergey 29596 *************************************************************************/ 29597 void spline3dlintransxyz(spline3dinterpolant* c, 29606 ae_frame _frame_block; 29617 ae_frame_make(_state, &_frame_block); 29618 ae_vector_init(&x, 0, DT_REAL, _state, ae_true); 29619 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 29620 ae_vector_init(&z, 0, DT_REAL, _state, ae_true); 29621 ae_vector_init(&f, 0, DT_REAL, _state, ae_true); 29622 ae_vector_init(&v, 0, DT_REAL, _state, ae_true); 29624 ae_assert(c->stype==-3||c->stype==-1, "Spline3DLinTransXYZ: incorrect C (incorrect parameter C.SType)
", _state); 29625 ae_vector_set_length(&x, c->n, _state); 29626 ae_vector_set_length(&y, c->m, _state); 29627 ae_vector_set_length(&z, c->l, _state); 29628 ae_vector_set_length(&f, c->m*c->n*c->l*c->d, _state); 29629 for(j=0; j<=c->n-1; j++) 29631 x.ptr.p_double[j] = c->x.ptr.p_double[j]; 29633 for(i=0; i<=c->m-1; i++) 29635 y.ptr.p_double[i] = c->y.ptr.p_double[i]; 29637 for(i=0; i<=c->l-1; i++) 29639 z.ptr.p_double[i] = c->z.ptr.p_double[i]; 29643 * Handle different combinations of zero/nonzero AX/AY/AZ 29645 if( (ae_fp_neq(ax,0)&&ae_fp_neq(ay,0))&&ae_fp_neq(az,0) ) 29647 ae_v_move(&f.ptr.p_double[0], 1, &c->f.ptr.p_double[0], 1, ae_v_len(0,c->m*c->n*c->l*c->d-1)); 29649 if( (ae_fp_eq(ax,0)&&ae_fp_neq(ay,0))&&ae_fp_neq(az,0) ) 29651 for(i=0; i<=c->m-1; i++) 29653 for(j=0; j<=c->l-1; j++) 29655 spline3dcalcv(c, bx, y.ptr.p_double[i], z.ptr.p_double[j], &v, _state); 29656 for(k=0; k<=c->n-1; k++) 29658 for(di=0; di<=c->d-1; di++) 29660 f.ptr.p_double[c->d*(c->n*(c->m*j+i)+k)+di] = v.ptr.p_double[di]; 29668 if( (ae_fp_neq(ax,0)&&ae_fp_eq(ay,0))&&ae_fp_neq(az,0) ) 29670 for(i=0; i<=c->n-1; i++) 29672 for(j=0; j<=c->l-1; j++) 29674 spline3dcalcv(c, x.ptr.p_double[i], by, z.ptr.p_double[j], &v, _state); 29675 for(k=0; k<=c->m-1; k++) 29677 for(di=0; di<=c->d-1; di++) 29679 f.ptr.p_double[c->d*(c->n*(c->m*j+k)+i)+di] = v.ptr.p_double[di]; 29687 if( (ae_fp_neq(ax,0)&&ae_fp_neq(ay,0))&&ae_fp_eq(az,0) ) 29689 for(i=0; i<=c->n-1; i++) 29691 for(j=0; j<=c->m-1; j++) 29693 spline3dcalcv(c, x.ptr.p_double[i], y.ptr.p_double[j], bz, &v, _state); 29694 for(k=0; k<=c->l-1; k++) 29696 for(di=0; di<=c->d-1; di++) 29698 f.ptr.p_double[c->d*(c->n*(c->m*k+j)+i)+di] = v.ptr.p_double[di]; 29706 if( (ae_fp_eq(ax,0)&&ae_fp_eq(ay,0))&&ae_fp_neq(az,0) ) 29708 for(i=0; i<=c->l-1; i++) 29710 spline3dcalcv(c, bx, by, z.ptr.p_double[i], &v, _state); 29711 for(k=0; k<=c->m-1; k++) 29713 for(j=0; j<=c->n-1; j++) 29715 for(di=0; di<=c->d-1; di++) 29717 f.ptr.p_double[c->d*(c->n*(c->m*i+k)+j)+di] = v.ptr.p_double[di]; 29727 if( (ae_fp_eq(ax,0)&&ae_fp_neq(ay,0))&&ae_fp_eq(az,0) ) 29729 for(i=0; i<=c->m-1; i++) 29731 spline3dcalcv(c, bx, y.ptr.p_double[i], bz, &v, _state); 29732 for(k=0; k<=c->l-1; k++) 29734 for(j=0; j<=c->n-1; j++) 29736 for(di=0; di<=c->d-1; di++) 29738 f.ptr.p_double[c->d*(c->n*(c->m*k+i)+j)+di] = v.ptr.p_double[di]; 29748 if( (ae_fp_neq(ax,0)&&ae_fp_eq(ay,0))&&ae_fp_eq(az,0) ) 29750 for(i=0; i<=c->n-1; i++) 29752 spline3dcalcv(c, x.ptr.p_double[i], by, bz, &v, _state); 29753 for(k=0; k<=c->l-1; k++) 29755 for(j=0; j<=c->m-1; j++) 29757 for(di=0; di<=c->d-1; di++) 29759 f.ptr.p_double[c->d*(c->n*(c->m*k+j)+i)+di] = v.ptr.p_double[di]; 29769 if( (ae_fp_eq(ax,0)&&ae_fp_eq(ay,0))&&ae_fp_eq(az,0) ) 29771 spline3dcalcv(c, bx, by, bz, &v, _state); 29772 for(k=0; k<=c->l-1; k++) 29774 for(j=0; j<=c->m-1; j++) 29776 for(i=0; i<=c->n-1; i++) 29778 for(di=0; di<=c->d-1; di++) 29780 f.ptr.p_double[c->d*(c->n*(c->m*k+j)+i)+di] = v.ptr.p_double[di]; 29794 * General case: AX<>0, AY<>0, AZ<>0 29795 * Unpack, scale and pack again. 29797 for(i=0; i<=c->n-1; i++) 29799 x.ptr.p_double[i] = (x.ptr.p_double[i]-bx)/ax; 29801 for(i=0; i<=c->m-1; i++) 29803 y.ptr.p_double[i] = (y.ptr.p_double[i]-by)/ay; 29805 for(i=0; i<=c->l-1; i++) 29807 z.ptr.p_double[i] = (z.ptr.p_double[i]-bz)/az; 29811 spline3dbuildtrilinearv(&x, c->n, &y, c->m, &z, c->l, &f, c->d, c, _state); 29813 ae_frame_leave(_state); 29817 /************************************************************************* 29818 This subroutine performs linear transformation of the spline. 29821 C - spline interpolant. 29822 A, B- transformation coefficients: S2(x,y) = A*S(x,y,z) + B 29825 C - transformed spline 29827 -- ALGLIB PROJECT -- 29828 Copyright 26.04.2012 by Bochkanov Sergey 29829 *************************************************************************/ 29830 void spline3dlintransf(spline3dinterpolant* c, 29835 ae_frame _frame_block; 29843 ae_frame_make(_state, &_frame_block); 29844 ae_vector_init(&x, 0, DT_REAL, _state, ae_true); 29845 ae_vector_init(&y, 0, DT_REAL, _state, ae_true); 29846 ae_vector_init(&z, 0, DT_REAL, _state, ae_true); 29847 ae_vector_init(&f, 0, DT_REAL, _state, ae_true); 29849 ae_assert(c->stype==-3||c->stype==-1, "Spline3DLinTransF: incorrect C (incorrect parameter C.SType)
", _state); 29850 ae_vector_set_length(&x, c->n, _state); 29851 ae_vector_set_length(&y, c->m, _state); 29852 ae_vector_set_length(&z, c->l, _state); 29853 ae_vector_set_length(&f, c->m*c->n*c->l*c->d, _state); 29854 for(j=0; j<=c->n-1; j++) 29856 x.ptr.p_double[j] = c->x.ptr.p_double[j]; 29858 for(i=0; i<=c->m-1; i++) 29860 y.ptr.p_double[i] = c->y.ptr.p_double[i]; 29862 for(i=0; i<=c->l-1; i++) 29864 z.ptr.p_double[i] = c->z.ptr.p_double[i]; 29866 for(i=0; i<=c->m*c->n*c->l*c->d-1; i++) 29868 f.ptr.p_double[i] = a*c->f.ptr.p_double[i]+b; 29872 spline3dbuildtrilinearv(&x, c->n, &y, c->m, &z, c->l, &f, c->d, c, _state); 29874 ae_frame_leave(_state); 29878 /************************************************************************* 29879 This subroutine makes the copy of the spline model. 29882 C - spline interpolant 29887 -- ALGLIB PROJECT -- 29888 Copyright 26.04.2012 by Bochkanov Sergey 29889 *************************************************************************/ 29890 void spline3dcopy(spline3dinterpolant* c, 29891 spline3dinterpolant* cc, 29896 _spline3dinterpolant_clear(cc); 29898 ae_assert(c->k==1||c->k==3, "Spline3DCopy: incorrect C (incorrect parameter C.K)
", _state); 29904 tblsize = c->n*c->m*c->l*c->d; 29905 cc->stype = c->stype; 29906 ae_vector_set_length(&cc->x, cc->n, _state); 29907 ae_vector_set_length(&cc->y, cc->m, _state); 29908 ae_vector_set_length(&cc->z, cc->l, _state); 29909 ae_vector_set_length(&cc->f, tblsize, _state); 29910 ae_v_move(&cc->x.ptr.p_double[0], 1, &c->x.ptr.p_double[0], 1, ae_v_len(0,cc->n-1)); 29911 ae_v_move(&cc->y.ptr.p_double[0], 1, &c->y.ptr.p_double[0], 1, ae_v_len(0,cc->m-1)); 29912 ae_v_move(&cc->z.ptr.p_double[0], 1, &c->z.ptr.p_double[0], 1, ae_v_len(0,cc->l-1)); 29913 ae_v_move(&cc->f.ptr.p_double[0], 1, &c->f.ptr.p_double[0], 1, ae_v_len(0,tblsize-1)); 29917 /************************************************************************* 29918 Trilinear spline resampling 29921 A - array[0..OldXCount*OldYCount*OldZCount-1], function 29922 values at the old grid, : 29926 A[..] x=oldxcount-1,y=0,z=0 29930 OldZCount - old Z-count, OldZCount>1 29931 OldYCount - old Y-count, OldYCount>1 29932 OldXCount - old X-count, OldXCount>1 29933 NewZCount - new Z-count, NewZCount>1 29934 NewYCount - new Y-count, NewYCount>1 29935 NewXCount - new X-count, NewXCount>1 29938 B - array[0..NewXCount*NewYCount*NewZCount-1], function 29939 values at the new grid: 29943 B[..] x=newxcount-1,y=0,z=0 29948 -- ALGLIB routine -- 29950 Copyright by Bochkanov Sergey 29951 *************************************************************************/ 29952 void spline3dresampletrilinear(/* Real */ ae_vector* a, 29953 ae_int_t oldzcount, 29954 ae_int_t oldycount, 29955 ae_int_t oldxcount, 29956 ae_int_t newzcount, 29957 ae_int_t newycount, 29958 ae_int_t newxcount, 29959 /* Real */ ae_vector* b, 29976 ae_vector_clear(b); 29978 ae_assert((oldycount>1&&oldzcount>1)&&oldxcount>1, "Spline3DResampleTrilinear:
length/width/height less than 1
", _state); 29979 ae_assert((newycount>1&&newzcount>1)&&newxcount>1, "Spline3DResampleTrilinear:
length/width/height less than 1
", _state); 29980 ae_assert(a->cnt>=oldycount*oldzcount*oldxcount, "Spline3DResampleTrilinear:
length/width/height less than 1
", _state); 29981 ae_vector_set_length(b, newxcount*newycount*newzcount, _state); 29982 for(i=0; i<=newxcount-1; i++) 29984 for(j=0; j<=newycount-1; j++) 29986 for(k=0; k<=newzcount-1; k++) 29988 ix = i*(oldxcount-1)/(newxcount-1); 29989 if( ix==oldxcount-1 ) 29993 xd = (double)(i*(oldxcount-1))/(double)(newxcount-1)-ix; 29994 iy = j*(oldycount-1)/(newycount-1); 29995 if( iy==oldycount-1 ) 29999 yd = (double)(j*(oldycount-1))/(double)(newycount-1)-iy; 30000 iz = k*(oldzcount-1)/(newzcount-1); 30001 if( iz==oldzcount-1 ) 30005 zd = (double)(k*(oldzcount-1))/(double)(newzcount-1)-iz; 30006 c0 = a->ptr.p_double[oldxcount*(oldycount*iz+iy)+ix]*(1-xd)+a->ptr.p_double[oldxcount*(oldycount*iz+iy)+(ix+1)]*xd; 30007 c1 = a->ptr.p_double[oldxcount*(oldycount*iz+(iy+1))+ix]*(1-xd)+a->ptr.p_double[oldxcount*(oldycount*iz+(iy+1))+(ix+1)]*xd; 30008 c2 = a->ptr.p_double[oldxcount*(oldycount*(iz+1)+iy)+ix]*(1-xd)+a->ptr.p_double[oldxcount*(oldycount*(iz+1)+iy)+(ix+1)]*xd; 30009 c3 = a->ptr.p_double[oldxcount*(oldycount*(iz+1)+(iy+1))+ix]*(1-xd)+a->ptr.p_double[oldxcount*(oldycount*(iz+1)+(iy+1))+(ix+1)]*xd; 30010 c0 = c0*(1-yd)+c1*yd; 30011 c1 = c2*(1-yd)+c3*yd; 30012 b->ptr.p_double[newxcount*(newycount*k+j)+i] = c0*(1-zd)+c1*zd; 30019 /************************************************************************* 30020 This subroutine builds trilinear vector-valued spline. 30023 X - spline abscissas, array[0..N-1] 30024 Y - spline ordinates, array[0..M-1] 30025 Z - spline applicates, array[0..L-1] 30026 F - function values, array[0..M*N*L*D-1]: 30027 * first D elements store D values at (X[0],Y[0],Z[0]) 30028 * next D elements store D values at (X[1],Y[0],Z[0]) 30029 * next D elements store D values at (X[2],Y[0],Z[0]) 30031 * next D elements store D values at (X[0],Y[1],Z[0]) 30032 * next D elements store D values at (X[1],Y[1],Z[0]) 30033 * next D elements store D values at (X[2],Y[1],Z[0]) 30035 * next D elements store D values at (X[0],Y[0],Z[1]) 30036 * next D elements store D values at (X[1],Y[0],Z[1]) 30037 * next D elements store D values at (X[2],Y[0],Z[1]) 30039 * general form - D function values at (X[i],Y[j]) are stored 30040 at F[D*(N*(M*K+J)+I)...D*(N*(M*K+J)+I)+D-1]. 30042 L - grid size, M>=2, N>=2, L>=2 30043 D - vector dimension, D>=1 30046 C - spline interpolant 30048 -- ALGLIB PROJECT -- 30049 Copyright 26.04.2012 by Bochkanov Sergey 30050 *************************************************************************/ 30051 void spline3dbuildtrilinearv(/* Real */ ae_vector* x, 30053 /* Real */ ae_vector* y, 30055 /* Real */ ae_vector* z, 30057 /* Real */ ae_vector* f, 30059 spline3dinterpolant* c, 30070 _spline3dinterpolant_clear(c); 30072 ae_assert(m>=2, "Spline3DBuildTrilinearV: M<2
", _state); 30073 ae_assert(n>=2, "Spline3DBuildTrilinearV: N<2
", _state); 30074 ae_assert(l>=2, "Spline3DBuildTrilinearV: L<2
", _state); 30075 ae_assert(d>=1, "Spline3DBuildTrilinearV: D<1
", _state); 30076 ae_assert((x->cnt>=n&&y->cnt>=m)&&z->cnt>=l, "Spline3DBuildTrilinearV:
length of X, Y
or Z is too short (Length(X/Y/Z)<N/M/L)
", _state); 30077 ae_assert((isfinitevector(x, n, _state)&&isfinitevector(y, m, _state))&&isfinitevector(z, l, _state), "Spline3DBuildTrilinearV: X, Y
or Z contains NaN
or Infinite value
", _state); 30079 ae_assert(f->cnt>=tblsize, "Spline3DBuildTrilinearV:
length of F is too
short (Length(F)<N*M*L*D)
", _state); 30080 ae_assert(isfinitevector(f, tblsize, _state), "Spline3DBuildTrilinearV: F contains NaN
or Infinite value
", _state); 30091 ae_vector_set_length(&c->x, c->n, _state); 30092 ae_vector_set_length(&c->y, c->m, _state); 30093 ae_vector_set_length(&c->z, c->l, _state); 30094 ae_vector_set_length(&c->f, tblsize, _state); 30095 for(i=0; i<=c->n-1; i++) 30097 c->x.ptr.p_double[i] = x->ptr.p_double[i]; 30099 for(i=0; i<=c->m-1; i++) 30101 c->y.ptr.p_double[i] = y->ptr.p_double[i]; 30103 for(i=0; i<=c->l-1; i++) 30105 c->z.ptr.p_double[i] = z->ptr.p_double[i]; 30107 for(i=0; i<=tblsize-1; i++) 30109 c->f.ptr.p_double[i] = f->ptr.p_double[i]; 30118 for(j=0; j<=c->n-1; j++) 30121 for(i=j+1; i<=c->n-1; i++) 30123 if( ae_fp_less(c->x.ptr.p_double[i],c->x.ptr.p_double[k]) ) 30130 for(i=0; i<=c->m-1; i++) 30132 for(j0=0; j0<=c->l-1; j0++) 30134 for(i0=0; i0<=c->d-1; i0++) 30136 t = c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+j)+i0]; 30137 c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+j)+i0] = c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+k)+i0]; 30138 c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+k)+i0] = t; 30142 t = c->x.ptr.p_double[j]; 30143 c->x.ptr.p_double[j] = c->x.ptr.p_double[k]; 30144 c->x.ptr.p_double[k] = t; 30147 for(i=0; i<=c->m-1; i++) 30150 for(j=i+1; j<=c->m-1; j++) 30152 if( ae_fp_less(c->y.ptr.p_double[j],c->y.ptr.p_double[k]) ) 30159 for(j=0; j<=c->n-1; j++) 30161 for(j0=0; j0<=c->l-1; j0++) 30163 for(i0=0; i0<=c->d-1; i0++) 30165 t = c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+j)+i0]; 30166 c->f.ptr.p_double[c->d*(c->n*(c->m*j0+i)+j)+i0] = c->f.ptr.p_double[c->d*(c->n*(c->m*j0+k)+j)+i0]; 30167 c->f.ptr.p_double[c->d*(c->n*(c->m*j0+k)+j)+i0] = t; 30171 t = c->y.ptr.p_double[i]; 30172 c->y.ptr.p_double[i] = c->y.ptr.p_double[k]; 30173 c->y.ptr.p_double[k] = t; 30176 for(k=0; k<=c->l-1; k++) 30179 for(j=i+1; j<=c->l-1; j++) 30181 if( ae_fp_less(c->z.ptr.p_double[j],c->z.ptr.p_double[i]) ) 30188 for(j=0; j<=c->m-1; j++) 30190 for(j0=0; j0<=c->n-1; j0++) 30192 for(i0=0; i0<=c->d-1; i0++) 30194 t = c->f.ptr.p_double[c->d*(c->n*(c->m*k+j)+j0)+i0]; 30195 c->f.ptr.p_double[c->d*(c->n*(c->m*k+j)+j0)+i0] = c->f.ptr.p_double[c->d*(c->n*(c->m*i+j)+j0)+i0]; 30196 c->f.ptr.p_double[c->d*(c->n*(c->m*i+j)+j0)+i0] = t; 30200 t = c->z.ptr.p_double[k]; 30201 c->z.ptr.p_double[k] = c->z.ptr.p_double[i]; 30202 c->z.ptr.p_double[i] = t; 30208 /************************************************************************* 30209 This subroutine calculates bilinear or bicubic vector-valued spline at the 30210 given point (X,Y,Z). 30213 C - spline interpolant. 30216 F - output buffer, possibly preallocated array. In case array size 30217 is large enough to store result, it is not reallocated. Array 30218 which is too short will be reallocated 30221 F - array[D] (or larger) which stores function values 30223 -- ALGLIB PROJECT -- 30224 Copyright 26.04.2012 by Bochkanov Sergey 30225 *************************************************************************/ 30226 void spline3dcalcvbuf(spline3dinterpolant* c, 30230 /* Real */ ae_vector* f, 30249 ae_assert(c->stype==-1||c->stype==-3, "Spline3DCalcVBuf: incorrect C (incorrect parameter C.SType)
", _state); 30250 ae_assert((ae_isfinite(x, _state)&&ae_isfinite(y, _state))&&ae_isfinite(z, _state), "Spline3DCalcVBuf: X, Y
or Z contains NaN/Infinite
", _state); 30251 rvectorsetlengthatleast(f, c->d, _state); 30254 * Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included) 30261 if( ae_fp_greater_eq(c->x.ptr.p_double[h],x) ) 30273 * Binary search in the [ y[0], ..., y[n-2] ] (y[n-1] is not included) 30280 if( ae_fp_greater_eq(c->y.ptr.p_double[h],y) ) 30292 * Binary search in the [ z[0], ..., z[n-2] ] (z[n-1] is not included) 30299 if( ae_fp_greater_eq(c->z.ptr.p_double[h],z) ) 30309 xd = (x-c->x.ptr.p_double[ix])/(c->x.ptr.p_double[ix+1]-c->x.ptr.p_double[ix]); 30310 yd = (y-c->y.ptr.p_double[iy])/(c->y.ptr.p_double[iy+1]-c->y.ptr.p_double[iy]); 30311 zd = (z-c->z.ptr.p_double[iz])/(c->z.ptr.p_double[iz+1]-c->z.ptr.p_double[iz]); 30312 for(i=0; i<=c->d-1; i++) 30316 * Trilinear interpolation 30320 c0 = c->f.ptr.p_double[c->d*(c->n*(c->m*iz+iy)+ix)+i]*(1-xd)+c->f.ptr.p_double[c->d*(c->n*(c->m*iz+iy)+(ix+1))+i]*xd; 30321 c1 = c->f.ptr.p_double[c->d*(c->n*(c->m*iz+(iy+1))+ix)+i]*(1-xd)+c->f.ptr.p_double[c->d*(c->n*(c->m*iz+(iy+1))+(ix+1))+i]*xd; 30322 c2 = c->f.ptr.p_double[c->d*(c->n*(c->m*(iz+1)+iy)+ix)+i]*(1-xd)+c->f.ptr.p_double[c->d*(c->n*(c->m*(iz+1)+iy)+(ix+1))+i]*xd; 30323 c3 = c->f.ptr.p_double[c->d*(c->n*(c->m*(iz+1)+(iy+1))+ix)+i]*(1-xd)+c->f.ptr.p_double[c->d*(c->n*(c->m*(iz+1)+(iy+1))+(ix+1))+i]*xd; 30324 c0 = c0*(1-yd)+c1*yd; 30325 c1 = c2*(1-yd)+c3*yd; 30326 f->ptr.p_double[i] = c0*(1-zd)+c1*zd; 30332 /************************************************************************* 30333 This subroutine calculates trilinear or tricubic vector-valued spline at the 30334 given point (X,Y,Z). 30337 C - spline interpolant. 30342 F - array[D] which stores function values. F is out-parameter and 30343 it is reallocated after call to this function. In case you 30344 want to reuse previously allocated F, you may use 30345 Spline2DCalcVBuf(), which reallocates F only when it is too 30348 -- ALGLIB PROJECT -- 30349 Copyright 26.04.2012 by Bochkanov Sergey 30350 *************************************************************************/ 30351 void spline3dcalcv(spline3dinterpolant* c, 30355 /* Real */ ae_vector* f, 30359 ae_vector_clear(f); 30361 ae_assert(c->stype==-1||c->stype==-3, "Spline3DCalcV: incorrect C (incorrect parameter C.SType)
", _state); 30362 ae_assert((ae_isfinite(x, _state)&&ae_isfinite(y, _state))&&ae_isfinite(z, _state), "Spline3DCalcV: X=NaN/Infinite, Y=NaN/Infinite
or Z=NaN/Infinite
", _state); 30363 ae_vector_set_length(f, c->d, _state); 30364 spline3dcalcvbuf(c, x, y, z, f, _state); 30368 /************************************************************************* 30369 This subroutine unpacks tri-dimensional spline into the coefficients table 30372 C - spline interpolant. 30378 D - number of components 30379 SType- spline type. Currently, only one spline type is supported: 30380 trilinear spline, as indicated by SType=1. 30381 Tbl - spline coefficients: [0..(N-1)*(M-1)*(L-1)*D-1, 0..13]. 30382 For T=0..D-1 (component index), I = 0...N-2 (x index), 30383 J=0..M-2 (y index), K=0..L-2 (z index): 30384 Q := T + I*D + J*D*(N-1) + K*D*(N-1)*(M-1), 30386 Q-th row stores decomposition for T-th component of the 30387 vector-valued function 30404 On each grid square spline is equals to: 30405 S(x) = SUM(c[i,j,k]*(x^i)*(y^j)*(z^k), i=0..1, j=0..1, k=0..1) 30410 NOTE: format of Tbl is given for SType=1. Future versions of 30411 ALGLIB can use different formats for different values of 30414 -- ALGLIB PROJECT -- 30415 Copyright 26.04.2012 by Bochkanov Sergey 30416 *************************************************************************/ 30417 void spline3dunpackv(spline3dinterpolant* c, 30423 /* Real */ ae_matrix* tbl, 30444 ae_matrix_clear(tbl); 30446 ae_assert(c->stype==-1, "Spline3DUnpackV: incorrect C (incorrect parameter C.SType)
", _state); 30451 *stype = ae_iabs(c->stype, _state); 30452 ae_matrix_set_length(tbl, (*n-1)*(*m-1)*(*l-1)*(*d), 14, _state); 30457 for(i=0; i<=*n-2; i++) 30459 for(j=0; j<=*m-2; j++) 30461 for(k=0; k<=*l-2; k++) 30463 for(di=0; di<=*d-1; di++) 30465 p = *d*((*n-1)*((*m-1)*k+j)+i)+di; 30466 tbl->ptr.pp_double[p][0] = c->x.ptr.p_double[i]; 30467 tbl->ptr.pp_double[p][1] = c->x.ptr.p_double[i+1]; 30468 tbl->ptr.pp_double[p][2] = c->y.ptr.p_double[j]; 30469 tbl->ptr.pp_double[p][3] = c->y.ptr.p_double[j+1]; 30470 tbl->ptr.pp_double[p][4] = c->z.ptr.p_double[k]; 30471 tbl->ptr.pp_double[p][5] = c->z.ptr.p_double[k+1]; 30472 du = 1/(tbl->ptr.pp_double[p][1]-tbl->ptr.pp_double[p][0]); 30473 dv = 1/(tbl->ptr.pp_double[p][3]-tbl->ptr.pp_double[p][2]); 30474 dw = 1/(tbl->ptr.pp_double[p][5]-tbl->ptr.pp_double[p][4]); 30477 * Trilinear interpolation 30481 for(i0=6; i0<=13; i0++) 30483 tbl->ptr.pp_double[p][i0] = 0; 30485 tbl->ptr.pp_double[p][6+2*(2*0+0)+0] = c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30486 tbl->ptr.pp_double[p][6+2*(2*0+0)+1] = c->f.ptr.p_double[*d*(*n*(*m*k+j)+(i+1))+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30487 tbl->ptr.pp_double[p][6+2*(2*0+1)+0] = c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30488 tbl->ptr.pp_double[p][6+2*(2*0+1)+1] = c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+(i+1))+di]-c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+(i+1))+di]+c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30489 tbl->ptr.pp_double[p][6+2*(2*1+0)+0] = c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30490 tbl->ptr.pp_double[p][6+2*(2*1+0)+1] = c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+(i+1))+di]-c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+(i+1))+di]+c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30491 tbl->ptr.pp_double[p][6+2*(2*1+1)+0] = c->f.ptr.p_double[*d*(*n*(*m*(k+1)+(j+1))+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+i)+di]+c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30492 tbl->ptr.pp_double[p][6+2*(2*1+1)+1] = c->f.ptr.p_double[*d*(*n*(*m*(k+1)+(j+1))+(i+1))+di]-c->f.ptr.p_double[*d*(*n*(*m*(k+1)+(j+1))+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+(i+1))+di]+c->f.ptr.p_double[*d*(*n*(*m*(k+1)+j)+i)+di]-c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+(i+1))+di]+c->f.ptr.p_double[*d*(*n*(*m*k+(j+1))+i)+di]+c->f.ptr.p_double[*d*(*n*(*m*k+j)+(i+1))+di]-c->f.ptr.p_double[*d*(*n*(*m*k+j)+i)+di]; 30498 for(ci=0; ci<=1; ci++) 30500 for(cj=0; cj<=1; cj++) 30502 for(ck=0; ck<=1; ck++) 30504 tbl->ptr.pp_double[p][6+2*(2*ck+cj)+ci] = tbl->ptr.pp_double[p][6+2*(2*ck+cj)+ci]*ae_pow(du, ci, _state)*ae_pow(dv, cj, _state)*ae_pow(dw, ck, _state); 30515 /************************************************************************* 30516 This subroutine calculates the value of the trilinear(or tricubic;possible 30517 will be later) spline at the given point X(and its derivatives; possible 30521 C - spline interpolant. 30528 FXY - d2S(x,y,z)/dXdY 30530 -- ALGLIB PROJECT -- 30531 Copyright 26.04.2012 by Bochkanov Sergey 30532 *************************************************************************/ 30533 static void spline3d_spline3ddiff(spline3dinterpolant* c, 30562 ae_assert(c->stype==-1||c->stype==-3, "Spline3DDiff: incorrect C (incorrect parameter C.SType)
", _state); 30563 ae_assert(ae_isfinite(x, _state)&&ae_isfinite(y, _state), "Spline3DDiff: X
or Y contains NaN
or Infinite value
", _state); 30566 * Prepare F, dF/dX, dF/dY, d2F/dXdY 30578 * Binary search in the [ x[0], ..., x[n-2] ] (x[n-1] is not included) 30585 if( ae_fp_greater_eq(c->x.ptr.p_double[h],x) ) 30597 * Binary search in the [ y[0], ..., y[n-2] ] (y[n-1] is not included) 30604 if( ae_fp_greater_eq(c->y.ptr.p_double[h],y) ) 30616 * Binary search in the [ z[0], ..., z[n-2] ] (z[n-1] is not included) 30623 if( ae_fp_greater_eq(c->z.ptr.p_double[h],z) ) 30633 xd = (x-c->x.ptr.p_double[ix])/(c->x.ptr.p_double[ix+1]-c->x.ptr.p_double[ix]); 30634 yd = (y-c->y.ptr.p_double[iy])/(c->y.ptr.p_double[iy+1]-c->y.ptr.p_double[iy]); 30635 zd = (z-c->z.ptr.p_double[iz])/(c->z.ptr.p_double[iz+1]-c->z.ptr.p_double[iz]); 30638 * Trilinear interpolation 30642 c0 = c->f.ptr.p_double[c->n*(c->m*iz+iy)+ix]*(1-xd)+c->f.ptr.p_double[c->n*(c->m*iz+iy)+(ix+1)]*xd; 30643 c1 = c->f.ptr.p_double[c->n*(c->m*iz+(iy+1))+ix]*(1-xd)+c->f.ptr.p_double[c->n*(c->m*iz+(iy+1))+(ix+1)]*xd; 30644 c2 = c->f.ptr.p_double[c->n*(c->m*(iz+1)+iy)+ix]*(1-xd)+c->f.ptr.p_double[c->n*(c->m*(iz+1)+iy)+(ix+1)]*xd; 30645 c3 = c->f.ptr.p_double[c->n*(c->m*(iz+1)+(iy+1))+ix]*(1-xd)+c->f.ptr.p_double[c->n*(c->m*(iz+1)+(iy+1))+(ix+1)]*xd; 30646 c0 = c0*(1-yd)+c1*yd; 30647 c1 = c2*(1-yd)+c3*yd; 30648 *f = c0*(1-zd)+c1*zd; 30653 ae_bool _spline3dinterpolant_init(void* _p, ae_state *_state, ae_bool make_automatic) 30655 spline3dinterpolant *p = (spline3dinterpolant*)_p; 30656 ae_touch_ptr((void*)p); 30657 if( !ae_vector_init(&p->x, 0, DT_REAL, _state, make_automatic) ) 30659 if( !ae_vector_init(&p->y, 0, DT_REAL, _state, make_automatic) ) 30661 if( !ae_vector_init(&p->z, 0, DT_REAL, _state, make_automatic) ) 30663 if( !ae_vector_init(&p->f, 0, DT_REAL, _state, make_automatic) ) 30669 ae_bool _spline3dinterpolant_init_copy(void* _dst, void* _src, ae_state *_state, ae_bool make_automatic) 30671 spline3dinterpolant *dst = (spline3dinterpolant*)_dst; 30672 spline3dinterpolant *src = (spline3dinterpolant*)_src; 30674 dst->stype = src->stype; 30679 if( !ae_vector_init_copy(&dst->x, &src->x, _state, make_automatic) ) 30681 if( !ae_vector_init_copy(&dst->y, &src->y, _state, make_automatic) ) 30683 if( !ae_vector_init_copy(&dst->z, &src->z, _state, make_automatic) ) 30685 if( !ae_vector_init_copy(&dst->f, &src->f, _state, make_automatic) ) 30691 void _spline3dinterpolant_clear(void* _p) 30693 spline3dinterpolant *p = (spline3dinterpolant*)_p; 30694 ae_touch_ptr((void*)p); 30695 ae_vector_clear(&p->x); 30696 ae_vector_clear(&p->y); 30697 ae_vector_clear(&p->z); 30698 ae_vector_clear(&p->f); 30702 void _spline3dinterpolant_destroy(void* _p) 30704 spline3dinterpolant *p = (spline3dinterpolant*)_p; 30705 ae_touch_ptr((void*)p); 30706 ae_vector_destroy(&p->x); 30707 ae_vector_destroy(&p->y); 30708 ae_vector_destroy(&p->z); 30709 ae_vector_destroy(&p->f); void lsfitlinearw(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep)
void polynomialpow2bar(const real_1d_array &a, const ae_int_t n, const double c, const double s, barycentricinterpolant &p)
_barycentricinterpolant_owner & operator=(const _barycentricinterpolant_owner &rhs)
void spline3dunpackv(spline3dinterpolant *c, ae_int_t *n, ae_int_t *m, ae_int_t *l, ae_int_t *d, ae_int_t *stype, ae_matrix *tbl, ae_state *_state)
virtual ~_pspline3interpolant_owner()
struct alglib_impl::ae_state ae_state
virtual ~_lsfitreport_owner()
ae_bool _lsfitreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
_rbfreport_owner & operator=(const _rbfreport_owner &rhs)
rbfmodel & operator=(const rbfmodel &rhs)
void _spline1dinterpolant_clear(void *_p)
ae_bool ae_fp_greater_eq(double v1, double v2)
void pspline2calc(const pspline2interpolant &p, const double t, double &x, double &y)
void pspline2calc(pspline2interpolant *p, double t, double *x, double *y, ae_state *_state)
virtual ~_polynomialfitreport_owner()
double pspline3arclength(const pspline3interpolant &p, const double a, const double b)
void spline1dfitcubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t m, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
void ae_serializer_init(ae_serializer *serializer)
_pspline2interpolant_owner & operator=(const _pspline2interpolant_owner &rhs)
void spline2ddiff(spline2dinterpolant *c, double x, double y, double *f, double *fx, double *fy, double *fxy, ae_state *_state)
void idwbuildnoisy(ae_matrix *xy, ae_int_t n, ae_int_t nx, ae_int_t d, ae_int_t nq, ae_int_t nw, idwinterpolant *z, ae_state *_state)
_barycentricfitreport_owner()
ae_bool _rbfmodel_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void pspline3build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p)
void spline1dconvcubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, ae_vector *x2, ae_int_t n2, ae_vector *y2, ae_state *_state)
void lsfitsetbc(lsfitstate *state, ae_vector *bndl, ae_vector *bndu, ae_state *_state)
void barycentricunpack(const barycentricinterpolant &b, ae_int_t &n, real_1d_array &x, real_1d_array &y, real_1d_array &w)
void barycentricfitfloaterhormann(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t m, ae_int_t *info, barycentricinterpolant *b, barycentricfitreport *rep, ae_state *_state)
void ae_v_moved(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha)
virtual ~_spline1dinterpolant_owner()
ae_bool _spline2dinterpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
idwinterpolant & operator=(const idwinterpolant &rhs)
double spline1dintegrate(const spline1dinterpolant &c, const double x)
void polynomialbuildcheb1(double a, double b, ae_vector *y, ae_int_t n, barycentricinterpolant *p, ae_state *_state)
double ae_sin(double x, ae_state *state)
void spline1dlintransx(const spline1dinterpolant &c, const double a, const double b)
void spline3dbuildtrilinearv(ae_vector *x, ae_int_t n, ae_vector *y, ae_int_t m, ae_vector *z, ae_int_t l, ae_vector *f, ae_int_t d, spline3dinterpolant *c, ae_state *_state)
alglib_impl::barycentricinterpolant * p_struct
void apperiodicmap(double *x, double a, double b, double *k, ae_state *_state)
virtual ~spline3dinterpolant()
ae_int_t ae_serializer_get_alloc_size(ae_serializer *serializer)
void barycentricbuildfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t d, barycentricinterpolant &b)
void spline1dlintransx(spline1dinterpolant *c, double a, double b, ae_state *_state)
void ae_serializer_sstart_str(ae_serializer *serializer, std::string *buf)
void rbfsetalgoqnn(const rbfmodel &s, const double q, const double z)
double pspline3arclength(pspline3interpolant *p, double a, double b, ae_state *_state)
ae_int_t & iterationscount
void ae_v_muld(double *vdst, ae_int_t stride_dst, ae_int_t n, double alpha)
virtual ~_spline1dfitreport_owner()
void barycentriclintransx(const barycentricinterpolant &b, const double ca, const double cb)
barycentricinterpolant & operator=(const barycentricinterpolant &rhs)
double ae_fabs(double x, ae_state *state)
void lsfitcreatef(ae_matrix *x, ae_vector *y, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, double diffstep, lsfitstate *state, ae_state *_state)
void lsfitsetbc(const lsfitstate &state, const real_1d_array &bndl, const real_1d_array &bndu)
_lsfitreport_owner & operator=(const _lsfitreport_owner &rhs)
double ae_tan(double x, ae_state *state)
void spline1dbuildmonotone(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c)
void barycentricbuildxyw(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, barycentricinterpolant *b, ae_state *_state)
double ae_pow(double x, double y, ae_state *state)
void spline1dconvdiffcubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, ae_vector *x2, ae_int_t n2, ae_vector *y2, ae_vector *d2, ae_state *_state)
void lsfitresults(lsfitstate *state, ae_int_t *info, ae_vector *c, lsfitreport *rep, ae_state *_state)
void barycentricbuildfloaterhormann(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t d, barycentricinterpolant *b, ae_state *_state)
_barycentricinterpolant_owner()
double rbfcalc2(const rbfmodel &s, const double x0, const double x1)
double pspline2arclength(pspline2interpolant *p, double a, double b, ae_state *_state)
void * ae_malloc(size_t size, ae_state *state)
void heapsortdpoints(ae_vector *x, ae_vector *y, ae_vector *d, ae_int_t n, ae_state *_state)
virtual ~spline2dinterpolant()
void lsfitcreatewfgh(ae_matrix *x, ae_vector *y, ae_vector *w, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, lsfitstate *state, ae_state *_state)
void rbfcalc(rbfmodel *s, ae_vector *x, ae_vector *y, ae_state *_state)
double beta(const double a, const double b)
ae_bool _spline2dinterpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void kdtreequeryresultsdistances(const kdtree &kdt, real_1d_array &r)
void barycentricfitfloaterhormann(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep)
virtual ~_pspline2interpolant_owner()
void ne(Image< double > &op1, const Image< double > &op2)
void spline1dbuildcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, spline1dinterpolant &c)
union alglib_impl::ae_matrix::@12 ptr
void spline1dfitpenalized(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
ae_bool _spline1dfitreport_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void spline1dfithermite(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
void spline1dfithermite(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t m, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
void barycentricdiff1(const barycentricinterpolant &b, const double t, double &f, double &df)
void spline1dbuildcatmullrom(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundtype, const double tension, spline1dinterpolant &c)
void barycentriclintransy(const barycentricinterpolant &b, const double ca, const double cb)
void spline1dgriddiff2cubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, real_1d_array &d1, real_1d_array &d2)
void rbfserialize(rbfmodel &obj, std::string &s_out)
void _barycentricfitreport_clear(void *_p)
void ae_frame_make(ae_state *state, ae_frame *tmp)
ae_bool aredistinct(ae_vector *x, ae_int_t n, ae_state *_state)
double rbfcalc2(rbfmodel *s, double x0, double x1, ae_state *_state)
ae_bool _idwinterpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void lsfitlinearw(ae_vector *y, ae_vector *w, ae_matrix *fmatrix, ae_int_t n, ae_int_t m, ae_int_t *info, ae_vector *c, lsfitreport *rep, ae_state *_state)
_barycentricfitreport_owner & operator=(const _barycentricfitreport_owner &rhs)
void polynomialfitwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep)
void spline2dresamplebilinear(const real_2d_array &a, const ae_int_t oldheight, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, const ae_int_t newwidth)
void polynomialfit(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t m, ae_int_t *info, barycentricinterpolant *p, polynomialfitreport *rep, ae_state *_state)
ae_bool _spline3dinterpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void pspline3diff(const pspline3interpolant &p, const double t, double &x, double &dx, double &y, double &dy, double &z, double &dz)
void rbfsetconstterm(rbfmodel *s, ae_state *_state)
void lsfitsetscale(const lsfitstate &state, const real_1d_array &s)
alglib_impl::barycentricfitreport * c_ptr()
void rbfunpack(const rbfmodel &s, ae_int_t &nx, ae_int_t &ny, real_2d_array &xwr, ae_int_t &nc, real_2d_array &v)
virtual ~_barycentricinterpolant_owner()
void _spline1dinterpolant_destroy(void *_p)
void lsfitsetxrep(const lsfitstate &state, const bool needxrep)
void spline2dresamplebicubic(const real_2d_array &a, const ae_int_t oldheight, const ae_int_t oldwidth, real_2d_array &b, const ae_int_t newheight, const ae_int_t newwidth)
void spline1dbuildmonotone(ae_vector *x, ae_vector *y, ae_int_t n, spline1dinterpolant *c, ae_state *_state)
void idwbuildnoisy(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolant &z)
void kdtreequeryresultstags(const kdtree &kdt, integer_1d_array &tags)
_rbfmodel_owner & operator=(const _rbfmodel_owner &rhs)
void spline2dlintransf(spline2dinterpolant *c, double a, double b, ae_state *_state)
void tagsortfastr(ae_vector *a, ae_vector *b, ae_vector *bufa, ae_vector *bufb, ae_int_t n, ae_state *_state)
void polynomialbar2cheb(const barycentricinterpolant &p, const double a, const double b, real_1d_array &t)
ae_int_t ae_sign(double x, ae_state *state)
void kdtreebuildtagged(const real_2d_array &xy, const integer_1d_array &tags, const ae_int_t n, const ae_int_t nx, const ae_int_t ny, const ae_int_t normtype, kdtree &kdt)
ae_bool _lsfitreport_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void rbfbuildmodel(const rbfmodel &s, rbfreport &rep)
void ae_serializer_ustart_str(ae_serializer *serializer, const std::string *buf)
void pspline2build(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p)
_spline2dinterpolant_owner()
void rbfcreate(const ae_int_t nx, const ae_int_t ny, rbfmodel &s)
void spline1dbuildcubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, spline1dinterpolant *c, ae_state *_state)
ae_int_t bisectmethod(double pa, double ma, double pb, double mb, double a, double b, double *x, ae_state *_state)
void pspline2diff(const pspline2interpolant &p, const double t, double &x, double &dx, double &y, double &dy)
void spline3dlintransxyz(const spline3dinterpolant &c, const double ax, const double bx, const double ay, const double by, const double az, const double bz)
void spline2dcopy(const spline2dinterpolant &c, spline2dinterpolant &cc)
void barycentricfitfloaterhormannwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, barycentricinterpolant &b, barycentricfitreport &rep)
virtual ~_spline3dinterpolant_owner()
ae_int_t kdtreequeryknn(const kdtree &kdt, const real_1d_array &x, const ae_int_t k, const bool selfmatch)
void lsfitcreatefg(ae_matrix *x, ae_vector *y, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, ae_bool cheapfg, lsfitstate *state, ae_state *_state)
void barycentriccopy(barycentricinterpolant *b, barycentricinterpolant *b2, ae_state *_state)
ae_int_t debugsolverfailures
void spline3dcalcv(spline3dinterpolant *c, double x, double y, double z, ae_vector *f, ae_state *_state)
void pspline3diff(pspline3interpolant *p, double t, double *x, double *dx, double *y, double *dy, double *z, double *dz, ae_state *_state)
void _spline2dinterpolant_clear(void *_p)
pspline2interpolant & operator=(const pspline2interpolant &rhs)
virtual ~spline1dinterpolant()
void _polynomialfitreport_clear(void *_p)
void spline1drootsandextrema(spline1dinterpolant *c, ae_vector *r, ae_int_t *nr, ae_bool *dr, ae_vector *e, ae_vector *et, ae_int_t *ne, ae_bool *de, ae_state *_state)
void lsfitcreatewfgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfitstate &state)
alglib_impl::polynomialfitreport * p_struct
void ae_serializer_stop(ae_serializer *serializer)
void spline2dbuildbilinearv(ae_vector *x, ae_int_t n, ae_vector *y, ae_int_t m, ae_vector *f, ae_int_t d, spline2dinterpolant *c, ae_state *_state)
virtual ~barycentricfitreport()
void _idwinterpolant_clear(void *_p)
void pspline3calc(const pspline3interpolant &p, const double t, double &x, double &y, double &z)
void ae_state_clear(ae_state *state)
double spline2dcalc(const spline2dinterpolant &c, const double x, const double y)
const alglib_impl::ae_matrix * c_ptr() const
rbfreport & operator=(const rbfreport &rhs)
void spline2dbuildbilinear(const real_1d_array &x, const real_1d_array &y, const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpolant &c)
ae_bool ae_fp_eq(double v1, double v2)
void barycentriclintransx(barycentricinterpolant *b, double ca, double cb, ae_state *_state)
void spline1dbuildlinear(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c)
void barycentricdiff2(barycentricinterpolant *b, double t, double *f, double *df, double *d2f, ae_state *_state)
ae_bool _spline1dinterpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
double polynomialcalccheb1(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t)
void spline3dresampletrilinear(const real_1d_array &a, const ae_int_t oldzcount, const ae_int_t oldycount, const ae_int_t oldxcount, const ae_int_t newzcount, const ae_int_t newycount, const ae_int_t newxcount, real_1d_array &b)
alglib_impl::spline2dinterpolant * p_struct
void pspline2tangent(pspline2interpolant *p, double t, double *x, double *y, ae_state *_state)
spline1dinterpolant & operator=(const spline1dinterpolant &rhs)
void lsfitsetgradientcheck(const lsfitstate &state, const double teststep)
double ae_cos(double x, ae_state *state)
ae_bool ae_matrix_init_copy(ae_matrix *dst, ae_matrix *src, ae_state *state, ae_bool make_automatic)
ae_bool ae_matrix_init(ae_matrix *dst, ae_int_t rows, ae_int_t cols, ae_datatype datatype, ae_state *state, ae_bool make_automatic)
void spline2dresamplebicubic(ae_matrix *a, ae_int_t oldheight, ae_int_t oldwidth, ae_matrix *b, ae_int_t newheight, ae_int_t newwidth, ae_state *_state)
void pspline3parametervalues(pspline3interpolant *p, ae_int_t *n, ae_vector *t, ae_state *_state)
void ae_matrix_destroy(ae_matrix *dst)
bool lsfititeration(const lsfitstate &state)
void lsfitlinear(const real_1d_array &y, const real_2d_array &fmatrix, const ae_int_t n, const ae_int_t m, ae_int_t &info, real_1d_array &c, lsfitreport &rep)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
lsfitreport & operator=(const lsfitreport &rhs)
void spline1dfitpenalizedw(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, ae_int_t m, double rho, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
void spline3dresampletrilinear(ae_vector *a, ae_int_t oldzcount, ae_int_t oldycount, ae_int_t oldxcount, ae_int_t newzcount, ae_int_t newycount, ae_int_t newxcount, ae_vector *b, ae_state *_state)
ae_bool _kdtree_init(void *_p, ae_state *_state, ae_bool make_automatic)
_polynomialfitreport_owner()
void polynomialcheb2bar(ae_vector *t, ae_int_t n, double a, double b, barycentricinterpolant *p, ae_state *_state)
void ae_serializer_clear(ae_serializer *serializer)
void lsfitcreatewf(ae_matrix *x, ae_vector *y, ae_vector *w, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, double diffstep, lsfitstate *state, ae_state *_state)
ae_bool _idwinterpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
void spline3dunpackv(const spline3dinterpolant &c, ae_int_t &n, ae_int_t &m, ae_int_t &l, ae_int_t &d, ae_int_t &stype, real_2d_array &tbl)
ae_bool _kdtree_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void spline2dunpackv(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, ae_int_t &d, real_2d_array &tbl)
void rbfsetalgomultilayer(const rbfmodel &s, const double rbase, const ae_int_t nlayers, const double lambdav)
void lsfitsetstpmax(lsfitstate *state, double stpmax, ae_state *_state)
void barycentricfitfloaterhormannwc(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, ae_vector *xc, ae_vector *yc, ae_vector *dc, ae_int_t k, ae_int_t m, ae_int_t *info, barycentricinterpolant *b, barycentricfitreport *rep, ae_state *_state)
virtual ~_rbfreport_owner()
void threshold(double *phi, unsigned long nvox, double limit)
void lsfitlinearc(ae_vector *y, ae_matrix *fmatrix, ae_matrix *cmatrix, ae_int_t n, ae_int_t m, ae_int_t k, ae_int_t *info, ae_vector *c, lsfitreport *rep, ae_state *_state)
void spline2dbuildbicubic(ae_vector *x, ae_vector *y, ae_matrix *f, ae_int_t m, ae_int_t n, spline2dinterpolant *c, ae_state *_state)
virtual ~_lsfitstate_owner()
void barycentricdiff1(barycentricinterpolant *b, double t, double *f, double *df, ae_state *_state)
lsfitstate & operator=(const lsfitstate &rhs)
ae_bool _barycentricinterpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
spline1dfitreport & operator=(const spline1dfitreport &rhs)
alglib_impl::barycentricfitreport * p_struct
void spline1dconvdiffinternal(ae_vector *xold, ae_vector *yold, ae_vector *dold, ae_int_t n, ae_vector *x2, ae_int_t n2, ae_vector *y, ae_bool needy, ae_vector *d1, ae_bool needd1, ae_vector *d2, ae_bool needd2, ae_state *_state)
alglib_impl::pspline3interpolant * c_ptr()
void spline1dbuildakima(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, spline1dinterpolant &c)
ae_bool _pspline3interpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void _barycentricinterpolant_destroy(void *_p)
void lsfitsetcond(lsfitstate *state, double epsf, double epsx, ae_int_t maxits, ae_state *_state)
ae_int_t ae_v_len(ae_int_t a, ae_int_t b)
void rbfcalcbuf(rbfmodel *s, ae_vector *x, ae_vector *y, ae_state *_state)
void ae_vector_destroy(ae_vector *dst)
void spline1dfitcubicwc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
ae_bool _pspline2interpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
void rbfgridcalc2(const rbfmodel &s, const real_1d_array &x0, const ae_int_t n0, const real_1d_array &x1, const ae_int_t n1, real_2d_array &y)
void rbfalloc(ae_serializer *s, rbfmodel *model, ae_state *_state)
void polynomialbuild(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p)
double polynomialcalccheb2(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t)
void pspline2parametervalues(pspline2interpolant *p, ae_int_t *n, ae_vector *t, ae_state *_state)
void tagsort(ae_vector *a, ae_int_t n, ae_vector *p1, ae_vector *p2, ae_state *_state)
ae_bool _polynomialfitreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
void spline2dcopy(spline2dinterpolant *c, spline2dinterpolant *cc, ae_state *_state)
void spline1dlintransy(const spline1dinterpolant &c, const double a, const double b)
void lsfitsetcond(const lsfitstate &state, const double epsf, const double epsx, const ae_int_t maxits)
void _idwinterpolant_destroy(void *_p)
void rbfgridcalc2(rbfmodel *s, ae_vector *x0, ae_int_t n0, ae_vector *x1, ae_int_t n1, ae_matrix *y, ae_state *_state)
void rbfsetpoints(rbfmodel *s, ae_matrix *xy, ae_int_t n, ae_state *_state)
double polynomialcalccheb1(double a, double b, ae_vector *f, ae_int_t n, double t, ae_state *_state)
double barycentriccalc(const barycentricinterpolant &b, const double t)
void lsfitfit(lsfitstate &state, void(*func)(const real_1d_array &c, const real_1d_array &x, double &func, void *ptr), void(*rep)(const real_1d_array &c, double func, void *ptr), void *ptr)
void lsfitsetxrep(lsfitstate *state, ae_bool needxrep, ae_state *_state)
polynomialfitreport & operator=(const polynomialfitreport &rhs)
void spline2dbuildbilinear(ae_vector *x, ae_vector *y, ae_matrix *f, ae_int_t m, ae_int_t n, spline2dinterpolant *c, ae_state *_state)
void spline2dbuildbicubic(const real_1d_array &x, const real_1d_array &y, const real_2d_array &f, const ae_int_t m, const ae_int_t n, spline2dinterpolant &c)
void ae_v_move(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n)
alglib_impl::pspline3interpolant * p_struct
alglib_impl::rbfreport * p_struct
_spline3dinterpolant_owner & operator=(const _spline3dinterpolant_owner &rhs)
alglib_impl::spline3dinterpolant * c_ptr()
void polynomialbuildcheb1(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p)
void spline2dunpackv(spline2dinterpolant *c, ae_int_t *m, ae_int_t *n, ae_int_t *d, ae_matrix *tbl, ae_state *_state)
double idwcalc(idwinterpolant *z, ae_vector *x, ae_state *_state)
double pspline2arclength(const pspline2interpolant &p, const double a, const double b)
void lsfitcreatewfg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const bool cheapfg, lsfitstate &state)
alglib_impl::lsfitreport * p_struct
ae_bool ae_isinf(double x, ae_state *state)
void ae_vector_clear(ae_vector *dst)
alglib_impl::rbfmodel * c_ptr()
void spline3dcalcv(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f)
alglib_impl::lsfitreport * c_ptr()
void spline1dunpack(const spline1dinterpolant &c, ae_int_t &n, real_2d_array &tbl)
void spline1dfitpenalized(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t m, double rho, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
ae_bool ae_fp_less(double v1, double v2)
_spline1dinterpolant_owner & operator=(const _spline1dinterpolant_owner &rhs)
void spline1dconvdiff2cubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, ae_vector *x2, ae_int_t n2, ae_vector *y2, ae_vector *d2, ae_vector *dd2, ae_state *_state)
double spline1dcalc(const spline1dinterpolant &c, const double x)
void idwbuildmodifiedshepardr(ae_matrix *xy, ae_int_t n, ae_int_t nx, double r, idwinterpolant *z, ae_state *_state)
alglib_impl::lsfitstate * c_ptr()
void spline1dfitcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
ae_bool _polynomialfitreport_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
ae_bool _spline1dinterpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
void pspline2diff2(pspline2interpolant *p, double t, double *x, double *dx, double *d2x, double *y, double *dy, double *d2y, ae_state *_state)
void spline3dcalcvbuf(spline3dinterpolant *c, double x, double y, double z, ae_vector *f, ae_state *_state)
ae_int_t ae_iceil(double x, ae_state *state)
void pspline3parametervalues(const pspline3interpolant &p, ae_int_t &n, real_1d_array &t)
void lsfitlinearwc(ae_vector *y, ae_vector *w, ae_matrix *fmatrix, ae_matrix *cmatrix, ae_int_t n, ae_int_t m, ae_int_t k, ae_int_t *info, ae_vector *c, lsfitreport *rep, ae_state *_state)
ae_int_t kdtreequeryrnn(const kdtree &kdt, const real_1d_array &x, const double r, const bool selfmatch)
ae_bool _densesolverlsreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
void polynomialcheb2bar(const real_1d_array &t, const ae_int_t n, const double a, const double b, barycentricinterpolant &p)
void _rbfmodel_clear(void *_p)
pspline3interpolant & operator=(const pspline3interpolant &rhs)
alglib_impl::barycentricinterpolant * c_ptr()
void _pspline3interpolant_clear(void *_p)
ae_bool _barycentricfitreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
_pspline3interpolant_owner()
_spline1dfitreport_owner()
void spline2dlintransxy(spline2dinterpolant *c, double ax, double bx, double ay, double by, ae_state *_state)
alglib_impl::spline1dinterpolant * c_ptr()
void spline1dfithermitewc(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, ae_vector *xc, ae_vector *yc, ae_vector *dc, ae_int_t k, ae_int_t m, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
ae_bool ae_fp_neq(double v1, double v2)
ae_bool ae_isnan(double x, ae_state *state)
ae_bool isfinitevector(ae_vector *x, ae_int_t n, ae_state *_state)
void pspline3diff2(pspline3interpolant *p, double t, double *x, double *dx, double *d2x, double *y, double *dy, double *d2y, double *z, double *dz, double *d2z, ae_state *_state)
void rvectorsetlengthatleast(ae_vector *x, ae_int_t n, ae_state *_state)
void spline1dbuildhermite(const real_1d_array &x, const real_1d_array &y, const real_1d_array &d, const ae_int_t n, spline1dinterpolant &c)
void spline1ddiff(spline1dinterpolant *c, double x, double *s, double *ds, double *d2s, ae_state *_state)
__host__ __device__ float length(float2 v)
void polynomialbar2pow(barycentricinterpolant *p, double c, double s, ae_vector *a, ae_state *_state)
_pspline2interpolant_owner()
ae_bool _spline1dfitreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
_pspline3interpolant_owner & operator=(const _pspline3interpolant_owner &rhs)
void ae_touch_ptr(void *p)
_lsfitstate_owner & operator=(const _lsfitstate_owner &rhs)
void polynomialbar2cheb(barycentricinterpolant *p, double a, double b, ae_vector *t, ae_state *_state)
void lsfitcreatewf(const real_2d_array &x, const real_1d_array &y, const real_1d_array &w, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const double diffstep, lsfitstate &state)
void polynomialfitwc(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, ae_vector *xc, ae_vector *yc, ae_vector *dc, ae_int_t k, ae_int_t m, ae_int_t *info, barycentricinterpolant *p, polynomialfitreport *rep, ae_state *_state)
double ae_maxreal(double m1, double m2, ae_state *state)
void spline2dbuildbicubicv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &f, const ae_int_t d, spline2dinterpolant &c)
void rbfcalc(const rbfmodel &s, const real_1d_array &x, real_1d_array &y)
void _kdtree_clear(void *_p)
alglib_impl::idwinterpolant * p_struct
void barycentriclintransy(barycentricinterpolant *b, double ca, double cb, ae_state *_state)
void spline2dlintransxy(const spline2dinterpolant &c, const double ax, const double bx, const double ay, const double by)
virtual ~pspline3interpolant()
ae_bool ae_vector_set_length(ae_vector *dst, ae_int_t newsize, ae_state *state)
void polynomialpow2bar(ae_vector *a, ae_int_t n, double c, double s, barycentricinterpolant *p, ae_state *_state)
void pspline3calc(pspline3interpolant *p, double t, double *x, double *y, double *z, ae_state *_state)
void _pspline2interpolant_clear(void *_p)
_spline1dinterpolant_owner()
void spline1dgriddiffcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, real_1d_array &d)
ae_bool _rbfmodel_init(void *_p, ae_state *_state, ae_bool make_automatic)
void pspline3diff2(const pspline3interpolant &p, const double t, double &x, double &dx, double &d2x, double &y, double &dy, double &d2y, double &z, double &dz, double &d2z)
void rbfsetalgomultilayer(rbfmodel *s, double rbase, ae_int_t nlayers, double lambdav, ae_state *_state)
void spline1dbuildakima(ae_vector *x, ae_vector *y, ae_int_t n, spline1dinterpolant *c, ae_state *_state)
virtual ~pspline2interpolant()
void spline1dbuildhermite(ae_vector *x, ae_vector *y, ae_vector *d, ae_int_t n, spline1dinterpolant *c, ae_state *_state)
void spline1dgriddiff2cubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, ae_vector *d1, ae_vector *d2, ae_state *_state)
void spline3dlintransf(spline3dinterpolant *c, double a, double b, ae_state *_state)
alglib_impl::pspline2interpolant * c_ptr()
alglib_impl::spline1dfitreport * c_ptr()
void lsfitcreatewfg(ae_matrix *x, ae_vector *y, ae_vector *w, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, ae_bool cheapfg, lsfitstate *state, ae_state *_state)
double ae_log(double x, ae_state *state)
void spline1dcopy(spline1dinterpolant *c, spline1dinterpolant *cc, ae_state *_state)
void _rbfreport_clear(void *_p)
struct alglib_impl::ae_vector ae_vector
const alglib_impl::ae_vector * c_ptr() const
void lsfitlinearc(const real_1d_array &y, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep)
void _lsfitreport_clear(void *_p)
double ae_minreal(double m1, double m2, ae_state *state)
void rbfbuildmodel(rbfmodel *s, rbfreport *rep, ae_state *_state)
void spline1dfithermitewc(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const real_1d_array &xc, const real_1d_array &yc, const integer_1d_array &dc, const ae_int_t k, const ae_int_t m, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
double polynomialcalceqdist(const double a, const double b, const real_1d_array &f, const ae_int_t n, const double t)
void polynomialbuildeqdist(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p)
void _barycentricinterpolant_clear(void *_p)
void spline2dunpack(spline2dinterpolant *c, ae_int_t *m, ae_int_t *n, ae_matrix *tbl, ae_state *_state)
double spline1dcalc(spline1dinterpolant *c, double x, ae_state *_state)
void spline2dbuildbilinearv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &f, const ae_int_t d, spline2dinterpolant &c)
double polynomialcalccheb2(double a, double b, ae_vector *f, ae_int_t n, double t, ae_state *_state)
void _spline3dinterpolant_clear(void *_p)
void generatereflection(ae_vector *x, ae_int_t n, double *tau, ae_state *_state)
void spline2dresamplebilinear(ae_matrix *a, ae_int_t oldheight, ae_int_t oldwidth, ae_matrix *b, ae_int_t newheight, ae_int_t newwidth, ae_state *_state)
struct alglib_impl::ae_matrix ae_matrix
alglib_impl::spline1dinterpolant * p_struct
void spline3dlintransf(const spline3dinterpolant &c, const double a, const double b)
void rbfsetzeroterm(const rbfmodel &s)
void _spline1dfitreport_clear(void *_p)
double spline3dcalc(spline3dinterpolant *c, double x, double y, double z, ae_state *_state)
alglib_impl::spline3dinterpolant * p_struct
void _kdtree_destroy(void *_p)
void spline1dlintransy(spline1dinterpolant *c, double a, double b, ae_state *_state)
void ae_state_init(ae_state *state)
virtual ~polynomialfitreport()
double spline1dintegrate(spline1dinterpolant *c, double x, ae_state *_state)
double ae_sqrt(double x, ae_state *state)
void ae_assert(ae_bool cond, const char *msg, ae_state *state)
union alglib_impl::ae_vector::@11 ptr
void pspline3tangent(pspline3interpolant *p, double t, double *x, double *y, double *z, ae_state *_state)
void rmatrixsolvels(const real_2d_array &a, const ae_int_t nrows, const ae_int_t ncols, const real_1d_array &b, const double threshold, ae_int_t &info, densesolverlsreport &rep, real_1d_array &x)
void rbfsetpoints(const rbfmodel &s, const real_2d_array &xy, const ae_int_t n)
void rbfsetalgoqnn(rbfmodel *s, double q, double z, ae_state *_state)
double spline2dcalc(spline2dinterpolant *c, double x, double y, ae_state *_state)
void lsfitsetgradientcheck(lsfitstate *state, double teststep, ae_state *_state)
ae_bool _barycentricinterpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
void ae_serializer_alloc_start(ae_serializer *serializer)
const char *volatile error_msg
void spline2dlintransf(const spline2dinterpolant &c, const double a, const double b)
void rbfcreate(ae_int_t nx, ae_int_t ny, rbfmodel *s, ae_state *_state)
void pspline2buildperiodic(ae_matrix *xy, ae_int_t n, ae_int_t st, ae_int_t pt, pspline2interpolant *p, ae_state *_state)
ae_bool _rbfreport_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void idwbuildmodifiedshepard(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const ae_int_t d, const ae_int_t nq, const ae_int_t nw, idwinterpolant &z)
void ivectorsetlengthatleast(ae_vector *x, ae_int_t n, ae_state *_state)
void spline1dfitpenalizedw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, const ae_int_t m, const double rho, ae_int_t &info, spline1dinterpolant &s, spline1dfitreport &rep)
virtual ~idwinterpolant()
#define ae_machineepsilon
void spline1dconvdiffcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2, real_1d_array &d2)
void spline3dlintransxyz(spline3dinterpolant *c, double ax, double bx, double ay, double by, double az, double bz, ae_state *_state)
void rbfunserialize(std::string &s_in, rbfmodel &obj)
virtual ~_spline2dinterpolant_owner()
ae_bool _lsfitstate_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
_idwinterpolant_owner & operator=(const _idwinterpolant_owner &rhs)
void polynomialbuildcheb2(double a, double b, ae_vector *y, ae_int_t n, barycentricinterpolant *p, ae_state *_state)
double ae_exp(double x, ae_state *state)
spline3dinterpolant & operator=(const spline3dinterpolant &rhs)
void _lsfitstate_clear(void *_p)
void lsfitlinearwc(const real_1d_array &y, const real_1d_array &w, const real_2d_array &fmatrix, const real_2d_array &cmatrix, const ae_int_t n, const ae_int_t m, const ae_int_t k, ae_int_t &info, real_1d_array &c, lsfitreport &rep)
void polynomialfit(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t m, ae_int_t &info, barycentricinterpolant &p, polynomialfitreport &rep)
barycentricfitreport & operator=(const barycentricfitreport &rhs)
alglib_impl::polynomialfitreport * c_ptr()
void pspline2buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline2interpolant &p)
void polynomialbuildeqdist(double a, double b, ae_vector *y, ae_int_t n, barycentricinterpolant *p, ae_state *_state)
void polynomialbar2pow(const barycentricinterpolant &p, const double c, const double s, real_1d_array &a)
spline2dinterpolant & operator=(const spline2dinterpolant &rhs)
void kdtreequeryresultsxy(const kdtree &kdt, real_2d_array &xy)
alglib_impl::idwinterpolant * c_ptr()
void lsfitcreatefg(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const bool cheapfg, lsfitstate &state)
double polynomialcalceqdist(double a, double b, ae_vector *f, ae_int_t n, double t, ae_state *_state)
void spline1ddiff(const spline1dinterpolant &c, const double x, double &s, double &ds, double &d2s)
void spline2ddiff(const spline2dinterpolant &c, const double x, const double y, double &f, double &fx, double &fy, double &fxy)
void ae_v_subd(double *vdst, ae_int_t stride_dst, const double *vsrc, ae_int_t stride_src, ae_int_t n, double alpha)
ae_bool ae_vector_init(ae_vector *dst, ae_int_t size, ae_datatype datatype, ae_state *state, ae_bool make_automatic)
void pspline3buildperiodic(const real_2d_array &xy, const ae_int_t n, const ae_int_t st, const ae_int_t pt, pspline3interpolant &p)
void spline2dcalcv(spline2dinterpolant *c, double x, double y, ae_vector *f, ae_state *_state)
_spline2dinterpolant_owner & operator=(const _spline2dinterpolant_owner &rhs)
ae_int_t ae_maxint(ae_int_t m1, ae_int_t m2, ae_state *state)
void rbfcalcbuf(const rbfmodel &s, const real_1d_array &x, real_1d_array &y)
ae_bool ae_isfinite(double x, ae_state *state)
double ae_sqr(double x, ae_state *state)
double rmatrixtrrcondinf(const real_2d_array &a, const ae_int_t n, const bool isupper, const bool isunit)
_spline3dinterpolant_owner()
void rbfserialize(ae_serializer *s, rbfmodel *model, ae_state *_state)
void solvecubicpolinom(double pa, double ma, double pb, double mb, double a, double b, double *x0, double *x1, double *x2, double *ex0, double *ex1, ae_int_t *nr, ae_int_t *ne, ae_vector *tempdata, ae_state *_state)
void spline1dconvdiff2cubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2, real_1d_array &d2, real_1d_array &dd2)
virtual ~_barycentricfitreport_owner()
alglib_impl::lsfitstate * p_struct
virtual ~_rbfmodel_owner()
ae_bool _pspline2interpolant_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void spline3dbuildtrilinearv(const real_1d_array &x, const ae_int_t n, const real_1d_array &y, const ae_int_t m, const real_1d_array &z, const ae_int_t l, const real_1d_array &f, const ae_int_t d, spline3dinterpolant &c)
void spline1dgriddiffcubic(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundltype, double boundl, ae_int_t boundrtype, double boundr, ae_vector *d, ae_state *_state)
void pspline2tangent(const pspline2interpolant &p, const double t, double &x, double &y)
void lsfitcreatefgh(ae_matrix *x, ae_vector *y, ae_vector *c, ae_int_t n, ae_int_t m, ae_int_t k, lsfitstate *state, ae_state *_state)
void rbfunserialize(ae_serializer *s, rbfmodel *model, ae_state *_state)
void idwbuildmodifiedshepardr(const real_2d_array &xy, const ae_int_t n, const ae_int_t nx, const double r, idwinterpolant &z)
void spline1dbuildcatmullrom(ae_vector *x, ae_vector *y, ae_int_t n, ae_int_t boundtype, double tension, spline1dinterpolant *c, ae_state *_state)
void polynomialbuild(ae_vector *x, ae_vector *y, ae_int_t n, barycentricinterpolant *p, ae_state *_state)
void solvepolinom2(double p0, double m0, double p1, double m1, double *x0, double *x1, ae_int_t *nr, ae_state *_state)
void tagsortfasti(ae_vector *a, ae_vector *b, ae_vector *bufa, ae_vector *bufb, ae_int_t n, ae_state *_state)
void pspline3build(ae_matrix *xy, ae_int_t n, ae_int_t st, ae_int_t pt, pspline3interpolant *p, ae_state *_state)
void rbfsetlinterm(rbfmodel *s, ae_state *_state)
void pspline2diff(pspline2interpolant *p, double t, double *x, double *dx, double *y, double *dy, ae_state *_state)
double spline3dcalc(const spline3dinterpolant &c, const double x, const double y, const double z)
ae_bool ae_vector_init_copy(ae_vector *dst, ae_vector *src, ae_state *state, ae_bool make_automatic)
double barycentriccalc(barycentricinterpolant *b, double t, ae_state *_state)
void spline1dfitcubicwc(ae_vector *x, ae_vector *y, ae_vector *w, ae_int_t n, ae_vector *xc, ae_vector *yc, ae_vector *dc, ae_int_t k, ae_int_t m, ae_int_t *info, spline1dinterpolant *s, spline1dfitreport *rep, ae_state *_state)
void lsfitcreatefgh(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, lsfitstate &state)
double rbfcalc3(rbfmodel *s, double x0, double x1, double x2, ae_state *_state)
void rbfsetconstterm(const rbfmodel &s)
_spline1dfitreport_owner & operator=(const _spline1dfitreport_owner &rhs)
ae_bool ae_fp_less_eq(double v1, double v2)
ae_int_t ae_round(double x, ae_state *state)
double idwcalc(const idwinterpolant &z, const real_1d_array &x)
alglib_impl::pspline2interpolant * p_struct
ae_bool _pspline3interpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
void spline2dunpack(const spline2dinterpolant &c, ae_int_t &m, ae_int_t &n, real_2d_array &tbl)
alglib_impl::ae_int_t ae_int_t
virtual ~barycentricinterpolant()
alglib_impl::rbfreport * c_ptr()
void ae_frame_leave(ae_state *state)
alglib_impl::rbfmodel * p_struct
void spline1dunpack(spline1dinterpolant *c, ae_int_t *n, ae_matrix *tbl, ae_state *_state)
void idwbuildmodifiedshepard(ae_matrix *xy, ae_int_t n, ae_int_t nx, ae_int_t d, ae_int_t nq, ae_int_t nw, idwinterpolant *z, ae_state *_state)
void ae_matrix_clear(ae_matrix *dst)
ae_bool lsfititeration(lsfitstate *state, ae_state *_state)
void rbfunpack(rbfmodel *s, ae_int_t *nx, ae_int_t *ny, ae_matrix *xwr, ae_int_t *nc, ae_matrix *v, ae_state *_state)
void spline1dbuildlinear(ae_vector *x, ae_vector *y, ae_int_t n, spline1dinterpolant *c, ae_state *_state)
void barycentricbuildxyw(const real_1d_array &x, const real_1d_array &y, const real_1d_array &w, const ae_int_t n, barycentricinterpolant &b)
ae_bool ae_fp_greater(double v1, double v2)
void spline2dcalcvbuf(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f)
void spline2dcalcvbuf(spline2dinterpolant *c, double x, double y, ae_vector *f, ae_state *_state)
alglib_impl::spline2dinterpolant * c_ptr()
ae_bool ae_matrix_set_length(ae_matrix *dst, ae_int_t rows, ae_int_t cols, ae_state *state)
void pspline3buildperiodic(ae_matrix *xy, ae_int_t n, ae_int_t st, ae_int_t pt, pspline3interpolant *p, ae_state *_state)
ae_bool _rbfreport_init(void *_p, ae_state *_state, ae_bool make_automatic)
void lsfitsetstpmax(const lsfitstate &state, const double stpmax)
void lsfitsetscale(lsfitstate *state, ae_vector *s, ae_state *_state)
void spline2dbuildbicubicv(ae_vector *x, ae_int_t n, ae_vector *y, ae_int_t m, ae_vector *f, ae_int_t d, spline2dinterpolant *c, ae_state *_state)
void lsfitcreatef(const real_2d_array &x, const real_1d_array &y, const real_1d_array &c, const ae_int_t n, const ae_int_t m, const ae_int_t k, const double diffstep, lsfitstate &state)
virtual ~spline1dfitreport()
ae_bool _spline3dinterpolant_init(void *_p, ae_state *_state, ae_bool make_automatic)
double rbfcalc3(const rbfmodel &s, const double x0, const double x1, const double x2)
_polynomialfitreport_owner & operator=(const _polynomialfitreport_owner &rhs)
void pspline3tangent(const pspline3interpolant &p, const double t, double &x, double &y, double &z)
void pspline2build(ae_matrix *xy, ae_int_t n, ae_int_t st, ae_int_t pt, pspline2interpolant *p, ae_state *_state)
void spline2dcalcv(const spline2dinterpolant &c, const double x, const double y, real_1d_array &f)
ae_int_t & iterationscount
alglib_impl::spline1dfitreport * p_struct
void spline1dconvcubic(const real_1d_array &x, const real_1d_array &y, const ae_int_t n, const ae_int_t boundltype, const double boundl, const ae_int_t boundrtype, const double boundr, const real_1d_array &x2, const ae_int_t n2, real_1d_array &y2)
void pspline2diff2(const pspline2interpolant &p, const double t, double &x, double &dx, double &d2x, double &y, double &dy, double &d2y)
ae_int_t ae_minint(ae_int_t m1, ae_int_t m2, ae_state *state)
void barycentricunpack(barycentricinterpolant *b, ae_int_t *n, ae_vector *x, ae_vector *y, ae_vector *w, ae_state *_state)
ae_bool _lsfitstate_init(void *_p, ae_state *_state, ae_bool make_automatic)
void pspline2parametervalues(const pspline2interpolant &p, ae_int_t &n, real_1d_array &t)
void lsfitlinear(ae_vector *y, ae_matrix *fmatrix, ae_int_t n, ae_int_t m, ae_int_t *info, ae_vector *c, lsfitreport *rep, ae_state *_state)
void polynomialbuildcheb2(const double a, const double b, const real_1d_array &y, const ae_int_t n, barycentricinterpolant &p)
ae_int_t & terminationtype
void barycentricdiff2(const barycentricinterpolant &b, const double t, double &f, double &df, double &d2f)
double ae_v_dotproduct(const double *v0, ae_int_t stride0, const double *v1, ae_int_t stride1, ae_int_t n)
void rbfsetzeroterm(rbfmodel *s, ae_state *_state)
ae_bool _barycentricfitreport_init_copy(void *_dst, void *_src, ae_state *_state, ae_bool make_automatic)
void rbfsetlinterm(const rbfmodel &s)
void lsfitresults(const lsfitstate &state, ae_int_t &info, real_1d_array &c, lsfitreport &rep)
void spline3dcalcvbuf(const spline3dinterpolant &c, const double x, const double y, const double z, real_1d_array &f)