-
Notifications
You must be signed in to change notification settings - Fork 435
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
Migrate MCMC notebook to gpflow2.0 #1100
Conversation
Other changes required including: * small change to leaf printing function (fix bug, preventing printing of composite kernels) * `parameters` and `trainable_parameters` now return tuples, not generators, like tf implementation of `variables`, `trainable_variables` * tfp.distributions now have a choice of dtype (by wrapping of parameters)
Codecov Report
@@ Coverage Diff @@
## develop #1100 +/- ##
===========================================
- Coverage 95.49% 95.48% -0.01%
===========================================
Files 67 68 +1
Lines 3084 3125 +41
===========================================
+ Hits 2945 2984 +39
- Misses 139 141 +2
Continue to review full report at Codecov.
|
Fpred, Ypred = [], [] | ||
num_samples = len(samples[0]) | ||
for i in range(burn, num_samples, thin): | ||
hparams = [hp[i] for hp in samples] |
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.
what does hp
stand for?
num_samples = len(samples[0]) | ||
for i in range(burn, num_samples, thin): | ||
hparams = [hp[i] for hp in samples] | ||
[var.assign(hp) for var, hp in zip(m.trainable_variables, hparams)] |
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.
How does this compare in speed to the tf1 with feed-dict?
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.
no clue. Theres clearly iteration overhead to consider as well as the unknown speed of assign
. I dont think we have a choice either way, though worth investigating
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.
Also, in general, I think this list comp is quite ugly and there should be a different way to set all the variables of the model, which is cleaner.
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.
Comparing them would be wrong as they are different things
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.
@condnsdmatters , there is a utility function for multiple assign
gpflow/likelihoods/robustmax.py
Outdated
@@ -22,7 +23,8 @@ class RobustMax(tf.Module): | |||
def __init__(self, num_classes, epsilon=1e-3, **kwargs): | |||
super().__init__(**kwargs) | |||
transform = tfp.bijectors.Sigmoid() | |||
prior = tfp.distributions.Beta(0.2, 5.) | |||
fdtype = lambda x: np.array(x, dtype=default_float()) |
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.
what does the f
stand for?
if this is something needed throughout the code base, would it be worthwhile putting it into gpflow.utilities
or so ?
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.
f
here stands for float
. i think this is a reasonable thing to go to utilities, perhaps under the name def to_default_float(x)
etc
gpflow/optimizers/mcmc.py
Outdated
sample = param.transform.forward(values) | ||
else: | ||
sample = values | ||
samples.append(sample.numpy()) |
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 the casting to numpy needed? Would this slow down the execution?
gpflow/optimizers/mcmc.py
Outdated
parameters: List of `Variable`'s or gpflow `Parameter`s used as a state of the Markov chain. | ||
""" | ||
|
||
target_log_prob_fn: Callable[[ModelParameters], tf.Tensor] |
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.
Actually, this is used as if it doesn't take any arguments, so maybe the type hint is wrong?
@condnsdmatters, Thanks for updating the notebook. Could we not mix thing up in a single PR?
That must be separate PR with testing and cetera. I have a suspicion that it has been resolved already.
I don't think that
I don't understand the problem with it. Could you explain what you are trying to do with it? In general, when I wrote Thanks! |
In reply to @awav, I think I misunderstood the helper you wrote - my understanding was I should use as is, rather than thinking about interfaces, etc. I'm very happy to discuss and change, I agree it seems to be a bit of an odd class atm. Vis a vis other changes:
I am more than happy to put these into separate commits and PRs, as I do agree that's better from a git commit history point of view. I can restructure these now. @st-- I'll also address all the comments in this PR before doing that. |
Co-Authored-By: st-- <st--@users.noreply.github.com>
Hello @condnsdmatters , I apologize for closing your PR. It was closed automatically when I moved |
gpflow/optimizers/mcmc.py
Outdated
|
||
return _target_log_prob_fn_closure | ||
|
||
def convert_samples_to_parameter_values(self, hmc_samples): |
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.
def convert_samples_to_parameter_values(self, hmc_samples): | |
def convert_to_constrained_values(self, hmc_samples): |
Co-Authored-By: Artem Artemev <art.art.v@gmail.com>
@awav I fundamentally cant change the grad function to remove None's due to the requirements that we differentiate w.r.t to the held params on the model. As it says in the tf.custom_gradient documentation:
|
Migrate MCMC notebook to gpflow 2 using tensorflow probabilities.
Changes required a few changes across the rest of the codebase, outside of the notebook.
parameters
andtrainable_parameters
now return tuples, not generators, like tf implementation ofvariables
,trainable_variables