# Optimizing a parameter space search

This is related to my previous question: Solve for parameters so that a relation is always satisfied

# The Problem

I am searching the parameter space of a large (many terms) function to find where the value of the function is positive semi-definite on its entire domain. Due to physical reasons, the function will always be pretty compact and quickly asymptote to zero, for reasonable choices of the parameters. All I need is to find 1 set of (non-trivial) values of the parameters so that the function is positive semi-definite everywhere. For clarity, all variables, functions, and parameters are real.

One function I am using is (in standard form):

-(1/2) (1/
4 o y Coth[n nw] Coth[
s sw] (-2 n x Sech[n (-nw + x^2 + y^2)]^2 +
2 n x Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) +
1/4 o x Coth[n nw] Coth[
s sw] (-2 n y Sech[n (-nw + x^2 + y^2)]^2 +
2 n y Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) - (
2 Coth[2] (-8 x y Sech[2 - x^2 - y^2]^2 Tanh[2 - x^2 - y^2] -
8 x y Sech[2 + x^2 + y^2]^2 Tanh[2 + x^2 + y^2]))/(
4 + z^2))^2 + (-((
8 z^2 Coth[2] (Tanh[2 - x^2 - y^2] + Tanh[2 + x^2 + y^2]))/(4 +
z^2)^3) + (
2 Coth[2] (Tanh[2 - x^2 - y^2] + Tanh[2 + x^2 + y^2]))/(4 +
z^2)^2 - (
Coth[2] (-2 Sech[2 - x^2 - y^2]^2 + 2 Sech[2 + x^2 + y^2]^2 -
8 x^2 Sech[2 - x^2 - y^2]^2 Tanh[2 - x^2 - y^2] -
8 x^2 Sech[2 + x^2 + y^2]^2 Tanh[2 + x^2 + y^2]))/(4 + z^2) - (
Coth[2] (-2 Sech[2 - x^2 - y^2]^2 + 2 Sech[2 + x^2 + y^2]^2 -
8 y^2 Sech[2 - x^2 - y^2]^2 Tanh[2 - x^2 - y^2] -
8 y^2 Sech[2 + x^2 + y^2]^2 Tanh[2 + x^2 + y^2]))/(
4 + z^2))^2 - (-(1/4) o x Coth[n nw] Coth[
s sw] (-2 n x Sech[n (-nw + x^2 + y^2)]^2 +
2 n x Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) -
1/4 o y Coth[n nw] Coth[
s sw] (-2 n y Sech[n (-nw + x^2 + y^2)]^2 +
2 n y Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) - (
8 z^2 Coth[2] (Tanh[2 - x^2 - y^2] + Tanh[2 + x^2 + y^2]))/(4 +
z^2)^3 + (
2 Coth[2] (Tanh[2 - x^2 - y^2] + Tanh[2 + x^2 + y^2]))/(4 +
z^2)^2 -
1/2 o Coth[n nw] Coth[
s sw] (-2 s z Sech[s (-sw + z^2)]^2 +
2 s z Sech[s (sw + z^2)]^2) (-Tanh[n (-nw + x^2 + y^2)] +
Tanh[n (nw + x^2 + y^2)]))^2 - (1/
4 o x Coth[n nw] Coth[
s sw] (-2 n x Sech[n (-nw + x^2 + y^2)]^2 +
2 n x Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) - (
Coth[2] (-2 Sech[2 - x^2 - y^2]^2 + 2 Sech[2 + x^2 + y^2]^2 -
8 x^2 Sech[2 - x^2 - y^2]^2 Tanh[2 - x^2 - y^2] -
8 x^2 Sech[2 + x^2 + y^2]^2 Tanh[2 + x^2 + y^2]))/(4 + z^2) +
1/4 o Coth[n nw] Coth[
s sw] (-2 s z Sech[s (-sw + z^2)]^2 +
2 s z Sech[s (sw + z^2)]^2) (-Tanh[n (-nw + x^2 + y^2)] +
Tanh[n (nw + x^2 + y^2)]))^2 - (1/
4 o y Coth[n nw] Coth[
s sw] (-2 n y Sech[n (-nw + x^2 + y^2)]^2 +
2 n y Sech[n (nw + x^2 + y^2)]^2) (-2 s z Sech[
s (-sw + z^2)]^2 + 2 s z Sech[s (sw + z^2)]^2) - (
Coth[2] (-2 Sech[2 - x^2 - y^2]^2 + 2 Sech[2 + x^2 + y^2]^2 -
8 y^2 Sech[2 - x^2 - y^2]^2 Tanh[2 - x^2 - y^2] -
8 y^2 Sech[2 + x^2 + y^2]^2 Tanh[2 + x^2 + y^2]))/(4 + z^2) +
1/4 o Coth[n nw] Coth[
s sw] (-2 s z Sech[s (-sw + z^2)]^2 +
2 s z Sech[s (sw + z^2)]^2) (-Tanh[n (-nw + x^2 + y^2)] +
Tanh[n (nw + x^2 + y^2)]))^2 -
1/2 ((4 z Coth[
2] (-2 x Sech[2 - x^2 - y^2]^2 +
2 x Sech[2 + x^2 + y^2]^2))/(4 + z^2)^2 -
3/4 o Coth[n nw] Coth[
s sw] (-2 n x Sech[n (-nw + x^2 + y^2)]^2 +
2 n x Sech[n (nw + x^2 + y^2)]^2) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) -
1/4 o x Coth[n nw] Coth[
s sw] (-2 n Sech[n (-nw + x^2 + y^2)]^2 +
2 n Sech[n (nw + x^2 + y^2)]^2 +
8 n^2 x^2 Sech[n (-nw + x^2 + y^2)]^2 Tanh[
n (-nw + x^2 + y^2)] -
8 n^2 x^2 Sech[n (nw + x^2 + y^2)]^2 Tanh[
n (nw + x^2 + y^2)]) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) -
1/4 o y Coth[n nw] Coth[
s sw] (8 n^2 x y Sech[n (-nw + x^2 + y^2)]^2 Tanh[
n (-nw + x^2 + y^2)] -
8 n^2 x y Sech[n (nw + x^2 + y^2)]^2 Tanh[
n (nw + x^2 + y^2)]) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) +
1/4 o x Coth[n nw] Coth[
s sw] (-Tanh[n (-nw + x^2 + y^2)] +
Tanh[n (nw + x^2 + y^2)]) (-2 s Sech[s (-sw + z^2)]^2 +
2 s Sech[s (sw + z^2)]^2 +
8 s^2 z^2 Sech[s (-sw + z^2)]^2 Tanh[s (-sw + z^2)] -
8 s^2 z^2 Sech[s (sw + z^2)]^2 Tanh[s (sw + z^2)]))^2 -
1/2 ((4 z Coth[
2] (-2 y Sech[2 - x^2 - y^2]^2 +
2 y Sech[2 + x^2 + y^2]^2))/(4 + z^2)^2 -
3/4 o Coth[n nw] Coth[
s sw] (-2 n y Sech[n (-nw + x^2 + y^2)]^2 +
2 n y Sech[n (nw + x^2 + y^2)]^2) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) -
1/4 o x Coth[n nw] Coth[
s sw] (8 n^2 x y Sech[n (-nw + x^2 + y^2)]^2 Tanh[
n (-nw + x^2 + y^2)] -
8 n^2 x y Sech[n (nw + x^2 + y^2)]^2 Tanh[
n (nw + x^2 + y^2)]) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) -
1/4 o y Coth[n nw] Coth[
s sw] (-2 n Sech[n (-nw + x^2 + y^2)]^2 +
2 n Sech[n (nw + x^2 + y^2)]^2 +
8 n^2 y^2 Sech[n (-nw + x^2 + y^2)]^2 Tanh[
n (-nw + x^2 + y^2)] -
8 n^2 y^2 Sech[n (nw + x^2 + y^2)]^2 Tanh[
n (nw + x^2 + y^2)]) (-Tanh[s (-sw + z^2)] +
Tanh[s (sw + z^2)]) +
1/4 o y Coth[n nw] Coth[
s sw] (-Tanh[n (-nw + x^2 + y^2)] +
Tanh[n (nw + x^2 + y^2)]) (-2 s Sech[s (-sw + z^2)]^2 +
2 s Sech[s (sw + z^2)]^2 +
8 s^2 z^2 Sech[s (-sw + z^2)]^2 Tanh[s (-sw + z^2)] -
8 s^2 z^2 Sech[s (sw + z^2)]^2 Tanh[s (sw + z^2)]))^2


