Skip to content

Commit

Permalink
Merge 73d75b9 into bd2330c
Browse files Browse the repository at this point in the history
  • Loading branch information
dm13450 authored Jul 16, 2020
2 parents bd2330c + 73d75b9 commit 9bf5c30
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 21 deletions.
28 changes: 14 additions & 14 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ version = "1.3.0"

[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "7d7578b00789cf16c5f68fad71868e773edd58a2"
git-tree-sha1 = "edad9434967fdc0a2631a65d902228400642120c"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.16"
version = "0.17.19"

[[Dates]]
deps = ["Printf"]
Expand All @@ -42,15 +42,15 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[Distributions]]
deps = ["FillArrays", "LinearAlgebra", "PDMats", "Printf", "QuadGK", "Random", "SpecialFunctions", "Statistics", "StatsBase", "StatsFuns"]
git-tree-sha1 = "c4ed10355637fcb0725dc6a27060f74df24f13cd"
git-tree-sha1 = "78c4c32a2357a00a0a7d614880f02c2c6e1ec73c"
uuid = "31c24e10-a181-5473-b8eb-7969acd0382f"
version = "0.23.2"
version = "0.23.4"

[[FillArrays]]
deps = ["LinearAlgebra", "Random", "SparseArrays"]
git-tree-sha1 = "6c89d5b673e59b8173c546c84127e5f623d865f6"
git-tree-sha1 = "be4180bdb27a11188d694ee3773122f4921f1a62"
uuid = "1a297f60-69ca-5386-bcde-b61e274b549b"
version = "0.8.9"
version = "0.8.13"

[[InteractiveUtils]]
deps = ["Markdown"]
Expand Down Expand Up @@ -82,9 +82,9 @@ version = "0.4.3"

[[OpenBLAS_jll]]
deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"]
git-tree-sha1 = "1887096f6897306a4662f7c5af936da7d5d1a062"
git-tree-sha1 = "0c922fd9634e358622e333fc58de61f05a048492"
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.9+4"
version = "0.3.9+5"

[[OpenSpecFun_jll]]
deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"]
Expand All @@ -93,9 +93,9 @@ uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e"
version = "0.5.3+3"

[[OrderedCollections]]
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
git-tree-sha1 = "293b70ac1780f9584c89268a6e2a560d938a7065"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.2.0"
version = "1.3.0"

[[PDMats]]
deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"]
Expand All @@ -113,9 +113,9 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[QuadGK]]
deps = ["DataStructures", "LinearAlgebra"]
git-tree-sha1 = "dc84e810393cfc6294248c9032a9cdacc14a3db4"
git-tree-sha1 = "0ab8a09d4478ebeb99a706ecbf8634a65077ccdc"
uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
version = "2.3.1"
version = "2.4.0"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
Expand All @@ -133,9 +133,9 @@ version = "0.6.1"

