FMINCON returns result equal to initial input vector
조회 수: 8 (최근 30일)
이전 댓글 표시
I am trying to calculate the optimal parameter in a price function through minimizing the error between the calculated price and the observed market price. I am using fmincon to minimize the objective function but it gives me the exact same result as the initial input vector no matter what value I put in, even if they increase the error. Can someone please explain what is wrong. Thanks!
%% Optimization
Z = [sig];
MSE = @(Z) (immse(call(Z(1)), MarketPrice));
initial =[0.2];
lb = [0]; ub = [10];
X1 = fmincon(MSE,initial,[],[],[],[],lb,ub)
댓글 수: 0
답변 (1개)
John D'Errico
2017년 3월 17일
We seem to answer this question over and over again. :)
There are many possible reasons why fmincon stops looking.
Check the exit code that fmincon returns. What is it? What does that tell you? Read the help for fmincon.
When you have an optimization to do for the first time, there are several things I recommend be done ALWAYS.
1. Test your function at the start point. Does it return something that makes sense? Think about what it does return. Is the result finite? a valid scalar value?
2. Change the input parameters slightly. Does your objective function change? Again, think about what you see.
Never just throw some complex mess of stuff at an optimizer without thinking about if your function actually does something rational. You could never have made a mistake? Really? Test your code, every piece, before you try to use it and expect something correct to come out.
Next, test your start point, if you have any constraints. Is the start point feasible? Check any constraints that may apply.
When you do call the optimizer, use 'Display','iter' as the option. Do so at least the first time you call it. Look at what is happening. Does it make sense?
Remember that fmincon requires an objective that is a finite scalar function of the parameters. It must be both continuous and differentiable.
If all else fails, use the debugger. Put a debug stop in your objective function. Look to see what parameters are being passed into your function. Then look to see if the function is doing something reasonable with those parameters. Remember that the first n times the objective is called it will be computing a finite difference gradient estimate. So the parameters won't change much.
Always apply common sense to what you see, to what you are doing. Write your code slowly, carefully. Test it at every opportunity. Test every piece.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!