I have a similar question compared to this post.
I am trying to maximize a function, which is a black-box to me. I have tools of gradient-free methods; in fact, this problem is reasonably smooth that I can even use the numerical approximation of gradients most of the time. However, there is this last problem: the domain where the function is defined is unknown. I cannot know whether the function is defined at this point before I evaluate it.
Therefore, what I did is if during evaluation I realized this function is undefined, I gave it the value of either
-nan. However, the program sometimes got to this point and try to evaluate its derivatives - and then the program just fails.
I don't think this is a rare problem, so I tried to search the web, but with no luck. I would like to bring this question up here, and would really appreciate any ideas that may help.