Suppose I want to sample from a continuous distribution $p(x)$. If I have an expression of $p$ in the form
$$p(x) = \sum_{i=1}^\infty a_i f_i(x)$$
where $a_i \geqslant 0, \sum_i a_i= 1$, and $f_i$ are distributions which can easily be sampled from, then I can easily generate samples from $p$ by:
- Sampling a label $i$ with probability $a_i$
- Sampling $X \sim f_i$
Is it possible to generalise this procedure if the $a_i$ are occasionally negative? I suspect I've seen this done somewhere - possibly in a book, possibly for the Kolmogorov distribution - so I'd be perfectly happy to accept a reference as an answer.
If a concrete toy example is helpful, let's say I'd like to sample from $$p(x,y) \propto \exp(-x-y-\alpha\sqrt{xy})\qquad x,y > 0$$ I'll then take $\alpha \in (0, 2)$ for technical reasons which should not matter too much, in the grand scheme of things.
In principle, I could then expand this as the following sum:
$$p(x,y) \propto \sum_{n=0}^\infty \frac{(-1)^n \alpha^n \left( \frac{n}{2} \right)! \left( \frac{n}{2} \right)!}{n!} \left( \frac{x^{n/2} e^{-x}}{\left( \frac{n}{2} \right)!}\right) \left( \frac{y^{n/2} e^{-y}}{\left( \frac{n}{2} \right)!}\right) .$$
The $(x,y)$-terms inside the sum can then be independently sampled from as Gamma random variates. My issue is evidently that the coefficients are "occasionally" negative.
Edit 1: I clarify that I am seeking to generate exact samples from $p$, rather than calculating expectations under $p$. For those interested, some procedures for doing so are alluded to in the comments.
Edit 2: I found the reference which includes a particular approach to this problem, in Devroye's 'Non-Uniform Random Variate Generation'. The algorithm is from 'A Note on Sampling from Combinations of Distributions', of Bignami and de Matteis. The method is effectively to bound the density from above by the positive terms of the sum, and then use rejection sampling based on this envelope. This corresponds to the method described in @Xi'an's answer.