gpt4 book ai didi

wolfram-mathematica - 使用 Mathematica 优化 : Use BinCounts in Objective Function

转载 作者:行者123 更新时间:2023-12-04 21:00:10 25 4
gpt4 key购买 nike

使用 Mathematica,我需要优化根据 BinCounts 定义的函数;
我想最大化的参数定义了 bin 分割点。

我认为问题在于 Mathematica 扩展了目标函数
就参数而言,在它们被赋予数字之前
值,所以 BinCounts提示 bin 规范不是“a
包含实数值、Infinity 和 -Infinity 的列表”。

我认为以下是我这种事情的一个最小例子
试图做和正在发生的事情。我将非常感谢您的建议
如何解决这个问题。

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

最佳答案

解决方案只是指定目标函数仅根据数字参数定义,如下所示:

g[a_?NumericQ, b_?NumericQ, c_?NumericQ] := Max[f[a, b, c]] - Min[f[a, b, c]]

关于wolfram-mathematica - 使用 Mathematica 优化 : Use BinCounts in Objective Function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1522537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com