Hi,
Maybe some mildly ambitious project that we could start now, would be to create some good spline routines.
There are some existing libraries in Fortran (notably fitpack) and in C (einspline).
Python/Scipy has some wrappers around fitpack, and there has been some discussion on the scipy mailing list this spring to create a new implementation in Cython (a compiled dialect of python so to say), but it hasn't produced any output yet, that I am aware of. There is also a Julia package called BSplines, that is currently restricted to dimension 1.
Dolo already includes cubic splines with derivatives and extrapolation, on regular grids. These are generated from a template file that generate Cython code, which is very similar in essence to the einspline code, except that it can handle dimensions >3. Templating is used only for the evaluation, while traditional coding is used for the filtering step. It would be very easy to adapt the templating, to produce Julia code inead. It could be generated once for all, or replaced later by Julia macros. That would give us (natural) cubic splines in Julia with little work to do.
Le lundi 30 septembre 2013 à 14:46 -0700, Pablo Winant a écrit :
> I have made a tentative implementation for cubic splines in Julia
> here: https://github.com/EconForge/splines_julia . This is very
> preliminary, incomplete and inelegant, but since I won't be making
> much progress on it in the following weeks, I thought it was better to
> share it now.
Thanks for contributing this!
How would you want to proceed for the next steps? I see the following
possible improvements:
- improve the interface so that instead of having two functions in the
API (one returning an array of coefficients, the second for evaluating
the spline), we would have only one function in the API which would
return a function object (that we can call directly later to evaluate
the spline). This is the approach taken by the BSplines package and I
think it is much more julia'ish. It may also involve some performance
improvements since it some constants may be optimized out in the process
by the LLVM JIT (to be verified)
- add derivatives
- rewrite the macro system in Julia (and drop the python code)
- think about how to integrate this code into the BSplines package
- benchmark it
I am willing to give some help but I would need a paper/reference to
understand better what the code is doing.
Also I ran the test file and got an error for the 2D code:
2D interpolation
ERROR: invperm: input is not a permutation
in invperm at combinatorics.jl:110
in \ at linalg/factorization.jl:372
in \ at linalg/dense.jl:519
in filter_coeffs at /home/sebastien/splines_julia/splines_filter.jl:3
in include at boot.jl:238
in include_from_node1 at loading.jl:96
at /home/sebastien/splines_julia/test.jl:52
> - rewrite the macro system in Julia (and drop the python
> code)
>
> I agree. There is still one drawback here: the macro code will
> probably more convoluted that the generated one. Maybe it is still
> possible to keep it somewhere when calling the macro, in order to see
> the output.
> Another thing: it is possible to avoid macros completely if we allow
> for recursive calls for each evaluation.
Which approach is preferable in your opinion?
I am willing to do the Julia macro stuff if we choose that path.
> Also I ran the test file and got an error for the 2D code:
>
> 2D interpolation
>
> ERROR: invperm: input is not a permutation
> in invperm at combinatorics.jl:110
> in \ at linalg/factorization.jl:372
> in \ at linalg/dense.jl:519
> in filter_coeffs
> at /home/sebastien/splines_julia/splines_filter.jl:3
> in include at boot.jl:238
> in include_from_node1 at loading.jl:96
> at /home/sebastien/splines_julia/test.jl:52
>
>
> Which system/juliia version do you use ? In principle the solution
> operator\ is supposed to be operated on sparse arrays, which is not
> consistent with the error message. What I don't understand is why you
> get the message only for 2d interpolation.
> Are you still using julia 0.1 ? (https://groups.google.com/forum/#!
> searchin/julia-dev/deprecate$20julia
> $200.1/julia-dev/l4lZKoJcn94/W6QBcdxRZ7kJ)
The test was done using a recent git snapshot (commit b3be803*
2013-10-04 13:15:40 UTC)
Some update on that front: I have added the computation of the gradient, and updated the api a bit. There are now many options to interpolate data that are demonstrated in this notebook: http://nbviewer.ipython.org/urls/raw.github.com/EconForge/splines_julia/master/cubic_splines_julia.ipynb . These options are:
csplines.jleval_UC_spline and eval_UC_spline_G (with the gradient). These call the relevant low-level function according to the dimension, an allocate the output.There are still some pitfalls I don’t like about the implementation, but it would be good, if the high-level api could be tested a bit to see whether we like it or not.
Pablo