-
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.
* replace static derivatives through free function * avoid copy in referenced function * trigger workflow * use correct header * fix tests by keeping both Hessian methods * Use only one version of "NumericalHessian()" and remove "dim" from "NablaNumerical()" and "NumericalHessian()" * Increase diagonal shift of the Hessian in "LocateMinimum()" * HessianDiagonalShift : 1e-2 -> 1e-3 * Update .github/workflows/test.yml --------- Co-authored-by: Philipp Basler <[email protected]> Co-authored-by: João Viana <[email protected]>
- Loading branch information
1 parent
3f01384
commit 287fcac
Showing
8 changed files
with
157 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
#include <functional> | ||
#include <vector> | ||
|
||
namespace BSMPT | ||
{ | ||
/** | ||
* @brief Numerical method to calculate the | ||
* gradient of a function f using finite differences method. | ||
* | ||
* This method is used while BSMPT is not able to | ||
* calculate the potential derivative analytically. We used the 4th order | ||
* method | ||
* | ||
* \f$\frac{\partial f}{\partial \phi_i} = \frac{1}{12 | ||
* \epsilon}\left(-f(\dots ,\vec{\phi}_i + 2 \epsilon ) + 8 f(\dots | ||
* ,\vec{\phi}_i + \epsilon )- 8 f(\dots ,\vec{\phi}_i - \epsilon ) + | ||
* f(\dots ,\vec{\phi}_i - 2 \epsilon )\right)\f$ | ||
* | ||
* where \f$ \epsilon \f$ is a small step. | ||
* | ||
* @param phi Where we want to calculate the gradient | ||
* @param f function | ||
* @param eps Size of finite differences step | ||
* @return std::vector<double> The \f$ dim \times 1 \f$ gradient of V taken at | ||
* phi | ||
*/ | ||
std::vector<double> | ||
NablaNumerical(const std::vector<double> &phi, | ||
const std::function<double(std::vector<double>)> &f, | ||
const double &eps); | ||
|
||
/** | ||
* @brief Numerical method to calculate the potential's (or other functions's) | ||
* hessian matrix using finite differences method. | ||
* | ||
* \f$\frac{\partial^2 V}{\partial \phi_i \phi_j} = \frac{1}{4 | ||
* \epsilon^2}\left(V(\dots, \vec{\phi}_i + \epsilon , \vec{\phi}_j + | ||
* \epsilon) - V(\dots, \vec{\phi}_i - \epsilon , \vec{\phi}_j + | ||
* \epsilon) - V(\dots, \vec{\phi}_i + \epsilon , \vec{\phi}_j - | ||
* \epsilon) + V(\dots, \vec{\phi}_i - \epsilon , \vec{\phi}_j - | ||
* \epsilon) \right)\f$ | ||
* | ||
* where \f$ \epsilon \f$ is a small step. | ||
* | ||
* @param phi Where we want to calculate the Hessian matrix | ||
* @param V Potential (or other function) | ||
* @param eps Size of finite differences step | ||
* @return std::vector<std::vector<double>> The \f$ dim \times \dim \f$ | ||
* hessian matrix of V taken at phi | ||
*/ | ||
std::vector<std::vector<double>> | ||
HessianNumerical(const std::vector<double> &phi, | ||
const std::function<double(std::vector<double>)> &V, | ||
double eps); | ||
} // namespace BSMPT |
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
Oops, something went wrong.