3D阵列最小化(优化)
假设我有以下5x5x5 3D数组,由二进制值组成:
space = [
[[0,1,0,0,1], [1,0,0,1,0], [0,1,0,1,1], [0,0,0,1,1], [0,1,1,0,1]],
[[1,1,1,0,1], [0,0,0,1,0], [0,0,1,1,1], [0,0,0,1,1], [0,1,0,0,0]],
[[0,1,0,1,0], [1,1,0,0,0], [1,0,0,1,0], [0,1,1,1,0], [0,1,1,1,1]],
[[0,1,0,1,0], [0,1,0,1,1], [1,1,0,1,0], [1,0,0,1,0], [0,0,0,0,0]],
[[1,0,0,1,1], [0,1,1,0,1], [0,1,0,1,1], [0,1,1,0,1], [1,0,1,0,0]],
]
和一个功能measure(space)
,该将此3D数组作为输入,并返回一个实际值。我的目标是找到最佳space
配置,该配置返回最小MEATE()
输出。
我如何使用 将 1d-array 作为输入(或您认为更适合此问题的任何其他功能/库)解决此优化问题?
编辑:要澄清,measure()
函数将3D数组转换为CAD模型(其中1
:solid; solid; 0 < /code>:void),然后将3D几何形状传递到电磁求解器(天线模拟器)中,以获取描述天线“效率”的结果(指标描述的效率越低,值越低,则越好天线的性能)。
Suppose I have the following 5x5x5 3D array, consisting of binary values:
space = [
[[0,1,0,0,1], [1,0,0,1,0], [0,1,0,1,1], [0,0,0,1,1], [0,1,1,0,1]],
[[1,1,1,0,1], [0,0,0,1,0], [0,0,1,1,1], [0,0,0,1,1], [0,1,0,0,0]],
[[0,1,0,1,0], [1,1,0,0,0], [1,0,0,1,0], [0,1,1,1,0], [0,1,1,1,1]],
[[0,1,0,1,0], [0,1,0,1,1], [1,1,0,1,0], [1,0,0,1,0], [0,0,0,0,0]],
[[1,0,0,1,1], [0,1,1,0,1], [0,1,0,1,1], [0,1,1,0,1], [1,0,1,0,0]],
]
and a function measure(space)
which takes this 3D array as the input, and returns a real value. My goal is to find the best space
configuration that returns the minimum measure()
output.
How may I use scipy.optimize.minimize
which takes a 1D-array as input (or any other function/library you might think is more appropriate for this problem) to solve this optimization problem?
EDIT: To clarify, the measure()
function converts the 3D array into a CAD model (where 1
: solid; 0
: void), and passes the 3D geometry into an electromagnetic solver (antenna simulator) to get a result describing the "efficiency" of the antenna (sort of what the metric describes, except the lower the value is, the better the performance of the antenna).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要使用一维优化功能,至少有三种(肯定更多)可以采用:
蛮力,在您的情况下,它将尝试2 ** 125,这似乎有点太多。
使用Montecarlo,即生成随机
解决方案,直到找到最好的或至少一个足够好的解决方案
的解决方案,这可能是您可以获得的最好的
对于这个问题。您可以使用 pygad
如果不是最好的话,请花很多时间获得一个好的解决方案。
在这里,我举了一个示例,您只需要指定fitness_function,在这种情况下,它可能会找到最佳解决方案。
通常,不知道如何“测量”保证最佳解决方案的唯一方法是蛮力。如果您知道“测量”的外观,则使用“数学”可能是第四种方法。但是在大多数情况下,遗传算法是针对此优化问题的足够解决方案。
Don't use a 1d optimization function, there are at least three (surely more) approaches you can take:
Brute force, in your case that would be trying 2**125, which seems a bit too much.
Using MonteCarlo, i.e generating random
solutions till finding the best, or at least one that is good enough
Using genetic algorithms, which will be probably the best you can get
for this problem. You can use PyGAD for instance, and it won't
take much time to get a good solution if not the best.
Here I put an example working where you only need to specify your fitness_function, in this case it will likely find the best solution.
In general without knowing how "measure" the only approach that guarantee the best solution is brute force. If you know how "measure" looks like, using "maths" could be a fourth approach. But for most cases the genetic algorithm is a good enough solution for this optimization problem.