Skip to content

Commit

Permalink
Run CI also on pre-release versions (#71)
Browse files Browse the repository at this point in the history
* Run CI also on pre-release versions

* Use StableRNGs in tests

* Increment patch number

* Increase tolerance of GPD fit tests
  • Loading branch information
sethaxen authored Aug 29, 2024
1 parent a9ab4a5 commit 27ef161
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
version:
- '1.6'
- '1'
- 'pre'
os:
- ubuntu-latest
arch:
Expand Down
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PSIS"
uuid = "ce719bf2-d5d0-4fb9-925d-10a81b42ad04"
authors = ["Seth Axen <[email protected]> and contributors"]
version = "0.9.5"
version = "0.9.6"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -20,6 +20,7 @@ Plots = "1.10.1"
Printf = "1.6"
RecipesBase = "1"
ReferenceTests = "0.9, 0.10"
StableRNGs = "1"
Statistics = "1.6"
julia = "1.6"

Expand All @@ -29,9 +30,9 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["DimensionalData", "Distributions", "Logging", "JLD2", "Plots", "Random", "ReferenceTests", "Test"]
test = ["DimensionalData", "Distributions", "Logging", "JLD2", "Plots", "ReferenceTests", "StableRNGs", "Test"]
23 changes: 11 additions & 12 deletions test/core.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using PSIS
using Test
using Random
using ReferenceTests
using StableRNGs
using Distributions: GeneralizedPareto, Normal, Cauchy, Exponential, TDist, logpdf
using LogExpFunctions: logsumexp, softmax
using Logging: SimpleLogger, with_logger
Expand Down Expand Up @@ -77,20 +77,19 @@ using DimensionalData: Dimensions, DimArray
@testset "show" begin
proposal = Normal()
target = TDist(7)
rng = MersenneTwister(42)
rng = StableRNG(42)
x = rand(rng, proposal, 100, 1, 30)
log_ratios = logpdf.(target, x) .- logpdf.(proposal, x)
reff = [100; ones(29)]
result = psis(log_ratios, reff)
@test sprint(show, "text/plain", result) == """
PSISResult with 100 draws, 1 chains, and 30 parameters
Pareto shape (k) diagnostic values:
Count Min. ESS
(-Inf, 0.5] good 2 (6.7%) 98
(0.5, 0.7] okay 6 (20.0%) 92
(0.7, 1] bad 4 (13.3%) ——
(1, Inf) very bad 17 (56.7%) ——
—— failed 1 (3.3%) ——"""
Count Min. ESS
(0.5, 0.7] okay 2 (6.7%) 99
(0.7, 1] bad 2 (6.7%) ——
(1, Inf) very bad 25 (83.3%) ——
—— failed 1 (3.3%) ——"""
end
end
end
Expand All @@ -112,7 +111,7 @@ end
k_exp = 1 - θ
for sz in ((100_000,), (100_000, 4), (100_000, 4, 5))
dims = length(sz) < 3 ? Colon() : 1:(length(sz) - 1)
rng = MersenneTwister(42)
rng = StableRNG(42)
x = rand(rng, proposal, sz)
logr = logpdf.(target, x) .- logpdf.(proposal, x)

Expand Down Expand Up @@ -226,7 +225,7 @@ end
end

io = IOBuffer()
rng = MersenneTwister(42)
rng = StableRNG(83)
x = rand(rng, Exponential(50), 1_000)
logr = logpdf.(Exponential(1), x) .- logpdf.(Exponential(50), x)
result = with_logger(SimpleLogger(io)) do
Expand All @@ -236,7 +235,7 @@ end
@test result.pareto_shape > 0.7
msg = String(take!(io))
@test occursin(
"Warning: Pareto shape k = 0.73 > 0.7. $(PSIS.BAD_SHAPE_SUMMARY)", msg
"Warning: Pareto shape k = 0.72 > 0.7. $(PSIS.BAD_SHAPE_SUMMARY)", msg
)

io = IOBuffer()
Expand Down Expand Up @@ -290,7 +289,7 @@ end
end

@testset "test against reference values" begin
rng = MersenneTwister(42)
rng = StableRNG(42)
proposal = Normal()
target = Cauchy()
sz = (5, 1_000, 4)
Expand Down
12 changes: 5 additions & 7 deletions test/generalized_pareto.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using Distributions
using PSIS
using Random
using StableRNGs
using Test

@testset "Generalized Pareto distribution" begin
@testset "fit_gpd" begin
@testset for μ in (-1, 5), σ in (0.5, 1.0, 2.0), k in (-1.0, 0.0, 0.3, 1.0, 2.0)
d = Distributions.GeneralizedPareto(μ, σ, k)
rng = MersenneTwister(42)
x = rand(rng, d, 200_000)
rng = StableRNG(42)
x = rand(rng, d, 100_000)
dhat = PSIS.fit_gpd(x; μ=μ, min_points=80)
@test dhat.μ == μ
@test dhat.σ σ atol = 0.01
@test dhat.k k atol = 0.01
@test PSIS.fit_gpd(x; μ=μ, min_points=80) ==
PSIS.fit_gpd(x; prior_adjusted=true, μ=μ, min_points=80)
@test dhat.σ σ atol = 0.02
@test dhat.k k atol = 0.02
dhat2 = PSIS.fit_gpd(x; prior_adjusted=false, μ=μ, min_points=80)
@test dhat dhat2
@test dhat == PSIS.prior_adjust_shape(dhat2, length(x))
Expand Down
Binary file modified test/references/normal_to_cauchy_reff_0.7.jld2
Binary file not shown.
Binary file modified test/references/normal_to_cauchy_reff_1.2.jld2
Binary file not shown.

2 comments on commit 27ef161

@sethaxen
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/114083

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.6 -m "<description of version>" 27ef16136e2d55d5702ee02e132c730323ed2ab2
git push origin v0.9.6

Please sign in to comment.