-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gaussian HMC - integration within cooling gaussians and complexity improvements #301
Changes from 2 commits
cca44a0
07b98bc
0426762
ede9bf0
4f76d52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,22 +224,23 @@ private : | |
} | ||
} | ||
|
||
inline void update_position(Point &p, Point &v, NT const& T, NT const& omega) | ||
{ | ||
NT C, Phi; | ||
for (size_t i = 0; i < p.dimension(); i++) | ||
{ | ||
C = std::sqrt(p[i] * p[i] + (v[i] * v[i]) / (omega * omega)); | ||
Phi = std::atan((-v[i]) / (p[i] * omega)); | ||
if (v[i] < 0.0 && Phi < 0.0) { | ||
Phi += M_PI; | ||
} else if (v[i] > 0.0 && Phi > 0.0) { | ||
Phi -= M_PI; | ||
} | ||
p.set_coord(i, C * std::cos(omega * T + Phi)); | ||
v.set_coord(i, -C * omega * std::sin(omega * T + Phi)); | ||
} | ||
inline void update_position(Point& p, Point& v, const NT& T, const NT& omega) { | ||
|
||
NT next_p, next_v; | ||
|
||
NT sinVal = std::sin(omega * T); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the trick, thanks, great! |
||
NT cosVal = std::cos(omega * T); | ||
|
||
NT factor1 = sinVal / omega; | ||
NT factor2 = -omega * sinVal; | ||
|
||
for (size_t i = 0; i < p.dimension(); i++) { | ||
next_p = cosVal * p[i] + v[i] * factor1; | ||
next_v = factor2 * p[i] + cosVal * v[i]; | ||
|
||
p.set_coord(i, next_p); | ||
v.set_coord(i, next_v); | ||
} | ||
} | ||
|
||
inline double get_max_distance(std::vector<Point> &pointset, Point const& q, double &rad) | ||
|
@@ -271,5 +272,4 @@ private : | |
}; | ||
|
||
|
||
#endif // RANDOM_WALKS_GAUSSIAN_HMC_WALK_HPP | ||
|
||
#endif // RANDOM_WALKS_GAUSSIAN_HMC_WALK_HPP |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,7 @@ | |
#include <chrono> | ||
|
||
#include "cartesian_geom/cartesian_kernel.h" | ||
#include "random_walks/gaussian_helpers.hpp" | ||
#include "random_walks/gaussian_ball_walk.hpp" | ||
#include "random_walks/gaussian_cdhr_walk.hpp" | ||
#include "random_walks/random_walks.hpp" | ||
#include "sampling/random_point_generators.hpp" | ||
#include "volume/math_helpers.hpp" | ||
|
||
|
@@ -457,7 +455,7 @@ double volume_cooling_gaussians(Polytope& Pin, | |
|
||
template | ||
< | ||
typename WalkTypePolicy = GaussianCDHRWalk, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't change the default random walk in |
||
typename WalkTypePolicy = GaussianHamiltonianMonteCarloExactWalk, | ||
typename RandomNumberGenerator = BoostRandomNumberGenerator<boost::mt11213b, double>, | ||
typename Polytope | ||
> | ||
|
@@ -472,7 +470,7 @@ double volume_cooling_gaussians(Polytope &Pin, | |
|
||
template | ||
< | ||
typename WalkTypePolicy = GaussianCDHRWalk, | ||
typename WalkTypePolicy = GaussianHamiltonianMonteCarloExactWalk, | ||
typename RandomNumberGenerator = BoostRandomNumberGenerator<boost::mt11213b, double>, | ||
typename Polytope | ||
> | ||
|
@@ -487,4 +485,4 @@ double volume_cooling_gaussians(Polytope &Pin, | |
return volume_cooling_gaussians<WalkTypePolicy>(Pin, rng, error, walk_length); | ||
} | ||
|
||
#endif // VOLUME_COOLING_GAUSSIANS_HPP | ||
#endif // VOLUME_COOLING_GAUSSIANS_HPP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please keep the empty ending line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I prefer the constant reference of type T to be written as
T const&
is there any reason for rewriting asconst T&
?