In this example, the parameter space is 5 dimensional with parameters $$o$$, $$s$$, $$sw$$, $$n$$, $$nw$$. However, I also have cases where it can be up to 10 dimensional, involving functions like Tanh and Exp. It's worth noting, in the above example function, the only positive definite term is independent of the parameters, so I need to find the parameters that minimize the negative terms so that the positive term dominates everywhere.

# Attempts

Thanks to the insight afforded to me in my previous question, I found the mathematica functions ForAll, resolve, and FindInstance can do the job for simple functions. I left the code

ForAll[{x,y,z}, Function>=0];
Resolve[%, Reals]


running overnight on the above example function and it still didn't have a result in the morning. Perhaps expected since the function is pretty complicated.

I also tried

ForAll[{x,y,z}, Function>=0];
FindInstance[%, {s,o,l}, Reals]


With similar results. It's actually running as I type this question out and still hasnt returned anything for an hour. I would expect it to be a bit quicker to return atleast something, since the function quickly asymptotes to zero, is pretty compact, and whose parameter space is also pretty compact.

I may be interesting to note that that the following code

Exists[{x}, x*Exp[-x^2/s] >= 1]
FindInstance[%, s, Reals]


fails with error on my version 12.1 even though a simple solution is $$s=8$$ for example. But this may be worth another post.

# Ideas

It would be great if I can utilize the power of my external GPU to search the parameter space. I was thinking I could partition the parameter space into even chunks and run a findinstance function on each partition on the GPU. However, I dont even know how findinstance works since it seems to be a proprietary algorithm.

Its also worth mentioning that I dont expect the parameters to take on unreasonable values like >1000 or <0.0000001. Perhaps I could cut out a (sufficiently large) region of the parameter space, partition it, and search the partitions using a parallelized version of FindInstance?

Since this problem is largely numerical, it should be possible to parallelize it and run it on a GPU. Thats my thoughts anyways.

I guess you could classify this problem as an optimization problem, since were basically trying to maximize the area under the curve.

I appreciate any insight you can give!

• Could you include the MATHEMATICA formula instead of Latex? Nov 27, 2020 at 13:45
• yes, of course. I suppose that would make more sense! Nov 27, 2020 at 14:03
• This is likely to be very hard by brute force: the parameter space is too large. Do you have intuition / physical reasons to suggest or limit the values of the parameters? Nov 27, 2020 at 17:01
• Luckily, yes. I have another function that is worked into this one whose parameters arent constrained at all (I set them myself). So I expect the parameters used in the example function above are of the same order as the ones I set myself. I dont expect the parameters to be any larger than 10 or smaller than 0.00001 for example. How would I scan over a continuous range of real numbers like that? Nov 27, 2020 at 17:48