Re: [TS 34965]--Re:large input to NMinimize causes NMinimize:"bcons" along with Less:nord ... and I don't think it should

*To*: mathgroup at smc.vnet.net*Subject*: [mg72581] Re: [TS 34965]--Re:large input to NMinimize causes NMinimize:"bcons" along with Less:nord ... and I don't think it should*From*: "Chris Chiasson" <chris at chiasson.name>*Date*: Thu, 11 Jan 2007 02:40:28 -0500 (EST)*References*: <200701101730.l0AHU1De026015@localhost.localdomain>

On Wed, 10 Jan 2007 17:30:01 UT, Tom Zeller wrote: > Chris, > > This one was just assigned to me yesterday. I apologize for the delay > in responding. I wonder what they were doing with my email in the mean time. > The first thing I tried was to get a simpler version of the code. > > In[17]:= > NMinimize[{b[1]*h[1],-1+Sqrt[(9000000000000*Piecewise[{{Sqrt[-200/3+h[1]^2]/2,\ > Im[Sqrt[-200+3*h[1]^2]]\[Equal]0&&Sqrt[-600+9*h[1]^2]<3*h[1]},{h[1]/2,Im[ > Sqrt[-200+3*h[1]^2]] > ¡Ù 0&&Sqrt[-600+9*h[1]^2]>=3*h[1]}}]^2)]¡Ü0},{b[ > 1],h[1]}] For some reason, I am seeing non ASCII characters (¡Ù,¡Ü) in this command. Something must have happened with the email. :-[ I have also been experimenting with reducing the complexity of the argument. As I mentioned earlier, the Piecewise statements were created with Piecewise[{{y,Im[y]==0&&y<h[i]/2}},h[i]/2] where y has a square root in it. I have taken another look at the code and I realized that when the argument to the square root (inside y) is positive, that y is always less than h[i]/2 - so that comparison may be dropped. Furthermore, I wrote a Cases statement for y that captures arg in Power[arg_,1/2] and then outputs arg>0 as the Piecewise condition. This eliminated the problems with NMinimize::bcons, until I increased the number of segments that I was trying to handle (the maximum value of i, which was originally 5, then 6, 7, 8, & 9) to 10 -- then NMinimize::bcons came back. Anyway, there is some kind of problem that happens when the complexity of the constraints is too high. I guess the developer(s) that wrote the routines might be able to diagnose what is going wrong, but I am giving up for now and going back to filtering my NMinimize argument. > Then I tried to work with the argument to eliminate the invalid comparison (thinking that that may be getting in the way.) I tried arbitrary values and found: By the way, both Piecewise and And have the attribute HoldAll. As far as I can tell, Piecewise evaluates conditions in order until one is True - and then evaluates the corresponding value entry. And evaluates conditions in order, stopping if it ever encounters a False. This means that, barring problems where the complex magnitude was below the threshold specified by Experimental`$EqualTolerance, Im[y]==0&&y<h@i/2 should not have produced Less::nord. > Wrapping the Sqrt's in Im did the trick (but may mess unacceptably with what you are trying to do): > > In[21]:= > -1+Sqrt[(9000000000000*Piecewise[{{Sqrt[-200/ > 3+h[1]^2]/2,Im[Sqrt[-200+3*h[1]^2]]\[Equal]0&&Im[ > Sqrt[-600+9*h[1]^2]]<3*h[ > 1]},{h[1]/2,Im[Sqrt[-200+3*h[1]^2]]¡Ù 0&&Im[ > Sqrt[-600+9*h[ > 1]^2]]>=3*h[1]}}]^2)]/. {b[1]\[Rule]1 ,h[1]\[Rule]1} > > Out[21]= > 1499999 > > > Still the bcons error appears with/without the Method setting: > > In[25]:= > NMinimize[{b[1]*h[1],-1+Sqrt[(9000000000000*Piecewise[{{Sqrt[-200/3+h[1]^2]/2,\ > Im[Sqrt[-200+3*h[1]^2]]\[Equal]0&&Im[Sqrt[-600+9*h[1]^2]]<3*h[1]},{h[1]/2,Im[ > Sqrt[-200+3*h[1]^2]]¡Ù 0&&Im[Sqrt[-600+9*h[1]^2]]>=3*h[ > 1]}}]^2)]},{b[1],h[1]}] > > From In[25]:= > \!\(\* > RowBox[{\(NMinimize::"bcons"\), \(\(:\)\(\ \)\), "\<\"The following > constraints are not > valid: \\!\\({\\(\\(-1\\)\\) + \\(\\(3000000\\\\ \\@\\(\\((\\(\ > \[Piecewise] \\*GridBox[{{\\(Times[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\), \\({\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)}\\)}, {\\(Times[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\), \\({\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)}\\)}}, ColumnAlignments -> {Left}, ColumnSpacings -> 1.2]\ > \\))\\)\\^2\\)\\)\\)}\\). Constraints should be equalities, inequalities, or \ > domain specifications involving the variables. \\!\\(\\*ButtonBox[\\\"More¡\\\ > \", ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ > ButtonData:>\\\"NMinimize::bcons\\\"]\\)\"\>"}]\) > > Out[25]= > \!\(\* > RowBox[{"NMinimize", "[", > RowBox[{ > RowBox[{"{", > RowBox[{\(b[1]\ h[1]\), ",", > RowBox[{\(-1\), "+", > RowBox[{"3000000", " ", > SqrtBox[ > SuperscriptBox[ > RowBox[{"(", > RowBox[{"\[Piecewise]", GridBox[{ > {\(1\/2\ \@\(\(-\(200\/3\)\) + h[ > 1]\^2\)\), \(Im[\@\(\(-200\) + 3\ h[1]\^2\)] \[Equal] 0 && > Im[\@\(\(-600\) + 9\ h[1]\^2\)] < 3\ h[1]\)}, > {\(h[ > 1]\/2\), \(Im[\@\(\(-200\) + 3\ h[1]\^2\)] ¡Ù 0 && > Im[\@\(\(-600\) + 9\ h[1]\^2\)] ¡Ý 3\ h[1]\)} > }, > ColumnSpacings->1.2, > > ColumnAlignments->{Left}]}], ")"}], \ > "2"]]}]}]}], "}"}], ",", \({b[1], h[1]}\)}], "]"}]\) > > In[26]:= > NMinimize[{b[1]*h[1],-1+Sqrt[(9000000000000*Piecewise[{{Sqrt[-200/3+h[1]^2]/2,\ > Im[Sqrt[-200+3*h[1]^2]]\[Equal]0&&Im[Sqrt[-600+9*h[1]^2]]<3*h[1]},{h[1]/2,Im[ > Sqrt[-200+3*h[1]^2]]¡Ù 0&&Im[Sqrt[-600+9*h[1]^2]]>=3*h[ > 1]}}]^2)]},{b[ > 1],h[1]},Method\[Rule]"DifferentialEvolution"] > > From In[26]:= > \!\(\* > RowBox[{\(NMinimize::"bcons"\), \(\(:\)\(\ \)\), "\<\"The following > constraints are not > valid: \\!\\({\\(\\(-1\\)\\) + \\(\\(3000000\\\\ \\@\\(\\((\\(\ > \[Piecewise] \\*GridBox[{{\\(Times[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\), \\(And[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\)}, {\\(Times[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\), \\(And[\\(\\(\[LeftSkeleton] 2 \ > \[RightSkeleton]\\)\\)]\\)}}, ColumnAlignments -> {Left}, ColumnSpacings -> \ > 1.2]\\))\\)\\^2\\)\\)\\)}\\). Constraints should be equalities, inequalities, \ > or domain specifications involving the variables. \ > \\!\\(\\*ButtonBox[\\\"More¡\\\", ButtonStyle->\\\"RefGuideLinkText\\\", \ > ButtonFrame->None, ButtonData:>\\\"NMinimize::bcons\\\"]\\)\"\>"}]\) > > Out[26]= > \!\(\* > RowBox[{"NMinimize", "[", > RowBox[{ > RowBox[{"{", > RowBox[{\(b[1]\ h[1]\), ",", > RowBox[{\(-1\), "+", > RowBox[{"3000000", " ", > SqrtBox[ > SuperscriptBox[ > RowBox[{"(", > RowBox[{"\[Piecewise]", GridBox[{ > {\(1\/2\ \@\(\(-\(200\/3\)\) + h[ > 1]\^2\)\), \(Im[\@\(\(-200\) + 3\ h[1]\^2\)] \[Equal] 0 && > Im[\@\(\(-600\) + 9\ h[1]\^2\)] < 3\ h[1]\)}, > {\(h[ > 1]\/2\), \(Im[\@\(\(-200\) + 3\ h[1]\^2\)] ¡Ù 0 && > Im[\@\(\(-600\) + 9\ h[1]\^2\)] ¡Ý 3\ h[1]\)} > }, > ColumnSpacings->1.2, > > ColumnAlignments->{Left}]}], ")"}], \ > "2"]]}]}]}], "}"}], ",", \({b[1], h[1]}\), > ",", \(Method \[Rule] \ > "DifferentialEvolution"\)}], "]"}]\) > > My thought is that NMinimize just does not see Piecewise as valid which is in accordance with the message. It may be that the problem needs to be recast to reflect that limitation. Let me know what if anything, I have missed and I am just picking my way at this point. > > > Tom Zeller > Wolfram Research Technical Support I don't think you missed anything. :-[ It would be nice if there were options to progressively disable the "structure optimization" (or whatever it is trying to do) and someone were to document them. > -------------- > By the way, the an earlier issue that I passed along to Quality control > > "NMinimize calls Attributes which generates ssle error for non argument when real argument of function is tested by NumberQ. " > > has been reported as fixed in development versions of V6. > -------------- If[$UserName==="Chris",Off[Attributes::ssle]] <OriginalCode/> If[$UserName==="Chris",On[Attributes::ssle]] Just kidding :-] -- http://chris.chiasson.name/