2
$\begingroup$

My goal is to use a gradient descent type method to maximize interpolating function1 with respect to the constraint that interpolating function2 <= 0.5. I am working with 4D data (please see below).

I created the two interpolating functions as follows:

f1 = Interpolation[data1, InterpolationOrder -> 1]
f2 = Interpolation[data2, InterpolationOrder -> 1]

And then I used the code outlined in this resource https://library.wolfram.com/infocenter/Books/8506/ConstrainedOptimization.pdf:

NMinimize[{-f2, f1 <=  0.5}, {x, y, z}]
Minimize[{-f2, f1 <=  0.5}, {x, y, z}]
FindMinimum[{-f2, f1 <=  0.5}, {x, y, z}]

NMinimize gives the error message: "NMinimize::bcons: The following constraints are not valid: {InterpolatingFunction[{{4.,8.},{0.5,7.},{0.7,2.}},{5,4225,0,{954,0,6},{2,2,2},0,0,0,0,Automatic,{},{},False},{<<23>>[{<<1>>},{<<1>>},{<<1>>}]},{0.750342,0.64151,0.622998,0.730189,0.236956,0.0920386,0.0884832,<<37>>,0.000752695,0.000144944,0.0000162,3.7210^-6,2.6710^-6,0.316358,<<904>>},{Automatic}]<=<<4>>}. Constraints should be equalities, inequalities, or domain specifications involving the variables."

Minimize gives no resulting value and just outputs the same thing that I input.

Find Minimum gives the error "FindInstance::exvar: The system contains a nonconstant expression InterpolatingFunction[{{4.,8.},{0.5,7.},{0.7,2.}},{5,4225,0,{954,0,6},{2,2,2},0,0,0,0,Automatic,{},{},False},{<<1>>},{0.750342,0.64151,0.622998,0.730189,0.236956,0.0920386,0.0884832,0.948879,<<35>>,0.00922568,0.000752695,0.000144944,0.0000162,3.7210^-6,2.6710^-6,0.316358,<<904>>},{Automatic}] independent of variables {[FormalX],[FormalY],[FormalZ]}."

Any help figuring out how to do this type of optimization will be very greatly appreciated. I have never done this in Mathematica and I am very confused.

Here is some of the data that I used in case anyone wants to test out what I'm talking about:

