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

add discrete wrapper #11

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jenchen1398
Copy link
Collaborator

No description provided.

> >
inline constexpr auto discrete(ProbType&& p_expr)
{
using p_t = details::convert_to_param_t<ProbType>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This converts value types, it doesn't convert containers.

Copy link
Owner

Choose a reason for hiding this comment

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

Yup do we need support for containers? I can write one if needed.

@jacobaustin123
Copy link
Collaborator

The lower-case discrete function needs to be the only way of building Discrete objects. So all Discrete tests need to be changed to use this method. I think you will need to apply the transformation to every element in the vector for it to work. James will have some ideas. The goal is for weights_.[5].get_values() to always work, because the value type is always a Variable (or a Constant, e.g.).

Copy link
Owner

@JamesYang007 JamesYang007 left a comment

Choose a reason for hiding this comment

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

👯

> >
inline constexpr auto discrete(ProbType&& p_expr)
{
using p_t = details::convert_to_param_t<ProbType>;
Copy link
Owner

Choose a reason for hiding this comment

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

Yup do we need support for containers? I can write one if needed.

@JamesYang007
Copy link
Owner

We pushed the current impl of discrete with the intention that we weren't really gonna use it with expressions, but just values. Expressions can have different types and using variadic templates with tuple is like the only way to do this. This gets difficult because you must know the index at compile-time.

@@ -92,7 +92,7 @@ inline void mh_posterior__(ModelType& model,
std::discrete_distribution disc_sampler({alpha, 1-2*alpha, alpha});
auto cand = disc_sampler(gen) - 1 + curr; // new candidate in curr + [-1, 0, 1]
// TODO: refactor common logic
if (dist.min() <= cand && cand <= dist.max()) { // if within dist bound
if (static_cast<int>(dist.min()) <= cand && cand <= static_cast<int>(dist.max())) { // if within dist bound
Copy link
Owner

Choose a reason for hiding this comment

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

wait this is not the correct casting - this will cause round issues when dist is continuous distribution. What you could do is something like static_cast<value_t>(...) <= static_cast<value_t>(cand) and you can get value_t from util::dist_expr_traits<whatever the distribution type is>::value_t.

@JamesYang007
Copy link
Owner

@all-contributors please add @jenchen1398 for code and design

@allcontributors
Copy link
Contributor

@JamesYang007

I've put up a pull request to add @jenchen1398! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants