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 Comments

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.
Data and alphas are the variables given as inputs to the main function, this is not where it goes wrong. It goes wrong with the variable 'alphaThreshold'. Since we optimize with respect to this variable 'alphaThreshold', we do not have the value of this variable yet and therefore we think that it might not work to use this as one of the inputvariables of the optimal_threshold function.
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.
Thank you very much for your help. We found the mistake in our code, there was no @ before calling the objectivefuncAlphaThreshold...

Sign in to comment.

Answers (0)

Categories

Asked:

on 23 Mar 2020

Commented:

on 25 Mar 2020

Community Treasure Hunt

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

Start Hunting!