Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help on fminsearch
Date: Sun, 8 Nov 2009 18:05:14 -0500
Organization: The MathWorks, Inc.
Lines: 49
Message-ID: <hd7ipf$r42$1@fred.mathworks.com>
References: <09b40b63-dab0-4d44-ae14-e078505de963@s31g2000yqs.googlegroups.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1257721455 27778 172.31.44.65 (8 Nov 2009 23:04:15 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 8 Nov 2009 23:04:15 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:583420



"Steven" <ytsteven@gmail.com> wrote in message 
news:09b40b63-dab0-4d44-ae14-e078505de963@s31g2000yqs.googlegroups.com...
> Hi, all
>
> I am a newbie and need some help on fminsearch. I worte this function
> on cox proportional hazard model, and try to maximise the likelihood
> on the coefficient of the covariates.
>
> But the code doesn't work, it only sticks to thei nitial values of the
> coefficients, ie. beta = ones(p,1) and won't do the optimisation.
> Could anybody please help me on this? Many Thanks!!
>
> function [logL] = myfun(beta)
>
> load mydata
>
> d = size(mydata);
> n = d(1,1);
> p = d(1,2)-2;
> t = mydata(1:n,1);
> ind = mydata(1:n,2);
> z = mydata(1:n,3:p+2);
> beta = ones(p,1);
>
> ebz = exp(z*beta);
> L = ones(n,1);
>
> for i = 1:n
>    if ind(i,1)== 1
>        L(i,1) = ebz(i)/sum(ebz(i:n));
>    end
> end
>
> logL = -sum(log(L));
>
> [beta] = fminsearch(@myfun,ones(p,1));

This line indicates to me that you're calling FMINSEARCH from inside myfun 
itself.  This is a BAD IDEA -- you WILL receive an error about the Recursion 
Limit when you call this function.  See Q4.15 in the newsgroup FAQ for an 
explanation of the problem and how to fix it.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