# Sampling posterior distribution of a function

I have the following problem: let's say I have a function $$y=f(x)$$. Let $$f$$ be defined for all $$x$$ but it it might not be invertible. Further assume $$x \sim p(x)$$ with some probability density $$p(x)$$.

Can I claim that $$p(y)$$ exists and that $$y \sim p(y)$$ if I draw a sample from $$p(x)$$ and compute $$y=f(x)$$?

Let's say further I could draw samples from the conditional probability $$p(x | z)$$. If I use samples from this distribution and evaluate $$y=f(x)$$, will $$y \sim p(y|z)$$?

I'm asking because I'm trying to wrap my head around Thompson sampling using Bayesian Neural Networks and I was wondering if we actually sample from the posterior distribution of the expected reward by sampling the posterior distribution of the Q-network parameters.

Edit: A short explaination of the answer(s) would be greatly appreciated. Thanks!

If $$X$$ is a random variable, values of $$X$$ appear with probabilities $$p(x)$$. If you transform those values using a function $$y = f(x)$$, still each of the transformed values will appear with some probability, i.e. $$Y$$ will be a random variable as well. $$Y$$ may not have "nice" form for the probability distribution, but it will have some probability distribution.
The easiest way to sample from $$Y$$ and then transform the values, if you don't know the distribution of $$Y$$.
If there is $$p(X|Z)$$, then there also is $$p(f(X)|Z)$$, i.e. $$p(Y|Z)$$, since $$Y$$ is transformed $$X$$.
One example of such transformed random variable is $$\chi^2$$ distribution. If $$Z \sim \mathcal{N}(0, 1)$$, then $$Q = Z^2 \sim \chi^2_1$$. Of course, this is an example of a distribution that has "nice", closed-form solution.