How to define the objective function to solve an optimization problem with Matlab?

Dear all,
I have an optimization problem, but I don’t know how to define the minimization function properly and which optimization algorithm available in Maltab is the most appropriate.
I had previously used fminsearch to curve fitting a fractional derivative model to experimental data and it was OK. However, now I don’t have an analytical equation and so I don’t know how to define the minimization function of even if it is possible to use the Matlab Optimization toolbox for that.
I have the experimental vibration spectrum of hundreds of machines and their division by a pattern spectrum, which I would call Failure spectrum from now on. The aim of the optimization is to define a limit function that will lead to X % of defective machines. The limit is not constant in frequency, it is the following function:
Ylim, 1=< x <= xini
Ylim/ratio, xini< x <= xini+wide
Ylim, xini+wide< x <= 500
where the variables to be optimized are Ylim, ratio, xini and wide.
The code I have written does the following:
  1. Initialize the variables and obtain the limit function.
  2. Compare the first failure spectrum with the limit function, if the failure spectrum is bigger than the limit at any frequency count 1 and continue with the next failure spectrum.
  3. Calculate the error between the define defective by the user and the defective obtain with the actual limit function. This error is the minimized function.
I have first tried with frmincon to restrict the value of the variables, but the value of the variables is all the time the same and nothing is optimized. I have then tried with fminsearch and patternsearch and the same happened. There is no a “Matlab error” but nothing is optimized. I know little about optimization and I am not sure if am defining in a wrong way the minimization function or this problem cannot be solved in this way. I would deeply appreciate any help or clarification.
This is part of the code where the error is calculate ( 2 and 3 steps of the code):
[r,c]=size(Failure_spec_matrix);
cont=cell(1,c);
for i=1:c
Filure=Failure_spec_matrix(:,i);
location=find(Filure>Limit_spec');
count(1,i)={location};
end
count_total=find(~cellfun(@isempty,cont));
error=(length(count_total)*100/c)-defective_defined;
Thank you very much in advance!!

 采纳的回答

If I understand you correctly, your objective function (the thing you are trying to minimize) is integer-valued. Small changes in the control variables (the things you can move to change the objective function) don't change the value of the objective function.
If I understand correctly, you might try patternsearch with a large initial mesh size.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation

3 个评论

Thank you very much for your quick answer Alan!
You are right, in some cases small changes in the control variables don’t change the value of the objective function. I have tried to use Patternsearch with a large initial mesh size, but the program is not working. It seems like the poll at all interactions is unsuccessful and so the algorithm does not change the current point at next iterations. Is there any other optimization algorithm that can be better for my problem? Or is the problem in the objective function?
This is part of the code where I define the use of Patternsearch:
fun=@Defective_optm
lb = [12,10,0.5,1];
ub = [100,100,10,500];
A=[];
b=[];
Aeq=[];
beq=[];
nonlcon = [];
options = optimoptions('patternsearch','Display','iter','UseCompletePoll',true,'InitialMeshSize',100);
[X,fval,exitflag,output] = patternsearch(fun,X,A,b,Aeq,beq,lb,ub,options)
And this is the result I have obtained:
Iter Func-count f(x) MeshSize Method
0 1 15.3846 100
1 3 15.3846 50 Refine Mesh
2 7 15.3846 25 Refine Mesh
3 11 15.3846 12.5 Refine Mesh
4 15 15.3846 6.25 Refine Mesh
5 22 15.3846 3.125 Refine Mesh
6 29 15.3846 1.563 Refine Mesh
7 36 15.3846 0.7813 Refine Mesh
8 43 15.3846 0.3906 Refine Mesh
9 50 15.3846 0.1953 Refine Mesh
10 57 15.3846 0.09766 Refine Mesh
11 64 15.3846 0.04883 Refine Mesh
12 71 15.3846 0.02441 Refine Mesh
13 78 15.3846 0.01221 Refine Mesh
14 85 15.3846 0.006104 Refine Mesh
15 92 15.3846 0.003052 Refine Mesh
16 99 15.3846 0.001526 Refine Mesh
17 106 15.3846 0.0007629 Refine Mesh
18 113 15.3846 0.0003815 Refine Mesh
19 120 15.3846 0.0001907 Refine Mesh
20 127 15.3846 9.537e-05 Refine Mesh
21 134 15.3846 4.768e-05 Refine Mesh
22 141 15.3846 2.384e-05 Refine Mesh
23 148 15.3846 1.192e-05 Refine Mesh
24 155 15.3846 5.96e-06 Refine Mesh
25 162 15.3846 2.98e-06 Refine Mesh
26 169 15.3846 1.49e-06 Refine Mesh
27 176 15.3846 7.451e-07 Refine Mesh
Optimization terminated: mesh size less than options.MeshTolerance.
X =
20.0000 20.0000 0.5000 400.0000
fval =
15.3846
exitflag =
1
output =
struct with fields:
function: @Ajustea
problemtype: 'boundconstraints'
pollmethod: 'gpspositivebasis2n'
maxconstraint: 0
searchmethod: []
iterations: 27
funccount: 176
meshsize: 7.4506e-07
rngstate: [1×1 struct]
message: 'Optimization terminated: mesh size less than options.MeshTolerance.'
Thank you in advance,
Lia
If you have validated your objective function (seen that it gives correct values for various inputs), then the only other thing I can suggest is to try surrogateopt. This is a global solver that is time-consuming to run, but attempts to find a global minimum for small-dimensional problems like yours.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
I have tried with surrogateopt as you suggested and it works fine. I deeply appreciate your help, thank you!
Lia

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Surrogate Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by