t1=cputime;
[est,var1,var2]=control('fn','GG',.438204,200000);
disp(['variance of crude estimator ' num2str(var1/200000)])  % variance of the crude estimator
disp('control variate')
disp([' estimator ' num2str(est) ' variance ' num2str(var2/200000)])
disp(['relative efficiency ' num2str(var1/var2)])
t1=[t1 cputime];
disp('****************************************')

%%%%%%%%%%%%%%%%%%%%%%%%%%%i
disp('stratified')
a=.7;
F=a*fn(unifrnd(0,a,1,100000))+(1-a)*fn(unifrnd(a,1,1,100000));
disp([' estimator ' num2str(mean(F)) ' variance ' num2str(var(F)/length(F))])
disp(['relative efficiency ' num2str(var1/(2*var(F)))])
t1=[t1 cputime];
disp('****************************************')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
disp('Optimized stratified sample')
[est,v,n]=stratified([0 .6 .85 1],200000);
disp([' estimator ' num2str(est) ' variance ' num2str(v)])
disp(['relative efficiency ' num2str(var1/(200000*v))])
t1=[t1 cputime];
disp('****************************************')

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
disp('combined stratified, antithetic')
U=unifrnd(0,1,1,50000);
F=.37*.5*(fn(.47+.37*U)+fn(.84-.37*U))+.16*.5*(fn(.84+.16*U)+fn(1-.16*U));
disp([' estimator ' num2str(mean(F)) ' variance ' num2str(var(F)/length(F))])
disp(['relative efficiency ' num2str(var1/(4*var(F)))])
t1=[t1 cputime];

disp('****************************************')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
disp('importance sampling')
u=rand(1,200000);
[est,v]=importance('fn','importancedens(IM)','Ginverse(u)',u);
disp([' estimator ' num2str(mean(est)) ' variance ' num2str(v/200000)])
disp(['relative efficiency ' num2str(var1/v)])
t1=[t1 cputime];
display(['times ' mat2str(diff(t1))])


   

