fminsearch
Hello Matlabbers,
I am trying to use minimumdistance estimation, and so as a toy
problem, I am starting by trying to fit the mean and variance
parameters of a normal distribution by minimizing the KS statistic. So
I wrote a little test function (see below) that generates normal
random numbers and then uses the KS distance (via a call to kstest2)
as the measure to minimize while searching through the mean
standarddeviation parameter space.
I have tried varying all the parameters for optimset, but the search
does not travel very far from the starting point. I cannot figure out
...
help with fminuncHello,
I have a gradient descent formulation of the problem and I am trying
to get that to work using fminunc but am a bit confused on how to go
about it.
So, one iteration of my gradient descent is as follows:
phi(n + 1) = phi(n) + s(x1  (x2 * grad(phi(n)) * D^2(phi(n)))
So, I start with an initial estimate of phi and the LHS is the next
estimate and I guess I want to do this till the norm of the difference
between the new and the old estimate is less than a certain threshold.
s in the equation is the stepsize which I am currently arbitrary
setting to some value (that ha...
fminunc, fminsearchHi John,
I used fminunc (instead of fminsearch), and got the following message:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
{ Warning: Gradient must be provided for trustregion algorithm;
using linesearch algorithm instead.}
> In fminunc at 347
In minestimation_simplex at 31
Firstorder
Iteration Funccount f(x) Stepsize optimality
0 61 46.4514 ...
fminsearch helpI am attempting to model experimental data by fitting an exponential
curve. I have been advised to use the fminsearch function which
makes sense.
However, the MATLAB documentation is not very clear in regards with
what I am doing.
Specifically, I have a vector of Experimental Data (DATA) and a
function with two parameters that I would like to fit to data
(A*exp(B*t)) where A and B are variable parameters and t is just the
time/index vector.
the help files lead me to believe I will need a separate mfile,
which is fine. I am still a bit confused on how to input
experimental data in and minim...
help with fminsearchHi, I am trying to fit a vonbertalanffy growth curve to some fish
growth data, using iterative least squares and the fminsearch
function.
The VonB function has three unknowns hence you need three initial
guesses. I can assign the function to a handle ok with this command:
VonB = @(Lmax,b,k) sum(((Lmax*(1b*exp(k*age)))(real data)).^2)
and this for the initial guess for the three parameters
x0 = [100 .8 .5]
but when I call for the fminsearch to find the minimun values
x = fminsearch(VonB,x0)
I get this, when I did define b? Any ideas?
??? Input argument "b" is undefined.
Error in =...
Help on fminsearchHi, 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:...
Stepsize for fminsearch/fminuncHi!
I would like to use fminsearch or fminunc with integer
steps. Apparently this is not possible as I read here in the
forum.
Anyone has an idea?
Thanks!
Volker
"Volker K" <klinkv.NOSPAM@yahoo.de> wrote in message
<fjujea$ds5$1@fred.mathworks.com>...
> Hi!
> I would like to use fminsearch or fminunc with integer
> steps. Apparently this is not possible as I read here in the
> forum.
Integer optimization (as opposed to continuous) uses an
entirely different class of algorithm. Just wait for the
person from TOMLAB to give you a hint on where to go in
thei...
fminsearch help #5I am trying to use fminsearch to find coefficients for a best fit line. My error function code:
function err = milkpox(co);
load milkadj.data;
t = milkadj(:,1);
milk = milkadj(:,2);
for i = 1:length(t)
err = sum((co(1)*sin(co(2)*t(i)) + (co(3)*t(i))+ co(4)  milk(i))^2);
end
My fminsearch call:
bfco = fminsearch('milkpox',[60,0.5,1.5,600]);
for i = 1:length(t)
yP4(i) = bfco(1)*sin(bfco(2)*t(i)) + (bfco(3)*t(i)) + bfco(4);
end
I found that when i compare a plot of (t,milk) and (t,yP4), the best fit from fminsearch does not fit well enough. What is going wrong?
Any help is...
Help on minimization with fminsearchHi.
I have 2 matrices Y,X and a parameter as T and 2 functions fun1,fun2.The goal is to find a T that minimize the fun2 which is as follow :
fun2=sum( sum( ( fun1(Y,T)X ).^2 )
Output of fun1 is a matrice with same dimentions
as Y and X.I wrote following code(fun1 is defined):
fun2=@(T) sum( sum( ( fun1(Y,T)X ).^2 );
out=fminsearch(fun2,Y,X,T);
Thanks
...
fminsearch help #4I am trying to use fminsearch to find coefficients for a function. I created a function file:
function milk83 = milkpox(co);
load milkadj.data;
x = milkadj(:,1);
milk83 = co(1)*sin(co(2)*t) + co(3)*t + co(4);
Then I tried to execute fminsearch as follows:
bfco = fminsearch('milkpox',[60,0.5,1.5,600]);
I received the following error message:
??? In an assignment A(:,matrix) = B, the number of elements in the subscript of A and the number
of columns in B must be the same.
Error in ==> C:\matlab_sv13\toolbox\matlab\funfun\fminsearch.m
On line 125 ==> fv(:,1) = feval(funfcn...
Help with fminunc: Please!!I'm trying to figure out what's going on with an optimization that is
taking MUCH longer than it should and is getting incorrect values. I'm
trying to maximize a (negative) likelihood using fminunc with
largescale set to 'off'. In other words, Matlab is computing the
gradient and Hessian.
After the initial iteration, "stepsize" is 1 for some reason. Does
anyone have any idea what's going on?
Also, how can I display the inverse Hessian and gradient that Matlab is
computing without modifying fminunc, fminsub, or the like?
Thanks a million,
Rachel
To clar...
fminsearch help #3I'm new to Matlab and want to use fminsearch. I wrote a function myfunction that takes a vector of three parameters and I want to use fminsearch to minimize the function. The function looks like this: out = function myfunction(v)
so i wrote [x,fval,exitflag,output] = fminsearch(@myfunction,v,options)
where v is a vector of starting values. After it runs, x has three answers when I am expecting one. What am I doing wrong?
In article <3101347.1135281589275.JavaMail.jakarta@nitrogen.mathforum.org>, Christine J <Christine.Jaw@bos.frb.org> wrote:
> I'm new to Matlab ...
Help needed with fminsearchHello,
I'm trying to find linear regression coefficients based on maximizing the correlation coefficient between a set of observed predictors (X) and observations (y) (instead of minimizing the LSE as is done with standard linear regression, i.e., b = [(X^TX)^1]X^Ty). In other words, I'm trying to find an optimum set of predictor coefficients based on minimizing a different cost function.
For example (using randn just for illustration but I intend to use real data),
>> X = randn(5,2)
X =
0.0301 0.8637
0.1649 0.0774
0.6277 1.2141
1.0933 ...
fminunc Options HelpHello all,
I am using the optimization minimization function fminunc, but it does not even go through 1 iteration (I set MaxIter = 100000). The list of options you can set is humungo! I'm a little lost and can't find a complete explanation of optimset options. This is the message I get after I fminunc is done running:
=====================================================
Warning: Gradient must be provided for trustregion algorithm;
using linesearch algorithm instead.
> In fminunc at 347
Firstorder
Iteration Func...
Difference between fminunc and fminsearchCould anyone know the main difference between fminunc and fminsearch
because both are for finding the minimum of a multivariate function?
thanks in advance
Jack wrote:
>
>
> Could anyone know the main difference between fminunc and
> fminsearch
> because both are for finding the minimum of a multivariate
> function?
> thanks in advance
The main difference?
The spelling of the names? ;)
The fact that they use very different
algorithms?
You might take a read through this doc:
<http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=8553&obje...
help:about fcn: FMINSEARCHi construct a function
function f=fum(x)
f=(x2).^21;
when i evaluate the following expression:
[x,y]=fminsearch(@fun,2.5)
the result is
x =
2.65625000000000
y =
0.34655929301330 + 0.47475246315573i
However it's obviously that the mimimum value is y=1 when x=2
will someone tell me why?
thanks
I'm not able to reproduce the problem; I get
the correct result in R13 with Service Pack 1:
>> [x,y]=fminsearch(@myfun,2.5)
x =
2
y =
1
Incidentally, since x is a scalar, ".^" in
the function is the same as just "^".
marcelo
antique wrote:
&...
Optimalisation with fminsearch and fminuncDear all,
I'm trying to estimate parameters and standard errors using the functions fminsearch and fminunc respectively. Using the fminsearch function works perfectly and creates parameter estimations. These estimations are my starting values for the fminunc function. However I get an error using this function, after 4 or 5 iterations:
??? Error using ==> roots at 28
Input to ROOTS must not contain NaN or Inf.
Can someone tell me what's going wrong?
Thanks!
Anne
On 16 Mai, 14:16, "Anne van Eekeren" <annevaneeke...@gmail.com>
wrote:
> Dear all,
>
> I...
Help with fminsearch in 2DHello  I'd like to use "fminsearch" to find appropriate fitting
parameters for a model function that I'm comparing with experimental
data.
My model function has 2 independent variables (not including the
parameters
I'm looking to fit).
I have a grip on how to use "fminsearch" for this purpose, but I'd
appreciate a critique on the following code for which I fit parameters
for a 2D Gaussian.
I'm fishing about for stylistic advice, because even though this code
works
I feel like it's sloppy. Notice how I define a "residual" function
that
...
fminsearch speed helpI'm having some issues with the fminsearch algorithm, and the speed of convergence. Now, I understand that fminsearch does not use a particularly fast algorithm, and I'm not expecting it to converge quickly, but I do have some concerns about the relative speed of iteration. Based on my understanding of how NelderMead works, the time it takes fminsearch to converge should be roughly linear in the number of iterations required (am I wrong about that?), however that is not what I am experiencing. The first few iterations take only a couple seconds each. Gradually that starts creeping...
help with fminsearch #3I'm trying to minimize r as follow:
r=[];
r = fminsearch(@(r) circular_error(r, I, angle_delta, crx, cry),
crar);
where "ciruclar_error" is an Mfile function well constructed, and
crar, I, angle_delta and crx have been defined yet.
However I have an error:
??? r = fminsearch(@(r),circular_error(r, I, angle_delta, crx, cry),
crar);

Error: "identifier" expected, "(" found.
Could anybody help me ????
Juan Jos� Cerrolaza wrote:
>
>
> I'm trying to minimize r as follow:
> r=[];
> r = fminsearch(@(r) circular_error(r, I,...
Does fminsearch or fminunc handle this?I have a function which takes two matrices of different sizes (e.g.
2x2 and 3x3) as inputs. I want to find out what inputs would minimise
the function. Does fminsearch or fminunc handle this kind of
function? If not, is there any alternative function I can use?
Thanks!
CK wrote:
>
>
> I have a function which takes two matrices of different sizes (e.g.
> 2x2 and 3x3) as inputs. I want to find out what inputs would
> minimise
> the function. Does fminsearch or fminunc handle this kind of
> function? If not, is there any alternative function I can use?
>
> Thanks!
it...
fminsearch vs. fminuncI cannot find a comparison of these two minimization functions. In
using them I find that they do not perform the same (specifically,
fminsearch finds a good solution where fminunc gives up). What I
really want is a guideline on the conditions under which each program
could be expected to produce good results.
Rob,
doc fminsearch
doc fminunc
Read the algorithm part. There are some comments on when fminsearch
performs better than fminunc.
Claudio
Rob Lynch wrote:
>
>
> I cannot find a comparison of these two minimization functions. In
> using them I find that they do not perf...
Help with fminsearch #2I had it working but forgot to save and cannot remember how I did it, this is my script
h=7
l=10
T2=10000
theta=10:10:80
W=4350
T1=(W.*h)./(l.*sind(theta))
Ry=WT1.*sind(theta)
Rx=T1.*cosd(theta)T2
R=(Ry.^2+Rx.^2).^(1./2)
I want to include a function in the script that will give me the value for theta when R is at its minimum.
Thanks
Anthony wrote:
> I had it working but forgot to save and cannot remember how I did it, this is my script
>
> h=7
> l=10
> T2=10000
> theta=10:10:80
> W=4350
> T1=(W.*h)./(l.*sind(theta))
> Ry=WT1.*sind(theta)
> Rx=T1.*cosd(thet...
fminsearch help #2I'm trying to optimize a sevenparameter function for a given dataset. For
now, the command looks like this:
[minimum,bof] = fminsearch(@(x) (fitfun(x,data)), initial_guess);
Where x is a 1x7 vector with the seven parameters in it. Now I want the
function to allow the user to limit the number of parameters by passing a
vector of the same size with one or more constraints. Suppose x(5) should be
constrained to 0, then one could pass the vector [nan nan nan nan 0 nan
nan], or something similar.
I get the impression that this is explained in the help fminsearch, but I
can't get it...