Jump to content

LVOOP Curve Fitting


Recommended Posts

Just wondering...

In the newer Non-linear Curve fit VI's (such as <vi.lib>gmath\NumericalOptimization\Nonlinear Curve Fit LM.vi), you need to supply a reference to a VI that implements the model function; you can optionally pass data you need in that VI in a Variant, which you need to de-variant in said VI.

Looks to me an ideal usecase for LVOOP: instead of supplying a reference-and-variant you could supply a generic 'modelfunction.lvclass' instance, the lvclass having a virtual 'generate' method, which can be overridden for each specific fit function. Any data you would need (and now have to slip in via the variant) can then be encapsulated in the modelfunction.lvclass.

I'm doing a lot of curve fitting these days, so I'm looking for ways to force my programs into a more modular structure before things get out of hand, and I'm the only one left understanding what's going on in the code. I'm thinking about implementing this sort of thing on-top-of / using the exisiting curve fitting VI's but can't help wondering: the LVOOP implementation seems obvious, so does anyone know if such a thing is planned for the next LV release?

/dirk

Link to comment

QUOTE (Aristos Queue @ Jun 13 2008, 06:54 PM)

I would be surprised if we did any such work on the math VIs until classes have been on RT for at least one release (to make sure they're stable).

I don't think the math VIs themselves are the issue.

Personally, I have had the same idea about using Objects for this kind of operation. You could quite easily mix up Gauss fit objects with other types and simply calculate an array of different individual functions. I was working with multi-gauss peakfits with different base-lines and simultaneous calibration.

Think of it as having "model" objects.

I think being able to put together a compound function like that would be great and would entail a level between the non-linear curve ft and the math VIs.

I never got around to it, but I think it's a quite viable route to go down.

Shane.

Link to comment

QUOTE (Aristos Queue @ Jun 13 2008, 06:54 PM)

I would be surprised if we did any such work on the math VIs until classes have been on RT for at least one release (to make sure they're stable).

That makes sense, and I guess it also makes it worth while to put some effort in.

I'm thinking along these lines, if anyone has comments on this please make them!

Some of the design choices may be sub-optimal, but at this point I want to use the existing math VI's without modification (so I can benefit from future versions)

This is may inventarization of the curve fitting routines in LV. My most important criterion is that an algorithm should return a covariance matrix so that I can compute error estimates en dependencies etc.

Type Coeff?/Covar Mtrx?/ Can be specialization of:

Linear Yes/No/ NLLS

Exponential Yes/No / NLLS

Power Yes/No / NLLS

Gauss Yes/No / NLLS

Logarithmic Yes/No / NLLS

Polynomial No/No / NLLS

Gen LS Linear No/Yes*/ NLLS

Cubic spline No/No/

Ciruclar No/No/

General NLLS Yes/Yes/

Constrained NLLS No/Yes*/

* covariance matrix is available, so coefficients can be calculated.

So, from I versatility-point-of-view I want to build everything on top of the NLLS algorithms.

Conceptually, the general NLLS can be thougth of as a specialized case of the constrained NLLS (with parameter bounds -Inf to Inf) but since the LV implementation is somewhat different for both cases I don't want to implement it that way. There will be a curvefit.lvclass wich has the methods Fit and ConstrainedFit (see below for details)

===========fit parameters ==============

class parameter (lvobject) // class defining a model parameter

members name : string; // for identification and reporting

value , // initial guesses at start of program, value at current iteration

standard error, // st error of the parameter (diagonal element of covariance matrix)

dependency: double; // dependency of the fit on this parameter (0-1 from covariance matrix)

methods ExportParameterArray(var coefs: array of double) {dynamic}

// adds current value to the coefficients array coefs used in the LM curve fitting

ImportParameterArray(coefs: array of double) {dynamic}

// extracts the updated value for this parameter from the coefs array used in the LM curve fitting

class constrained_parameter (parameter) // child class of paramter.lvclass for a constrained model paramter

members vary: enum{yes,no,withinlimits}; // treat parameter as variable (yes), constant (no) or limited variable (withinlimits)

upperbound, // when vary=withinlimits, these define the upper and lower bounds for the paramter

lowerbound: double;

methods ExportParameterArray(var coefs: array of double) {override}

// adds current value to the coefficients array coefs depending on the value of vary

ImportParameterArray(coefs: array of double) {override}

// extracts the updated value for this parameter from the coefs array depending on the value of vary

========= fit models =============

class fitmodel(lvobject) // parent class for custom fit models.

members parameters: array of parameter.lvclass; // defines the model parameters (note: can hold child classes of parameters.lvclass as well)

X: array of double // X values. (note: these are not allways needed, so I guess I should move this to more specific class)

methods Generate {dynamic} // implements the model. virtual method, it must be overwritten

class myfitmodel(fitmodel) // implementation of custom model

members ............ // can be anything you need to make this model work

methods Generate {override} // implements the model.

========= curve fitting =============

class curvefitting(lvobject) // class implementing NLLS curve fitting

members model: fitmodel.lvclass; // defines the model

Y, // dependent data

weights, // weigths to be used in the fit best fit, // holds the best model fit to the data

error bounds: array of double // used to calculate confidence and prediction bounds

methods Fit {dynamic} // implements the NLLS curve fit

FitConstrained {dynamic} // implements the constrained NLLS curve fit

FitStatistics // implements the constrained NLLS curve fit

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.