Medusa  1.1
Coordinate Free Mehless Method implementation
InverseMultiquadric.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_INVERSEMULTIQUADRIC_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_INVERSEMULTIQUADRIC_HPP_
3 
10 #include <cmath>
13 
14 namespace mm {
15 
16 template <typename scal_t>
17 InverseMultiquadric<scal_t>::InverseMultiquadric(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 InverseMultiquadric<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 }
31 
33 template <class scal_t>
34 template <int dimension>
36  scalar_t f = 1.0/shape_/shape_;
37  scal_t inverse = 1.0 / std::sqrt(1+f*r2);
38  return - dimension*f*ipow(inverse, 3) + 3*r2*f*f*ipow(inverse, 5);
39 }
41 
42 template <class scal_t>
43 scal_t InverseMultiquadric<scal_t>::operator()(scal_t r2) const {
44  return 1.0 / std::sqrt(r2/shape_/shape_ + 1);
45 }
46 
48 template <class S>
49 std::ostream& operator<<(std::ostream& os, const InverseMultiquadric<S>& b) {
50  return os << "InverseMultiquadric RBFs with shape " << b.shape();
51 }
52 
53 } // namespace mm
54 
55 #endif // MEDUSA_BITS_APPROXIMATIONS_INVERSEMULTIQUADRIC_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::InverseMultiquadric
Inverse Multiquadric Radial Basis Function.
Definition: InverseMultiquadric_fwd.hpp:29
mm::InverseMultiquadric::shape_
scalar_t shape_
Shape parameter.
Definition: InverseMultiquadric_fwd.hpp:34
InverseMultiquadric_fwd.hpp
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
mm::InverseMultiquadric::InverseMultiquadric
InverseMultiquadric(scalar_t shape=1)
Creates a InverseMultiQuadratic RBF basis with shape parameter shape.
Definition: InverseMultiquadric.hpp:17
assert_msg
#define assert_msg(cond,...)
Assert with better error reporting.
Definition: assert.hpp:75
mm::InverseMultiquadric::scalar_t
scal_t scalar_t
Scalar type used for computations.
Definition: InverseMultiquadric_fwd.hpp:31
assert.hpp
mm::InverseMultiquadric::shape
scalar_t shape() const
Returns shape parameter.
Definition: InverseMultiquadric_fwd.hpp:41
mm::Lap
Represents the Laplacian operator.
Definition: Monomials_fwd.hpp:20
mm::InverseMultiquadric::operator()
scalar_t operator()(scalar_t r2, int derivative) const
Evaluate derivative of this RBF wrt.
Definition: InverseMultiquadric.hpp:22