RFC: tracing variables within `JointDistribution`s

Aperta
#1,842 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia leggendo il comportamento esistente di JointDistribution.Root e i metodi relativi a CDF/CMF/PDF/PMF descritti nella issue. Definisci la semantica di Trace intorno al processo di generazione in avanti, quindi verifica che i valori tracciati compaiano in model.sample(), mentre log_prob possa ignorarli e accettare le variabili rimanenti senza ricalcolare l’espressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Background

Sometimes it would be useful to be able to trace intermediate values computed as part of a JointDistribution* model. The current solution to this is to make use of tfd.Deterministic. As an example, supposing we would like to trace the mean of a simple linear regression on a single feature, a user might write:

@tfd.JointDistributionCoroutine
def model():
    intercept = yield tfd.Normal(loc=0.0, scale=1.0, name="intercept")
    slope = yield tfd.Normal(loc=0.0, scale=1.0, name="slope")

    mean = tfd.Deterministic(intercept + slope * feature, name="mean")

    yield tfd.Normal(loc=mean, scale=1.0, name="response")

A call to model.sample() will return a named tuple including the value of mean, conditional on alpha and beta (and feature). However, if we wish to compute the log probability density of the model given response, intercept, and slope, we also have to pass into model.log_prob a value of mean. Here, mean must be consistent with intercept and slope, which requires the user to duplicate the expression for mean outside the model object. e.g.

intercept = 0.1
slope = 0.2
feature = 0.5
response = 0.21

# Since `mean` is deterministic, we should not have to re-compute it outside of `model`
mean = intercept + slope * feature
lp = model.log_prob(intercept=intercept, slope=slope, mean=mean, response=response)

This seems wasteful in terms of keystrokes, but also error-prone if model changes.

Suggested solution

A potential solution would be to include a sub-class similar to JointDistribution.Root called JointDistribution.Trace which would flag an expression for tracing in the forward generating process (i.e. model.sample()), but exclude the associated variable from the CDF/CMF and PDF/PMF-related methods. Thus we could write:

@tfd.JointDistributionCoroutine
def model():
    intercept = yield tfd.Normal(loc=0.0, scale=1.0, name="intercept")
    slope = yield tfd.Normal(loc=0.0, scale=1.0, name="slope")

    mean =Trace(intercept + slope * feature, name="mean")

    yield tfd.Normal(loc=mean, scale=1.0, name="response")

draw = model.sample(seed=[0,0])

# `mean` is simply ignored
model.log_prob(draw)

# `mean` does not have to be supplied
model.log_prob(intercept=draw.intercept, slope=draw.slope, response=draw.response) 

Does this seem like a feasible addition? (I may have some resource to devote to it)

Lingua principale
Jupyter Notebook
Stelle
4.4k
Fork
1.1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tensorflow/probability

Tutte le issue di tensorflow/probability

Issue simili

Altre issue su Machine Learning

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.