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 中查找有关 Problem-Based Optimization Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!