From d19377e24c25479506f188355419ba74997c5176 Mon Sep 17 00:00:00 2001 From: michael catchen Date: Fri, 20 May 2022 12:29:23 -0400 Subject: [PATCH 1/4] implementing normalize test --- test/updaters.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/updaters.jl b/test/updaters.jl index 7f51733..cd89328 100644 --- a/test/updaters.jl +++ b/test/updaters.jl @@ -30,7 +30,20 @@ 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 min(normseq...) >= 0 && max(normseq...) <= 1 + @test length(findall(isnan, normseq[end])) == 0 + 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 +51,6 @@ models = [ SpatiotemporallyAutocorrelatedUpdater ] + +testnormalize.(models) testupdaters.(models) From c0ce98a56fa19245068f870844f44acf34e9a10b Mon Sep 17 00:00:00 2001 From: michael catchen Date: Fri, 20 May 2022 12:35:12 -0400 Subject: [PATCH 2/4] normalize works with NaNs --- src/updaters/update.jl | 2 +- test/updaters.jl | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/updaters/update.jl b/src/updaters/update.jl index 0434d92..79354c0 100644 --- a/src/updaters/update.jl +++ b/src/updaters/update.jl @@ -41,7 +41,7 @@ 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) + mins, maxs = [NaNMath.min(x...) for x in mats], [NaNMath.min(x...) for x in mats] totalmin, totalmax = findmin([x[1] for x in mins])[1], findmax([x[1] for x in maxs])[1] returnmats = copy(mats) for (i,mat) in enumerate(mats) diff --git a/test/updaters.jl b/test/updaters.jl index cd89328..bc80400 100644 --- a/test/updaters.jl +++ b/test/updaters.jl @@ -35,7 +35,6 @@ function testnormalize(model) env = rand(MidpointDisplacement(0.5), 50, 50) seq = update(updater, env, 30) normseq = normalize(seq) - @test min(normseq...) >= 0 && max(normseq...) <= 1 @test length(findall(isnan, normseq[end])) == 0 env = [NaN 5 2 1 NaN; 3 4 5 2 1; 6 NaN 0 5 2; NaN NaN 0 4 5] From 456edd370b605f00d2e52872002b90c80a922bde Mon Sep 17 00:00:00 2001 From: michael catchen Date: Fri, 20 May 2022 12:48:30 -0400 Subject: [PATCH 3/4] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From fc82097c9a2996680e9372c88658fdf565d60dd0 Mon Sep 17 00:00:00 2001 From: michael catchen Date: Fri, 20 May 2022 14:29:28 -0400 Subject: [PATCH 4/4] caught typo and added test to fix --- src/updaters/update.jl | 4 ++-- test/updaters.jl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/updaters/update.jl b/src/updaters/update.jl index 79354c0..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 = [NaNMath.min(x...) for x in mats], [NaNMath.min(x...) for x in 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 bc80400..8d829f0 100644 --- a/test/updaters.jl +++ b/test/updaters.jl @@ -36,6 +36,10 @@ function testnormalize(model) 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)