OPTIMIZATION WITH PATTERNSEARCH ERROR
이전 댓글 표시
We are trying to optimize our objective with respect to a variable, but we need this variable in another function in which we calculate 2 values which are needed to compute our objective value. Our matlab code is giving the error that we do not have enough input arguments in the line in which we call optimal_threshold function.
Our code:
alphathreshold = patternsearch(objectivefuncAlphaThreshold...
,alphathreshold0, ...
[], [], [], [], [], []);
function objectivevalue = objectivefuncAlphaThreshold (alphaThreshold)
[gamma_objective, MV_objective, weightsTotalmatrix] = optimal_threshold(Data, alphas, alphaThreshold);
objectivevalue = (gamma_objective-meanGamma)/stdvGamma + (MV_objective - meanMV)/stdvMV;
end
Can anyone help us?
댓글 수: 4
Ameer Hamza
2020년 3월 23일
We don't have access to the variables and functions used in your code. It is difficult to see the problem otherwise.
The function objectivefuncAlphaThreshold use several variables, e.g., Data, alphas, etc. Where are they defined and how is their value appear inside the scope of the function.
Jill Langenberg
2020년 3월 24일
Ameer Hamza
2020년 3월 24일
Ok. I got this from your comment: objectivefuncAlphaThreshold is defined inside the main function, and the objective function calls another function that uses the optimization variable as its input. If this is the case, then the value of alphaThreshold is passed to the objective function by patternsearch, and therefore, it is defined whenever the function is called. There is no issue in your code, and it should work fine.
So the second suspect for the cause of this error is the function optimal_threshold. Without actually running the code, it is difficult for me to debug, but I suspect that the definition of optimal_threshold function has a different signature. You can try to add a breakpoint at this line so that the code execution will halt at this line just before the occurrence of error. You can then examine the values of variables and try to call the function optimal_threshold manually from the command window.
Jill Langenberg
2020년 3월 25일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Choose a Solver에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!