简体   繁体   English

使用fmincon函数MATLAB进行定义的步长变化

[英]Make defined step variation with fmincon function MATLAB

I'm using the optimization toolbox "fmincon" of MATLAB, but I'm having the next problem: 我正在使用MATLAB的优化工具箱“ fmincon”,但遇到下一个问题:

I have 6 parameters to vary, a couple of them most vary in even numbers, from 4 to 16 (this values can vary, but always will vary in even numbers). 我有6个参数可以变化,其中几个参数的偶数变化最大,从4到16(此值可以变化,但始终会以偶数变化)。 So let's define them like this: 因此,让我们这样定义它们:

x1=[4:2:16];
x2=[4:2:16];

Another couple of variables must change between 300 and 1500, in steps of 100, I mean: 另外两个变量必须在300到1500之间变化,以100为步长,我的意思是:

x3=[300:100:1500];
x4=[300:100:1500];

The last couple just vary between 4 and 6, like these: 最后一对在4到6之间变化,如下所示:

x5=4:6;
x6=4:6;

The restriction of the parameters are these: 这些参数的限制如下:

x1<=x2
x3<=x4
x5<=x6

A very important thing here is that the variation that makes fmincon can't make little changes, I mean, the first value of x1 which is 4 , can't be 4.0000000001 , because in my objective function that changes will make no difference; 这里非常重要的一点是,使fmincon产生的变化几乎不会发生变化,我的意思是x1的第一个值为4 ,不能为4.0000000001 ,因为在我的目标函数中,变化不会有任何影响; and there is my problem, because the steps are too little, so the variation will make nothing, and the algorithm stops, saying that there's no variation of the objective function. 这是我的问题,因为步数太少,所以变化不会有任何结果,算法会停止运行,并说目标函数没有变化。

I have set in the fmincon , DiffMinChange=1 , and that works for the first iteration, and them, it starts to make too little steps. 我已经设置了fminconDiffMinChange=1 ,并且它适用于第一次迭代,而对于它们,它们开始做的步伐太少了。 This is the initial configuration for fmincon : 这是fmincon的初始配置:

options1 = optimset('Display','iter',...
    'Algorithm','sqp','PlotFcns',@optimplotfval,...
    'MaxIter',400,'MaxFunEvals',2000,'DiffMinChange',1);

The initial restrictions are: 最初的限制是:

A=[1 -1 0 0 0 0;0 0 1 -1 0 0;0 0 0 0 1 -1];
b=[0;0;0];

To be more clear, what I'm looking for is make 3 ranges, lets defined like these: 更清楚地说,我正在寻找的是使3个范围,让我们这样定义:

R1=[x1:2:x2];
R2=[x3:100:x4];
R3=[x5:x6];

EDIT 1: You may to know that each evaluating of the objective function will take about 2-3 hours. 编辑1:您可能会知道,对目标函数的每次评估大约需要2-3个小时。

As you can see, finally what I'm looking for is the variation of an interval, for that reason the limit in the beginning can't be bigger than the limit in the top, otherwise the rank will be empty. 如您所见,最后我要寻找的是间隔的变化,因此,开始时的限制不能大于顶部的限制,否则排名将为空。

Well, this doesn't address how to make fmincon respect these constraints, but just a potential thought... 好吧,这并不涉及如何使fmincon尊重这些约束,而只是一种潜在的想法...

Given the ranges you want, you have a 7x7x13x13x3x3 space of potential variable combinations, which is a total of ~75000 combinations, before you restrict to x1<=x2, x3<=x4, x5<=x6. 给定所需的范围,在限制为x1 <= x2,x3 <= x4,x5 <= x6之前,您有7x7x13x13x3x3x3的潜在变量组合空间,总计约75000个组合。 That's not a huge space - why not just evaluate the objective function at every combination of the parameters, and then use min to find the minimum of your objective function? 那不是一个很大的空间-为什么不只对每个参数组合都评估目标函数,然后使用min来找到目标函数的最小值?

Since fmincon is an optimizer for continuous problems, and your problem is discrete, there is a misfit between problem and solution approach, see for instance wiki . 由于fmincon是针对连续问题的优化器,并且您的问题是离散的,因此问题和解决方案方法之间存在不匹配的地方,例如参见wiki

You could try a discrete optimization solver, such as branch and bound . 您可以尝试使用离散优化求解器,例如branch和bound Since the number of points in your feassible region is quite limited, a brute force approach could also work (depends on the time your objective function needs). 由于您的可行区域中的点数非常有限,因此也可以使用蛮力方法(取决于目标功能所需的时间)。 Something like this should work for your objective function fun : 这样的事情应该对您的目标函数fun

lb = [4 4 300 300 4 4]; % lower bound
st = [2 2 100 100 1 1]; % step size
ub = [16 16 1500 1500 6 6]; % upoper bound

% init the best solution as infinity
bestF = inf;
bestX = nan(6,1);

% construct all permutations
for idx = 1:numel(lb)
    % construct range
    nextRange = (lb(idx):st(idx):ub(idx))';
    if (idx==1)
        permutations = nextRange;
    else
        a = repmat(permutations,numel(nextRange),1);
        b = repmat(nextRange,1,size(permutations,1))';
        permutations = [a,b(:)];
    end
    % remove permutations that do not satisfy constraints
    if (idx==2)
        permutations(permutations(:,1) > permutations(:,2),:) = [];
    end
    if (idx==4)
        permutations(permutations(:,3) > permutations(:,4),:) = [];
    end
    if (idx==6)
        permutations(permutations(:,5) > permutations(:,6),:) = [];
    end
end

N = size(permutations,1);

assert(N == 7*4 * 13*7 * 6)

for idx = 1:N
    candX = permutations(idx,:)';
    % evaluate ...
    candF = fun(candX);
    % ... and if improvement, update best
    if (candF < bestF)
        bestF = candF;
        bestX = candX;
    end
end

% results
bestF
bestX

The number of permutations equals 15288, so if your objective function fun needs .1 seconds (which is quite a lot ;)), you have to wait for 25 minutes for an answer. 排列数等于15288,因此,如果您的目标函数fun需要.1秒(这是很多;)),则必须等待25分钟才能得到答案。

I've been reading in a lot of forums, and I found a very interesting solution, I tried and actually it works pretty well. 我在许多论坛上都读过书,发现了一个非常有趣的解决方案,我尝试了一下,实际上效果很好。 What I found is that there are some differences between the objective functions. 我发现目标功能之间存在一些差异。 What I been trying here is using fmincon, but this function only works for objective functions that changes in all the range, in other words, is differenciable in all the range. 我在这里尝试使用的是fmincon,但是此功能仅适用于在所有范围内都发生变化的目标函数,换句话说,在所有范围内都可以区分。 But here there is a difference because this function only works with some specific values, and the objective function will be the same if the variation is not significant; 但是这里有所不同,因为此函数仅适用于某些特定值,并且如果变化不大,则目标函数将相同。 in other words, is not differenciable in all the range. 换句话说,并非在所有范围内都是可区分的。 What I found, is that there's a function in MATLAB called "patter search", and I tried and I got wonderfull results, It quite similar to fmincon, but it works different. 我发现,在MATLAB中有一个名为“模式搜索”的函数,我尝试了一下,并得到了不错的结果,它与fmincon十分相似,但工作原理不同。 I recomend it for this kind of problems. 对于这种问题,我建议这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM