Runtime compilation in InMin of functions to be minimised

With help from the tinycc compiler project, the InMin library can now compile, at-runtime, a function to minimise from its string representation in a C-like language.

So far this facility has been implemented for easy fitting of one dimensional functions with arbitrary number of parameters. The rules are as follows:

  • The syntax is exactly that for C expressions
  • The parameters to the function should be used as p[0], p[1], etc
  • The independent variable value is available in variable x
  • Functions acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, fmod, frexp, ldexp, log, log10, modf, pow, sin, sinh, sqrt, tan, tanh and standard C-language operators are available.

A very simple example used from the R-interface is:

inmin_1ds("p[0]*x+p[1]*x*x+p[2]", c(0,0,0), c(0, 1, 2, 3, 4), c(1, 2, 3, 4, 5))

Which minimises functions f(x)=a*x+b*x^2+c, with initial values for a, b and c all equal to zero, and for which the observed values are 1, 2, 3, 4, 5 for inputs 0, 1, 2, 3, 4.

Internally the string "p[0]*x+p[1]*x*x+p[2]" is inserted into a stub function and compiled to machine code and then this function is directly minimised -- there is no byte code and essentially zero overhead compared to a hand-crafted and compiled function.

This feature is available in versions of InMin 0.4 and above, available from http://www.bnikolic.co.uk/inmin/inmin-library.html