Sample from distribution important sampling

86 Views Asked by At

I am currently studying Monte Carlo methods and have some trouble understanding how to use importance sampling to perform Monte Carlo integration. What I don't understand will probably be best shown with an example.

Say I have some function $f(x)=x(1-x)$ and I want to estimate the integral of it between $0$ and $1$. To do it I use importance sampling. I choose $p(x)=\sin(x)$, then the integral is equal to $\frac1N \sum\frac{f(x)}{p(x)}$, but I need to sample my points accordingly to the distribution $\sin(x)$ and I am a bit unsure on how to do it in practice.
If I generate random numbers uniform on $(0,1)$ and the evaluate that for pdf $\sin(x)$ so that I get my points from $points=\sin(x)$, and then to obtain the integral I just evaluate my sum with the points I just sampled. When I try to do so I get a value very far from true value of $1/6$.

The result is way better when I just sample $X$ as normal distribution and do ordinary Monte Carlo integration. What do I do wrong and how should I think about it?