5

Mathematica を使用して、次のように定義された関数を最適化する必要がありBinCountsます。最大化したい引数は、ビンのカットポイントを定義します。

問題は、Mathematica が数値を与える前に引数に関して目的関数を展開することだと思います。そのためBinCounts、bin 仕様は「実数値、無限大、および -無限大を含むリスト」ではないと不平を言います。

以下は、私がやろうとしていることと何が起こっているかの最小限の例だと思います。この問題に対処する方法についてアドバイスをいただければ幸いです。

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.}}
4

1 に答える 1

3

解決策は、次のように、目的関数が数値引数に関してのみ定義されるように指定することです。

g[a_?NumericQ, b_?NumericQ, c_?NumericQ] := Max[f[a, b, c]] - Min[f[a, b, c]]
于 2009-10-06T09:49:09.217 に答える