I would like to do a 2D functional integration with 2D bounds. That is, I would like to integrate over a non-rectangular region, with things like AdaptiveIntegratorMultiDim or GSLMCIntegrator. Is this possible? It seems that only rectangular regions are supported, but I want to make sure.
That is very helpful. Since I have a slightly different problem, I run it past you:
The boundaries are different: I need x>1-0.5y-0.5sqrt(y^2-a^2). This is easily done by changing the example a bit. See below:
double f2(const double *X)
//if(x<=1.0 - 0.5*y - 0.5*sqrt(y*y-a*a)) return 0;
double f = 0.0;
double t = X; // "t" (i.e. the original "x")
double y = X; // "y"
double x = (0.5*y + 0.5*sqrt(y*y-a*a)) * t + (1.0 - 0.5*y - 0.5*sqrt(y*y-a*a)); // calculate new "x"
//when t=0, x = 1.0 - 0.5*y - 0.5*sqrt(y*y-a*a), i.e. the lower bound.
//when t=1, x=1
// calculate the original function "f(x,y)"
f = 1.0/(x+y-1.0-a*a/4);
f *= (0.5*y + 0.5*sqrt(y*y-a*a)); // multiply the result by "dx/dt"
The real follow-up question is whether this is also applicable to TFoam densities. I see that it is applicable to all cases of simple integration, but TFoam is sampling from the distribution also. I see no reason why the method should not work (it is just calculus I guess). But do the experts see some problem with shifting basis in this way for the density function in TFoam? Explicitly, could I set the function above via TFoam->SetRho(f2), and expect better sampling than the brutal method?
Of course I will experiment with it, but any expert comments are welcome.
EDIT. I added part of the function I am sampling/integrating to show that there is at least a potential problem with divergence.
It seems that since my function is singular if you get too far out of the region, that the change of variables does not work.
The constraint x>1 - 0.5y - 0.5sqrt(yy-aa) results in x+y>1+a*a/4+O(a^4). So the constraint keeps the denominator from becoming singular. When I change variables, the formula is evaluated at a singular value.
I don’t immediately see how to avoid this. I keep looking. Any thoughts?
I was wrong about the singular values and solved it. (Was due to y values leaving valid regions).
I checked TFoam, and it seems I must apply the original transformation in the sampling phase if I expect to get sampled data in the original x,y.