# Some questions related to Likelihood network

**URL:** <https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59>\
**Category:** General\
**Created:** [February 6, 2024, 7:51pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59 "2024-02-06T19:51:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jice](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jice](https://discuss.bayesflow.org/u/Jice)\
**Post date:** [February 6, 2024, 7:51pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/1 "2024-02-06T19:51:57Z")

</div>

I am trying to learn a likelihood network using BayesFlow. The simulation budget is 800 training datasets. I followed the steps in JANA paper for the joint learning of posterior and likelihood, I have a few questions, hope we can discuss and figure out. Thanks!

1. I tried to directly learn likelihood network P(raw data|theta) using invertible network, the results are pretty bad, possibly due to the limited training data.
2. I wonder if have sufficient training data, I believe it is possible to learn P(raw data|theta). But I found the outputs from function **[amortizer.sample\_data(validation\_sims, n\_samples=1000)]** is 3-dimensional, that is, _(n\_datasest, n\_posterior samples, n\_features in time series data)_. My expectation is probabilistic prediction (n\_datasest, n\_posterior samples, n\_time steps, n\_features in time series data)\*, which is 4-dimensional. Does anyone give some ideas on how to output probabilistic time series data using BayesFlow? Maybe I missed some points/functions?
3. Alternatively, we can learn the likelihood network for compressed data, e.g., P(compressed data|theta), which is found much easier to learn. I used to compress time series data outside of BayeFlow, such as applying signal processing to data, then fed the compressed data into BayesFlow. Is it possible to directly learn P(compressed data|theta) in BayesFlow? When I define the AmortizedLikelihood, I did not see any arguments related to summary net.  
4, Besides BayeFlow, any suggestions for likelihood network estimation using other methods, which can probabilistically predict time-series data?  
Thank for the attention, guys. This forum is incredibly meaningful and supportive!

---

<div class="post-metadata">

**Author:** ![elseml](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/elseml/32/19_2.png) [@elseml](https://discuss.bayesflow.org/u/elseml)\
**Post date:** [February 7, 2024, 3:08pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/2 "2024-02-07T15:08:51Z")

</div>

Hi Jice,

welcome to the forum! I do not know about the complexity of the approximation task, but 800 training data sets sounds like a very small training budget. Is it possible to increase the amount of data sets?  
Regarding your time series questions, maybe @marvinschmitt or @KLDivergence as authors of the JANA paper have some suggestions?

Cheers,  
Lasse

---

<div class="post-metadata">

**Author:** ![Jice](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jice](https://discuss.bayesflow.org/u/Jice)\
**Post date:** [February 7, 2024, 6:43pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/3 "2024-02-07T18:43:03Z")

</div>

Hi Lasse,  
Thanks for your answer! the 800 training data seems too small. But, for many engineering problems, especially in my area of structutal engieering, running the simulation once would be very expensive, leading to relatively small amount of training data. I even increase the datasets and applied to multivariate time series data, such as 1500x100x4, the likelihood network P(raw data|theta) still does not perform well and can not output 4-dimensional prediction (1500, n\_posterior samples, 100, 4).

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [February 7, 2024, 7:09pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/4 "2024-02-07T19:09:47Z")

</div>

Jice, the code for learning a surrogate for time series is here. This does not use a vanilla likelihood network, but a one with recurrent memory.

> <https://github.com/bayesflow-org/JANA-Paper/tree/main/experiments/epidemiology>
>
> //github.com/bayesflow-org/JANA-Paper/tree/main/experiments/epidemiology

However, we used online learning and it seems pretty much infeasible to learn a proper surrogate from small data using that architecture.

I believe two promising approaches would be 1) learning the likelihood of informative summary statistics; 2) learning a variational recurrent surrogate with some limiting assumptions (e.g., Gaussian p(data\_t | parameters).

---

<div class="post-metadata">

**Author:** ![Jice](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jice](https://discuss.bayesflow.org/u/Jice)\
**Post date:** [February 7, 2024, 9:46pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/5 "2024-02-07T21:46:13Z")

</div>

Thank you so much! I will take a look at the example.  
You are right! Using summary statistics to learn likelihood is much easier. I tried to learn a likelihood network by the frequency-domain data rather than time-domain data, the results are good enough.

---

<div class="post-metadata">

**Author:** ![KLDivergence](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/kldivergence/32/15_2.png) [@KLDivergence](https://discuss.bayesflow.org/u/KLDivergence)\
**Post date:** [February 7, 2024, 10:02pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/6 "2024-02-07T22:02:54Z")

</div>

Yes, tuning the network should lead to even better results. Generally speaking, smaller data sets require more regularization for the networks to generalize well.

---

<div class="post-metadata">

**Author:** ![Jice](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jice](https://discuss.bayesflow.org/u/Jice)\
**Post date:** [February 7, 2024, 10:26pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/7 "2024-02-07T22:26:58Z")

</div>

I tried to load the model in the example you referred, I guess the trained model is saved in the checkpoints, but I am not sure which file in the checkpoints is the right model and how to load the model? Did you save weights of joint\_amortizer?

---

<div class="post-metadata">

**Author:** ![marvinschmitt](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/marvinschmitt/32/98_2.png) [@marvinschmitt](https://discuss.bayesflow.org/u/marvinschmitt)\
**Post date:** [February 8, 2024, 8:59pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/8 "2024-02-08T20:59:30Z")

</div>

Hi,

> I tried to load the model in the example you referred, I guess the trained model is saved in the checkpoints, but I am not sure which file in the checkpoints is the right model and how to load the model? Did you save weights of joint\_amortizer?

The Jupyter notebook `covid19_joint_memory_MMD.ipynb` [1] contains the training and evaluation code. It loads the checkpoint from `checkpoints/joint_mmd`. The repository contains the saved checkpoint, so it should work from what I see (please correct me if I’m wrong @KLDivergence).

@Jice did you download the entire folder and try to load the checkpoint that way? After initializing the trainer, you should get a message telling you that a checkpoint with 100 epochs has been loaded.

Cheers,  
Marvin

[1] [JANA-Paper/experiments/epidemiology/covid19\_joint\_memory\_MMD.ipynb at main · bayesflow-org/JANA-Paper · GitHub](https://github.com/bayesflow-org/JANA-Paper/blob/main/experiments/epidemiology/covid19_joint_memory_MMD.ipynb)

---

<div class="post-metadata">

**Author:** ![Jice](https://avatars.discourse-cdn.com/v4/letter/j/c77e96/32.png) [@Jice](https://discuss.bayesflow.org/u/Jice)\
**Post date:** [February 12, 2024, 7:25pm UTC](https://discuss.bayesflow.org/t/some-questions-related-to-likelihood-network/59/9 "2024-02-12T19:25:35Z")

</div>

Thanks for the reply and help. I have not downloaded the entire folder yet, I will try to run the Jupyter notebook and see how it works.  
Thanks again!

Jice