data1 = {{{4.0, 2.5, 0.7}, 0.750341814}, {{4.0, 2.75, 0.7}, 
   0.641510140}, {{4.0, 3.0, 0.7}, 0.622998451}, {{4.5, 2.3, 0.7}, 
   0.730188891}, {{4.5, 2.6, 0.7}, 0.236956251}, {{4.5, 3.2, 0.7}, 
   0.092038571}, {{4.5, 3.5, 0.7}, 0.088483203}, {{5.0, 2.25, 0.7}, 
   0.948879277}, {{5.0, 2.6, 0.7}, 0.190624075}, {{5.0, 2.95, 0.7}, 
   0.135275036}, {{5.0, 3.3, 0.7}, 0.032763743}, {{5.0, 3.65, 0.7}, 
   0.029430211}, {{5.0, 4.0, 0.7}, 0.027537075}, {{5.5, 2.5, 0.7}, 
   0.281232137}, {{5.5, 2.9, 0.7}, 0.054980707}, {{5.5, 3.3, 0.7}, 
   0.023085488}, {{5.5, 3.7, 0.7}, 0.031317836}, {{5.5, 4.1, 0.7}, 
   0.010820878}, {{5.5, 4.5, 0.7}, 0.010161860}, {{6.0, 2.3, 0.7}, 
   0.397089577}, {{6.0, 2.75, 0.7}, 0.074292346}, {{6.0, 3.2, 0.7}, 
   0.015918433}, {{6.0, 3.65, 0.7}, 0.004494633}, {{6.0, 4.1, 0.7}, 
   0.002195262}, {{6.0, 4.55, 0.7}, 0.001750180}, {{6.0, 5.0, 0.7}, 
   0.001701018}, {{6.5, 2.5, 0.7}, 0.322173220}, {{6.5, 3.0, 0.7}, 
   0.037894300}, {{6.5, 3.5, 0.7}, 0.005178418}, {{6.5, 4.0, 0.7}, 
   0.001170227}, {{6.5, 4.5, 0.7}, 0.001044620}, {{6.5, 5.0, 0.7}, 
   0.000228311}, {{6.5, 5.5, 0.7}, 0.000204873}, {{7.0, 2.15, 0.7}, 
   0.799562745}, {{7.0, 2.7, 0.7}, 0.169379167}, {{7.0, 3.25, 0.7}, 
   0.019800399}, {{7.0, 3.8, 0.7}, 0.001902681}, {{7.0, 4.35, 0.7}, 
   0.000501842}, {{7.0, 4.9, 0.7}, 0.000126206}, {{7.0, 5.45, 0.7}, 
   0.000026700}, {{7.0, 6.0, 0.7}, 0.000020600}, {{7.5, 2.3, 0.7}, 
   1.215594070}, {{7.5, 2.9, 0.7}, 0.050740772}, {{7.5, 3.5, 0.7}, 
   0.009225684}, {{7.5, 4.1, 0.7}, 0.000752695}, {{7.5, 4.7, 0.7}, 
   0.000144944}, {{7.5, 5.3, 0.7}, 0.000016200}, {{7.5, 5.9, 0.7}, 
   0.000003720}, {{7.5, 6.5, 0.7}, 0.000002670}, {{8.0, 2.45, 0.7}, 
   0.316357500}, {{8.0, 3.1, 0.7}, 0.049589355}, {{8.0, 3.75, 0.7}, 
   0.001624453}, {{8.0, 4.4, 0.7}, 0.000321852}, {{8.0, 5.05, 0.7}, 
   0.000043800}, {{8.0, 5.7, 0.7}, 0.000003320}, {{8.0, 6.35, 0.7}, 
   0.000001040}, {{8.0, 7.0, 0.7}, 0.000000425}, {{4.0, 2.0, 0.83}, 
   1.123030977}, {{4.0, 2.25, 0.83}, 0.643862594}, {{4.0, 2.5, 0.83}, 
   0.494527641}, {{4.0, 2.75, 0.83}, 0.460772203}, {{4.0, 3.0, 0.83}, 
   0.449952666}, {{4.5, 2.0, 0.83}, 1.177597462}, {{4.5, 2.3, 0.83}, 
   0.246286304}, {{4.5, 2.6, 0.83}, 0.126303219}, {{4.5, 2.9, 0.83}, 
   0.805843164}, {{4.5, 3.2, 0.83}, 0.064124542}, {{4.5, 3.5, 0.83}, 
   0.063221002}, {{5.0, 1.9, 0.83}, 0.959095797}, {{5.0, 2.25, 0.83}, 
   0.395763200}, {{5.0, 2.6, 0.83}, 0.068053440}, {{5.0, 2.95, 0.83}, 
   0.058924421}, {{5.0, 3.3, 0.83}, 0.018638068}, {{5.0, 3.65, 0.83}, 
   0.016715326}, {{5.0, 4.0, 0.83}, 0.016485697}, {{5.5, 2.1, 0.83}, 
   0.801945073}, {{5.5, 2.5, 0.83}, 0.121609842}, {{5.5, 2.9, 0.83}, 
   0.022526237}, {{5.5, 3.3, 0.83}, 0.010862152}, {{5.5, 3.7, 0.83}, 
   0.010286207}, {{5.5, 4.1, 0.83}, 0.007491423}, {{5.5, 4.5, 0.83}, 
   0.007211895}, {{6.0, 2.3, 0.83}, 0.160576165}, {{6.0, 2.75, 0.83}, 
   0.029644050}, {{6.0, 3.2, 0.83}, 0.007040139}, {{6.0, 3.65, 0.83}, 
   0.003064983}, {{6.0, 4.1, 0.83}, 0.002347885}, {{6.0, 4.55, 0.83}, 
   0.002231154}, {{6.0, 5.0, 0.83}, 0.002229741}, {{6.5, 2.0, 0.83}, 
   0.743003719}, {{6.5, 2.5, 0.83}, 0.091745464}, {{6.5, 3.0, 0.83}, 
   0.011634382}, {{6.5, 3.5, 0.83}, 0.001858806}, {{6.5, 4.0, 0.83}, 
   0.000625568}, {{6.5, 4.5, 0.83}, 0.000476692}, {{6.5, 5.0, 0.83}, 
   0.000270385}, {{6.5, 5.5, 0.83}, 0.000263443}, {{7.0, 2.15, 0.83}, 
   0.289692249}, {{7.0, 2.7, 0.83}, 0.070986865}, {{7.0, 3.25, 0.83}, 
   0.005445419}, {{7.0, 3.8, 0.83}, 0.000569259}, {{7.0, 4.35, 0.83}, 
   0.000184639}, {{7.0, 4.9, 0.83}, 0.000050600}, {{7.0, 5.45, 0.83}, 
   0.000019100}, {{7.0, 6.0, 0.83}, 0.000017700}, {{7.5, 2.3, 0.83}, 
   0.427847385}, {{7.5, 2.9, 0.83}, 0.016100380}, {{7.5, 3.5, 0.83}, 
   0.003665870}, {{7.5, 4.1, 0.83}, 0.000201233}, {{7.5, 4.7, 0.83}, 
   0.000060600}, {{7.5, 5.3, 0.83}, 0.000005190}, {{7.5, 5.9, 0.83}, 
   0.000002460}, {{7.5, 6.5, 0.83}, 0.000002090}, {{8.0, 2.45, 0.83}, 
   0.096275542}, {{8.0, 3.1, 0.83}, 0.017935820}, {{8.0, 3.75, 0.83}, 
   0.000604182}, {{8.0, 4.4, 0.83}, 0.000079200}, {{8.0, 5.05, 0.83}, 
   0.000017500}, {{8.0, 5.7, 0.83}, 0.000000999}, {{8.0, 6.35, 0.83}, 
   0.000000476}, {{8.0, 7.0, 0.83}, 0.000000303}, {{4.0, 2.25, 0.96}, 
   1.177242345}, {{4.0, 2.5, 0.96}, 0.903436502}, {{4.0, 2.75, 0.96}, 
   0.332421564}, {{4.0, 3.0, 0.96}, 0.328294859}, {{4.5, 2.0, 0.96}, 
   0.610951015}, {{4.5, 2.3, 0.96}, 0.673977792}, {{4.5, 2.6, 0.96}, 
   0.108851985}, {{4.5, 2.9, 0.96}, 0.125798036}, {{4.5, 3.2, 0.96}, 
   0.164368921}, {{4.5, 3.5, 0.96}, 0.083522130}, {{5.0, 2.25, 0.96}, 
   0.173705123}, {{5.0, 2.6, 0.96}, 0.414522040}, {{5.0, 2.95, 0.96}, 
   0.197962721}, {{5.0, 3.3, 0.96}, 0.025581569}, {{5.0, 3.65, 0.96}, 
   0.026675785}, {{5.0, 4.0, 0.96}, 0.025212890}, {{5.5, 2.1, 0.96}, 
   0.441425969}, {{5.5, 2.5, 0.96}, 0.044996441}, {{5.5, 2.9, 0.96}, 
   0.306236219}, {{5.5, 3.3, 0.96}, 0.010891276}, {{5.5, 3.7, 0.96}, 
   0.006561283}, {{5.5, 4.1, 0.96}, 0.000851567}, {{5.5, 4.5, 0.96}, 
   0.000718190}, {{6.0, 1.85, 0.96}, 0.807149508}, {{6.0, 2.3, 0.96}, 
   0.065261072}, {{6.0, 2.75, 0.96}, 0.062784999}, {{6.0, 3.2, 0.96}, 
   0.073790906}, {{6.0, 3.65, 0.96}, 0.013393139}, {{6.0, 4.1, 0.96}, 
   0.002261782}, {{6.0, 4.55, 0.96}, 0.001243003}, {{6.0, 5.0, 0.96}, 
   0.001121045}, {{6.5, 2.0, 0.96}, 1.145752994}, {{6.5, 2.5, 0.96}, 
   0.190715368}, {{6.5, 3.0, 0.96}, 0.039221201}, {{6.5, 3.5, 0.96}, 
   0.023321520}, {{6.5, 4.0, 0.96}, 0.000322579}, {{6.5, 4.5, 0.96}, 
   0.000220124}, {{6.5, 5.0, 0.96}, 0.000187539}, {{6.5, 5.5, 0.96}, 
   0.000196152}, {{7.0, 2.15, 0.96}, 0.554272538}, {{7.0, 2.7, 0.96}, 
   0.028907939}, {{7.0, 3.25, 0.96}, 0.009721355}, {{7.0, 3.8, 0.96}, 
   0.002695021}, {{7.0, 4.35, 0.96}, 0.000084600}, {{7.0, 4.9, 0.96}, 
   0.000142253}, {{7.0, 5.45, 0.96}, 0.000037600}, {{7.0, 6.0, 0.96}, 
   0.000034100}};



   data2 = {{{4.0, 2.5, 0.7}, 1825638.3969999999}, {{4.0, 2.75, 0.7}, 
   1724222.467}, {{4.0, 3.0, 0.7}, 1642032.871}, {{4.5, 2.3, 0.7}, 
   1854987.9919999999}, {{4.5, 2.6, 0.7}, 
   1705997.1269999999}, {{4.5, 3.2, 0.7}, 
   1492211.864}, {{4.5, 3.5, 0.7}, 1416414.175}, {{5.0, 2.25, 0.7}, 
   1838521.2130000002}, {{5.0, 2.6, 0.7}, 
   1657210.419}, {{5.0, 2.95, 0.7}, 1515504.514}, {{5.0, 3.3, 0.7}, 
   1403475.8590000002}, {{5.0, 3.65, 0.7}, 
   1313632.943}, {{5.0, 4.0, 0.7}, 1243469.29}, {{5.5, 2.5, 0.7}, 
   1673804.5769999998}, {{5.5, 2.9, 0.7}, 
   1499202.05}, {{5.5, 3.3, 0.7}, 1363569.187}, {{5.5, 3.7, 0.7}, 
   1256514.6809999999}, {{5.5, 4.1, 0.7}, 
   1171796.743}, {{5.5, 4.5, 0.7}, 1105440.165}, {{6.0, 2.3, 0.7}, 
   1761443.8190000001}, {{6.0, 2.75, 0.7}, 
   1537810.2040000001}, {{6.0, 3.2, 0.7}, 
   1370202.236}, {{6.0, 3.65, 0.7}, 1240452.455}, {{6.0, 4.1, 0.7}, 
   1137210.962}, {{6.0, 4.55, 0.7}, 1056733.831}, {{6.0, 5.0, 0.7}, 
   994385.1308}, {{6.5, 2.5, 0.7}, 1641853.405}, {{6.5, 3.0, 0.7}, 
   1425165.07}, {{6.5, 3.5, 0.7}, 1262873.913}, {{6.5, 4.0, 0.7}, 
   1137578.723}, {{6.5, 4.5, 0.7}, 1037990.926}, {{6.5, 5.0, 0.7}, 
   961077.5862}, {{6.5, 5.5, 0.7}, 902696.5156}, {{7.0, 2.15, 0.7}, 
   1836694.5659999999}, {{7.0, 2.7, 0.7}, 
   1537852.989}, {{7.0, 3.25, 0.7}, 
   1328450.5559999999}, {{7.0, 3.8, 0.7}, 
   1171256.773}, {{7.0, 4.35, 0.7}, 1050080.866}, {{7.0, 4.9, 0.7}, 
   954035.877}, {{7.0, 5.45, 0.7}, 880665.0223}, {{7.0, 6.0, 0.7}, 
   825700.3843}, {{7.5, 2.3, 0.7}, 1739780.707}, {{7.5, 2.9, 0.7}, 
   1447164.261}, {{7.5, 3.5, 0.7}, 1241853.154}, {{7.5, 4.1, 0.7}, 
   1089986.5559999999}, {{7.5, 4.7, 0.7}, 
   973268.6319}, {{7.5, 5.3, 0.7}, 882716.8063}, {{7.5, 5.9, 0.7}, 
   812719.8843}, {{7.5, 6.5, 0.7}, 759854.6725}, {{8.0, 2.45, 0.7}, 
   1647668.73}, {{8.0, 3.1, 0.7}, 1366059.112}, {{8.0, 3.75, 0.7}, 
   1168252.432}, {{8.0, 4.4, 0.7}, 1020992.728}, {{8.0, 5.05, 0.7}, 
   908604.2184}, {{8.0, 5.7, 0.7}, 820844.7401}, {{8.0, 6.35, 0.7}, 
   753595.9017}, {{8.0, 7.0, 0.7}, 703633.5985}, {{4.0, 2.0, 0.83}, 
   2018289.761}, {{4.0, 2.25, 0.83}, 1890663.007}, {{4.0, 2.5, 0.83}, 
   1788071.095}, {{4.0, 2.75, 0.83}, 1701044.687}, {{4.0, 3.0, 0.83}, 
   1632910.4419999998}, {{4.5, 2.0, 0.83}, 
   1934243.685}, {{4.5, 2.3, 0.83}, 1779632.375}, {{4.5, 2.6, 0.83}, 
   1657469.8269999998}, {{4.5, 2.9, 0.83}, 
   1557370.45}, {{4.5, 3.2, 0.83}, 1476857.989}, {{4.5, 3.5, 0.83}, 
   1410963.305}, {{5.0, 1.9, 0.83}, 1940867.365}, {{5.0, 2.25, 0.83}, 
   1746026.48}, {{5.0, 2.6, 0.83}, 1596546.918}, {{5.0, 2.95, 0.83}, 
   1477049.404}, {{5.0, 3.3, 0.83}, 1381061.372}, {{5.0, 3.65, 0.83}, 
   1301990.0729999999}, {{5.0, 4.0, 0.83}, 
   1241398.777}, {{5.5, 2.1, 0.83}, 1785463.573}, {{5.5, 2.5, 0.83}, 
   1594840.5790000001}, {{5.5, 2.9, 0.83}, 
   1446892.08}, {{5.5, 3.3, 0.83}, 
   1331446.3059999999}, {{5.5, 3.7, 0.83}, 
   1238565.025}, {{5.5, 4.1, 0.83}, 
   1163619.8090000001}, {{5.5, 4.5, 0.83}, 
   1105297.283}, {{6.0, 2.3, 0.83}, 
   1655369.4740000002}, {{6.0, 2.75, 0.83}, 
   1469443.386}, {{6.0, 3.2, 0.83}, 1325426.857}, {{6.0, 3.65, 0.83}, 
   1212210.146}, {{6.0, 4.1, 0.83}, 1122233.172}, {{6.0, 4.55, 0.83}, 
   1050716.784}, {{6.0, 5.0, 0.83}, 995461.9561}, {{6.5, 2.0, 0.83}, 
   1798291.485}, {{6.5, 2.5, 0.83}, 1546739.957}, {{6.5, 3.0, 0.83}, 
   1363093.63}, {{6.5, 3.5, 0.83}, 1222583.733}, {{6.5, 4.0, 0.83}, 
   1111645.925}, {{6.5, 4.5, 0.83}, 1024967.692}, {{6.5, 5.0, 0.83}, 
   956236.3007}, {{6.5, 5.5, 0.83}, 903703.0732}, {{7.0, 2.15, 0.83}, 
   1700586.6619999998}, {{7.0, 2.7, 0.83}, 
   1453964.937}, {{7.0, 3.25, 0.83}, 
   1273237.4270000001}, {{7.0, 3.8, 0.83}, 
   1135337.705}, {{7.0, 4.35, 0.83}, 1027855.275}, {{7.0, 4.9, 0.83}, 
   943468.5092}, {{7.0, 5.45, 0.83}, 877501.7975}, {{7.0, 6.0, 0.83}, 
   827340.708}, {{7.5, 2.3, 0.83}, 1614584.554}, {{7.5, 2.9, 0.83}, 
   1371301.265}, {{7.5, 3.5, 0.83}, 1194308.89}, {{7.5, 4.1, 0.83}, 
   1059602.106}, {{7.5, 4.7, 0.83}, 955129.4112}, {{7.5, 5.3, 0.83}, 
   873440.8529}, {{7.5, 5.9, 0.83}, 
   810232.4509999999}, {{7.5, 6.5, 0.83}, 
   762267.3347}, {{8.0, 2.45, 0.83}, 1537762.459}, {{8.0, 3.1, 0.83}, 
   1297367.76}, {{8.0, 3.75, 0.83}, 1123677.977}, {{8.0, 4.4, 0.83}, 
   992427.6695}, {{8.0, 5.05, 0.83}, 890887.4116}, {{8.0, 5.7, 0.83}, 
   811914.6927}, {{8.0, 6.35, 0.83}, 751053.9011}, {{8.0, 7.0, 0.83}, 
   705433.4887}, {{4.0, 2.25, 0.96}, 
   1828024.7130000002}, {{4.0, 2.5, 0.96}, 
   1744444.3830000001}, {{4.0, 2.75, 0.96}, 
   1674720.746}, {{4.0, 3.0, 0.96}, 1616854.769}, {{4.5, 2.0, 0.96}, 
   1829325.034}, {{4.5, 2.3, 0.96}, 1710008.313}, {{4.5, 2.6, 0.96}, 
   1610703.7030000002}, {{4.5, 2.9, 0.96}, 
   1527864.519}, {{4.5, 3.2, 0.96}, 
   1459332.9419999998}, {{4.5, 3.5, 0.96}, 
   1403317.9719999998}, {{5.0, 2.25, 0.96}, 
   1661860.34}, {{5.0, 2.6, 0.96}, 1539826.333}, {{5.0, 2.95, 0.96}, 
   1440650.7680000002}, {{5.0, 3.3, 0.96}, 
   1358658.493}, {{5.0, 3.65, 0.96}, 1291758.576}, {{5.0, 4.0, 0.96}, 
   1237451.801}, {{5.5, 2.1, 0.96}, 1675487.35}, {{5.5, 2.5, 0.96}, 
   1523401.9230000002}, {{5.5, 2.9, 0.96}, 
   1400769.7219999998}, {{5.5, 3.3, 0.96}, 
   1301829.295}, {{5.5, 3.7, 0.96}, 1220936.543}, {{5.5, 4.1, 0.96}, 
   1155585.378}, {{5.5, 4.5, 0.96}, 
   1103793.0729999999}, {{6.0, 1.85, 0.96}, 
   1757955.146}, {{6.0, 2.3, 0.96}, 1561884.72}, {{6.0, 2.75, 0.96}, 
   1407948.372}, {{6.0, 3.2, 0.96}, 1285886.175}, {{6.0, 3.65, 0.96}, 
   1187551.9270000001}, {{6.0, 4.1, 0.96}, 
   1108199.767}, {{6.0, 4.55, 0.96}, 
   1044915.8470000001}, {{6.0, 5.0, 0.96}, 
   995178.0803}, {{6.5, 2.0, 0.96}, 
   1663896.2219999998}, {{6.5, 2.5, 0.96}, 
   1464140.99}, {{6.5, 3.0, 0.96}, 1310108.155}, {{6.5, 3.5, 0.96}, 
   1188448.767}, {{6.5, 4.0, 0.96}, 1091521.031}, {{6.5, 4.5, 0.96}, 
   1013705.87}, {{6.5, 5.0, 0.96}, 952292.5175}, {{6.5, 5.5, 0.96}, 
   904596.5571}, {{7.0, 2.15, 0.96}, 1581377.844}, {{7.0, 2.7, 0.96}, 
   1379491.4209999999}, {{7.0, 3.25, 0.96}, 
   1225531.168}, {{7.0, 3.8, 0.96}, 1105133.229}, {{7.0, 4.35, 0.96}, 
   1009706.7059999999}, {{7.0, 4.9, 0.96}, 
   933709.8657}, {{7.0, 5.45, 0.96}, 873895.2218}, {{7.0, 6.0, 0.96}, 
   828561.4393}};
