@@ -5,183 +5,13 @@ Common interface for all subtypes of `HawkesProcess`.
55"""
66abstract type HawkesProcess <: AbstractPointProcess end
77
8- """
9- UnivariateHawkesProcess{R<:Real,D} <: HawkesProcess
10-
11- Univariate Hawkes process with exponential decay kernel and mark
12- distribution `D`.
13-
14- Denote the events of the process by (tᵢ, mᵢ), where tᵢ is the event time
15- and mᵢ ∈ M the corresponding mark. The conditional intensity function
16- of the Hawkes process is given by
17-
18- λ(t) = μ + ∑_{tᵢ < t} α mᵢ exp(-ω (t - tᵢ)).
19-
20- Notice that the mark only affects the jump size.
21-
22- # Fields
23- - `μ::R`: baseline intensity (immigration rate)
24- - `α::R`: jump size
25- - `ω::R`: decay rate.
26- - `mark_dist::D`: distribution of marks
27- """
28- struct UnivariateHawkesProcess{T<: Real ,D} <: HawkesProcess
29- μ:: T
30- α:: T
31- ω:: T
32- mark_dist:: D
33- end
34-
35- function Base. show (io:: IO , hp:: UnivariateHawkesProcess )
36- return print (io, " UnivariateHawkesProcess($(hp. μ) , $(hp. α) , $(hp. ω) , $(hp. mark_dist) )" )
37- end
38-
39- """
40- UnmarkedUnivariateHawkesProcess{R<:Real} <: HawkesProcess
41-
42- Unmarked univariate Hawkes process with exponential decay kernel.
43-
44- Denote the events of the process by tᵢ. The conditional intensity function
45- of the Hawkes process is given by
46-
47- λ(t) = μ + ∑_{tᵢ < t} α exp(-ω (t - tᵢ)).
48-
49- # Fields
50- - `μ::R`: baseline intensity (immigration rate)
51- - `α::R`: jump size
52- - `ω::R`: decay rate.
53-
54- Alias for UnivariateHawkesProcess{R, Dirac{Nothing}}.
55- """
56- const UnmarkedUnivariateHawkesProcess{R<: Real } = UnivariateHawkesProcess{R,Dirac{Nothing}}
57-
58- function Base. show (io:: IO , hp:: UnmarkedUnivariateHawkesProcess )
59- return print (io, " UnmarkedUnivariateHawkesProcess$((hp. μ, hp. α, hp. ω)) " )
60- end
61-
62- """
63- MultivariateHawkesProcess{R} <: HawkesProcess
64-
65- Unmarked multivariate temporal Hawkes process with exponential decay
66-
67- For a process with m = 1, 2, ..., M marginal processes, the conditional intensity
68- function of the m-th process is given by
69-
70- λₘ(t) = μₘ + ∑_{l=1,...,M} ∑_{tˡᵢ < t} αₘₗ exp(-βₘₗ(t - tˡᵢ)),
71-
72- where tˡᵢ is the i-th element in the l-th marginal process.
73- μ is a vector of length M with elements μₘ. α and ω are M×M
74- matrices with elements αₘₗ and ωₘₗ.
75-
76- The process is represented as a marked process, where each marginal
77- process m = 1, 2, ..., M is represented by events (tᵐᵢ, m), tᵐᵢ being
78- the i-th element with mark m.
79-
80- # Fields
81- - `μ::Vector{<:Real}`: baseline intensity (immigration rate)
82- - `α::Matrix{<:Real}`: Jump size.
83- - `ω::Matrix{<:Real}`: Decay rate.
84- """
85- struct MultivariateHawkesProcess{T<: Real } <: HawkesProcess
86- μ:: T
87- α:: Matrix{T}
88- ω:: Matrix{T}
89- mark_dist:: Categorical{Float64,Vector{Float64}} # To keep consistent with PoissonProcess. Helps in simulation.
90- end
91-
92- function Base. show (io:: IO , hp:: MultivariateHawkesProcess{T} ) where {T<: Real }
93- return print (
94- io,
95- " MultivariateHawkesProcess\n μ = $(T .(hp. μ .* probs (hp. mark_dist))) \n α = $(hp. α) \n ω = $(hp. ω) " ,
96- )
97- end
98-
99- Base. length (mh:: MultivariateHawkesProcess ) = size (mh. α)[1 ]
100-
101- # # Constructors
102- # ## UnivariatehawkesProcess
103- function HawkesProcess (μ:: Real , α:: Real , ω:: Real , mark_dist; check_args:: Bool = true )
104- check_args && check_args_Hawkes (μ, α, ω, mark_dist)
105- return UnivariateHawkesProcess (promote (μ, α, ω)... , mark_dist)
106- end
107-
108- function HawkesProcess (μ:: Real , α:: Real , ω:: Real ; check_args:: Bool = true )
109- return HawkesProcess (μ, α, ω, Dirac (nothing ); check_args= check_args)
110- end
111-
112- # ## MultivariateHawkesProcess
113- function HawkesProcess (
114- μ:: Vector{<:Real} , α:: Matrix{<:Real} , ω:: Matrix{<:Real} ; check_args:: Bool = true
115- )
116- check_args && check_args_Hawkes (μ, α, ω)
117- R = promote_type (eltype (μ), eltype (α), eltype (ω))
118- return MultivariateHawkesProcess (R (sum (μ)), R .(α), R .(ω), Categorical (μ / sum (μ)))
119- end
120-
121- # For M independent marginal processes
122- function HawkesProcess (
123- μ:: Vector{<:Real} , α:: Vector{<:Real} , ω:: Vector{<:Real} ; check_args:: Bool = true
124- )
125- check_args && check_args_Hawkes (μ, diagm (α), diagm (ω))
126- R = promote_type (eltype (μ), eltype (α), eltype (ω))
127- return MultivariateHawkesProcess (R (sum (μ)), R .(α), R .(ω), Categorical (μ / sum (μ)))
128- end
129-
130- # Check args
131- # # Univariate Hawkes
132- function check_args_Hawkes (μ:: Real , α:: Real , ω:: Real , mark_dist)
133- if any ((μ, α, ω) .< 0 )
134- throw (
135- DomainError (
136- " μ = $μ , α = $α , ω = $ω " ,
137- " HawkesProcess: All parameters must be non-negative." ,
138- ),
139- )
140- end
141- mean_α = mark_dist isa Dirac{Nothing} ? α : mean (mark_dist) * α
142- if mean_α >= ω
143- throw (
144- DomainError (
145- " α = $(mean_α) , ω = $ω " ,
146- " HawkesProcess: mᵢα must be, on average, smaller than ω. Stability condition." ,
147- ),
148- )
149- end
150- if ! isa (mark_dist, Dirac{Nothing}) && minimum (mark_dist) < 0
151- throw (
152- DomainError (
153- " Mark distribution support = $((support (mark_dist). lb, support (mark_dist). ub)) " ,
154- " HawkesProcess: Support of mark distribution must be contained in non-negative numbers" ,
155- ),
156- )
157- end
158- return nothing
159- end
160-
161- # # Multivariate Hawkes
162- function check_args_Hawkes (μ:: Vector{<:Real} , α:: Matrix{<:Real} , ω:: Matrix{<:Real} )
163- if length (μ) != size (α)[2 ]
164- throw (DimansionMismatch (" α must have size $(length (μ)) ×$(length (μ)) " ))
165- end
166- if length (μ) != size (ω)[2 ]
167- throw (DimansionMismatch (" ω must have size $(length (μ)) ×$(length (μ)) " ))
168- end
169- if any (sum (α ./ ω; dims= 1 ) .>= 1 )
170- throw (
171- DomainError (
172- " α = $α , ω = $ω " ,
173- " HawkesProcess: Sum of α/β over each row must be smaller than 1. Stability condition." ,
174- ),
175- )
176- end
177- if any (μ .< zero (μ)) || any (α .< zero (α)) || any (ω .< zero (ω))
178- throw (
179- DomainError (
180- " μ = $μ , α = $α , ω = $ω " ,
181- " HawkesProcess: All elements of μ, α and ω must be non-negative." ,
182- ),
183- )
184- end
185- ω[α .== 0 ] .= 1 # Protects against division by 0 in simulation
186- return nothing
187- end
8+ # #=
9+ # If type parameter for `HawkesProcess` was NOT explicitly provided,
10+ # use `Float64` as the standard type
11+ # =#
12+ # function StatsAPI.fit(
13+ # HP::Type{<:HawkesProcess}, h::History{H,M}; kwargs...
14+ # ) where {H<:Real,M}
15+ # T = promote_type(Float64, H)
16+ # return fit(HP{T}, h; kwargs...)
17+ # end
0 commit comments