How to compute importance sampling? I am trying implement importance sampling of this integral
$$
\mathfrak{I} = \int\limits_{-\infty }^{\infty }{\sqrt{\left| \frac{\theta }{1-\theta } \right|}}f(\theta )\text{d}\theta
$$
where $f(\theta )\propto {{(1+{{\theta }^{2}}/5)}^{-3}}$ is a t-distribution with df=5.
I already sampled from the above distribution and was told to use samples from 1 and 2 below:


*

*Importance function equal to
$$
0.5\{{{g}_{1}}(\theta )+{{g}_{2}}(\theta )\},
$$
where 
$$
{{g}_{1}}(\theta )=\frac{1}{\pi }\frac{1}{1+{{\theta
    }^{2}}}
$$ 
and
$$
{{g}_{2}}(\theta )=\frac{1}{4\sqrt{\left|1-\theta
    \right| }} \quad\text{on}\quad\space [0,2]
$$

*Importance function equal to 
$$
g'(\theta)\propto \frac{1}{\sqrt{\left| 1-\theta  \right|}}\exp (-\left| 1-\theta  \right|)
$$
How should I do this?  I have searched around, and vaguely understands concept.  Could someone explain more in detail what I should do?  Seems like I have all the tools I need.
 A: In case your difficulty is with the simulation per se, here is my R code to compare simulations from $f$ (plain), $g$ equal to
$$
\frac{1}{2} \frac{1}{\pi} \frac{1}{1+x^2} + \frac{1}{2}\frac{1}{4}\frac{\mathbb{I}_{[0,2]}(x)}{\sqrt{|1-x|}}
$$
(mixture of Cauchy and power distributions) and $m$ equal to
$$
\frac{1}{2}\frac{1}{\Gamma(1/2)}\frac{1}{\sqrt{|1-x|}}\exp\{-|1-x|\}
$$
(folded Gamma).
Simulating from $f$ is straightforward
> sam1=matrix(rt(10^6,df=5),ncol=100)
> fam1=h(sam1)

where
> h
function(x){ 
sqrt(abs(x/{1-x}))}

Simulating from $g$ requires simulating from the square-root part. If you integrate out $1/4{\sqrt{|1-x|}}$ over $[0,2]$, you get either $1-\sqrt{1-x}$ over $[0,1]$ or $\sqrt{x-1}$ over $[1,2]$, which means that this distribution can be represented as 
$$
1\pm \mathcal{U}(0,1)^2.
$$
(In the following, I force both subsamples to have the same size $5\cdot10^5$, which is a Rao-Blackwellisation trick to reduce the variance with no impact on the expectation.)
> sam22=1+sample(c(-1,1),5*10^5,rep=TRUE)*runif(5*10^5)^2
> sam21=rcauchy(5*10^5)
> sam2=matrix(sample(c(sam21,sam22)),ncol=100)
> fam2=h(sam2)*dt(sam2,df=5)/g(sam2)

where

g=function(x){.5*dcauchy(x)+.125*((x>0)*(x<2))/sqrt(abs(1-x))}

Simulating from $m$ follows from the folded representation:
> sam3=matrix(1+sample(c(-1,1),10^6,rep=TRUE)*rgamma(10^6,.5),ncol=100)
> fam3=h(sam3)*dt(sam3,df=5)/(.5*dgamma(abs(1-sam3),.5))

The comparison of the three simulation methods is illustrated in the following boxplot (that we should use in the next edition of Monte Carlo Statistical Methods!) 

