Search Comments and Ratings

go

Comments and Ratings

   
Date File Comment by Comment Rating
23 Nov 2009 mgrep Returns the names of all m-files in a directory or directory tree that contain a search string. Author: John D'Errico Shaw, Kevin

Awesome! It works as advertised.
It allowed me to search through a deep .m file hierarchy and find a dreadfully annoying error message string in an unknown file (added by a colleague) and to remove it. Yeah!

23 Nov 2009 Automatic Numerical Differentiation Numerical derivative of an analytically supplied function, also gradient, Jacobian & Hessian Author: John D'Errico Doria, David

22 Nov 2009 Variable Precision Integer Arithmetic Arithmetic with integers of fully arbitrary size. Arrays and vectors of vpi numbers are supported. Author: John D'Errico D'Errico, John

Sorry about that. Only the binomfactors code uses consolidator, and only nchoosek calls binomfactors. I never caught it in testing, since consolidator is on my search path.

Anyway, and would be more efficient to use a call to unique there, then accumarray anyway, since no tolerance is employed.

I've submitted a new release. It will be there on Monday morning.

22 Nov 2009 Variable Precision Integer Arithmetic Arithmetic with integers of fully arbitrary size. Arrays and vectors of vpi numbers are supported. Author: John D'Errico O'Connor, Derek

John,

The demo_vpi.m needs your consolidator function:

http://www.mathworks.com/matlabcentral/fileexchange/8354-consolidator

Great package.

Derek O'Connor

21 Nov 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Cheng, Raymond

Thanks for your sharing.

16 Nov 2009 Polyfitn N-d polynomial regression model Author: John D'Errico D'Errico, John

As I explained the first time, you need to put polyfitn into a directory that is on your search path.

help addpath
help savepath
help pathtool

Your particular test problem gives me the results:

uv = rand(100,2);
w = sin(sum(uv,2));
p = polyfitn(uv,w,'u, v');

polyn2sympoly(p)
ans =
    0.76152*u + 0.73572*v

Nothing special needs be done except putting it in a directory where matlab can find it.

16 Nov 2009 Polyfitn N-d polynomial regression model Author: John D'Errico alex, Alexandros

So if I want to run this script
uv = rand(100,2);
w = sin(sum(uv,2));
p = polyfitn(uv,w,'u, v');
if exist('sympoly') == 2
  polyn2sympoly(p)
end
if exist('sym') == 2
  polyn2sym(p)
end

do I have to "call" the script "polyfitn" with a specific command?
Generaly what should I do in order to run the above script while polyfitn is a custom script of a user?

16 Nov 2009 Polyfitn N-d polynomial regression model Author: John D'Errico D'Errico, John

If you are trying to place downloaded files into the Matlab/toolbox directories, this is generally wrong. Those directories are cached by matlab when it starts up, so any files that you put in those directories will not be seen until you restart matlab. Also, anytime you make any changes to files that you put in those directories, the changes will not be recognized by matlab.

Better is to create your own new (and separate) directory for downloaded files. Add that directory on your search path, using the pathtool function, or using addpath and then savepath.

15 Nov 2009 Polyfitn N-d polynomial regression model Author: John D'Errico alex, Alexandros

The function polyfitn will probably help me but I don't know how to install this function.
I downloaded the file and I pasted it in the toolbox subfolder of Program files/Matlab....
However when I run this
uv = rand(100,2);
w = sin(sum(uv,2));
p = polyfitn(uv,w,'u, v');
if exist('sympoly') == 2
  polyn2sympoly(p)
end
if exist('sym') == 2
  polyn2sym(p)
end

it returns
??? Undefined function or method 'polyfitn' for input arguments of type 'double'.

Error in ==> testxk at 3
p = polyfitn(uv,w,'u, v');

What's wrong?

14 Nov 2009 Eigenshuffle Consistently sorted eigenvalue and eigenvector sequences Author: John D'Errico De Pitta', Maurizio

03 Nov 2009 bindex.m BINDEX solves the binning problem. Author: John D'Errico Skynet

The built-in function HISTC can also return bin indexes.

02 Nov 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico James

29 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico D'Errico, John

The new version just got uploaded to repair the 'active-set' problems incurred with the newer optimization toolbox releases.

