cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
relative_error.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
4#define pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
5
13
14namespace pRC
15{
16 template<class XA, class XB, class RA = RemoveReference<XA>,
17 class RB = RemoveReference<XB>, If<IsFloat<typename RA::Value>> = 0,
18 If<IsFloat<typename RB::Value>> = 0,
19 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
20 If<IsInvocable<Norm<>, XA>> = 0,
21 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
22 ResultOf<Norm<>, XA>>> = 0>
23 static inline constexpr auto relativeError(XA &&a, XB &&b)
24 {
25 return absoluteError(a, b) / norm(a);
26 }
27
28 template<class XA, class XB, class RA = RemoveReference<XA>,
29 class RB = RemoveReference<XB>, If<IsFloat<typename RA::Value>> = 0,
30 If<Not<IsFloat<typename RB::Value>>> = 0,
31 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
32 If<IsInvocable<Norm<>, XA>> = 0,
33 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
34 ResultOf<Norm<>, XA>>> = 0>
35 static inline constexpr auto relativeError(XA &&a, XB &&b)
36 {
37 return relativeError(a, cast<Float<>>(b));
38 }
39
40 template<class XA, class XB, class RA = RemoveReference<XA>,
41 class RB = RemoveReference<XB>,
42 If<Not<IsFloat<typename RA::Value>>> = 0,
43 If<IsFloat<typename RB::Value>> = 0,
44 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
45 If<IsInvocable<Norm<>, XA>> = 0,
46 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
47 ResultOf<Norm<>, XA>>> = 0>
48 static inline constexpr auto relativeError(XA &&a, XB &&b)
49 {
50 return relativeError(cast<Float<>>(a), b);
51 }
52
53 template<class XA, class XB, class RA = RemoveReference<XA>,
54 class RB = RemoveReference<XB>,
55 If<Not<IsFloat<typename RA::Value>>> = 0,
56 If<Not<IsFloat<typename RB::Value>>> = 0,
57 If<IsInvocable<AbsoluteError, XA, XB>> = 0,
58 If<IsInvocable<Norm<>, XA>> = 0,
59 If<IsInvocable<Div, ResultOf<AbsoluteError, XA, XB>,
60 ResultOf<Norm<>, XA>>> = 0>
61 static inline constexpr auto relativeError(XA &&a, XB &&b)
62 {
63 return relativeError(cast<Float<>>(a), cast<Float<>>(b));
64 }
65}
66#endif // pRC_CORE_VALUE_FUNCTIONS_RELATIVE_ERROR_H
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
static constexpr auto absoluteError(XA &&a, XB &&b)
Definition absolute_error.hpp:18
static constexpr auto relativeError(XA &&a, XB &&b)
Definition relative_error.hpp:23
static constexpr auto cast(Complex< T > const &a)
Definition cast.hpp:13
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11