[Date Index]
[Thread Index]
[Author Index]
Re: FindMaximum/NMaximize vs. Excel Solver
*To*: mathgroup at smc.vnet.net
*Subject*: [mg106886] Re: FindMaximum/NMaximize vs. Excel Solver
*From*: John <jhurley13 at gmail.com>
*Date*: Tue, 26 Jan 2010 06:34:12 -0500 (EST)
*References*: <hj98d9$g8f$1@smc.vnet.net>
I received an answer from Daniel Lichtblau at Wolfram, and posed this
additional question:
Stepping back, what would be the right syntax for NMaximize for this
problem:
w is the list of wagers to optimize, a list of 20 elements;
each wager must be between 0 and 100;
the sum of the wagers is 100
It seems gross to list out individual variables when Mathematica is so
powerful at list processing.
Thanks,
John
--------
His response was as follows, and was just what I was looking for,
since I wanted the "Mathematica" way of doing it:
It can be set up as below. Notice I do not explicitly list variables.
probabilities = {0.2,0.2,0.2,0.2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.1,0.1};
len = Length[probabilities];
odds = {7,5,5,5,5,5,5,5,5,5,5,5,5,5,1,1,2,2,2,2};
vars = Array[w,len];
tot = 100;
c1 = Map[#>=0&, vars];
ep = (vars(1+odds)-tot);
sp = ep.probabilities;
var = (ep-sp)^2;
obj = sp / Sqrt[Dot[probabilities,var]];
Timing[NMaximize[{obj,Flatten[{c1,Total[vars]==tot}]}, vars]]
That works, but takes around four times longer than FindMaximum. The
speed of NMaximize is not troubling to me, but FindMaximum might be
slow for this. That is, I'm not sure whether the timing is expected or
indicates a speed bump.
Daniel
--------
In a later message, we were looking at timings:
Daniel,
Thank you so much for your reply. It not only answers my question, but
reminds me how much I still need to learn about Mathematica. If
nothing else, I have to take a long look at "a = b" vs. "a:=b".
I was still curious about why it took so long, and found that
simplifying obj helped speed things up by 20% or so:
obj = sp/Sqrt[Dot[probabilities, var]] // Simplify;
Timing[NMaximize[{obj, Flatten[{Total[vars] == tot, c1}]}, vars,
AccuracyGoal -> 6, PrecisionGoal -> 9]]
Just for fun, I tried the different methods available from NMaximize,
and found:
SimulatedAnnealing 19.2039
RandomSearch 1329.74
DifferentialEvolution 18.9437
NelderMead 99.743
Default 23.7308
FindMaximum 5.43854
If it is OK with you, I'd like to post your response back to the group
since it helped me so much; I can attribute it to you or to an
anonymous helper. Thanks again.
John
[...]
That's fine with me. Possibly someone will get competitive and maybe
figure out a tweak that makes FindMaximum or NMaximize handle this
faster. For FindMaximum, I doubt it will be method-related because I
believe that function has but one choice (interior point) when given
constraints (unless everything is linear or, at worst, objective is
quadratic).
One possible improvement would be to maximize the square, since (I
think) everything is nonnegative. Could use obj2, given as below.
obj2 = Simplify[Rationalize[obj]^2,
Assumptions -> Map[0 <= # <= 100 &, vars]]
Daniel
One other thing. If you get rid of variables that correspond to zero
probability, the timings become tremendously faster. I do not think
this type of smarts could be automated (in NMaximize or Findmaximum),
unfortunately.
Daniel
----------
I was still curious about why it took so long, and found that
simplifying obj helped speed things up by 20% or so:
obj = sp/Sqrt[Dot[probabilities, var]] // Simplify;
Timing[NMaximize[{obj, Flatten[{Total[vars] == tot, c1}]}, vars,
AccuracyGoal -> 6, PrecisionGoal -> 9]]
Just for fun, I tried the different methods available from NMaximize,
and found:
SimulatedAnnealing 19.2039
RandomSearch 1329.74
DifferentialEvolution 18.9437
NelderMead 99.743
Default 23.7308
FindMaximum 5.43854
Thanks for the replies.
Prev by Date:
**Re: Creating new ColorFunction / ColorDataFunction**
Next by Date:
**Re: More memory-efficient inner product for large last**
Previous by thread:
**Re: FindMaximum/NMaximize vs. Excel Solver**
Next by thread:
**Washington DC Area Mathematica Special Interest Group**
| |