Using Mathematica, I need to optimize a function defined in terms BinCounts; the arguments I want to maximize determine the bin cutoffs.
I think the problem is that Mathematica extends the objective function in terms of the arguments before they get numerical values, so it BinCountscomplains that the bin specification is not a "list containing real values, infinity and -Infinity".
I think the following example is a minimal example of what I'm doing trying to do and what is happening. I would be very grateful for advice on how to solve this problem.
In[1]:= data = RandomReal[1, 30]; (* Make some test data. *)
In[2]:= f[a_, b_, c_] := BinCounts[data, {{0, a, b, c, 1}}] (* Shorthand to use below… *)
In[12]:= g[a_, b_, c_] := Max[f[a, b, c]] - Min[f[a, b, c]] (* Objective function. *)
In[13]:= NMaximize[{g[a, b, c], 0 < a < b < c < 1}, {a, b, c}] (* Try to oprimize. *)
During evaluation of In[13]:= BinCounts::cvals: The bin specification {{0,a,b,c,1}} is not a list containing real values, Infinity, and -Infinity. >>
During evaluation of In[13]:= BinCounts::cvals: The bin specification {{0,a,b,c,1}} is not a list containing real values, Infinity, and -Infinity. >>
During evaluation of In[13]:= BinCounts::cvals: The bin specification {{0,a,b,c,1}} is not a list containing real values, Infinity, and -Infinity. >>
During evaluation of In[13]:= General::stop: Further output of BinCounts::cvals will be suppressed during this calculation. >>
Out[13]= {0., {a -> 0., b -> 0., c -> 1.}}