[[Rmath_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "1660f8fefbf5ab9c67560513131d4e933012fc4b"
git-tree-sha1 = "d76185aa1f421306dec73c057aa384bad74188f0"
uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f"
version = "0.2.2+0"
version = "0.2.2+1"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
StatsBase = "0.33"
Distributions = "0.23"
StatsBase = "0.33"
julia = "1"
8 changes: 7 additions & 1 deletion src/intensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ function intensity(ts::Array{<:Number, 1}, events::Array{<:Number, 1}, backgroun
return output
end

function intensity(ts::Array{<:Number, 1}, events::Array{<:Number, 1}, background, kappa::Float64, kernel::Distributions.Distribution)
kernel_pdf, kernel_cdf = generate_kernel_functions(kernel)
intensity(ts, events, background, kappa, kernel_pdf)
end


function intensity(ts::Number, events::Array{<:Number, 1},
background::Number, kappa::Float64, kernel::Function)
bgContrib = background
Expand All @@ -37,7 +43,7 @@ end

function kernel_contribution(ts::Number, events::Array{<:Number, 1}, kappa::Float64, kernel::Function)
evalEvents = events[events .< ts]
s = zero(ts)
s::Number = zero(ts)
if !isempty(evalEvents)
kernEval::Array{Number, 1} = kernel.(ts .- evalEvents)
s = kappa * sum(kernEval)
Expand Down
6 changes: 5 additions & 1 deletion src/likelihood.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ Calculate the log likelihood of a Hawkes process for given parameters.
# Arguments
* `events` Vector of events to calculate the likelihood for.
* `background` Background rate.
* `kappa` Kappa parameter.
* `kernel` Function or distribution of the kernel.
* `maxT` Maximum time of the process.
# Notes
Expand Down
5 changes: 5 additions & 0 deletions src/simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function simulate(bg::Number, kappa::Float64, kern::Function, maxT::Number)
sort(allevents)
end

function simulate(bg::Number, kappa::Float64, kernD::Distributions.Distribution, maxT::Number)
kern, kern_cdf = generate_kernel_functions(kernD)
return simulate(bg, kappa, kern, maxT)
end

function poisson_simulation(rate::Number, maxT::Number)
nevents = rand(Distributions.Poisson(rate*maxT))
event_times = sort(rand(Distributions.Uniform(0, maxT), nevents))
Expand Down
12 changes: 12 additions & 0 deletions test/intensity_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,17 @@
@test HawkesProcesses.intensity(testEvents, testEvents, bg, kappa, kern) [bg, bg + kappa * kern(1), bg + kappa * kern(1) + kappa * kern(2)] atol=0.01
end

@testset "Distribution Intensity" begin
bg = 0.5
kappa = 0.5
kern = Distributions.Exponential(1/0.5)
testEvents = [1, 2, 3]
inferTests && @inferred HawkesProcesses.intensity(0, testEvents, bg, kappa, kern)

int = HawkesProcesses.intensity([1,2,3], testEvents, bg, kappa, kern)
@test length(int) == 3

end


end
11 changes: 11 additions & 0 deletions test/likelihood_test.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

@testset "Likelihood" begin

kernD = Distributions.Exponential(1/0.5)
bg = 0.5
kappa = 0.5
l = HawkesProcesses.likelihood(sort(rand(10)), bg, kappa, kernD, 1)

@test length(l) == 1
inferTests && @inferred HawkesProcesses.likelihood(sort(rand(10)), bg, kappa, kernD, 1)
end
9 changes: 9 additions & 0 deletions test/parent_probabilites_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,14 @@
@test testProbs[1] == bg
end

@testset "Full" begin

inferTests && @inferred HawkesProcesses.parent_probs(sort(rand(100)), bg, kappa, kern)
pp = HawkesProcesses.parent_probs(sort(rand(100)), bg, kappa, kern)

@test length(pp) == 100

end


end
6 changes: 4 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ using HawkesProcesses
using Distributions
using Test

inferTests = false
inferTests = Bool(parse(Int64, get(ENV, "INFER_TESTS", "1")))

my_tests = ["event_difference_test.jl",
"parent_probabilites_test.jl",
Expand All @@ -11,7 +11,9 @@ my_tests = ["event_difference_test.jl",
"simulate_test.jl",
"intensity_test.jl",
"compensator_test.jl",
"time_change_test.jl"]
"time_change_test.jl",
"likelihood_test.jl",
"test_utils.jl"]

println("Running tests: ")

Expand Down
12 changes: 10 additions & 2 deletions test/simulate_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ using Distributions
inferTests && @inferred HawkesProcesses.poisson_simulation(0.5, 10)
inferTests && @inferred HawkesProcesses.poisson_simulation(x->x, 10)
end
@testset "Hawkes Simulation" begin
@testset "Hawkes Simulation with Kernel Function" begin
kern(x) = pdf.(Distributions.Exponential(1/0.5), x)
testevents = HawkesProcesses.simulate(0.5, 0.5, kern, 10)

@test length(testevents) > 0

inferTests && @inferred HawkesProcesses.simulate(0.5, 0.5, kern, 100)
end

@testset "Hawkes Simulation with Distribution" begin
kernD = Distributions.Exponential(1/0.5)
testevents = HawkesProcesses.simulate(0.5, 0.5, kernD, 10)

@test length(testevents) > 0
inferTests && @inferred HawkesProcesses.simulate(0.5, 0.5, kernD, 100)
end


end
9 changes: 9 additions & 0 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@testset "Utility Tests" begin

@testset "Kernel Generating Functions" begin
res = HawkesProcesses.generate_kernel_functions(Exponential())
inferTests && @inferred HawkesProcesses.generate_kernel_functions(Exponential())
@test length(res) == 2
end

end

0 comments on commit 9bf5c30

Please sign in to comment.