22 Oct 2009 Polyfitn N-d polynomial regression model Author: John D'Errico D'Errico, John

James,

You don't need every possible combination of (x,y,z) to be known to estimate a model, certainly not a first order model like this. To estimate the 3 unknown parameters in this model, in theory, you need at least 3 data points at a minimum. In practice, you won't get very good estimates of those parameters with only 3 data points.

In the past, I often had clients ask me how much data they needed to obtain. After all, data is often scarce, expensive, hard to obtain. It costs money, and time. You can't have too much data, at least if it is good data.

In practice, if you end up with 10 or 20 points to estimate these three parameters, that will (probably) be entirely adequate. More data will give you higher quality estimates. Even 6 points, carefully chosen, if the noise is low enough, will often be adequate. Only you know the quality of your data, and how much you have, as well as how accurately you need the model to be estimated.

If you have further questions, I can only suggest you send me an e-mail, with your data, and any other information you have on the problem.

John

21 Oct 2009 Polyfitn N-d polynomial regression model Author: John D'Errico James

Hi John,

I am new to all this stuff. actually to MATLAB itself.
I have 2D data I want to fit (to a 2-variable function) with 3 parameters: z = A + B*x +C*y. But that is scarce matrix, i.e. with holes. I do not have data (or z if you prefer) for each and every combination of x and y, but only for a sall number of them.

Any way around this ?

I appreciate your help in that matter.

James

20 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Chris

Very nice John, I will cite you in our papers.

I also got this warning:
Warning: Options LargeScale = 'off' and Algorithm = 'trust-region-reflective' conflict.
Ignoring Algorithm and running active-set method. To run trust-region-reflective, set
LargeScale = 'on'. To run active-set without this warning, use Algorithm = 'active-set'.

and added this line after line numer 158 in your slmengine.m file;
fminconoptions.Algorithm = 'active-set';

now I don't get the warning anymore.

19 Oct 2009 Automatic Numerical Differentiation Numerical derivative of an analytically supplied function, also gradient, Jacobian & Hessian Author: John D'Errico Adam

Hello,

Hessian does not work, neither in any example nor when I try to use it. It gives the message:
Function 'subsindex' is not defined for values of class 'function_handle'.
All other functions seem to be great though..
Best,

Adam

16 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico D'Errico, John

The warning message that fmincon returns is new, due apparently to a change in the optimization toolbox. It is only a warning though, that does not hurt the operation of the code itself.

I'll fix the problem.

16 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Cvet, Didi

Hi
I think that this kind of toolbox is great idea and I am doing some tests over this file. I have very specific data points and while doing my experiments I've tried to use 'knots', 'free' option but I get this warning message:

Warning: Options LargeScale = 'off' and Algorithm = 'trust-region-reflective' conflict.
Ignoring Algorithm and running active-set method. To run trust-region-reflective, set
LargeScale = 'on'. To run active-set without this warning, use Algorithm = 'active-set'.

I've tried to add this row
>>fminconoptions.Algorithm = 'Active-set';
in your slmengine.m code but it doesn't work.

Thanks for shearing this!
Best wishes
Dijana

14 Oct 2009 Optimization Tips and Tricks Tips and tricks for use of the optimization toolbox, linear and nonlinear regression. Author: John D'Errico Danila

Very nice and thorough compilation of tips and tricks.

11 Oct 2009 Polyfitn N-d polynomial regression model Author: John D'Errico Andreas

Great work !
Thank you very much. It is really easy to use, allows a lot of user specifications and is quite fast imho.

09 Oct 2009 Graphical data selection tool A graphical tool to modify your plots and locate data points Author: John D'Errico M

N-I-C-E.
I cannot understand why something similar is not implemented in matlab yet.
It would be nice if one could add several selections by pressing e. g. "Ctrl".

04 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico D'Errico, John

Fabian - This is more difficult to solve. Ordinarily, one would simply fit x(t) and y(t) independently. However, your constraint is on the term

sqrt((dx/dt)^2 + (dy/dt)^2)

Do you need a cubic result? If so, then it is more complex yet, since any overall slope type of constraint is bad enough to formulate for a cubic.

