Closed vwiela closed 1 year ago
Hi,
The proposal distribution in mcmc.pmmh
is a Gaussian random walk; i.e. the proposed parameter value is simulated from $\theta^p | \theta \sim N(\theta, \Sigma)$. The proposal covariance $\Sigma$ is either given by the user, or, if not, it is adapted (as in adaptive MCMC, i.e. it is estimated sequentially from past MCMC states).
First, can you ask you whether this point was clear to you? Otherwise, I think I should review the documentation. (This point is explained at least in the corresponding notebook tutorial, but maybe not in the docstrings.)
Anyway, I guess what happens here is that eventually the algorithm proposes a value of theta which gives you singular cov matrices (I'm talking about the cov matrix of the proposal of the states this time, inside each PF). Could you adapt the prior so that the prior probability of this happening is really zero?
In that case, pmmh
will not even run the PF, and the problem should not arise.
Thanks for your response. It isn't clear to me how I could give the proposal covariance for the simulation of the new $\theta^p$. But unless this it is well explaind in the notebook tutorials.
My covariance matrix gets singular if it appears that $\gamma=0$ is chosen. But since I gave as a prior a truncated normal distirbution which is truncated at $10^{-5}$ this should not be possible, because 0 is out of range. But still it simulates $\gamma=0$ or at least so small that the values in the covariance matrix become numerically indistinguishable close I guess.
First, to set the covariance matrix of the proposal, use argument rw_cov
; see here:
https://particles-sequential-monte-carlo-in-python.readthedocs.io/en/latest/_autosummary/particles.mcmc.PMMH.html#particles.mcmc.PMMH
But now that you mention it, I can see that the docstring is not super-clear... I'll try to fix it shortly.
Second, yes, you're right, a value below $10^{-5}$ should not be proposed, since it's outside the prior range. I'll look into it, but, in the mean time, you could adapt your model to forbid values below $10^{-5}$ (e.g. by forcing $\gamma$ to be $=10^{-5}$ whenever the supplied value is smaller.
More details are now given in the docstrings of PMMH and parent classes regarding parameter rw_cov
, and more generally how to calibrate random walk proposals.
Hello again,
I am still trying to implement particle filters for the following SDE-model:
$$ \begin{cases} dS(t) = -\alpha S(t)I(t)dt+\frac{1}{\sqrt{100}}\sqrt{\alpha S(t)I(t)}dB_1(t) \ dI(t) = \alpha S(t)I(t)-\gamma I(t)dt-\frac{1}{\sqrt{100}}\sqrt{\alpha S(t)I(t)}dB_1(t)+\frac{1}{\sqrt{100}}\sqrt{\gamma I(t)}dB_2(t) \end{cases} $$
For $X=(S,I)^T$ this can be written as
$$ dX(t) = \mu(X(t))dt+\sigma(X(t))dB(t) $$
with
$$ \mu(X)=\left(\begin{array}{c} -\alpha X[1]X[2] \ \alpha X[1]X[2]-\gamma*X[2] \end{array}\right) \text{ and } \sigma(X)=\frac{1}{\sqrt{100}}\left(\begin{array}{cc} \sqrt{\alpha X[1]X[2]} & 0\ -\sqrt{\alpha X[1]X[2]} & \sqrt{\gamma X[2]} \end{array}\right) $$
The symmetric product of the diffusion coefficient would then be the positive (semi-)definite matrix
$$ \Sigma(X)=\frac{1}{100}\left(\begin{array}{cc} \alpha X[1]X[2] & -\alpha X[1]X[2]\ -\alpha X[1]X[2] & \alpha X[1]X[2]+\gamma X[2] \end{array}\right) $$
I already saw the new multivariate distribution to deal with varying covariance matrices across particles, thanks for that. I use a similar, self-implemented one. My problem is now, that when I want to run the following code for the guided particle filter:
I eventually get the error message
So I still encounter problems with the covariance matrix. In this case I guess it is because of the parameter values being quite close or below zero. That is why I already gave truncated and log-transformed prios on them to ensure that they don't "destroy" my covariance matrix. But looking on the
pmmh.theta.chain
that is created until I get the error, I see that the parameters are first always being zero and then being values in the order of $10^{-60}$ or even a lot smaller. And this makes my covariance matrix then being either unsolvable for the decomposition or singular since the values are too close together.So my question is, how does the chain sample the parameter vector $\theta=(\beta, \gamma,\sigma)^T$ and is there a way to restric this to some particular space, so that I can avoid to small values for example.
Thanks for your your ideas and help again.