-
Notifications
You must be signed in to change notification settings - Fork 1
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
Improved Grid_points and rand_p #50
base: main
Are you sure you want to change the base?
Conversation
* Add support for rng and eltype in rand_itn * Bump ITN version * added error catching for gridpoints and function for random gridpoint sampling * change to overload Random.rand * Rename to prevent dimension overload * Rename calculate_fx(yz) to evaluate * Rename calculate_x(yz) to calculate_p * Rename delta_x(yz) to delta_p * created improved grid_points() * grid_points can take arbitrary ranges * Return dimension_indices * Changed instances of dimension in grid_points() and rand() to use d instead * updated grid_points() and rand() to incorporate feedback * grid_points() uses simpler method when span is default * changed to rand_p() and added enforced points * fix minor edge case * Formatting --------- Co-authored-by: Ryan Levy <[email protected]> Co-authored-by: Joseph Tindall <[email protected]>
Add RNG passing
* Add support for rng and eltype in rand_itn * Bump ITN version * Rename to prevent dimension overload * Rename calculate_fx(yz) to evaluate * Rename calculate_x(yz) to calculate_p * Rename delta_x(yz) to delta_p * Return dimension_indices * add 1d polynomial interpolation * added black box function ITNs for fourier/chebyshev * working chebyshev * experimenting with function_itn * add data_itensornetwork() * started 2D functions, expanded data into QTT * working 2D function TNs * 2D data to ITN * clean up code * rename examples and add image to ITN example * function/data itn now takes top coefficients by magnitude by default * formatting * add data_itn documentation * move interpolation functions to new file * add compat version info --------- Co-authored-by: Ryan Levy <[email protected]> Co-authored-by: Joseph Tindall <[email protected]>
* added clenshaw interpolation * update how max_coeffs works * add attribution and rename vars
…eaned up code a bit
… rand_p robust to big L
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ryan!
I think the biggest change here is that rand_p
changes the return value from Float to BigFloat. I have some concerns with this:
- I'm not sure we have tightened up passing
Number
everywhere (we could maybe just have a test that we can evaluate a basic function on a grid or something) - grid_points doesn't match this behavior (basically everywhere just does base^L).
- I'm also not sure we want to enforce BigInt/BigFloat for say
L=4
. We could disbatch on havingbase
be BigInt and force the user to deal with this, but I'm not 100% on this at the moment
For performance reasons I previously swapped index_value_to_scalar
to return float(base)^L
instead of base^L
, but that won't work here due to InexactErrors. We could try to reconcile these choices though
@JoeyT1994 what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also add support for multidimensional grid points.
Like we have a function where we pass a vector of dimensions
and then zip up the result of grid_points
called on each of the dimensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you elaborate more on what your idea for this would look like?
for example, if you passed in a vector dimensions = [1,3]
, and suppose that grid_points(s,1) = [0, 1]
and grid_points(s,3) = [0.3, 0.4, 0.5]
, would grid_points(s, [1, 3])
then be something like [[0, 0.3], [0, 0.4], [0, 0.5], [1, 0.3], [1, 0.4], [1, 0.5]]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes so if for each dimension I
you input you generate some vector of Ni
points then it would return the iterative product which consists of every unique combination of points:
e.g. [0.25, 0.5], [0.625, 0.975, 0.9875] -> [(0.25, 0.625), (0.25, 0.975),(0.25, 0.9875), (0.5, 0.625), (0.5, 0.975), (0.5, 0.9875)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would it be better to return an array of tuples or an array of arrays here?
I initially leaned towards having an array of arrays because evaluate
takes in an array to specify the point it should evaluate the function at.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ryananselm! I added some suggestions, let me know how you get on.
src/IndexMaps/realindexmap.jl
Outdated
|
||
if !exact_grid | ||
grid_points = range(span[1], span[2] - (span[2] - span[1]) / N; length=N) | ||
else #exact_grid = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am think this function should follow some more straightforward logic to simplify this code (even if its not quite optimal):
- Generate an inexact grid using the
range
function - If
exact_grid = true
Round all the results to the nearest decimal compatible with the spacing2^-L
(write a helper function for this) and return only the unique values you get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made these changes in the simplify grid_points commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Ryan! I think we're getting there
For now, to deal with the BigFloat issue, I made it such that it only uses |
src/IndexMaps/realindexmap.jl
Outdated
end | ||
|
||
function round_to_nearest_exact_point(point::Number, L::Int) | ||
return round(point * 2.0^min(63, L)) / 2.0^min(63, L) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes base 2, but we shouldnt right? However, for base 2 we can use a trick
round(ldexp(point,L))/2.0^L
That seems to work for any L that can be represented by point
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I generalized this function to take in the base as an argument
Thanks Ryan, maybe hold off until Joey can comment, but could you specialize anything with |
This PR contains only the grid_points and rand_p related changes.