Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .github/workflows/Format-PR.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/Format.yml

This file was deleted.

2 changes: 1 addition & 1 deletion docs/examples/Basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions docs/examples/Hawkes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -66,7 +66,7 @@ function eventplot(
xlabel="Time (minutes)",
ylabel="Events",
)
scatter(
return scatter(
event_times,
ones(length(event_times));
markershape=:vline,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/Inhomogeneous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/HypothesisTests/PPTests/bootstrap_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/HypothesisTests/point_process_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

#=
Expand Down
4 changes: 2 additions & 2 deletions src/bounded_point_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/history.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down Expand Up @@ -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

"""
Expand Down
2 changes: 1 addition & 1 deletion src/multivariate/independent_multivariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion src/univariate/hawkes/hawkes_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 7 additions & 5 deletions src/univariate/poisson/inhomogeneous/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/univariate/poisson/inhomogeneous/integration_config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions src/univariate/poisson/inhomogeneous/intensity_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
JuliaFormatter = "1.0.62"
2 changes: 1 addition & 1 deletion test/history.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/hypothesis_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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"

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

Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions test/inhomogeneous_poisson_process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using DensityInterface
using Documenter
using Distributions
using ForwardDiff
using JuliaFormatter
using LinearAlgebra
using Pkg
using PointProcesses
Expand All @@ -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.
Expand Down
Loading