我有一个目标函数fun
,其中输入参数x
应通过particleswarm()
:https://de.mathworks.com/help/gads/particleswarm.html
我想为已定义的方案找到x
的最佳值。因此,除了x
函数fun
还接受方案参数s1
和s2
:
function f = objective(x, s1, s2)
现在,如何告诉求解器仅优化x
并忽略s1
和s2
的输入参数?
答案 0 :(得分:1)
我认为应该是这样
$.ajax({
// Get the values of the cce json file
url: 'file.json',
success: function (data) {
data.forEach(function(row) {
if (row.ATTR == feature.properties.AATR) {
// code to execute here
// once the condition is met once, stop execution of foreach
} else {
// some other code to execute
// keep going
}
这就是针对fminunc之类的内置优化器的方法
编辑:然后,如果我正确地理解了particleswarm是您自己编写的优化程序,则particlewarm的函数定义将为
out = particleswarm(@(x)fun(x,s1,s2))
或者,如果您正在执行类似BFGS之类的操作,则需要对优化函数进行初始猜测x0的更改,则可以通过以下方式调用优化器
function [ out ] = particleswarm( func )
函数定义为
out = particleswarm(x0, @(x)fun(x,s1,s2))