Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using multidimensional interpolation #2

Closed
slizovskiy opened this issue Dec 9, 2015 · 12 comments
Closed

Using multidimensional interpolation #2

slizovskiy opened this issue Dec 9, 2015 · 12 comments
Assignees

Comments

@slizovskiy
Copy link

Dear Andrew,
Could you extend the documentation by providing a simple example for multidimensional interpolation on a regular grid, please. In particular, how to enter and allocate space for tensor elements and how to save/load them. I suppose, this is done in the third-party libraries, but a basic example will be very helpful anyway.
Would the interpolation work a bit outside the domain (as extrapolation)? This could have been a useful feature.
Thank you!
Sergey

@awsteiner
Copy link
Owner

You are correct, there is no good tensor example, so I will work on it and get back to you as soon as I can. In the mean time, you may find src/base/tensor_ts.cpp helpful. However, I should warn you, O2scl includes only a very basic scheme for grid-based interpolation in higher dimensions in the tensor_grid class, but I don't recommend it's use for anything other than linear interpolation. (The classes interpm_neigh and interpm_idw work best on data which is not specified on a grid.) What rank tensor do you have?

Oh and I forgot: extrapolation is essentially always supported in O2scl for all of the interpolation methods.

@slizovskiy
Copy link
Author

Thank you for your reply! I have 6 D interpolation with around 1000000 sample points on a regular grid. There is a more sophisticated Bspline library called "splinter", BUT it takes enormous time even for linear BSpline. That's why I need a good FAST implementation of linear interpolation or some inverse square interpolation. Hope that your library will be helpful, but an example would be very helpful.
Best wishes,
Sergey

@slizovskiy
Copy link
Author

Thank you for referring to tensor_ts.cpp! I will try to write my example myself and will hopefully share it here.

@awsteiner
Copy link
Owner

Ok. Check out https://github.com/awsteiner/o2scl/blob/master/examples/ex_tensor.cpp . I try to make my classes agnostic with regard to the base vector type, so tensor_grid::interp_linear() always works. However, tensor_grid::interpolate() only works if the base vector types are from ublas.

@slizovskiy
Copy link
Author

That is a helpful example! Are there any save/load methods in tensor_grid class? I have read from the manual that you use HDF library for that. Is it hard to make a simple example that would save/load the tensor_grid with http://web.utk.edu/~asteine1/o2scl/html/classo2scl__hdf_1_1hdf__file.html functions?

@awsteiner
Copy link
Owner

The file ex_tensor.cpp now demonstrates this as well (the I/O functions are at the bottom of hdf_io.h). Note however that HDF5 I/O only works if the tensor is built upon std::vector types, since ublas vectors are not (so far as I know) guaranteed to be contiguous in memory.

@slizovskiy
Copy link
Author

Thank you! This is really helpful!

The file ex_tensor.cpp now demonstrates this as well (the I/O
functions are at the bottom of hdf_io.h). Note however that HDF5 I/O
only works if the tensor is built upon std::vector types, since ublas
vectors are not (so far as I know) guaranteed to be contiguous in memory.


Reply to this email directly or view it on GitHub
#2 (comment).

@slizovskiy
Copy link
Author

Dear Andrew, a useful improvement for the future could be the functions to integrate and differentiate on the (possibly non-equally spaced) tensor grid. This is not easy in general, but, at least the linear interpolation can be easily integrated.

@slizovskiy
Copy link
Author

Dear Andrew,
I have attempted to use tensor_grid template class with complex
field and this resulted in an error.
Is it hard to make it work for complex? At least, the linear
interpolation should be straightforward.
Best wishes,
Sergey

On 09/12/15 15:20, Andrew W. Steiner wrote:

You are correct, there is no good tensor example, so I will work on it
and get back to you as soon as I can. In the mean time, you may find
src/base/tensor_ts.cpp helpful. However, I should warn you, O_2 scl
includes only a very basic scheme for grid-based interpolation in
higher dimensions in the tensor_grid class, but I don't recommend it's
use for anything other than linear interpolation. (The classes
interpm_neigh and interpm_idw work best on data which is not specified
on a grid.) What rank tensor do you have?


Reply to this email directly or view it on GitHub
#2 (comment).

@awsteiner
Copy link
Owner

I'm not sure....let me try this later this week.

@ny2292000
Copy link

ny2292000 commented Jan 13, 2020

Dear Andrew,

I am facing the problem of calculating the proton fraction of a neutron star where Gravitation is irrelevant (zero pressure).

Can your work be applied to that scenario?
https://arxiv.org/pdf/1303.4662.pdf

By the way, I also had trouble in the make all for o2scl on ubuntu 18.04

Marco

@awsteiner
Copy link
Owner

Marco,

 1) I'd prefer you create a new issue rather than commenting on an unrelated issue. No need to repeat this comment, but I just note this for next time. 

 2) It's not clear exactly what you mean by "Gravitation is irrelevant". The proton fraction can be computed at any density and that calculation does not include any effect of gravity (using e.g. the calc_eos() function in the nstar_cold class). However, the phrase "proton fraction of a neutron star" implies you're thinking about a neutron star where ignoring gravity is a poor approximation. In any case, check out https://neutronstars.utk.edu/code/o2scl/eos/html/cnstar.html and see if that helps.

Take care,
Andrew

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants