Help with fminsearch, fminunc

  • Permalink
  • submit to reddit
  • Email
  • Follow


I'm having problems using these optimizers to optimize the output of a Simulink model.  Specifically, it's a trajectory model of a rocket with multiple burns. The burns are short, with long coast periods. The motor on-off times are measured in seconds, so run in the range 1000..100000.  

Fminsearch works fine for small numbers of burns, but chokes on larger ones.  A little digging shows that it builds its initial simplex by percentage offsets from the initial state, and the large steps sometimes make it miss the optimum entirely.  I've tried to limit the initial offsets, but without much success.

With fminunc, I have the opposite problem.  It tries to develop a gradient using divided differences, but the delta-x values it uses are way too small.  Like 100 ms out of a 1000 s burn.  When these times are sent to the Simulink model, it returns the same values for all cases.  So fminunc decides that the surface is flat, there is no gradient.  So it declares victory and returns.  Again, I've tried to force the function to use larger steps, by setting the DiffMinChange option, but fminunc seems to be ignoring it and using a step 100 times smaller.

I'm not a novice user of Matlab and Simulink. I've used fminsearch many times before, but not in cases where I had to tinker with the default settings.  I feel that I'm close to getting both optimizers tamed enough to work, but the solution remains just out of reach.  I'm hoping someone out there can give me a few magic words that will get me on the right path.  Thanks.
0
Reply jcrens (282) 10/7/2011 2:12:08 PM

See related articles to this posting


"Jack Crenshaw" <jcrens@earthlink.net> wrote in message <j6n1bo$nfn$1@newscl01ah.mathworks.com>...
> I'm having problems using these optimizers to optimize the output of a Simulink model.  Specifically, it's a trajectory model of a rocket with multiple burns. The burns are short, with long coast periods. The motor on-off times are measured in seconds, so run in the range 1000..100000.  
>
> Fminsearch works fine for small numbers of burns, but chokes on larger ones.  A little digging shows that it builds its initial simplex by percentage offsets from the initial state, and the large steps sometimes make it miss the optimum entirely.  I've tried to limit the initial offsets, but without much success.
=================
 
I'm assuming the "burns" are the variables to be optimizied? If so, it sounds like a known limitation of FMINSEARCH. FMINSEARCH is really on theoretically gauranteed to work with 1 variable. It's known to have empirical success with a handful of variables, but there's no solid theory behind the multi-variable case.





> With fminunc, I have the opposite problem.  It tries to develop a gradient using divided differences, but the delta-x values it uses are way too small.  Like 100 ms out of a 1000 s burn.  
=======

That doesn't sound "way too small". Are you sure your objective function doesn't involve any rounding, floor, or ceil operations? That would be illegal for FMINUNC, since it would make your function non-differentiable?
0
Reply mattjacREMOVE (3194) 10/7/2011 2:38:25 PM

"Matt J" wrote in message <j6n2t1$1s$1@newscl01ah.mathworks.com>...
>
> 
> > With fminunc, I have the opposite problem.  It tries to develop a gradient using divided differences, but the delta-x values it uses are way too small.  Like 100 ms out of a 1000 s burn.  
> =======
> 
> That doesn't sound "way too small". Are you sure your objective function doesn't involve any rounding, floor, or ceil operations? That would be illegal for FMINUNC, since it would make your function non-differentiable?
=============

Alternatively, your objective function could be poorly scaled. Why not measure the motor on/off times in minutes or even hours, rather than seconds, since they are always at least 15 minutes long..
0
Reply mattjacREMOVE (3194) 10/7/2011 2:45:30 PM

"Matt J" wrote in message <j6n3aa$1qr$1@newscl01ah.mathworks.com>...
>
> Alternatively, your objective function could be poorly scaled. Why not measure the motor on/off times in minutes or even hours, rather than seconds, since they are always at least 15 minutes long..
===============

