Skip to content

Update notebook examples with new variational API #2097

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

Closed
wants to merge 4 commits into from
Closed

Update notebook examples with new variational API #2097

wants to merge 4 commits into from

Conversation

ferrine
Copy link
Member

@ferrine ferrine commented Apr 30, 2017

Moving to new variational API, linked with #1968

  • lda-advi-aevb.ipynb
  • GLM-hierarchical-advi-minibatch.ipynb
  • GLM-hierarchical-ADVI.ipynb
  • gaussian-mixture-model-advi.ipynb
  • convolutional_vae_keras_advi.ipynb

@twiecki twiecki added the WIP label May 1, 2017
@ferrine
Copy link
Member Author

ferrine commented May 1, 2017

I found that normalizing loss can make convergence slower due to weaker gradients. I'll make it optional for user in a separate PR

@ferrine ferrine mentioned this pull request May 1, 2017
@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

Previous callback stopped earlier for hierarchical model when convergence was not achieved. The new one did not stop at all though(remark: it stopped once).

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

That's done. CC @taku-y, @twiecki

I've changed callback here. This change should be approved or disapproved. In case it's ok I'll revert that commit and change the callback in separate PR

@fonnesbeck
Copy link
Member

Can you replace the fit method calls with function calls in the notebooks?

@twiecki
Copy link
Member

twiecki commented May 2, 2017

Agreed. Moreover, the partial construct everywhere is not nice API, can't we pass an object, or optimizer_kwargs?

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

@fonnesbeck pm.fit does not return elbo history. In case we want to access inference history we need inference object.

@twiecki
Copy link
Member

twiecki commented May 2, 2017

@ferrine Couldn't we store that in the returned object, like we did before?

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

@twiecki good point, but I don't think that's bad api. Since 2 optimizers can be passed in the future, there will be 2 more kwarg

@twiecki
Copy link
Member

twiecki commented May 2, 2017

@ferrine Not bad, but not user-friendly I would argue. Can we not pass in Optimizer(lrate=.5), must it be a class?

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

@twiecki ofc we can but ideologically they'd be better distinguished

@twiecki
Copy link
Member

twiecki commented May 2, 2017

@ferrine not sure I follow, distinguished to what?

@fonnesbeck
Copy link
Member

I've said this before, but I feel pretty strongly about keeping the default interface consistent across fitting methods -- particularly in our examples.

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

I think that pm.fit can return loss history additionally as a separate array object. I do not want to attach new attribute to approximation as loss history is not related with approximation itself.

approx, losses = pm.fit(...)

What about optimizers. What about wrapping them in a classes?
Capital case Adam will represent a class that can be inited before call and lower case adam will remain functions as in Lasagne. So we will just add some lines below every definition

@twiecki
Copy link
Member

twiecki commented May 2, 2017

@ferrine Why wouldn't the loss be part of the approximation? To me it makes sense.

I see now, I somehow thought we already used classes in updates.py, which is clearly wrong. So yes, turning optimizers into classes is the right approach here.

@ferrine
Copy link
Member Author

ferrine commented May 2, 2017

@twiecki Approximation purpose is to store parameters and allow sampling. Inference purpose is to fit the approx. These two tasks differ a lot. The right design is to make objects serve one particular thing. Mixing inference with approximation violates this idea.

@twiecki
Copy link
Member

twiecki commented May 3, 2017

@ferrine I think the loss history of an approximation can be coherently included in the approximation class. I do see your point, but the API trumps code purity in my opinion. I love the pm.fit() analog to pm.sample(), but having one function return two things and the other just one is incoherent.

@ferrine
Copy link
Member Author

ferrine commented May 15, 2017

Can I introduce a lightweight wrapper over results so that they store both approximation and stats?

@twiecki
Copy link
Member

twiecki commented May 15, 2017

@ferrine Definitely, how would you do that on a high level?

@ferrine
Copy link
Member Author

ferrine commented May 15, 2017

I'll try. High level is needed. I always write some weird callbacks to have custom watch list of statistics. Adding watch_list as kwarg to fit will solve the problem and they will be returned with inference result. Later it will be possible to use step methods along with it.

@twiecki
Copy link
Member

twiecki commented May 15, 2017

Sounds good. FWIW callbacks are usually frowned upon, look for callback hell.

@ferrine ferrine mentioned this pull request May 27, 2017
4 tasks
@ferrine
Copy link
Member Author

ferrine commented May 27, 2017

Rebased

@ferrine
Copy link
Member Author

ferrine commented May 27, 2017

@twiecki following our discussion about VI stats, check out #2230

@ferrine
Copy link
Member Author

ferrine commented Jun 12, 2017

Solved by #2171

@ferrine ferrine closed this Jun 12, 2017
@ferrine ferrine deleted the update_advi_notebooks branch June 12, 2017 20:20
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