question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extending Predictive to support sampling by plate name

See original GitHub issue

Following our earlier discussion with @fritzo and @adamgayoso , creating this issue. Would be great if Predictive class can support sampling of all variables in a given plate, automatically pulling all site values in a given plate(plate_name) or all sites not is that plate, including both samples and observed values:

trace = poutine.trace(model).get_trace(*args, **kwargs)  # you'll need to fill in args,kwargs
cell_samples = {
    name: site["value"]
    for name, site in trace.nodes.items()
    if site["type"] == "sample"
    if any(f.name == plate_name for f in site["cond_indep_stack"])
}

This functionality would simplify dealing with local variables within a minibatch plate, by making it easy to do separate predictive calls for the minibatch plate variables and global variables.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vitklcommented, Mar 17, 2021

Yes, exactly like @jamestwebber described - we need a way to sample both the global variables and the local variables (including amortised variables). The idea is that by doing predictive sampling by plate name you can isolate local variables from global variables and sample them via 2 separate calls. I think 2 separate calls are needed because if you iterate over the data loader global variables will be sampled in every iteration of the data loader whereas local variable will be only sampled once in their respective minibatch. Separating allows sampling global variable once (where I count y_fg as global: d_cg = x_cf @ y_fg and x_cf is minibatched in c plate).

I see 2 separate problems:

  1. How to tell predictive to sample local variables from a batch plate
  2. How to concatenate the batches of local variables correctly (which need recognising the plate dimension)
1reaction
jamestwebbercommented, Mar 19, 2021

it sounds like Predictive is missing support for vectorization somewhere, but I suspect I’m misunderstanding.

It’s very possible that I just don’t understand the right pattern for accomplishing this. For me, the intended workflow is something like

  1. Learn a model of some large dataset using mini-batches for training
  2. Make a Predictive instance with pred = Predictive(model, guide=guide, num_samples=1000)
  3. Collect the posterior on my large dataset by iterating through the same data loader
posteriors = []
for x, y in data_loader:
    posteriors.append(pred(x, y))

aggregate_posterior_minibatches()

So that in the end I’d have a posterior over both the global variables (i.e. some background effect) and the minibatch-specific ones (for example, cell-specific loading factors).

Read more comments on GitHub >

github_iconTop Results From Across the Web

§ 1002.2 Definitions. | Consumer Financial Protection Bureau
(v) A refusal to extend credit because the creditor does not offer the type of credit or credit plan requested. Official interpretation of...
Read more >
SVI — Pyro documentation
A trace implementation of ELBO-based SVI that supports - exhaustive enumeration over discrete sample sites, and - local parallel sampling over any sample...
Read more >
pyro-ppl/numpyro - GitHub
As you may have noticed from the examples, NumPyro supports all Pyro primitives like sample , param , plate and module , and...
Read more >
Predicting Antibody Developability Profiles Through Early ...
The term 'developability' encompasses the feasibility of molecules to successfully progress from discovery to development via evaluation of their ...
Read more >
Class Prediction with Agilent Mass Profiler Professional
Introduction to class prediction 2 ... the class membership of unknown samples. ... (7) Select one or more prediction model algorithms that support...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found