Medusa  1.1
Coordinate Free Mehless Method implementation
Polyharmonic.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_POLYHARMONIC_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_POLYHARMONIC_HPP_
3 
9 #include "Polyharmonic_fwd.hpp"
11 
12 namespace mm {
13 
14 template <typename scal_t, int k>
16  assert_msg(order_ > 0, "Order must be supplied if compile type order is -1.");
17 }
18 
19 template <typename scal_t, int k>
20 Polyharmonic<scal_t, k>::Polyharmonic(int order) : order_((k < 0) ? order : k) {
21  assert_msg(order % 2 == 1, "Order must be odd, got %d.", order);
22 }
23 
24 template <typename scal_t, int k>
25 scal_t Polyharmonic<scal_t, k>::operator()(scal_t r2, int derivative) const {
26  assert_msg(derivative >= 0, "Derivative of negative order %d requested.", derivative);
27  if (r2 < 1e-15) {
28  return 0;
29  }
30  scalar_t r = std::sqrt(ipowneg(r2, order_ - 2*derivative));
31  while (--derivative >= 0) {
32  r *= (order_/2.0 - derivative);
33  }
34  return r;
35 }
37 template <typename scal_t, int k>
38 template <int dimension>
39 scal_t Polyharmonic<scal_t, k>::operator()(scal_t r2, Lap<dimension>) const {
40  assert_msg(order_ > 2, "Order must be > 2 to compute the Laplacian, got %d.", k);
41  return (dimension + order_ - 2)*order_*ipow(std::sqrt(r2), order_ - 2);
42 }
44 
46 template <class S, int K>
47 std::ostream& operator<<(std::ostream& os, const Polyharmonic<S, K>& b) {
48  return os << "Polyharmonic RBF of order " << b.order_ << '.';
49 }
50 
51 } // namespace mm
52 
53 #endif // MEDUSA_BITS_APPROXIMATIONS_POLYHARMONIC_HPP_
mm::Polyharmonic::order_
const int order_
Exponent of the RBF.
Definition: Polyharmonic_fwd.hpp:38
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::ipowneg
T ipowneg(T b, int e)
Compute possibly negative integer power b^e.
Definition: numutils.hpp:72
mm::Polyharmonic::Polyharmonic
Polyharmonic()
Default constructor. Only applicable when order given as template argument.
Definition: Polyharmonic.hpp:15
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::Polyharmonic::order
int order() const
Get order of the RBF.
Definition: Polyharmonic_fwd.hpp:47
mm::Polyharmonic
Polyharmonic Radial Basis Function of odd order.
Definition: Polyharmonic_fwd.hpp:32
mm::Lap
Represents the Laplacian operator.
Definition: Monomials_fwd.hpp:20
mm::Polyharmonic::operator()
scalar_t operator()(scalar_t r2, int derivative) const
Evaluate derivative of this RBF wrt.
Definition: Polyharmonic.hpp:25
Polyharmonic_fwd.hpp
mm::Polyharmonic::scalar_t
scal_t scalar_t
Scalar type used for computations.
Definition: Polyharmonic_fwd.hpp:34