Minimize function by choosing a variable that enters indirectly
古いコメントを表示
Hello,
I am running a simulation of non-parametric estimation in which I need to minimize (maximize) a certain log-likelihood function. The function and commands I am using are:
LL=@(Bbin) (-1)*(sum(Yc'*log(proby*(fxnc./fxna))+(ones(M,1)-Yc)'*... log(ones(M,1)-proby*(fxnc./fxna))));
Bbin = fminsearch(LL,[-1;-1;-1])
As you can see, I am trying to find the Bbin that minimizes LL, but Bbin does not directly enter into my function "LL". Instead, it is used to calculate variables "fxnc" and "fxna". Those variables are calculated in such a way that I cannot add their calculation into the LL function (the code for how they are calculated is pasted below, but I don't believe it is relevant and may just add extra confusion). As you might guess, when trying to minimize LL, Matlab treats fxnc and fxna as an exogenous matrix, and therefore changing Bbin does not effect the LL function. Naturally, it spits out my original values for Bbin [-1;-1;-1]. How can I tell Matlab that varying Bbin changes fxnc and fxna?
Thanks!
Code for how fxnc and fxna are calculated:
%Calculate conditional means for Yc M=sum(Y); index=Xc*Bbin; si=std(index); fxnc=zeros(M,1); h=1.06*si*M^(-0.2); d=zeros(M,1); for j=1:M d(:,1)=(index(j,1)-index(:,1))./h; fx1c=normpdf(d); fxnc(j,1)=mean(fx1c/h); end
%Calculate conditional means for Y fxn=zeros(N,1); index=X*Bbin; si=std(index); h=1.06*si*N^(-0.2); d=zeros(N,1); for j=1:N d(:,1)=(index(j,1)-index(:,1))./h; fx1=normpdf(d); fxn(j,1)=mean(fx1/h); end
7 件のコメント
Star Strider
2012 年 9 月 28 日
編集済み: Star Strider
2012 年 9 月 28 日
I can't figure out what you're doing, and I can't simulate your code to calculate means for Yc and Y, and LL. (Even when I plug in random numbers, it crashes. I can't get your d(:,1) assignment to work no matter what I try.) Since I can't test my ideas, this is a comment rather than an Answer.
It would help if you formatted your code, and provided some descriptions of the magnitudes and sizes of your variable vectors and matrices.
As a possible solution to your problem, I suggest you consider a for loop that defines Yc, Y, LL, and the rest, and iterates until you're happy with the results. You'll need to initialize outside the loop with guesses for the first pass.
Jason
2012 年 9 月 28 日
Jan
2012 年 9 月 29 日
If "if true" should be removed, you could be so kind and remove by your own by editing the comment.
Star Strider
2012 年 9 月 29 日
編集済み: Star Strider
2012 年 9 月 29 日
@Jason — I had time to experiment with your routine. Thank you for formatting it and providing the complete code.
One significant problem I discovered in looking through your code is that in your LL() function, Bbin doesn't actually appear anywhere as a parameter to be optimized! That's why it always returns the initial ‘guess’ values for it.
My next question: what precisely are you optimizing for? How do you define Bbin in terms of the rest of LL()? (NOTE that Bbin is a [3 x 1] vector and LL() produces a scalar.)
Also in LL(), note that the expression:
(ones(M,1)-Yc)'
is and will always be identically = 0 since Yc is a column vector of ones. So the second expression in LL()
(ones(M,1)-Yc)'*log(ones(M,1)-proby*(fxnc./fxna))
will therefore always be identically = 0 as well.
I'll keep this open for a bit while you sort out LL() and post a correction to it. I can't figure out what you're doing, so I can't correct it myself.
Jason
2012 年 9 月 30 日
Star Strider
2012 年 9 月 30 日
編集済み: Star Strider
2012 年 9 月 30 日
What do you want to do and how do you want Bbin to be optimised? What's your objective?
I'm lost.
Jason
2012 年 9 月 30 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Parallel Computing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!