Bayesian inference with pymc3 in BVEP

74 views
Skip to first unread message

lala z

unread,
Apr 20, 2022, 8:45:15 AM4/20/22
to TVB Users
         Hello, I'm running Bayesian inversion with pymc3 of BVEP recently,but my results are particularly bad. I want to make sure whether my process is correct and find a solution。
         First, I use TVB to simulate the epileptic activity of patients. The results are as follows:
75775c9c5ff9205c4e66601548dc1a4.png
Then I reduced the number of data points to 320:
03f04df88ba927ea50ef0c2c29c7aea.png
Then these data are used as observation data for Bayesian inference,I put the parameter target_ accept was adjusted from 0.95 to 0.99 so that the value of divergence was 0:
488974e3d61852ff5aee0e93517092b.png
the results are as follows:
096c6d81ed62689613508ed724ad165.png
The predicted result is very different from the real value。
The results above show that rhat statistic is larger than 1.4 for some parameters,the sampler did not converge, So I guess we should increase the value of tune?Maybe you have other suggestions? I would appreciate it if you could give me some suggestions!

WOODMAN Michael

unread,
Apr 25, 2022, 4:41:34 AM4/25/22
to tvb-...@googlegroups.com
hi

That your PZ is not confused with HZ is encouraging.  I would suggest first tuning some of the hyperparameters of the model with optimisation, which will be much faster, enabling you to confirm the EZ, PZ and HZ w/o confusion first, before going to sampling. 

cheers,
Marmaduke

On 20 Apr 2022, at 14:45, 'lala z' via TVB Users <tvb-...@googlegroups.com> wrote:

         Hello, I'm running Bayesian inversion with pymc3 of BVEP recently,but my results are particularly bad. I want to make sure whether my process is correct and find a solution。
         First, I use TVB to simulate the epileptic activity of patients. The results are as follows:
<75775c9c5ff9205c4e66601548dc1a4.png>
Then I reduced the number of data points to 320:
<03f04df88ba927ea50ef0c2c29c7aea.png>
Then these data are used as observation data for Bayesian inference,I put the parameter target_ accept was adjusted from 0.95 to 0.99 so that the value of divergence was 0:
<488974e3d61852ff5aee0e93517092b.png>
the results are as follows:
<096c6d81ed62689613508ed724ad165.png>
The predicted result is very different from the real value。
The results above show that rhat statistic is larger than 1.4 for some parameters,the sampler did not converge, So I guess we should increase the value of tune?Maybe you have other suggestions? I would appreciate it if you could give me some suggestions!

--
You received this message because you are subscribed to the Google Groups "TVB Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tvb-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tvb-users/7a82d643-fc48-4288-b3f4-6e9fb5d9319cn%40googlegroups.com.
<096c6d81ed62689613508ed724ad165.png><75775c9c5ff9205c4e66601548dc1a4.png><03f04df88ba927ea50ef0c2c29c7aea.png><488974e3d61852ff5aee0e93517092b.png>

lala z

unread,
May 4, 2022, 11:32:18 PM5/4/22
to TVB Users
Hello, I got an exciting result by increasing the value of tune. The predicted time series matches the observed data, but when I increase the value of tune, there are new problems. The value of divergence will increase, and the predicted value of η  is also inconsistent with the real value. Do you think I should increase the value of tune again?, Perhaps what other parameters should be adjusted? The results are as follows:
c940f3cdd12eddf9af753cbf7324196.png

meysam....@gmail.com

unread,
May 5, 2022, 7:34:43 AM5/5/22
to TVB Users
Hi,
Thanks for the question.
First, you need to set the the seizure onset later in time (cut the data e.g., to get EZ onset in red after 20sec as shown on https://github.com/ins-amu/BVEP/blob/master/PyMC3/BVEP_noncen_pymc3_patient1.ipynb). Then increasing the tune (warm-up) is always helpful (e.g., 2500). In your results, \Rhat should be larger than 1.1 and the chains have not converged yet, which is due to the estimation on hyperparameters (eps and sig).

lala z

unread,
May 5, 2022, 7:54:28 AM5/5/22
to TVB Users
OK,Thank you very much for your reply, which is very helpful to me, but I still have two questions as follows: First, why we need to set the seizure onset later in time?Second, How should I adjust these two  hyperparameters  ?How should I adjust these two super parameters? Is it to change the mean value of its distribution or increase the variance?

meysam....@gmail.com

unread,
May 9, 2022, 6:31:49 AM5/9/22
to TVB Users
The main reason is to obtain a full limit cycle for EZ and PZ (if you plot x vs z variables) . From the last plot you sent, it can be seen that you have correctly classified 2 EZ and 3 PZ. Note HZ are always non-identifiable as they are far from fixed point (eta_critical=-2.05).  However, to get better convergence, a bit later onset will be better in agreement with the initial conditions that are set here as the mean values in their priors. In the version you are running, indeed you are sampling these two parameters, which are very challenging (they determine the dynamical and observation noise levels). For an easier life, you can fix them a priori (around eps=0.06, sig=0.16) to also get faster convergence (see pair plot in https://github.com/ins-amu/BVEP/blob/master/Stan/BVEP_source_noncentered_stan_patient1_NUTS.ipynb). Finally, for the VEP model Stan converge faster than PyMC3 (eg., with 1000-2000 warmup rather than 2500 in PyMC3).

lala z

unread,
May 9, 2022, 9:52:25 AM5/9/22
to TVB Users
Thank you very much for your reply, but I don't understand whether to adjust the distribution of eps and sig, that is, eps=N(0.06,1),sig=N(0.16,1), or directly assign eps= 0.06, sig = 0.16?

meysam....@gmail.com

unread,
May 13, 2022, 3:50:08 AM5/13/22
to TVB Users
you can place informative prior to them (e.g.,  eps=N(0.06,0.01),sig=N(0.16,0.01)), but it is better to directly assign fixed values to them (e.g., eps= 0.06, sig = 0.16) and remove them from parameters in the code.
Message has been deleted
Message has been deleted

lala z

unread,
May 26, 2022, 10:17:51 PM5/26/22
to TVB Users
Hello, I'm sorry to bother you again. I don't know why. The program is often interrupted in the middle, and there have been such errors all the time:
9e513362b253d8cfedf958ad1514be6.png
d60d633191ea0066f829dad89e41094.png
How can I solve them?


WOODMAN Michael

unread,
May 30, 2022, 5:52:21 AM5/30/22
to tvb-...@googlegroups.com
Hi,

Zero derivatives are sometimes problematic for the sampler, using because it's gotten to a part of parameter space where the program has lost precision. You should try to make the priors more informative.

cheers,
Marmaduke

> On 27 May 2022, at 04:15, 'lala z' via TVB Users <tvb-...@googlegroups.com> wrote:
>
> <9e513362b253d8cfedf958ad1514be6.png>

Reply all
Reply to author
Forward
0 new messages