I might use a brute force approach. Use a pair of independent models, x(t), y(t). You can put a global constraint on dx/dt and dy/dt on these models, limiting the maximum and minimum slopes attained.

Now, go back, and test the actual velocity when the two curves are united into a parametric path in the (x,y) plane. If sqrt((dx/dt)^2 + (dy/dt)^2) never exceeds your velocity limit, then you are done. Otherwise, you will now need to use fmincon to perturb the parameters of the splines, while minimizing the global sum of squares of errors to (x(t), y(t)).

The constraints for this will clearly be nonlinear. You might set one constraint at every point, but this will not constrain the true maximum velocity attained. So you might sample each curve at perhaps 1000 points, returning 1000 nonlinear constraints along the curve. This will give you a necessary condition on the velocity, but it need not be truly sufficient. Thus it might exceed the aim max velocity by a tiny amount.

Finally, the optimization over the spline parameter space will also have other linear constraints on those parameters. I suppose one could (if you were adventuresome) go into the SLM code to extract (and return) the actual equations used to estimate the model as it is sent to lsqlin. Fmincon would need to employ those constraints too.

HTH,
John

03 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Kloosterman, Fabian

Dear John,

I wonder if it is possible with your functions to fit a spline to a set of (x,y) coordinates over time (each data point also has an associated weight). I want to constrain the velocity of the fitted spline trajectory, which means I can't just fit (x,t) and (y,t) separately. If this is not possible with your SLM tools, do you have any suggestions how to approach this problem?

Thanks, Fabian

02 Oct 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Chamane

excellent

02 Oct 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Ulrich

01 Oct 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Olsen, Jeem79

I just used your package to fit my stress-strain curves obtained from image acquisition and processing, and it works perfectly. Thanks for a great job! However, is it possible to extract only the fitted curve? I didn't see an obvious option for that in your documentation.

Jeem79

29 Sep 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Adsetts Edberg Hansen, Michael

28 Sep 2009 inpaint_nans Interpolates (& extrapolates) NaN elements in a 2d array. Author: John D'Errico Jon

24 Sep 2009 Moving window standard deviation A (fast) windowed std on a time series Author: John D'Errico D'Errico, John

Simplest is to replace the nans by interpolation. Use my inpaint_nans (also on the file exchange) to do this. Then apply this code to compute the moving standard deviation. High variance sections of the curve will still be high variance after this process. The virtue of this scheme is that both parts are fully vectorized codes.

The alternative is to use a loop, computing a windowed standard deviation on varying numbers of points by excluding the nan elements. This scheme may be tripped up if you have enough nan elements. Of course, with very many nan elements, no scheme will be perfect.

24 Sep 2009 Moving window standard deviation A (fast) windowed std on a time series Author: John D'Errico Rosie

This is just what I need except I have NaNs in my timeseries...how can I deal with these?

23 Sep 2009 Optimization Tips and Tricks Tips and tricks for use of the optimization toolbox, linear and nonlinear regression. Author: John D'Errico Shaun

Hi John,

As pointed out by Eric, I guess, for newer versions, you need an update.

Shaun

function stop = optimplot(x, optimValues, state)
% plots the current point of a 2-d otimization
stop = false;
hold on;
plot(x(1),x(2),'.');
drawnow

17 Sep 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico Joshua

16 Sep 2009 fminsearchbnd Bound constrained optimization using fminsearch. Author: John D'Errico D'Errico, John

Ryan,

This is really not a bound constrained problem. Your constraint is a general one, either a linear or a nonlinear inequality constraint.

The simple solution is to use a code that allows explicit linear or nonlinear constraints. There are a few on the FEX. In fact my fminsearchcon on the FEX does that, by applying a penalty to the problem when a constraint is violated. You might also look at optimize, by Rody Oldenhuis. This code allows explicit constraints of all forms.

However, there is a simple way to solve this class of problem with fminsearchbnd. Use another class of transformation. For example, suppose one wishes to minimize the function f(x,y), subject to the "bound" constraint that x <= erf(y).

Transform your problem such that

u = x + erf(y)
v = x - erf(y)

Clearly, v must be bounded above by 0. So use fminsearchbnd to optimize over the two dimensional domain (u,v). Inside your objective function, for any value of (u,v) you will compute the parameters (x,y) as