Or, if you know in advance that certain burns are going to be much longer than others (I'm not an aerospace engineer...), measure the longer ones in hours and the shorter ones in minutes.
0
Reply mattjacREMOVE (3194) 10/7/2011 2:54:14 PM

On 10/7/2011 10:12 AM, Jack Crenshaw wrote:
> I'm having problems using these optimizers to optimize the output of a
> Simulink model. Specifically, it's a trajectory model of a rocket with
> multiple burns. The burns are short, with long coast periods. The motor
> on-off times are measured in seconds, so run in the range 1000..100000.
> Fminsearch works fine for small numbers of burns, but chokes on larger
> ones. A little digging shows that it builds its initial simplex by
> percentage offsets from the initial state, and the large steps sometimes
> make it miss the optimum entirely. I've tried to limit the initial
> offsets, but without much success.
>
> With fminunc, I have the opposite problem. It tries to develop a
> gradient using divided differences, but the delta-x values it uses are
> way too small. Like 100 ms out of a 1000 s burn. When these times are
> sent to the Simulink model, it returns the same values for all cases. So
> fminunc decides that the surface is flat, there is no gradient. So it
> declares victory and returns. Again, I've tried to force the function to
> use larger steps, by setting the DiffMinChange option, but fminunc seems
> to be ignoring it and using a step 100 times smaller.
>
> I'm not a novice user of Matlab and Simulink. I've used fminsearch many
> times before, but not in cases where I had to tinker with the default
> settings. I feel that I'm close to getting both optimizers tamed enough
> to work, but the solution remains just out of reach. I'm hoping someone
> out there can give me a few magic words that will get me on the right
> path. Thanks.

There are at least two options that regulate the size of steps for 
fminunc: DiffMinChange and DiffMaxChange. Depending on the version of 
MATLAB you have, you might need to set both. You might also need to set 
the TypicalX vector to something more typical of your problem than the 
default vector of ones.

If you have Global Optimization Toolbox (or Genetic Algorithm and Direct 
Search Toolbox) you can try the patternsearch solver with a large 
initial mesh size.

You could also rescale the problem to minutes or hours, as Matt suggested.

Good luck,

Alan Weiss
MATLAB mathematical toolbox documentation
0
Reply aweiss (880) 10/7/2011 3:52:46 PM
comp.soft-sys.matlab 203649 articles. 536 followers. Post

4 Replies
415 Views

Similar Articles

[PageSpeed] 59


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

fminsearch
Hello Matlabbers, I am trying to use minimum-distance 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 fminunc
Hello, 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 step-size which I am currently arbitrary setting to some value (that ha...

fminunc, fminsearch
Hi John, I used fminunc (instead of fminsearch), and got the following message: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> { Warning: Gradient must be provided for trust-region algorithm; using line-search algorithm instead.} > In fminunc at 347 In minestimation_simplex at 31 First-order Iteration Func-count f(x) Step-size optimality 0 61 46.4514 ...

fminsearch help
I 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 m-file, which is fine. I am still a bit confused on how to input experimental data in and minim...

help with fminsearch
Hi, 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*(1-b*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 fminsearch
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:...

Stepsize for fminsearch/fminunc
Hi! 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 #5
I 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 fminsearch
Hi. 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 #4
I 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 #3
I'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 fminsearch
Hello, 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 Help
Hello 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 hu-mungo! 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 trust-region algorithm; using line-search algorithm instead. > In fminunc at 347 First-order Iteration Func-...

Difference between fminunc and fminsearch
Could 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: FMINSEARCH
i construct a function function f=fum(x) f=(x-2).^2-1; 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 fminunc
Dear 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 2D
Hello -- 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 help
I'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 Nelder-Mead 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 #3
I'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 M-file 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. fminunc
I 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 #2
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=W-T1.*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=W-T1.*sind(theta) > Rx=T1.*cosd(thet...

fminsearch help #2
I'm trying to optimize a seven-parameter 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...