8 #ifndef SIG_UTIL_ERROR_CONVERGENCE_HPP
9 #define SIG_UTIL_ERROR_CONVERGENCE_HPP
11 #include "../sigutil.hpp"
12 #include "../distance/norm.hpp"
13 #include "../helper/maybe.hpp"
14 #include "../helper/helper_modules.hpp"
26 template <
class T,
class F>
27 double operator()(T
const& value, T
const& last_value, F
const& norm_func)
const
29 return norm_func(value, last_value);
41 template <
class T,
class F>
42 double operator()(T
const& value, T
const& last_value, F
const& norm_func)
const
44 return norm_func(value, last_value) / norm_func(last_value);
66 const double epsilon_;
85 last_value_ <<= value;
119 template <
class T,
class Criteria = RelativeError,
class F = Norm<2>>
122 const double epsilon_;
124 const Criteria criteria_;
134 ManageConvergence(
double epsilon, F norm_func =
norm_L2) : epsilon_(epsilon), norm_func_(norm_func), criteria_(Criteria()), last_value_(
Nothing(T())), conv_(false) {}
143 conv_ =
isJust(last_value_) && criteria_(value,
fromJust(last_value_), norm_func_) < epsilon_;
144 last_value_ <<= value;
bool update(double value)
状態の更新と収束判定
bool is_convergence() const
ManageConvergence(double epsilon, F norm_func=norm_L2)
コンストラクタ
const Norm< 2 > norm_L2
L2ノルムを求める関数(関数オブジェクト)
auto Nothing() -> typename impl::SameIf< T, void, typename boost::none_t, Maybe< T >>::type
値コンストラクタ
bool update(T value)
状態の更新とノルム計算、および収束判定
bool is_convergence() const
double operator()(T const &value, T const &last_value, F const &norm_func) const
ManageConvergenceSimple(double epsilon)
コンストラクタ
bool isJust(Maybe< T > const &m)
Justであるか調べる関数.Maybe a -> Bool.
double operator()(T const &value, T const &last_value, F const &norm_func) const
boost::optional< T > Maybe
double get_value() const
前回の値の取得
const AbsoluteError absolute_error
T & fromJust(Maybe< T > &m)
Justから値を取り出す関数.Maybe a -> a.
const RelativeError relative_error