x = (u + v)/2;
y = erfinv(u - x);

Now you can finish evaluating the function f(x,y).

The only problem here happens if you also had other fixed bounds on x and y. But many other transformations would also have worked. For example, this transformation:

u = x
v = x - erf(y)

will still allow simple bound constraints on the parameter x, as well as allowing the nonlinear constraint x <= erf(y) as a bound constraint.

John

16 Sep 2009 fminsearchbnd Bound constrained optimization using fminsearch. Author: John D'Errico Webb, Ryan

 Great Function. Used it mane times.

However, now I have a trickier problem where one of the boundaries is a function of one of the variables. Making UB a function of xtrans is possible, but how would fminsearchbnd determine this intent given that the cases for transformation (k) are determined solely by the initial numerical values of the constraints? Thoughts?

16 Sep 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico D'Errico, John

Pete - A goal to be finished as soon as I can is to write a gui that will wrap SLM inside. Note that the computational tool in SLM is called SLMENGINE. This was purposeful, since my expectation is that most users would use the gui form when I am able to offer it. So I have definitely been planning for a gui wrapper.

Even at that though, SLM would not have allowed you to just draw a curve through your data freehand, and then return the coefficients of that curve. A freehand drawn curve may be arbitrarily complex, or not even a single-valued function. SLM is best when you fit the curve, then apply your own special knowledge of a system to be modeled, in the form of constraints on the overall shape of the underlying functional form. But a drawn curve to follow is too broad of a constraint to follow. So SLM might not be capable in general of returning such a functional form in that eventuality.

As well, this becomes a unique problem. Is the problem then to find the curve that fits the original data, and has the general shape of the freehand drawn curve? This involves two separate problems of approximation. It seems one must use a tool to smooth and approximate the drawn curve. Then take that same tool and try to fit the drawn curve through the data? This task would take some serious amount of effort, and would never be possible to do so where it would be transparent to the user. Worse, suppose the curve in the end had some lack of fit to the data (as perceived by the user?) Where did the lack of fit arise? Is it lack of fit to the freehand drawn curve? Or is it lack of fit to the data itself?

15 Sep 2009 SLM - Shape Language Modeling Least squares spline modeling using shape primitives Author: John D'Errico sherer, Pete

Would it be possible to add the GUI such that users can simply drag/adjust the fitted line in the way they want. The scripts then return the functional form and coefficients of the adjusted line. Maybe as an additional script or something.

11 Sep 2009 Moving window standard deviation A (fast) windowed std on a time series Author: John D'Errico Adam

09 Sep 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico D'Errico, John

Use of an interpolant followed by a smooth is a poor second choice, for several reasons.

Gridfit finds the surface that is as smooth as possible, that is consistent with the data. Smoothing a interpolated surface after the fact does not ensure that the result is consistent with the data. When you do a posterior smooth of the surface, the act of smoothing is now disconnected from the data.

Next, if you use griddata to interpolate a surface in advance, you will only get a result that lies within the convex hull of the data. Griddata will not extrapolate unless you use the v4 option, and that option is VERY slow for any significant number of points. Gridfit can extrapolate using several methods, depending upon your goals.

Extrapolation is an important capability of gridfit. But, extrapolation can come in many different forms. For example, consider a data set which is just slightly concave along one edge of the data. The published demo has a good example of this. See the second example, fitting a trigonometric surface. Along the edges of that data, see that the griddata interpolant generates long, thin triangles. Long thin triangles are terrible for interpolation, so what happens is you see strange interpolation artifacts along the edges.

Gridfit allows you to have replicates in your data, treating them properly in a least squares sense to generate the surface. Try out griddata with replicate data points. Even near replicate points can introduce nasty artifacts in the interpolant. Worse, the delaunay triangulation used in griddata will often have problems if you have sets of collinear data points. This is no problem at all for gridfit.

Finally, you can easily control the extent of smoothing done by gridfit.

In short, griddata has its purposes. There are general circumstances when I recommend griddata. But I would never recommend the use of griddata to be then followed by a smoothing operator.

09 Sep 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Bulatov, Yaroslav