$\endgroup$
10
  • $\begingroup$ Probably you want to use NMinimize[{-f2[x,y,z], f1[x,y,z] <= 0.5}, {x, y, z}]. $\endgroup$ Commented Nov 28, 2021 at 17:18
  • $\begingroup$ Also, many optimization algorithms won't work well because you use InterpolationOrder -> 1. That means that the functions f1 and f2 are not differentiable. InterpolationOrder -> 3 should cure this. $\endgroup$ Commented Nov 28, 2021 at 17:19
  • $\begingroup$ @HenrikSchumacher Thank you! I actually just realized this a moment ago. Unfortunately when I add the [x,y,z] I am still getting errors. It did give a value when I dropped the constraint. Do you have any suggestions? $\endgroup$ Commented Nov 28, 2021 at 17:24
  • $\begingroup$ Depends on the error you get (I have not tried the code myself). $\endgroup$ Commented Nov 28, 2021 at 17:24
  • $\begingroup$ @HenrikSchumacher Every time I tried to increase the interpolation order it gave me an unstructured grid warning. I think this may be fixed by sorting the data (from similar posts I have encountered) but I don't know how to do this for my data set. Do you have any suggestions on how to fix this? Thank you again! $\endgroup$ Commented Nov 28, 2021 at 17:24

