Hi! I'm working on using NMaximize to maximize the area overlap between two regions, where NMaximize is maximizing over the space of Affine transformations applied to one of the two regions. I've run into an issue where NMaximize seems to pass the dummy variable names (a,b,c) into the function to be maximized rather than numerical values, which produces an error. Here's my code so far.
j = 3;
regionPreAtOrigin =
TransformedRegion[groupedCellRegionListPre[[j]],
TranslationTransform[-groupedCellCentroidListPre[[j]]]];
regionPostAtOrigin =
TransformedRegion[groupedCellRegionListPost[[j]],
TranslationTransform[-groupedCellCentroidListPost[[j]]]];
affineFunction[a_, b_, c_, d_] :=
Area[RegionIntersection[
TransformedRegion[regionPreAtOrigin,
AffineTransform[{{{a, b}, {c, d}}, {0, 0}}]],
regionPostAtOrigin]]/(Area[
TransformedRegion[regionPreAtOrigin,
AffineTransform[{{{a, b}, {c, d}}, {0, 0}}]]] +
Area[regionPostAtOrigin]/2)
affineFunction[1, 0, 0, 1]
Plot[affineFunction[x, 0, 0, 1], {x, -5, 5}]
NMaximize[affineFunction[x, 0, 0, 1], {x}]
NMaximize[{affineFunction[t1,t2,t3,t4],t1*t4-t2*t3>0},
{t1,t2,t3,t4}]
groupedCellRegionListPre[[j]] and post are both valid regions, the output of "affineFunction[1,0,0,1]' (the identity transformation) outputs ~0.5, which is what I expect, and I know the function works because the plot works fine. I also know it has maximum, from the afforementioned plot. I also added the restriction to NMaximize such that it won't apply any transformations with non-positive determinants, which would produce errors. Despite all this, here is the output for the code above:
I aborted the code because if I leave it running it crashes mathematica. So that's odd as well. Thanks for any help y'all can provide!