OPTIMIZATION WITH PATTERNSEARCH ERROR
Show older comments
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 Comments
Ameer Hamza
on 23 Mar 2020
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
on 24 Mar 2020
Ameer Hamza
on 24 Mar 2020
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
on 25 Mar 2020
Answers (0)
Categories
Find more on Problem-Based Optimization Setup in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!