diff --git a/.github/workflows/Format-PR.yml b/.github/workflows/Format-PR.yml deleted file mode 100644 index 0b265d8..0000000 --- a/.github/workflows/Format-PR.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: Format Suggestions -on: - pull_request: -jobs: - code-style: - runs-on: ubuntu-latest - steps: - - uses: julia-actions/julia-format@v2 \ No newline at end of file diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml deleted file mode 100644 index 8977b5e..0000000 --- a/.github/workflows/Format.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: Formatter -on: - schedule: - - cron: '0 0 * * *' - push: - branches: - - 'main' - tags: ['*'] -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v1 - with: - version: '1' - arch: x64 - show-versioninfo: true - - uses: julia-actions/cache@v1 - - name: Install JuliaFormatter and format - shell: julia --color=yes {0} - run: | - using Pkg - Pkg.add("JuliaFormatter") - using JuliaFormatter - format(".") - - # https://github.com/marketplace/actions/create-pull-request - # https://github.com/peter-evans/create-pull-request#reference-example - - name: Create Pull Request - id: cpr - uses: peter-evans/create-pull-request@v6 - with: - token: ${{ secrets.GITHUB_TOKEN }} - commit-message: Format .jl files - title: 'Automatic JuliaFormatter.jl run' - branch: auto-juliaformatter-pr - delete-branch: true - labels: formatting, automated pr, no changelog - - name: Check outputs - run: | - echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}" - echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}" \ No newline at end of file diff --git a/docs/examples/Basics.jl b/docs/examples/Basics.jl index 6f10d9f..11c7bbf 100644 --- a/docs/examples/Basics.jl +++ b/docs/examples/Basics.jl @@ -82,7 +82,7 @@ raster # We can bin the data in small time windows to get a sense of the event rate over time. From the assumptions above, we expect the distribution of # counts to be roughly Poisson distributed with rate λ * Δt in each bin of width Δt. bin_width = 1.0 -bins = collect(h.tmin:bin_width:h.tmax) # bin edges +bins = collect((h.tmin):bin_width:(h.tmax)) # bin edges counts = fit(Histogram, h.times, bins).weights; # counts per bin # Plot counts over time (counts/bin_width is a crude rate estimate) diff --git a/docs/examples/Hawkes.jl b/docs/examples/Hawkes.jl index 1f22523..44d37b5 100644 --- a/docs/examples/Hawkes.jl +++ b/docs/examples/Hawkes.jl @@ -42,7 +42,7 @@ dt = DateTime("12/22 3:09 pm", fmt) function parse_timestamp_min(s::AbstractString; year=2024) dt = DateTime(s, dateformat"m/d I:M p") - DateTime(year, month(dt), day(dt), hour(dt), minute(dt)) + return DateTime(year, month(dt), day(dt), hour(dt), minute(dt)) end data.TimestampDT = parse_timestamp_min.(String.(data.Timestamp)) @@ -66,7 +66,7 @@ function eventplot( xlabel="Time (minutes)", ylabel="Events", ) - scatter( + return scatter( event_times, ones(length(event_times)); markershape=:vline, @@ -145,8 +145,9 @@ println("Branching ratio (n = α/ω): ", hawkes_model.α / hawkes_model.ω) #hid ts = sort(data.t) function λ_hawkes(t::Real) - hawkes_model.μ + - sum((hawkes_model.α * exp(-hawkes_model.ω * (t - ti)) for ti in ts if ti < t); init=0.0) + return hawkes_model.μ + sum( + (hawkes_model.α * exp(-hawkes_model.ω * (t - ti)) for ti in ts if ti < t); init=0.0 + ) end u = range(0.0, maximum(ts) + 1.0; length=2000) diff --git a/docs/examples/Inhomogeneous.jl b/docs/examples/Inhomogeneous.jl index c271e5b..7e0bafa 100644 --- a/docs/examples/Inhomogeneous.jl +++ b/docs/examples/Inhomogeneous.jl @@ -252,7 +252,7 @@ models = [ ] println("\nModel Comparison (Negative Log-Likelihood):") # hide -println("-" ^ 50) # hide +println("-"^50) # hide for (name, model) in models # hide nll = compute_nll(model, h) # hide println(" $name: ", round(nll; digits=2)) # hide diff --git a/src/HypothesisTests/PPTests/bootstrap_test.jl b/src/HypothesisTests/PPTests/bootstrap_test.jl index 228f65f..839d5a3 100644 --- a/src/HypothesisTests/PPTests/bootstrap_test.jl +++ b/src/HypothesisTests/PPTests/bootstrap_test.jl @@ -94,7 +94,7 @@ function BootstrapTest( # Simulates a process and uses the process estimated from # the simulation to calculate the test statistic sim = simulate(local_rng, pp_est, h.tmin, h.tmax) - sim_est = fit(PP, sim, rng=local_rng) + sim_est = fit(PP, sim; rng=local_rng) chunk[i] = statistic(S, sim_est, sim) end end diff --git a/src/HypothesisTests/point_process_tests.jl b/src/HypothesisTests/point_process_tests.jl index 1f4d0eb..92002f3 100644 --- a/src/HypothesisTests/point_process_tests.jl +++ b/src/HypothesisTests/point_process_tests.jl @@ -19,7 +19,7 @@ Calculate the p-value of a goodness-of-fit test on a process. function StatsAPI.pvalue(::PointProcessTest) end function Base.show(io::IO, t::PointProcessTest) - print(io, "$(typeof(t)) - pvalue = $(pvalue(t))") + return print(io, "$(typeof(t)) - pvalue = $(pvalue(t))") end #= diff --git a/src/bounded_point_process.jl b/src/bounded_point_process.jl index 6a3803a..057832a 100644 --- a/src/bounded_point_process.jl +++ b/src/bounded_point_process.jl @@ -34,8 +34,8 @@ mark_distribution(bpp::BoundedPointProcess, args...) = mark_distribution(bpp.pp, intensity(bpp::BoundedPointProcess, args...) = intensity(bpp.pp, args...) log_intensity(bpp::BoundedPointProcess, args...) = log_intensity(bpp.pp, args...) function ground_intensity_bound(bpp::BoundedPointProcess, args...) - ground_intensity_bound(bpp.pp, args...) + return ground_intensity_bound(bpp.pp, args...) end function integrated_ground_intensity(bpp::BoundedPointProcess, args...) - integrated_ground_intensity(bpp.pp, args...) + return integrated_ground_intensity(bpp.pp, args...) end diff --git a/src/history.jl b/src/history.jl index af73102..68920f7 100644 --- a/src/history.jl +++ b/src/history.jl @@ -177,7 +177,7 @@ event_times(h::History) = h.times Return the sorted vector of event times for `h` in dimension `d`. """ function event_times(h::History, d::Int) - h.N == 1 && d == 1 ? h.times : (@view h.times[h.dims .== d]) + return h.N == 1 && d == 1 ? h.times : (@view h.times[h.dims .== d]) end """ @@ -216,7 +216,7 @@ event_marks(h::History) = h.marks Return the vector of event marks in dimension `d` of `h`, sorted according to their event times. """ function event_marks(h::History, d::Int) - h.N == 1 && d == 1 ? h.marks : (@view h.marks[h.dims .== d]) + return h.N == 1 && d == 1 ? h.marks : (@view h.marks[h.dims .== d]) end """ diff --git a/src/multivariate/independent_multivariate.jl b/src/multivariate/independent_multivariate.jl index 193c288..b3bbdd4 100644 --- a/src/multivariate/independent_multivariate.jl +++ b/src/multivariate/independent_multivariate.jl @@ -47,7 +47,7 @@ function intensity(pp::IndependentMultivariateProcess, m, t, h) end function log_intensity(pp::IndependentMultivariateProcess, m, t, h, d) - log(intensity(pp, m, t, h, d)) + return log(intensity(pp, m, t, h, d)) end log_intensity(pp::IndependentMultivariateProcess, m, t, h) = log.(intensity(pp, m, t, h)) diff --git a/src/univariate/hawkes/hawkes_process.jl b/src/univariate/hawkes/hawkes_process.jl index 57ffad6..4c05494 100644 --- a/src/univariate/hawkes/hawkes_process.jl +++ b/src/univariate/hawkes/hawkes_process.jl @@ -34,7 +34,7 @@ struct HawkesProcess{T<:Real} <: AbstractUnivariateProcess throw(DomainError((α, ω), "Parameter ω must be strictly smaller than α")) T = promote_type(T1, T2, T3) (μ_T, α_T, ω_T) = convert.(T, (μ, α, ω)) - new{T}(μ_T, α_T, ω_T) + return new{T}(μ_T, α_T, ω_T) end end diff --git a/src/univariate/poisson/inhomogeneous/fit.jl b/src/univariate/poisson/inhomogeneous/fit.jl index abba084..9c4418c 100644 --- a/src/univariate/poisson/inhomogeneous/fit.jl +++ b/src/univariate/poisson/inhomogeneous/fit.jl @@ -66,11 +66,13 @@ function StatsAPI.fit( ) # Define objective function - objective(params) = negative_loglikelihood_ipp( - h, - from_params(F, params; intensity_kwargs...); - integration_config=integration_config, - ) + function objective(params) + return negative_loglikelihood_ipp( + h, + from_params(F, params; intensity_kwargs...); + integration_config=integration_config, + ) + end result = optimize(objective, init_params, optimizer; autodiff=autodiff) diff --git a/src/univariate/poisson/inhomogeneous/integration_config.jl b/src/univariate/poisson/inhomogeneous/integration_config.jl index 2a8f41f..b8bbbde 100644 --- a/src/univariate/poisson/inhomogeneous/integration_config.jl +++ b/src/univariate/poisson/inhomogeneous/integration_config.jl @@ -37,7 +37,7 @@ struct IntegrationConfig function IntegrationConfig(; solver=QuadGKJL(), abstol::Float64=1e-8, reltol::Float64=1e-8, maxiters::Int=1000 ) - new(solver, abstol, reltol, maxiters) + return new(solver, abstol, reltol, maxiters) end end diff --git a/src/univariate/poisson/inhomogeneous/intensity_methods.jl b/src/univariate/poisson/inhomogeneous/intensity_methods.jl index 4f62b47..282db2a 100644 --- a/src/univariate/poisson/inhomogeneous/intensity_methods.jl +++ b/src/univariate/poisson/inhomogeneous/intensity_methods.jl @@ -56,7 +56,7 @@ function intensity_bound( f::PolynomialIntensity{R}, t::T, h::History; - lookahead_factor::Real=1/100, + lookahead_factor::Real=1 / 100, n_samples::Int=10 * length(f.coefficients), ) where {R,T} dur = duration(h) # or max_time(h) - min_time(h) @@ -101,7 +101,7 @@ function intensity_bound(f::ExponentialIntensity{R}, t::T; lookahead::T=one(T)) end function intensity_bound( - f::ExponentialIntensity{R}, t::T, h::History; lookahead_factor::Real=1/100 + f::ExponentialIntensity{R}, t::T, h::History; lookahead_factor::Real=1 / 100 ) where {R,T} dur = duration(h) lookahead = T(lookahead_factor * dur) @@ -222,7 +222,7 @@ function intensity_bound( f::LinearCovariateIntensity{R}, t::T, h::History; - lookahead_factor::Real=1/100, + lookahead_factor::Real=1 / 100, n_samples::Int=100, ) where {R,T} dur = duration(h) @@ -255,7 +255,7 @@ function intensity_bound(f::F, t::T; lookahead::T=one(T), n_samples::Int=100) wh end function intensity_bound( - f::F, t::T, h::History; lookahead_factor::Real=1/100, n_samples::Int=100 + f::F, t::T, h::History; lookahead_factor::Real=1 / 100, n_samples::Int=100 ) where {F,T} dur = duration(h) lookahead = T(lookahead_factor * dur) diff --git a/test/Project.toml b/test/Project.toml index 98b3491..d1eeda4 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -4,10 +4,14 @@ DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Optim = "429524aa-4258-5aef-a3af-852621145aeb" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsAPI = "82ae8749-77ed-4fe6-ae5f-f523153014b0" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" \ No newline at end of file +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +JuliaFormatter = "1.0.62" \ No newline at end of file diff --git a/test/history.jl b/test/history.jl index 189d20a..5ed977d 100644 --- a/test/history.jl +++ b/test/history.jl @@ -1,5 +1,5 @@ @testset "Univariate History" begin - h = History([0.2, 0.8, 1.1], 0.0, 2.0, ["a", "b", "c"]); + h = History([0.2, 0.8, 1.1], 0.0, 2.0, ["a", "b", "c"]) @test duration(h) == 2.0 @test nb_events(h) == 3 diff --git a/test/hypothesis_tests.jl b/test/hypothesis_tests.jl index f640f91..c980245 100644 --- a/test/hypothesis_tests.jl +++ b/test/hypothesis_tests.jl @@ -19,7 +19,7 @@ h2 = History(collect(0:999), 0, 1000) bt1 = BootstrapTest(KSDistance{Uniform}, PP, h2; n_sims=10000) @test bt1.n_sims == 10000 - @test isapprox(bt1.stat, 1/1000, rtol=0.01); + @test isapprox(bt1.stat, 1 / 1000, rtol=0.01) @test pvalue(bt1) isa Float64 @test pvalue(bt1) > 0.99 @test string(bt1) == "BootstrapTest - pvalue = 1.0" @@ -27,7 +27,7 @@ h2 = History(collect(0:999), 0, 1000) bt2 = BootstrapTest(KSDistance{Exponential}, PP, h2) @test bt2.n_sims == 1000 - @test bt2.stat ≈ 1 - exp(-1); + @test bt2.stat ≈ 1 - exp(-1) @test pvalue(bt2) isa Float64 @test pvalue(bt2) < 0.01 @@ -45,8 +45,8 @@ end @test nbt1.n_sims == 1000 @test nbt2.n_sims == 10000 - @test isapprox(nbt1.stat, 1/1000, rtol=0.01); - @test isapprox(nbt1.stat, nbt2.stat, rtol=0.01); + @test isapprox(nbt1.stat, 1 / 1000, rtol=0.01) + @test isapprox(nbt1.stat, nbt2.stat, rtol=0.01) @test pvalue(nbt1) isa Float64 @test pvalue(nbt1) > 0.99 @test pvalue(nbt2) > 0.99 @@ -57,8 +57,8 @@ end @test nbt3.n_sims == 1000 @test nbt4.n_sims == 1000 - @test nbt3.stat ≈ 1 - exp(-1); - @test nbt3.stat ≈ nbt4.stat; + @test nbt3.stat ≈ 1 - exp(-1) + @test nbt3.stat ≈ nbt4.stat @test pvalue(nbt3) isa Float64 @test pvalue(nbt3) < 0.01 @test pvalue(nbt4) < 0.01 diff --git a/test/inhomogeneous_poisson_process.jl b/test/inhomogeneous_poisson_process.jl index b6cefb4..70077d7 100644 --- a/test/inhomogeneous_poisson_process.jl +++ b/test/inhomogeneous_poisson_process.jl @@ -509,9 +509,9 @@ end # λ(t) = exp(η(t)) @test intensity_cov(0.0) ≈ exp(1.0) rtol = 1e-6 - @test intensity_cov(1.0) ≈ exp(1.0 + 0.5*1.0) rtol = 1e-6 + @test intensity_cov(1.0) ≈ exp(1.0 + 0.5 * 1.0) rtol = 1e-6 - @test intensity_cov(0.25) ≈ exp(1.0 + 0.5*0.25 + 0.3*1.0) rtol = 1e-6 + @test intensity_cov(0.25) ≈ exp(1.0 + 0.5 * 0.25 + 0.3 * 1.0) rtol = 1e-6 end @testset "Simulation" begin @@ -1122,7 +1122,7 @@ end @testset "InhomogeneousPoissonProcess with custom integration config" begin intensity = ExponentialIntensity(2.0, 0.1) - custom_config = IntegrationConfig(abstol=1e-10, reltol=1e-10, maxiters=5000) + custom_config = IntegrationConfig(; abstol=1e-10, reltol=1e-10, maxiters=5000) pp = InhomogeneousPoissonProcess(intensity; integration_config=custom_config) @test pp isa InhomogeneousPoissonProcess @@ -1147,7 +1147,7 @@ end end @testset "Custom config" begin - config = IntegrationConfig(abstol=1e-12, reltol=1e-10, maxiters=10000) + config = IntegrationConfig(; abstol=1e-12, reltol=1e-10, maxiters=10000) config_str = string(config) @test occursin("IntegrationConfig", config_str) @test occursin("abstol=1.0e-12", config_str) @@ -1404,7 +1404,7 @@ end h = simulate(rng, pp_true, 0.0, 20.0) # Fit with custom integration config - custom_config = IntegrationConfig(abstol=1e-10, reltol=1e-10, maxiters=5000) + custom_config = IntegrationConfig(; abstol=1e-10, reltol=1e-10, maxiters=5000) pp_est = fit( InhomogeneousPoissonProcess{PolynomialIntensity{Float64},Dirac{Nothing}}, h, diff --git a/test/runtests.jl b/test/runtests.jl index c5e41ec..1a47516 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,6 +3,7 @@ using DensityInterface using Documenter using Distributions using ForwardDiff +using JuliaFormatter using LinearAlgebra using Pkg using PointProcesses @@ -16,13 +17,18 @@ Random.seed!(63) DocMeta.setdocmeta!(PointProcesses, :DocTestSetup, :(using PointProcesses); recursive=true) @testset verbose = true "PointProcesses.jl" begin + @testset verbose = false "Code Formatting" begin + if VERSION >= v"1.10" + @test JuliaFormatter.format(PointProcesses; verbose=false, overwrite=false) + end + end @testset verbose = false "Code quality (Aqua.jl)" begin Aqua.test_all(PointProcesses; ambiguities=false, deps_compat=(; check_extras=false)) end @testset verbose = false "Code Linting" begin # Skip JET on Julia pre-releases (where JET typically hasn't caught up # yet and there is no compatible JET version to resolve against). JET is - # not listed in test/Project.toml's [deps] for the same reaso, having + # not listed in test/Project.toml's [deps] for the same reason, having # it there would make `Pkg.test` fail at the resolution step on # prereleases, before this guard ever runs. Install on demand only when # we're on a stable Julia.