cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
fixed.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_ALGORITHMS_OPTIMIZER_LINE_SEARCH_FIXED_H
4#define pRC_ALGORITHMS_OPTIMIZER_LINE_SEARCH_FIXED_H
5
8
10{
11 struct Fixed
12 {
13 private:
14 static constexpr Float<> defaultStepSize()
15 {
16 return 1;
17 }
18
19 public:
20 constexpr Fixed(Float<> const stepSize = defaultStepSize())
21 : mStepSize(stepSize)
22 {
23 }
24
25 template<class T = Float<>>
26 constexpr decltype(auto) stepSize() const
27 {
28 return cast<T>(mStepSize);
29 }
30
31 template<IsTensor X, IsFloat T = Value<X>, class F, class FC>
36 constexpr auto operator()(X &x, ResultOf<F, X const &, X &> &f, X &g,
37 typename ResultOf<ScalarProduct, X, X>::Type &d, F &&function,
38 FC &&constraint, X const &p, T alpha = identity<T>(),
39 T const alphaMin = zero<T>(),
40 T const alphaMax = identity<T>(NumericLimits<T>::max())) const
41 {
42 x = x - stepSize<T>() * g;
43 f = function(x, g);
44
45 return stepSize<T>();
46 }
47
48 template<IsTensor X, IsFloat T = Value<X>, class F>
51 constexpr auto operator()(X &x, ResultOf<F, X const &, X &> &f, X &g,
52 typename ResultOf<ScalarProduct, X, X>::Type &d, F &&function,
53 X const &p, T alpha = identity<T>(), T const alphaMin = zero<T>(),
54 T const alphaMax = identity<T>(NumericLimits<T>::max())) const
55 {
56 return operator()(
57 x, f, g, d, forward<F>(function),
58 [](auto &&x) -> decltype(auto)
59 {
60 return forward<decltype(x)>(x);
61 },
62 p, alpha, alphaMin, alphaMax);
63 }
64
65 private:
66 Float<> const mStepSize;
67 };
68}
69#endif // pRC_ALGORITHMS_OPTIMIZER_LINE_SEARCH_FIXED_H
Definition value.hpp:12
Definition concepts.hpp:43
Definition value.hpp:24
Definition concepts.hpp:31
int x
Definition gmock-matchers-containers_test.cc:376
const char * p
Definition gmock-matchers-containers_test.cc:379
Definition bracketing.hpp:11
static constexpr auto cast(T const &a)
Definition cast.hpp:11
std::invoke_result_t< F, Args... > ResultOf
Definition basics.hpp:59
static constexpr auto identity()
Definition identity.hpp:13
static constexpr auto zero()
Definition zero.hpp:12
Definition limits.hpp:13
Definition fixed.hpp:12
constexpr Fixed(Float<> const stepSize=defaultStepSize())
Definition fixed.hpp:20
constexpr decltype(auto) stepSize() const
Definition fixed.hpp:26
constexpr auto operator()(X &x, ResultOf< F, X const &, X & > &f, X &g, typename ResultOf< ScalarProduct, X, X >::Type &d, F &&function, FC &&constraint, X const &p, T alpha=identity< T >(), T const alphaMin=zero< T >(), T const alphaMax=identity< T >(NumericLimits< T >::max())) const
Definition fixed.hpp:36
constexpr auto operator()(X &x, ResultOf< F, X const &, X & > &f, X &g, typename ResultOf< ScalarProduct, X, X >::Type &d, F &&function, X const &p, T alpha=identity< T >(), T const alphaMin=zero< T >(), T const alphaMax=identity< T >(NumericLimits< T >::max())) const
Definition fixed.hpp:51