1 Answer 1

3
$\begingroup$

You could try somthing like this. Using a MeshRegion as domain guarantess that the optimization algorithm won't leave the domain of definition of f1 and f2. (Using f1 and f2 for extrapolation might do crazy things.) Not having the data, I cannot check whether this works...

R1 = ConvexHullMesh[data1[[All, 1]]];
R2 = ConvexHullMesh[data2[[All, 1]]];
R = RegionIntersection[R1, R2];
f1 = Interpolation[data1, InterpolationOrder -> 1];
f2 = Interpolation[data2, InterpolationOrder -> 1];

sol = NMinimize[
        {-f2[x, y, z], f1[x, y, z] <= 0.5}, 
        {x, y, z} \[Element] R
      ]

X = {x, y, z} /. sol[[2]];
f1 @@ X <= 0.5
RegionMember[R, X]

True

True

For some reason, the kernel crashes on this. But as piecwise-linear functions on some tetrahedral mesh are minimized: Those attain there extrema also on the set of vertices -- and the latter are precisely the points in the datasets. So this should also find the minimum:

pos = Position[data1[[All, 2]], _?(# <= 0.5 &)];
minind = Ordering[Extract[-data2[[All, 2]], pos], -1, 1][[1]];
minimum = data2[[pos[[minind, 1]], 1]]
minvalue = data2[[pos[[minind, 1]], 2]]

{8., 7., 2.}

722571.

$\endgroup$
18
  • $\begingroup$ Thank you for your response! I have tried it and I got several errors before the kernel quits. I have updated the data so the {x,y,z} regions match $\endgroup$ Commented Nov 28, 2021 at 17:47
  • $\begingroup$ @HenrikSchumacher data1and data2 are provided at the and of the question. Itrie your code: It evaluates together with some messages {-2.40514*10^6, {x -> 1.08319, y -> 1.66811, z -> 1.25984}} $\endgroup$ Commented Nov 28, 2021 at 17:47
  • 1
    $\begingroup$ @mathemagician617 Yes it runs without crash but gives several messages $\endgroup$ Commented Nov 28, 2021 at 17:50
  • 1
    $\begingroup$ Hm. "NelderMead" was probably not a good idea. It seems to work when I remove it. I think the remaining messages pop up only because the iterates of the optimization algorithm temporarily leave the domains of f1 and f2. Since the final point is feasible, I would not wonder to much about that. But I am not sure whether the point found is indeed the global optimum. $\endgroup$ Commented Nov 28, 2021 at 17:57
  • 1
    $\begingroup$ However, a piecewise-linear function (that's what you generate with InterpolationOrder -> 1) attains its maximum and minimum always on a vertex of the underlying triangulation. So pos = Position[data1[[All, 2]], _?(# <= 0.5 &)]; minind = Ordering[Extract[data2[[All, 2]], pos], -1, 1][[1]]; minimum = data2[[pos[[minind, 1]], 1]] minvalue = data2[[pos[[minind, 1]], 2]] should give you the minimal point. $\endgroup$ Commented Nov 28, 2021 at 18:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.