What is the advantage of using gridfit instead of griddata followed by smoothing?

07 Sep 2009 fminsearchbnd Bound constrained optimization using fminsearch. Author: John D'Errico Will

Excellent modification to create a very useful algorithm. Thanks!

04 Sep 2009 Eigenshuffle Consistently sorted eigenvalue and eigenvector sequences Author: John D'Errico Ondrej

I thought so, that it couldn't be any harder than eigenvalues, but then I looked here
http://www.math.uu.nl/publications/preprints/1180.ps

Actually the code there seems to work pretty well. So schurly, no need to reinvent schurshuffle

03 Sep 2009 Eigenshuffle Consistently sorted eigenvalue and eigenvector sequences Author: John D'Errico D'Errico, John

For schur, I'd like to help. But schurly, then I would have to call the solution the schurshuffle.

http://www.youtube.com/watch?v=0V-VgRqsEcg

Seriously, it seems the same methodology would work. And with a name like the schurshuffle, I'd hate to pass up the opportunity.

03 Sep 2009 Eigenshuffle Consistently sorted eigenvalue and eigenvector sequences Author: John D'Errico Ondrej

Is it possible to write the same functionality but for schur decomposition? Schur function in matlab returns the eigenvalues on diagonal in same order as eig function..which is not always nice. Thanks.

27 Aug 2009 Polyfitn N-d polynomial regression model Author: John D'Errico D'Errico, John

Assuming that you have an array, that contains only w(x,y,z) for each element of the array, use ndgrid to generate the combinations of (x,y,z). Then call polyfitn with the data.

27 Aug 2009 Polyfitn N-d polynomial regression model Author: John D'Errico Xu, Chao

Hallo John,
Nice work!
I am a newbie in matlab and still got some questions about 3d fit.
I have a 3d dataset F(128,128,16) and would like to get the polynomial function F(x,y,z), how should I do it?

thanks!

25 Aug 2009 Surface Fitting using gridfit Model 2-d surfaces from scattered data Author: John D'Errico Arevalo, Daniel

Hello John, the function is really nice but I'm wondering if it would be possible to use it with non-rectangular domains where the nodes are just specified with (xn,yn) pairs n=1,..., N
Thanks for any help !

20 Aug 2009 Moving window standard deviation A (fast) windowed std on a time series Author: John D'Errico Ralph

19 Aug 2009 Automatic Numerical Differentiation Numerical derivative of an analytically supplied function, also gradient, Jacobian & Hessian Author: John D'Errico Michelle

Hi John,

Thanks for the timely and detailed reply! I had assumed that derivest handles all cases. Now I see jacobianest is a standalone function. Thanks again! And great code!

Michelle

18 Aug 2009 Automatic Numerical Differentiation Numerical derivative of an analytically supplied function, also gradient, Jacobian & Hessian Author: John D'Errico D'Errico, John

Hi Michelle,

The problem is, when you define myfun as you have, it is not a scalar valued function. It returns a vector argument. Thus we can do this:

myfun=inline('[exp(x);exp(2*x)]');

myfun(2)
ans =
       7.3891
       54.598

See that there are two numbers returned for a scalar input.

(By the way, I'd strongly recommend the use of function handles and anonymous functions instead of inline functions. An inline function is comparatively very slow to evaluate.)

The derivest code computes the derivative of a scalar valued function. Change your function to return a scalar value, as do myfun1 and myfun2 below, and derivest works as designed.

myfun1 = inline('exp(x)');
[d,err]=derivest(myfun1,1,'Vectorized','no')

d =
       2.7183
err =
   9.3127e-15

myfun2 = inline('exp(2*x)');
[d,err]=derivest(myfun2,1,'Vectorized','no')
d =
       14.778
err =
   1.8401e-13

Now, how might one define the derivative of a vector valued function? This is defined mathematically as the Jacobian. In fact, in the derivest suite, I have provided the jacobianest function to compute what you wish. It works on a vector valued function, returning a jacobian matrix. Here, since the parameter of these functions is a scalar, the Jacobian matrix is just a vector of length 2.

[d,err] = jacobianest(myfun,1)
d =
       2.7183
       14.778
err =
   3.6841e-14
   1.4736e-13
 
John

 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com