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

Feature/distance gradient #13

Merged
merged 14 commits into from
Feb 14, 2021
Merged

Feature/distance gradient #13

merged 14 commits into from
Feb 14, 2021

Conversation

tpoisot
Copy link
Contributor

@tpoisot tpoisot commented Feb 12, 2021

Do not merge - this is DistanceGradient but there is a problem we need to solve before.

This was referenced Feb 12, 2021
@codecov-io
Copy link

codecov-io commented Feb 12, 2021

Codecov Report

Merging #13 (6e2d955) into main (a5ce6df) will decrease coverage by 9.88%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #13      +/-   ##
==========================================
- Coverage   47.61%   37.73%   -9.89%     
==========================================
  Files           7        8       +1     
  Lines          42       53      +11     
==========================================
  Hits           20       20              
- Misses         22       33      +11     
Flag Coverage Δ
unittests 37.73% <0.00%> (-9.89%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/NeutralLandscapes.jl 100.00% <ø> (ø)
src/algorithms/distancegradient.jl 0.00% <0.00%> (ø)
src/algorithms/nogradient.jl 0.00% <0.00%> (ø)
src/landscape.jl 90.90% <0.00%> (-9.10%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5ce6df...6e2d955. Read the comment docs.

@tpoisot
Copy link
Contributor Author

tpoisot commented Feb 12, 2021

Here we go!

index

function _landscape!(mat, alg::DistanceGradient)
@assert maximum(alg.sources) <= length(mat)
@assert minimum(alg.sources) > 0
indices = vcat(CartesianIndices(mat)...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reduce(vcat, CartesianIndices(mat)) is a more performant version - the splatting will be very slow for matrices of any relevant size.

Copy link
Member

@mkborregaard mkborregaard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a number of thoughts here.

  1. NearestNeighbours works for points in any location. I've always thought that for regular grids, it must be possible to define nearest neighbors (kdtrees) algorithmically.
  2. I think the most common use case for this package is for simulation analyses - in which case you might often generate multiple random landscapes from the same object? Would it make sense for objects like this, that requires a lot of preprocessing, to have a type that catches e.g. the kdtree, making new random matrices fast?

@mkborregaard
Copy link
Member

I am stupid. To get the results we need, the KDTree must be built on the sources of course. So in answers to above:

  1. It does not look like there is such an algorithm (I've also asked around)
  2. It makes no sense to cache the KDTree when it is built on the sources.

So that's that. I've made up for it by making a PR against this PR (#20) which is more performant and (hopefully) has a little cleaner code.

@tpoisot tpoisot merged commit 642be05 into main Feb 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants