現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
What procedure I should use to minimize this function?
1 回表示 (過去 30 日間)
古いコメントを表示
amine&&
2016 年 7 月 7 日
How i should proceed to minimize The objective function?
Thanks!
20 件のコメント
jgg
2016 年 7 月 7 日
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)
jgg
2016 年 7 月 7 日
編集済み: jgg
2016 年 7 月 7 日
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.
amine&&
2016 年 7 月 7 日
When I use :
>> func = @(a,b)mFunction(a,b,yS)
func =
@(a,b)mFunction(a,b,yS)
>> x = fmincon(func,xnew,A,b,Aeq,beq,lb,ub)
MATLAB launches the following error :
Error using @(a,b)mFunction(a,b,yS)
Not enough input arguments.
Error in fmincon (line 534)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Thanks!
jgg
2016 年 7 月 7 日
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
2016 年 7 月 7 日
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.
amine&&
2016 年 7 月 7 日
編集済み: amine&&
2016 年 7 月 7 日
I totally greement with you. We do not load the data for each use of the function. but I do not know is there a way to recover without being required to load every time. especially when I try to start the minimization procedure I obtien the following error message :
>> x = fmincon(func,xnew,A,b,Aeq,beq,lb,ub)
Undefined function or variable 'y'.
Error in mFunction (line 51)
X = mean((y(26:264)-PREV2(26:264)).^2);
Error in @(x)mFunction(x(1),x(2),yS)
Error in fmincon (line 534)
initVals.f = feval(funfcn{3},X,varargin{:});
Thanks!
jgg
2016 年 7 月 7 日
編集済み: jgg
2016 年 7 月 7 日
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&&
2016 年 7 月 7 日
In my case. The following code works perfectly
>> lb = [0,0];
>> ub = [1,1];
>> A = [];
>> b = [];
>> Aeq = [];
>> beq = [];
>> x0 = [0.5,0.5];
>> x = fmincon(@(x)mFunction(x(1),x(2)),x0,A,b,Aeq,beq,lb,ub)
MATLAB gives me as solution :
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
0.0026 0.9964
Whereas when I draw the graph in 3D solution is a little meadows equal to [0.99,0.99]. Thanks!
amine&&
2016 年 7 月 7 日
Even if i change the initial point "e.g (0.99,0.99)", its given't the correct result. For tolerance I do not know how to change it
jgg
2016 年 7 月 7 日
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&&
2016 年 7 月 7 日
I checked and this is what I got :
>> mFunction(0.99,0.99)
ans =
6.6666e-04
>> mFunction(0.8,0.8)
ans =
8.7804e-04
>> mFunction(0.6,0.6)
ans =
0.0014
>> mFunction(0.1,0.1)
ans =
0.0037
jgg
2016 年 7 月 7 日
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?
jgg
2016 年 7 月 7 日
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&&
2016 年 7 月 7 日
I totally agree with you. I am trying to verify this hypothesis. I rependre you later if I find the solution to this problem.
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)