Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

vgnecula
Copy link
Contributor

@vgnecula vgnecula commented May 27, 2024

Integrate the Exact Gaussian HMC in cooling gaussian

@vgnecula vgnecula changed the title Gaussian HMC in Cooling Gaussian GSoC Develop May 27, 2024
@TolisChal
Copy link
Member

Thanks @vgnecula! This is a useful PR. Could you please change the title of the PR to represent the actual changes that this PR is carrying?

@vgnecula vgnecula changed the title GSoC Develop Gaussian HMC - integration within cooling gaussians and complexity improvements May 27, 2024
@@ -457,7 +455,7 @@ double volume_cooling_gaussians(Polytope& Pin,

template
<
typename WalkTypePolicy = GaussianCDHRWalk,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't change the default random walk in volume_cooling_gaussians<>.
You can create a new example in folder examples that it will call this function templated with GaussianHamiltonianMonteCarloExactWalk. You can write 3-4 examples that compute volumes of polytopes from 10 to 50 dimensions. You can use the volesti polytope generators.

Copy link
Contributor

@vfisikop vfisikop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks for this PR @vgnecula !
I have a few comments.

endif ()


add_definitions(${CMAKE_CXX_FLAGS} "-std=c++11") # enable C++11 standard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not needed

typedef BoostRandomNumberGenerator<boost::mt19937, NT, 3> RNGType;
typedef HPolytope<Point> HPOLYTOPE;

void calculateAndVerifyVolume(HPOLYTOPE& polytope, const std::string& description, NT expectedVolume, NT epsilon, NT L) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are not very consistent but we use lowercase and "_" for function names.


// birkhoff polytope dimension 3
HPOLYTOPE birkhoffPolytope = generate_birkhoff<HPOLYTOPE>(3);
calculateAndVerifyVolume(birkhoffPolytope, "Birkhoff polytope (dim 3)", -1, epsilon, 8); // Theoretical volume not easily available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the Birkhoff polytope B(3) is not 3-dimensional, but 4-dimensional. In general B(n) is (n-1)^2 dimensional, see https://en.wikipedia.org/wiki/Birkhoff_polytope
Also (theoretical) volumes for n<=10 are available here https://oeis.org/A037302 (could be useful for experiments).

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) {
Copy link
Contributor

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 as const T&?

@@ -487,4 +498,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep the empty ending line


update_delta<WalkType>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you removing update_delta?

#endif

NT a_stop = 0.0;
const NT tol = 0.001;
unsigned int it = 0;
unsigned int n = P.dimension();
const unsigned int totalSteps = ((int)150/((1.0 - frac) * error))+1;

if (a_vals[0]<a_stop) a_vals[0] = a_stop;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing this check? If the computed (first) gaussian has negative variance then we set it to zero. @TolisChal is this check actually needed?

curr_fn += eval_exp(p, next_a) / eval_exp(p, a_vals[it]);
for (unsigned int j = 0; j < totalSteps; ++j) {
walk.template apply(P, p, a_vals[it], walk_length, rng);
curr_its++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this not an integer, although I do not know the reason (@TolisChal ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that could be an integer

// Set the last a_i equal to zero
if (next_a>0 && curr_fn/curr_its>(1.0+tol))
{
// pick the last gaussian
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the opposite of the last comment, why? It seems that the code indeed remove the last Gaussian (found by that ratio tolerance test) by setting its variance equals to zero.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any reason to delete this check. @vgnecula could you please comment on that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I don't know why I modified the comment, as the code seems to do the exact same thing. It probably remained like that from when I was trying to check a bug. Sorry!

@vgnecula vgnecula closed this Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants