Skip to content

Commit

Permalink
Merge pull request #8 from dm13450/dev
Browse files Browse the repository at this point in the history
Event Probabilities
  • Loading branch information
dm13450 committed Sep 2, 2020
2 parents a399639 + ec3b3ab commit ca64ac8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

[![Coverage Status](https://coveralls.io/repos/github/dm13450/HawkesProcesses.jl/badge.svg?branch=master)](https://coveralls.io/github/dm13450/HawkesProcesses.jl?branch=master)

[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://dm13450.github.io/HawkesProcesses.jl/stable)

[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://dm13450.github.io/HawkesProcesses.jl/dev)

# HawkesProcesses

A Julia package for fitting, analysing and plotting Hawkes processes.
Expand Down
1 change: 1 addition & 0 deletions src/HawkesProcesses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module HawkesProcesses
include("time_change.jl")
include("compensator.jl")
include("utils.jl")
include("event_probability.jl")

export fit, HierarchicalHawkesFit

Expand Down
23 changes: 23 additions & 0 deletions src/event_probability.jl
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
27 changes: 27 additions & 0 deletions test/event_probability_test.jl
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
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ my_tests = ["event_difference_test.jl",
"compensator_test.jl",
"time_change_test.jl",
"likelihood_test.jl",
"test_utils.jl"]
"test_utils.jl",
"event_probability_test.jl"]

println("Running tests: ")

Expand Down

0 comments on commit ca64ac8

Please sign in to comment.