Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!r24g2000prf.googlegroups.com!not-for-mail
From: Steven <ytsteven@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Help on fminsearch
Date: Sun, 8 Nov 2009 05:39:25 -0800 (PST)
Organization: http://groups.google.com
Lines: 84
Message-ID: <4f147eb6-0798-4831-8713-bd688c12a1e1@r24g2000prf.googlegroups.com>
References: <09b40b63-dab0-4d44-ae14-e078505de963@s31g2000yqs.googlegroups.com> 
	<bd6f5cbd-b390-436e-b740-2d13064169ef@l13g2000yqb.googlegroups.com> 
	<hd6c5v$g56$1@fred.mathworks.com>
NNTP-Posting-Host: 124.170.104.238
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1257687565 31100 127.0.0.1 (8 Nov 2009 13:39:25 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sun, 8 Nov 2009 13:39:25 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: r24g2000prf.googlegroups.com; posting-host=124.170.104.238; 
	posting-account=8IzR6AoAAADtXVpNmJ2BoypqTzJEOQO_
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; WOW64; 
	Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 
	3.5.30729; .NET CLR 3.0.30729; InfoPath.2; OfficeLiveConnector.1.4; 
	OfficeLivePatch.1.3; CIBA),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:583336


On Nov 8, 11:05 pm, "John D'Errico" <woodch...@rochester.rr.com>
wrote:
> Steven <ytste...@gmail.com> wrote in message <bd6f5cbd-b390-436e-b740-2d1306416...@l13g2000yqb.googlegroups.com>...
> > On Nov 8, 10:15?pm, "John D'Errico" <woodch...@rochester.rr.com>
> > wrote:
> > > Steven <ytste...@gmail.com> wrote in message <09b40b63-dab0-4d44-ae14-e078505de...@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);
>
> > > You do recognize that regardless of the value of
> > > beta as it is passed in, that this line will overwrite it?
>
> > > John- Hide quoted text -
>
> > > - Show quoted text -
>
> > Hi, John
>
> > Do you mean this line ----> beta = ones(p,1); ?
>
> > But without this line, I always have the error message like "beta is
> > undefined" or something...
>
> How are you calling this?
>
> Do you actually have the call to fminsearch
> INSIDE the myfun function?
>
> Telling me "or something" gives no useful
> information as to the actual error.
>
> Are you trying to run myfun as a script? Are
> you using "run" on it?
>
> Do you realize that loading the data file for
> EVERY function call here is a terrible way to
> waste CPU time? Ok, maybe that was wrong.
> It is actually a very GOOD way if your goal is
> to waste CPU time. Load the variable ONCE in
> your mainline, and then pass it in to myfun
> using an anonymous function call.
>
> John- Hide quoted text -
>
> - Show quoted text -

I wasn't with a machine with Matlab installed just now. The error is
"Input argument "beta" is undefined."

Is there a way to minimise a function without writing a function?

I don't want to load the data in the function, but the likelihood is
calculated based on the event indicator in the data. I don't know how
to do it without actualy loading the data into the function. (I don't
know hoe to declare variable in a function whithout assigning value)

I checked the help file which gives an example of  x = fminsearch
(fun,x0) based on banana function, and it doesn't need to declare
variable.