-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimizer's callbacks passed via constructor, (now are a parameter pa…
…ck of an optimizer template, stored inside the class), type_erasure wrapper for a general concept of optimizer, scalar_field exposes its domain dimensionality at compile time
- Loading branch information
Showing
10 changed files
with
154 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This file is part of fdaPDE, a C++ library for physics-informed | ||
// spatial and functional data analysis. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef __GRID_START_H__ | ||
#define __GRID_START_H__ | ||
|
||
#include "../../utils/symbols.h" | ||
|
||
namespace fdapde { | ||
namespace core { | ||
|
||
// implementation of the backatracking line search method for step selection | ||
class GridStart { | ||
private: | ||
double alpha_ = 2.0; | ||
double beta_ = 0.5; | ||
double gamma_ = 0.5; | ||
public: | ||
// constructors | ||
GridStart(double alpha, double beta, double gamma) : alpha_(alpha), beta_(beta), gamma_(gamma) {}; | ||
|
||
// backtracking based step search | ||
template <typename Opt, typename Obj> bool pre_update_step(Opt& opt, Obj& obj) { | ||
double alpha = alpha_; // restore to user defined settings | ||
double m = opt.grad_old.dot(opt.update); | ||
if (m < 0) { // descent direction | ||
while (obj(opt.x_old) - obj(opt.x_old + alpha * opt.update) // Armijo–Goldstein condition | ||
+ gamma_ * alpha * m < 0) { | ||
alpha *= beta_; | ||
} | ||
} | ||
opt.h = alpha; | ||
return false; | ||
} | ||
}; | ||
|
||
} // namespace core | ||
} // namespace fdapde | ||
|
||
#endif // __GRID_START_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// This file is part of fdaPDE, a C++ library for physics-informed | ||
// spatial and functional data analysis. | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef __OPTIMIZER_H__ | ||
#define __OPTIMIZER_H__ | ||
|
||
#include "../utils/symbols.h" | ||
#include "../utils/type_erasure.h" | ||
|
||
namespace fdapde { | ||
namespace core { | ||
|
||
// a type-erasure wrapper for an optimization algorithm optimizing objectives of type F | ||
template <typename F> struct Optimizer__ { | ||
static constexpr int N = F::DomainDimension; | ||
using VectorType = typename std::conditional<N == Dynamic, DVector<double>, SVector<N>>::type; | ||
// function pointers forwardings | ||
template <typename O> using fn_ptrs = fdapde::mem_fn_ptrs<&O::template optimize<F>, &O::optimum, &O::value>; | ||
// implementation | ||
template <typename T> VectorType optimize(F& objective, const T& x0) { | ||
return fdapde::invoke<VectorType, 0>(*this, objective, x0); | ||
} | ||
VectorType optimum() { return fdapde::invoke<VectorType, 1>(*this); } | ||
double value() { return fdapde::invoke<double, 2>(*this); } | ||
}; | ||
template <typename F> using Optimizer = fdapde::erase<fdapde::heap_storage, Optimizer__<F>>; | ||
|
||
} // namespace core | ||
} // namespace fdapde | ||
|
||
#endif // __OPTIMIZER_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters