bgrimstad / splinter

Library for multivariate function approximation with splines (B-spline, P-spline, and more) with interfaces to C++, C, Python and MATLAB
Mozilla Public License 2.0
414 stars 115 forks source link

Physics usage #94

Closed mikevitz closed 6 years ago

mikevitz commented 6 years ago

Hi, I will be trying to use this package for function interpolation in 4 dimensions of spacetime. That is, there is a function f(x,y,z,t) that I can evaluate easily on a 4-d grid in parallel. But to find the minimum of the function I need to have a continuous evaluation, so I will use interpolation to get the value of f at arbitrary points.

I have some questions/requests: 1) Is the limitation to 100,000 sample points coming from processing time or memory allocation? If it is memory allocation, I have access to a machine that has several TBs of RAM. But if it is processing time, I can plan to have the program run for weeks, but not months.

2) Is it possible to include a basic gcc compilation command for the test functions in the cpp interface? I have installed splinter version 3, but am having trouble compiling anything to an executable.

bgrimstad commented 6 years ago

Hi @mikevitz,

  1. The limitation of N=100,000 sample points is only a practical rule-of-thumb. When building a B-spline, the main workload is the solving of a sparse linear system of equations, which is roughly O(N^3). Processing time will be your limiting factor, not memory. A good advise is to try with fewer samples first. When you increase the number of samples (or resolution of your grid), you will get a feeling of how the solve time scales. The increase in accuracy from processing for, say 1 day, compared to 10 minutes, may not be worth the wait. It depends on your application/requirements, of course.

  2. Not sure if I understood you correctly, but you can use Catch-flags to (dis-)enable certain tests. I think @gablank can better help you with this.

Please make sure that you are able to store the B-spline after processing. In the master-branch (v3.0), it is possible to store the B-spline in a binary format. This format is due to change, and I would advise that you also store the resulting knots, degrees, and control points in a non-serialized/text format to ensure that you can reuse them in a later version. In the upcoming release we will provide storage in JSON format.

Lastly, for optimization of the resulting spline you may use a multi-start gradient descent heuristic for local optimization using the gradients supplied by SPLINTER. Alternatively, you may attempt to use CENSO for global optimization, but this will require some effort to set up.

Best regards, Bjarne

PS: Out of curiosity, what kind of system does your function represent?

mikevitz commented 6 years ago

Hi @bgrimstad, I'll play around more with it to understand the answer to my first question. Thanks!

For #2 I just mean that for the simple test program, in the section on cpp interface, you say "Below is a simple example demonstrating the use of SPLINTER. Remember to compile with a C++11 compatible compiler!"

Could you provide a simple compilation command example with known good compiler, like g++ -I/path_to_include -o testSplinter.x testSplinter.cpp -L/path_to_lib

I will be sure to work on the Bspline storage, but maybe wait for version 4.0 :) But as you may guess, I am just beginning to understand the software...

Many thanks for the attention! Best Regards, Mike

P.S. I have two uses. One is to calculate the probability from quantum field theory the probability of a particular event (muon decays), given the values of phase space (they are actually energy variables, not positions, so f(px,py,pz,E) not f(x,y,z,t)...) The formula is hugely complicated to take into account higher order effects. I could pass this directly to the minimization, but this results in a huge slowdown. If I evaluate on a grid, I can parallelize it, but then must recover a continuous structure to use in the minimization. So I interpolate...

The other use is finding a minimum of a chi-square function. Again, the evaluation at each point in parameter space takes a long time, so I would like to parallelize the calculation, i.e. just scan over chi-squared values. Intermediate values can be interpolated, creating a continuous structure. Then I can feed the scan into a canned minimization routine.

gablank commented 6 years ago

Hello @mikevitz!

Maybe I can be of help with your second question. First of all, what operating system are you using? Assuming you are using some version of Debian (Ubuntu++), these are the steps to compile SPLINTER with an example program (tested with a fresh Ubuntu 14.04):

I hope this was of use to you!

mikevitz commented 6 years ago

That seems to have got it exactly! I get a lot of warnings during compilation of the main.cpp to executable. They are all of the form warning: ignoring attributes on template argument or else deprecated declarations.

It seems to mostly be problems in Eigen. And they are warnings that can be turned off with the right flags. But I attach the warnings warnings.txt for completeness.

Many thanks for the help!

bgrimstad commented 6 years ago

Thank you.

The warnings are related to #97. The issue will be solved with the new release.