diff --git a/Project.toml b/Project.toml index 97aedec..3f72b3f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "NeutralLandscapes" uuid = "71847384-8354-4223-ac08-659a5128069f" authors = ["Timothée Poisot ", "Michael Krabbe Borregaard ", "Michael David Catchen ", "Rafael Schouten ", "Virgile Baudrot "] -version = "0.1.0" +version = "0.1.1" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/src/updaters/update.jl b/src/updaters/update.jl index 0434d92..4facf5b 100644 --- a/src/updaters/update.jl +++ b/src/updaters/update.jl @@ -41,8 +41,8 @@ and 1. Note that this does not preserve the `rate` parameter for a given difference between the total maximum and total minimum across all `mats`. """ function normalize(mats::Vector{M}) where {M<:AbstractMatrix} - mins, maxs = findmin.(mats), findmax.(mats) - totalmin, totalmax = findmin([x[1] for x in mins])[1], findmax([x[1] for x in maxs])[1] + mins, maxs = [NaNMath.min(x...) for x in mats], [NaNMath.max(x...) for x in mats] + totalmin, totalmax = NaNMath.min(mins...), NaNMath.max(maxs...) returnmats = copy(mats) for (i,mat) in enumerate(mats) returnmats[i] = (mat .- totalmin) ./ (totalmax - totalmin) diff --git a/test/updaters.jl b/test/updaters.jl index 7f51733..8d829f0 100644 --- a/test/updaters.jl +++ b/test/updaters.jl @@ -30,7 +30,23 @@ function testupdaters(model) @test env != oldenv end +function testnormalize(model) + updater = model() + env = rand(MidpointDisplacement(0.5), 50, 50) + seq = update(updater, env, 30) + normseq = normalize(seq) + @test length(findall(isnan, normseq[end])) == 0 + for m in normseq + @test min(m...) >= 0 && max(m...) <= 1 + end + + env = [NaN 5 2 1 NaN; 3 4 5 2 1; 6 NaN 0 5 2; NaN NaN 0 4 5] + seq = update(updater, env, 30) + normseq = normalize(seq) + @test length(findall(isnan, normseq[end])) == 5 + +end models = [ TemporallyVariableUpdater, @@ -38,4 +54,6 @@ models = [ SpatiotemporallyAutocorrelatedUpdater ] + +testnormalize.(models) testupdaters.(models)