-
Notifications
You must be signed in to change notification settings - Fork 106
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
Gibbs with Gradients demo #524
base: main
Are you sure you want to change the base?
Conversation
(MkImage rows cols pixels) = fromJust $ loadImageP6 "examples/peace.ppm" | ||
|
||
-- Convert to binary image. | ||
def pixelToBool (x:Char) : Bool = (W8ToI x) < 0 |
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.
This is confusing isn't this already going to return false?
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.
You'd think so, but casting an unsigned W8 to a signed int means that half the values are negative. This is evidently a confusing way to have written this, though.
addnoise = rand (ixkey2 (newKey 0) i j) < noisefrac | ||
case addnoise of | ||
True -> not image_bool.i.j | ||
False -> image_bool.i.j |
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.
Can tje above 3 lines be written
(not addnoise) & image_bool.i.j
?
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 it's xor
, but the syntax for that is .^.
and I thought this would be easier to read.
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.
This is awesome. I especially enjoyed the commentary. IMO this is good to go, except that I'd like to reduce the size of the peace.ppm
image. Checking in binary files is generally a bad practice and I'd like to avoid doing that as much as possible. Plus, are there any licensing constraints on it?
which is a Boolean vector `n=>Bool`, | ||
and an unnormalized probability mass function `f`. | ||
The pmf maps Boolean vectors of the same size as `x` and maps | ||
them to an unnormalized log probability density. |
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.
maps twice?
'The Gibbs with Gradients sampler has a slightly different function signature | ||
than standard Gibbs. Instead of its log probability function taking in a | ||
discrete array, it takes in an array of floats of the same size. | ||
This is because Gibbs with Gradients needs to be able to differentiate the energy function |
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.
is pmf/pdf the same as the energy function?
of Algorithm 1 from the paper. In fact, the reason this demo got | ||
started was because I wasn't sure I understood the pseudocode | ||
in our own paper. Writing the algorithm in this terse (but machine-checked) | ||
format made me realize we were missing a line from the algorithm box. |
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.
Whoah, nice!
Yes, I realize this. How about if I host the image somewhere, and use the shell to download it?
Nope, it's in the public domain. Source |
Downloading via the shell sounds good! Alternatively you could assume that it's in the file system and add the download instructions (+ insert them in CI). That's what we do for the tutorial IIRC. |
'Main algorithm from "Oops I Took A Gradient: Scalable Sampling for Discrete Distributions"
by Will Grathwohl, Kevin Swersky, Milad Hashemi, David Duvenaud, Chris J. Maddison
Arxiv Link demonstrated on an Ising model.
This one already works - the main thing that needs to be done is make the colors nicer.