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

Generalize from Double #191

Open
reubenharry opened this issue Sep 13, 2022 · 1 comment
Open

Generalize from Double #191

reubenharry opened this issue Sep 13, 2022 · 1 comment

Comments

@reubenharry
Copy link
Contributor

Use type families in type classes to move from Double to an instance dependent number type. (Seems to work, just needs to be polished.)

@idontgetoutmuch
Copy link
Member

I also tried to do this but without type families but have so far not succeeded. Here's a gist containing everything necessary in one file: https://github.com/tweag/monad-bayes/blob/Generalising-the-sampler/test/gist.hs.

I did also try your (@reubenharry) type family approach but was foxed by the type error given by this function

mhTrans' :: (StatefulGen g m, MonadReader g m) =>
             MonadDistribution m => Weighted (Density Identity) a -> Trace a -> m (Trace a)
mhTrans' m = mhTrans (hoistW (hoistD (return . runIdentity)) m)

I notice that you (@reubenharry) also didn't complete this: https://github.com/tweag/monad-bayes/blob/generalizeFromDouble2/src/Control/Monad/Bayes/Traced/Common.hs#L98.

-- | A variant of 'mhTrans' with an external sampling monad.
mhTrans' :: MonadSample m => Weighted (Density Identity) a -> Trace (Real m) a -> m (Trace (Real m) a)
mhTrans' m = undefined -- mhTrans (Weighted.hoist (FreeSampler.hoist (return . runIdentity)) m)

If either you (@reubenharry) or @turion had any ideas, they would be gratefully received.

PS I added in some code to do AD.

PPS My plan is to implement https://arxiv.org/pdf/2106.10238.pdf and then https://arxiv.org/pdf/2211.01100.pdf.

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

No branches or pull requests

2 participants