Page 1 of 1 [ 10 posts ]
 Print view Previous topic | Next topic
Function similar to Polyfit?
Author Message

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Function similar to Polyfit?
Hi. I'm trying to convert a matlab gaussian fit function to yorick but I need to use a function that will find the coefficients of a polynomial p(x) of degree n that fits the data, p(x(i)) to y(i).

Is there a function available already in yorick? or do I need to include a special yorick library?
I'm looking for something similar to matlab's polyfit.

I read up on fil_poly() and poly() functions but they don't find the coefficients for me.

Thanks again,
Ronak

Tue Jul 05, 2011 11:41 am
Yorick Master

Joined: Sun Sep 26, 2004 10:33 am
Posts: 150
Location: Australia
Re: Function similar to Polyfit?
Personally, I like lmfit(). I believe you can find it in yeti.
It's a generic multi-parameters fitting routine using levenberg-marquardt minimization.
You give it a functional form to fit your data and it does the fitting for you.

Tue Jul 05, 2011 3:05 pm
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Re: Function similar to Polyfit?
The Yutils plugin provides poly1_fit and poly2_fit, for fitting in one dimension and two dimensions. They are found in poly.i.

Wed Jul 06, 2011 8:25 am

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Re: Function similar to Polyfit?
Thank you very much! I was able to use poly1_fit() fine. The only difference is that the coefficients returned are reversed but that's not a big deal at all.

Just a follow up question. How come the following poly functions aren't in the Yorick index?

 Code:> about,poly 1 - poly              4 - poly1_fit         7 - poly2_deriv 2 - poly1             5 - poly1_gcv_fit     8 - poly2_fit 3 - poly1_deriv       6 - poly2

Ronak

Thu Jul 07, 2011 8:27 am
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Re: Function similar to Polyfit?
I believe the index you linked to only lists core Yorick functions, and so won't include anything from plugins. Most of the functions you listed are from plugins, I believe. (The index is also dated 2005, so it may be missing things added to the Yorick core over the past 7 years.)

Thu Jul 07, 2011 9:36 am
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Re: Function similar to Polyfit?
I know nothing about matlab (and not much about the various yorick plugins). In yorick, type
 Quote:library

To print the Y_SITE/i/README file, which contains a summary of (nearly) all the functions in the yorick distribution i/ directory. There is a whole section on fitting.

The standard 1D minimax polynomial and rational function fitters are cheby and rcheby. The fitlsq and splinelsq functions provide interesting alternatives based on the interpolation functions interp and spline. For least squares fit (possibly multidimensional) polynomials or linear combinations of arbitrary basis functions, the regress function does the job. Finally, for non-linear least squares fitting, the levmar function often works pretty well. As you apply these functions to more and more complicated situations, you can expect numerical problems, which can usually be cleared up by rescaling some of your variables. In the case of levmar, you often need to supply parameter bounds explicitly. Some creativity is required; the functions aren't miraculous.

By the way, levmar is a newer extensive reworking of lmfit; it has some important additional functionality, and a much cleaner interface. I believe the only reason to use lmfit is in legacy code or minor modifications to legacy code. For new code, you should certainly look at levmar before lmfit, if for no other reason than levmar is in the core distribution and lmfit is not.

In general, I try to slowly migrate the best features of the various plugins into the core; for example, many of the simpler yeti functions have been migrated (mostly by Eric). It is difficult to forward-reference such migrations, especially since I sometimes can't resist "improving" the original API. The library command is a good place to look from time to time, as are std.doc and graph.doc (see below). I'd like to make the Web pages automatically update when I push new source code up to github, but I haven't figured out how to make that happen yet. I think it is possible with the github software, but I can't quite see how to do it...

Y_SITE/doc/std.doc has documentation for the simpler everyday functions, and Y_SITE/doc/graph.doc has documentation for all the graphics functions. To find Y_SITE, yorick's site directory, you can start yorick and type Y_SITE -- it is a variable containing the name of the Y_SITE directory. Or just type help with no arguments and read the basic information about your yorick installation.

Fri Jul 08, 2011 7:05 pm

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Re: Function similar to Polyfit?
The library command helped a lot on researching functions in Yorick. I'll look more into levmar and lmfit.

Offtopic but is there a way to reverse data in an array? This is because it would save some time if I could keep the coefficients in the same index as before.
 Quote:> arr = [1,2,3,4,5,6,7,8,9];> arr2 = reverse, arr;> arr2;[9,8,7,6,5,4,3,2,1];

Ronak

Tue Jul 12, 2011 8:35 am
Yorick Master

Joined: Wed Jun 01, 2005 11:34 am
Posts: 112
Re: Function similar to Polyfit?
To reverse, just supply a range with a negative step value.

 Code:> arr = [1,2,3,4,5,6,7,8,9]> arr2 = arr(::-1)> arr2[9,8,7,6,5,4,3,2,1]

See http://yorick.sourceforge.net/refcard/qrlang09.php

Tue Jul 12, 2011 8:59 am
Yorick Master

Joined: Mon Nov 22, 2004 9:43 am
Posts: 354
Location: Livermore, CA, USA
Re: Function similar to Polyfit?
Please at least skim the manual. For any yorick array index, you can specify min:max or min:max:step to get a subset of that index. In the second form, the step (or stride) can be negative to get the array elements in reverse order.

Wed Jul 13, 2011 1:02 pm

Joined: Tue Jun 07, 2011 1:46 pm
Posts: 32
Location: UNH
Re: Function similar to Polyfit?
I'm sorry about that. I did read the manual when starting to work with this program and I remember I read what dnagle said. I'll have to refresh my memory by reading/skimming the manual before asking future questions.

Ronak

Thu Jul 14, 2011 9:17 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 10 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ General    Announcements    Discussion & Support    Plugins    Bug Report