如何在MATLAB的全局优化工具箱中定义要优化的目标函数变量?

时间:2019-08-23 19:12:43

标签: matlab particle-swarm

我有一个目标函数fun,其中输入参数x应通过particleswarm()https://de.mathworks.com/help/gads/particleswarm.html

进行优化。

我想为已定义的方案找到x的最佳值。因此,除了x函数fun还接受方案参数s1s2

function f = objective(x, s1, s2)

现在,如何告诉求解器仅优化x并忽略s1s2的输入参数?

1 个答案:

答案 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))