-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from dm13450/dev
Event Probabilities
- Loading branch information
Showing
5 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
event_probability(startT, endT, events, background, kappa, kernel) | ||
Forecast the probability of an event in defined time window. | ||
# Arguments | ||
* `startT::Number`: Left boundary of the forecasting window. | ||
* `endT::Number`: Right boundary of the forecasting window. | ||
* `events::Array{<:Number,1}`: Observed events | ||
* `background`: Background rate | ||
* `kappa::Float64`: Kappa value | ||
* `kernel::Distribution`: Kernel distribution | ||
# Notes | ||
* As we are integregating the intensity function on a constant background, constant kappa and distriubtion for the kernel are supported. | ||
""" | ||
|
||
function event_probability(startT::Number, endT::Number, events::Array{<:Number}, background::Number, kappa::Number, kernel::Distribution) | ||
|
||
filter!(x-> x <= endT, events) | ||
background*(endT - startT) + kappa * sum( cdf.(kernel, endT .- events) .- cdf.(kernel, startT .- events) ) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
@testset "Event Probabilities" begin | ||
|
||
@testset "Basic Test" begin | ||
|
||
bg = 0.5 | ||
kappa = 0.5 | ||
kern = Distributions.Exponential(1/0.5) | ||
events = [1,2,3] | ||
startT = 4 | ||
endT = 5 | ||
prob = HawkesProcesses.event_probability(startT, endT, events, bg, kappa, kern) | ||
@test isa(prob, Number) | ||
end | ||
|
||
@testset "Value Test" begin | ||
bg = 0.5 | ||
kappa = 0.5 | ||
kern = Distributions.Exponential(1/0.5) | ||
events = [1,2,3] | ||
startT = 400 | ||
endT = 500 | ||
prob = HawkesProcesses.event_probability(startT, endT, events, bg, kappa, kern) | ||
@test prob == 50 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters