STS components with batching on the initial states break

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

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python, tensorflow

Direzione di ricerca

Inizia eseguendo l’esempio TensorFlow Probability fornito e confronta gli output di joint_distribution con make_state_space_model e il relativo filtro forward. Traccia come vengono gestiti LocalLevel, Sum, initial_state_prior e le relative forme del batch; il lavoro è completato quando gli stati iniziali batched producono log likelihood coerenti invece di moltiplicarli sul batch.

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

Descrizione

I am trying to run many time series models with different initial states via batching, it seems to be supported in some parts of the code although not explicit in the documentation, so I am wondering if this is a bug or just not supported? Either way I think it would be useful to have working.

The following example shows some weird results you can get currently whereby the joint_distribution function seems to give the wrong answer (it works as expected for batch_shape=[]) where it seems to sum 3*3 log likelihoods instead of 3:

import tensorflow_probability as tfp

print(tf.__version__)
# 2.18.0

print(tfp.__version__)
# 0.25.0

sts = tfp.sts
tfd = tfp.distributions

batch_shape = [3]
num_timesteps = 10
param_vals = [1.0, 2.0]
observations = tf.ones(batch_shape + [num_timesteps, 1])

local_level = sts.LocalLevel(
    initial_level_prior=tfd.Normal(loc=tf.zeros(batch_shape), scale=1.0)
)

print(local_level.batch_shape)
# ()
print(local_level.initial_state_prior.batch_shape)
# (3,)

model = sts.Sum(components=[local_level])

# joint dist
joint_dist = model.joint_distribution(observed_time_series=observations)
joint_dist_log_prob = joint_dist.log_prob(param_vals)

print(joint_dist_log_prob)
# tf.Tensor(-167.13658, shape=(), dtype=float32)

# ssm
ssm = model.make_state_space_model(num_timesteps=num_timesteps, param_vals=param_vals)
log_likelihood = sum(
    ssm.forward_filter(observations, final_step_only=True).log_likelihoods
)
prior = sum(p.prior.log_prob(x) for p, x in zip(model.parameters, param_vals))

print(log_likelihood + prior)
# tf.Tensor(-60.865345, shape=(), dtype=float32)

print(log_likelihood * 3 + prior)
# tf.Tensor(-167.13658, shape=(), dtype=float32)

At a guess this is due to the components only considering their parameters and not the initial state for their batch shape. I am happy to work on a fix or feature addition if that is helpful. Thanks!

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.