What procedure I should use to minimize this function?
Show older comments
How i should proceed to minimize The objective function?
Thanks!
20 Comments
jgg
on 7 Jul 2016
You'll probably want to try a couple of things, but since you have a constraint optimization problem, I suggest fmincon first.
It's also a very, very good idea to move this:
%load the dataset
filename = 'BS_1.xlsx';
y = xlsread(filename);
yS=y(1:288);
Out of your function. You want all the data loading and stuff to be done a single time, not every function evaluation. Pass it into your function:
function X=mFunction(alpha,beta,yS)
instead, then optimize an anonymous version instead:
func = @(a,b)mFunction(a,b,yS)
That's why you have to do the other stuff I pointed out.
1) Re-write your function so it takes yS as an input instead of loading it
2) Make an anonymous version of the function which inputs yS
3) Optimize the anonymous function.
These are the bottom two things in my post.
John D'Errico
on 7 Jul 2016
Why ask the same question over and over again?
amine&&
on 7 Jul 2016
jgg
on 7 Jul 2016
Think about it this way; when you minimize your function, you're going to be calling the function thousands, if not millions of times.
Every time you call the function, you have to:
1) Create a filename object
2) Read data from the hard drive into memory
3) Turn the loaded data into a matlab matrix
4) Process the matrix in yS
This is load of un-necessary work which is going to make your minimization much, much slower. If it takes 1 second to read it, and you're going to run this a hundred thousand times, you're wasting 27 hours for no reason.
jgg
on 7 Jul 2016
Your func takes two input; you're only passing one.
If you need to optimize over both alpha and beta you probably need to write a function like this:
func = @(x)mFunction(x(1),x(2),yS);
instead. But, this requires these to be scalars; I don't know you function well enough. Just be aware that when you optimize you pass a single vector, so your function needs to take a single vector.
You're passing yS not y. Your function cannot use something you do not call. You could just pass y instead; change everything above to use y instead of yS, and add the line which creates yS to your function.
This is very straightforward; you need to think carefully about what you're trying to do, and then make sure everything works. The goal is to remove your data loading from your function; you will have to tweak what is passed into the function and how the function is written to get this to work, but it's not difficult to do.
Your workflow, when you do optimization is like this:
data = loadData();
func = @(x)myFunction(x,data)
output = doOptimize(func);
amine&&
on 7 Jul 2016
amine&&
on 7 Jul 2016
jgg
on 7 Jul 2016
Check the function value near the points; are you sure that it is an optimum? You might have a subtle bug in your function you will need to track down.
amine&&
on 7 Jul 2016
jgg
on 7 Jul 2016
What about at the solution you actually found from the solver?
jgg
on 7 Jul 2016
You said that you ran the optimization and it gave you a point (0.0026 0.9964); what is the value of the function at that point?
amine&&
on 7 Jul 2016
jgg
on 7 Jul 2016
This value is actually smaller than the 0.99, 0.99 point you found, so the optimization is working properly; this IS the minimum of that function. You probably need to look more closely at the function you are optimizing if this isn't what you expect.
amine&&
on 7 Jul 2016
Answers (0)
Categories
Find more on Surrogate Optimization 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!