&ot Journeys' End

Journeys' End

We walk many paths, many roads
Till death halts our steps.
Every day a new adventure,
A new journey of self discovery.

20080716

unoffical libfg repository

I have set up an unofficial git respository for libfg patches and new swig generated python interface, as Gavin Baker (the author) appears to be busy with other things. This is a maintance only repository as far as libfg goes - I don't plan on adding any more features (since all the ones I need are there already). I will however work to produce a more pythonic interface to libfg, as the swig generated interface is a straight port of C api into Python.

Currently the repository contains the following fixes and enhancements:

  • RGB565 and RGB555 patch by Adalbert Prokop
  • fg_new_compatible_frame patch by echoline
  • mmap fix by me
  • swig generated Python interface by me

If you have a patch against libfg, please post it at the libfg project's page first, and then to me if Gavin does not respond. I do not intend to take over development of libfg, and it is my hope Gavin will in the future make this obselete/redundant.

Cheers,
Steve

Labels: , , , , , ,

20070414

Writing fitting functions for lmfit

lmfit expects fitting functions with prototypes in the form:

double function_name(double, double *);

For example:

double sin_fit(double t, double * p)
{
return p[0] + p[1] * sin ( 2 * M_PI * ( p[2] * t + p[3]));
}


Note that while lm_minimize takes a pointer to an array of parameters, it may not always pass that pointer to the fitting function. Because of this passing fixed parameters to the fitting function using the 3rd argument will yield incorrect results. For example, the following code is wrong:

double wrong_fit(double t, double *p)
{
return p[0]*p[0] + p[1];
}

....

double p[2];

p[0] = 1;
p[1] = magic_number;

...

lm_minimize(..., 1, p, ..., ..., ...., ...);

Here the fitting function wrong_fit relies on a fixed parameter p[1] which it expects to contain the value magic_number. However it will be passed such a p that only p[0] has a valid value and p[1] is undefined. This will lead to incorrect operation.

To work around this, you can use global variables, as follows:

double magic = magic_number;

...

double right_fit(double t, double * p)
{
return p[0]*p[0] + magic;
}

....

double p = 1;

...

lm_minimize(..., 1, &p, ..., ..., ..., ...);


Cheers,
Steve

Labels: ,