-
Notifications
You must be signed in to change notification settings - Fork 6
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
Creating ics on grid for basins of attraction is super slow for higher dimensions #76
Comments
I wouldn't use lab = zeros(Int32, N)
for i in 1:N
lab[i] = mapper( ic_generator())
end The A more condensend version: |
Ah, nice idea! But in this case I need to use |
So the problem is just initial condition caching? Because I assume you have a low dimensional feature space. |
Yup. This line takes way too long just to create the ics when the dimension of the grid is high (100+).
Yup, |
What about a special sampler with an internal queue:
I am not sure it is possible, I am just throwing an idea |
It is because of static arrays. We need to allow And once this PR is merged, to allow for a keyword, or some heuristic, to use vectors if dimension is very high. |
BTW I had this problem elsewhere as well, that StateSpaceSet.jl doesn't work with vectors in ComplexityMeasures.jl. |
Partly, but indexing the cartesian indices is also very slow. For example this code:
just hangs on my computer when I try it. So I'm not sure if
would do it, unfortunately. |
This cannot be possible, because indexing the cartesian indices is as fast as indexing a linear range |
Also, your code gives me infinite stack overflow messages well before I go into the cartesian indices :D already from |
|
Ah no sorry this is because of my printing hack :D |
Okay, now I finally understand the problem. "Indexing the cartesian indices" means to obtain the indices themselves. And yes, indeed, simply doing
|
Here you are creating a monster array: |
@KalelR you should open an issue at the main Julia repo that Cartesian Index access becomes slow and allocates in high dimensional arrays. This is too deeply internal of Julia for us to do anything. |
Actually, I don't think anyone can do anything. The same limitation that comes from regular tuples goes into Cartesian Indices as well. Tuples are limited to 32 "dimensions" to be fast if I recall correctly. We would need to use Vectors to index things above some dimension. |
Indeed, I haven't found a way to fix it using CartesianIndices, but Vectors do work great. Since typically we are working on a 2D projection of the basins, there are only two important dimensions, and the ics on others (which could be a lot) are fixed anyway. So a solution that's working for me now is to use CartesianIndices only for the dimensions have length > 1 (corresponding to the dimensions of the ics that are varying), and then build the grid from those indices. Then I put the grid of varying ics together with the fixed ics to construct the vector of the full ics. It works great for my use-case, but I would like to test it further in other cases, I just don't have time at the moment. I'll put the code here anyway in case anyone is interested: function generate_ics_on_grid(grid::NTuple{B, T}) where {B, T}
grid_lengths = length.(grid)
idxs_varying_dims = findall(len->len>1, grid_lengths)
reduced_grid = grid[idxs_varying_dims]
I_reduced = CartesianIndices(length.(reduced_grid))
A_reduced = [generate_ic_on_grid(reduced_grid, i) for i in vec(I_reduced)]
ics_fixed = [grid_dim[1] for grid_dim in grid]
A = _expand_A(A_reduced, ics_fixed, idxs_varying_dims)
return Dataset(A)
end
function _expand_A(vec_reduced, ic_fixed, idxs_varying_dims)
vec = [deepcopy(ic_fixed) for _ in vec_reduced]
for i in eachindex(vec)
vec[i][idxs_varying_dims] .= vec_reduced[i]
end
return vec
end Oh, and using regular vectors when the dimension gets beyond a value (in my case, 30) also helps: function generate_ic_on_grid(grid::NTuple{B, T}, ind) where {B, T}
mx_dimension_sparse = 30
if B < mx_dimension_sparse
return _generate_ic_on_grid(grid, ind)
else
return _generate_ic_on_grid_vec(grid, ind)
end
end
function _generate_ic_on_grid_vec(grid::NTuple{B, T}, ind) where {B, T}
gens = [(grid[k][ind[k]]) for k=1:B]
return gens
end |
Hey
I need to calculate basins of attraction for a high-dimensional system (100+), but I noticed that
basins_of_attraction
is super slow for these cases because of the creation of the initial conditions on a grid. EspecificallyA = StateSpaceSet([generate_ic_on_grid(grid, i) for i in vec(I)])
is very slow for higher dimensions (was taking more than an hour to run...).
I think there are two reasons: evaluating the
CartesianIndices
becomes slow, and also maybe becausegenerate_ic_on_grid
allocates StaticVectors.What would be a good solution for this?
Thanks a lot!
The text was updated successfully, but these errors were encountered: