Medusa  1.1
Coordinate Free Mehless Method implementation
WLSApproximant.hpp
Go to the documentation of this file.
1 #ifndef MEDUSA_BITS_APPROXIMATIONS_WLSAPPROXIMANT_HPP_
2 #define MEDUSA_BITS_APPROXIMATIONS_WLSAPPROXIMANT_HPP_
3 
9 #include "WLSApproximant_fwd.hpp"
11 
12 namespace mm {
13 
14 template <typename basis_t>
15 WLSApproximant<basis_t>::WLSApproximant(const basis_t& basis, const vector_t& point,
16  const std::vector<vector_t>& support, scalar_t scale,
17  const Eigen::Matrix<scalar_t, Eigen::Dynamic, 1>& coefficients,
18  scalar_t residual) :
19  basis_(basis), point_(point), support_(support), scale_(scale),
20  coefficients_(coefficients), residual_(residual) {
21  int n = support_.size();
22  for (int i = 0; i < n; ++i) {
23  support_[i] -= point;
24  support_[i] /= scale;
25  }
26 }
27 
28 template <typename basis_t>
31  int m = basis_.size();
32  vector_t local_point = (point - point_) / scale_;
33  Eigen::Matrix<scalar_t, Eigen::Dynamic, 1> b(m);
34  for (int i = 0; i < m; ++i) {
35  b(i) = basis_.eval(i, local_point, support_);
36  }
37  return b.dot(coefficients_);
38 }
39 
40 template <typename basis_t>
41 template <typename operator_t>
43 WLSApproximant<basis_t>::operator()(const vector_t& point, const operator_t& op) const {
44  int m = basis_.size();
45  vector_t local_point = (point - point_) / scale_;
46  Eigen::Matrix<scalar_t, Eigen::Dynamic, 1> b(m);
47  for (int i = 0; i < m; ++i) {
48  b(i) = basis_.evalOp(i, local_point, op, support_, scale_);
49  }
50  return b.dot(coefficients_);
51 }
52 
53 
54 } // namespace mm
55 
56 #endif // MEDUSA_BITS_APPROXIMATIONS_WLSAPPROXIMANT_HPP_
mm
Root namespace for the whole library.
Definition: Gaussian.hpp:14
mm::WLSApproximant::scalar_t
basis_t::scalar_t scalar_t
Scalar type.
Definition: WLSApproximant_fwd.hpp:29
mm::WLSApproximant::scale
scalar_t scale() const
Get the scale.
Definition: WLSApproximant_fwd.hpp:70
WLSApproximant_fwd.hpp
numutils.hpp
mm::WLSApproximant::WLSApproximant
WLSApproximant(const basis_t &basis, const vector_t &point, const std::vector< vector_t > &support, scalar_t scale, const Eigen::Matrix< scalar_t, Eigen::Dynamic, 1 > &coefficients, scalar_t residual=NaN)
Construct a WLS approximant with known coefficients.
Definition: WLSApproximant.hpp:15
mm::WLSApproximant::point
const vector_t & point() const
Get the center point.
Definition: WLSApproximant_fwd.hpp:68
mm::WLSApproximant::vector_t
basis_t::vector_t vector_t
Vector type.
Definition: WLSApproximant_fwd.hpp:30
mm::WLSApproximant::operator()
scalar_t operator()(const vector_t &point) const
Evaluate the approximant at given point.
Definition: WLSApproximant.hpp:30
mm::WLSApproximant::support_
std::vector< vector_t > support_
Local scaled stencil points.
Definition: WLSApproximant_fwd.hpp:35