Skip to content

Multivariate history#79

Draft
JoseKling wants to merge 4 commits intomainfrom
MultivariateHistory
Draft

Multivariate history#79
JoseKling wants to merge 4 commits intomainfrom
MultivariateHistory

Conversation

@JoseKling
Copy link
Copy Markdown
Owner

Implementation of multivariate processes. Discussion in Issue #73

  • History

Contains an array times with the event times, an array marks with corresponding marks, and another array dims with corresponding dimension

  • AbstractPointProcess

Takes vectors of parameters and mark distributions. Methods such as ground_intensity now return a vector, each value corresponding to one dimension.

- Change the models to hold vectors of parameters instead of single
  parameters
- Update methods to return multivariate histories
- Update tests

Steps
- Update general interface for `AbstractPointProcess`
- Update `simulation.jl`
- Update homogeneous Poisson and related methods
- Update inhomogeneous Poisson and related methods
- Update hypothesis tests
    - They work only for univariate processes. Generalization for the
      futrue
- Ignore Hawkes processes, since they will be implemented in another PR
- Takes an array of parameters
- Methods like `ground_intensity` return an array
- Added methods with an argument `d::Int` to get the values from
  specific dimensions
This reverts commit 90f08d6.
Instead of making all processes multivariate, implement tem separately.
- `AbstractMultivariateProcess`
- `IndependenteMultivariateProcess`
- `DependentMultivariateProcess`?
- Other processes, such as `MultivariateHawkesProcess`

Return the sorted vector of event times for `h` in dimension `d`.
"""
event_times(h::History, d::Int) = h.N == 1 && d == 1 ? h.times : (@view h.times[h.dims .== d])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
event_times(h::History, d::Int) = h.N == 1 && d == 1 ? h.times : (@view h.times[h.dims .== d])
function event_times(h::History, d::Int)
h.N == 1 && d == 1 ? h.times : (@view h.times[h.dims .== d])
end


Return the vector of event marks in dimension `d` of `h`, sorted according to their event times.
"""
event_marks(h::History, d::Int) = h.N == 1 && d == 1 ? h.marks : (@view h.marks[h.dims .== d])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
event_marks(h::History, d::Int) = h.N == 1 && d == 1 ? h.marks : (@view h.marks[h.dims .== d])
function event_marks(h::History, d::Int)
h.N == 1 && d == 1 ? h.marks : (@view h.marks[h.dims .== d])
end

if check_args
@assert h.tmin <= t < h.tmax
@assert (length(h) == 0) || (h.times[end] <= t)
@assert (d === nothing && h.N ==1) || 1 <= d <= h.N
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@assert (d === nothing && h.N ==1) || 1 <= d <= h.N
@assert (d === nothing && h.N == 1) || 1 <= d <= h.N

"""
function Base.append!(h::History, ts::Vector{<:Real}, ms; check=true)
if check
function Base.append!(h::History, ts::Vector{<:Real}, ms=fill(nothing, length(ts)), ds=fill(nothing, length(ts)); check_args=true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function Base.append!(h::History, ts::Vector{<:Real}, ms=fill(nothing, length(ts)), ds=fill(nothing, length(ts)); check_args=true)
function Base.append!(
h::History,
ts::Vector{<:Real},
ms=fill(nothing, length(ts)),
ds=fill(nothing, length(ts));
check_args=true,
)

Comment on lines +354 to +355
dims = [h1.dims; h2.dims]
return History(; times=times, tmin=h1.tmin, tmax=h2.tmax, marks=marks, dims=dims, check_args=false)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
dims = [h1.dims; h2.dims]
return History(; times=times, tmin=h1.tmin, tmax=h2.tmax, marks=marks, dims=dims, check_args=false)
dims = [h1.dims; h2.dims]
return History(;
times=times, tmin=h1.tmin, tmax=h2.tmax, marks=marks, dims=dims, check_args=false
)

)
end


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

return PoissonProcess(λ, [Dirac(nothing) for _ in eachindex(λ)])
end


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change


function PoissonProcess(λ::Vector{R}, mark_dist::D; check_args::Bool=true) where {R<:Real,D}
return PoissonProcess(λ, [mark_dist for _ in eachindex(λ)]; check_args=check_args)
end No newline at end of file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
end
end

`UnivariatePoissonProcess{R}` is simply a type alias for `PoissonProcess{R,Dirac{Nothing}}`.
"""
const UnivariatePoissonProcess{R<:Real} = PoissonProcess{R,Dirac{Nothing}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

end
return PoissonProcess(sum(λ), Categorical(λ / sum(λ)); check_args=check_args)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant