Medusa  1.1
Coordinate Free Mehless Method implementation
Multiquadric.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_MULTIQUADRIC_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_MULTIQUADRIC_HPP_
3 
9 #include "Multiquadric_fwd.hpp"
11 #include <cmath>
13 
14 namespace mm {
15 
16 template <typename scal_t>
17 Multiquadric<scal_t>::Multiquadric(scal_t shape) : shape_(shape) {
18  assert_msg(shape_ > 0, "Shape should be greater than 0, got %s.", shape_);
19 }
20 
21 template <class scal_t>
22 scal_t Multiquadric<scal_t>::operator()(scal_t r2, int derivative) const {
23  assert_msg(derivative >= 0, "Derivative of negative order %d requested.", derivative);
24  scalar_t f = r2/shape_/shape_;
25  scalar_t c = 0.5;
26  for (int i = 1; i < derivative; ++i) {
27  c *= (0.5 - i);
28  }
29  return c / ipow(shape_, 2*derivative) / std::sqrt(ipow(f+1, 2*derivative - 1));
30 }
32 template <class scal_t>
33 template <int dimension>
34 scal_t Multiquadric<scal_t>::operator()(scal_t r2, Lap <dimension>) const {
35  scalar_t f = 1.0/shape_/shape_;
36  scal_t inverse = 1.0 / std::sqrt(1+f*r2);
37  return dimension*f*inverse - r2*f*f*ipow(inverse, 3);
38 }
40 
41 template <class scal_t>
42 scal_t Multiquadric<scal_t>::operator()(scal_t r2) const {
43  return std::sqrt(r2/shape_/shape_ + 1);
44 }
45 
47 template <class S>
48 std::ostream& operator<<(std::ostream& os, const Multiquadric<S>& b) {
49  return os << "Multiquadric RBFs with shape " << b.shape();
50 }
51 
52 } // namespace mm
53 
54 #endif // MEDUSA_BITS_APPROXIMATIONS_MULTIQUADRIC_HPP_
Multiquadric_fwd.hpp
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
scalar_t
Scalar scalar_t
Type of the elements, alias of Scalar.
Definition: MatrixBaseAddons.hpp:16
mm::Multiquadric::shape
scalar_t shape() const
Returns shape parameter.
Definition: Multiquadric_fwd.hpp:41
mm::ipow
double ipow(double base)
Compile time integer power, returns base raised to power exponent.
Definition: numutils.hpp:40
mm::operator<<
std::ostream & operator<<(std::ostream &os, const Gaussian< S > &b)
Output basic information about given Gaussian RBF.
Definition: Gaussian.hpp:37
numutils.hpp
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::Multiquadric::scalar_t
scal_t scalar_t
Scalar type used for computations.
Definition: Multiquadric_fwd.hpp:31
mm::Multiquadric::operator()
scalar_t operator()(scalar_t r2, int derivative) const
Evaluate derivative of this RBF wrt.
Definition: Multiquadric.hpp:22
assert.hpp
mm::Multiquadric
Multiquadric Radial Basis Function.
Definition: Multiquadric_fwd.hpp:29
mm::Multiquadric::Multiquadric
Multiquadric(scalar_t shape=1.0)
Creates a MultiQuadratic with shape parameter shape.
Definition: Multiquadric.hpp:17
mm::Multiquadric::shape_
scalar_t shape_
Shape parameter.
Definition: Multiquadric_fwd.hpp:34
mm::Lap
Represents the Laplacian operator.
Definition: Monomials_fwd.hpp:20