-
Notifications
You must be signed in to change notification settings - Fork 1
Interface for Multivariate processes #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
e98f3e6
7f45b10
28c32f6
c2d4ba1
af47ed7
4052588
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,6 @@ function MonteCarloTest( | |
| throw(ArgumentError("Test is not valid for empty event history.")) | ||
| end | ||
|
|
||
| pp_est = fit(PP, h) | ||
| pp_est = fit(PP, h)::AbstractPointProcess # JET complains if not specified | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is bein caused by the type stability issue i'm p sure
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the message I get. ┌ MonteCarloTest(S::Type{<:Statistic}, PP::Type{<:AbstractPointProcess}, h::History; kwargs...) @ PointProcesses /home/jkling/projects/PointProcesses.jl/src/HypothesisTests/PPTests/monte_carlo_test.jl:114 Apparently, the static analysis thinks that |
||
| return MonteCarloTest(S, pp_est, h; kwargs...) | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,3 +39,12 @@ end | |
| function integrated_ground_intensity(bpp::BoundedPointProcess, args...) | ||
| return integrated_ground_intensity(bpp.pp, args...) | ||
| end | ||
|
|
||
| function time_change(h::History{T}, pp::BoundedPointProcess) where {T} | ||
| if min_time(h) < min_time(pp) || max_time(h) > max_time(pp) | ||
| throw(ArgumentError("History is defined outside the bounds of the process")) | ||
| end | ||
| return time_change(h, pp.pp) | ||
| end | ||
|
|
||
| simulate(pp::BoundedPointProcess) = simulate(pp.pp, pp.tmin, pp.tmax) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new fallabck covers this?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this only delegates
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see, the question is if this is now redundant. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -153,8 +153,13 @@ end | |
| function History(; times, tmin, tmax, marks=nothing, dims=nothing, check_args=true) | ||
| if times isa Vector{<:Real} | ||
| marks === nothing && (marks = fill(nothing, length(times))) | ||
| dims === nothing && (dims = fill(nothing, length(times))) | ||
| return History(times, tmin, tmax, marks, dims; check_args=check_args) | ||
| if dims === nothing | ||
| dims = fill(nothing, length(times)) | ||
| N = 1 | ||
| else | ||
| N = length(unique(dims)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This counts distinct dim values present, not the actual dimension count
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes. In the case we are passing vectors, instead of one vector per dimension, this is the only way to deduce the number of dimensions in the history. |
||
| end | ||
| return History(times, tmin, tmax, marks, dims, N; check_args=check_args) | ||
| else | ||
| marks === nothing && | ||
| (marks = [fill(nothing, length(times[i])) for i in 1:length(times)]) | ||
|
|
@@ -464,12 +469,7 @@ function Base.cat(h1::History, h2::History) | |
| ) | ||
| end | ||
|
|
||
| """ | ||
| time_change(h, Λ) | ||
|
|
||
| Apply the time rescaling `t -> Λ(t)` to history `h`. | ||
| """ | ||
| function time_change(h::History, Λ) | ||
| function time_change(h::History{T}, Λ) where {T} | ||
| new_times = Λ.(event_times(h)) | ||
| new_marks = copy(event_marks(h)) | ||
| new_tmin = Λ(min_time(h)) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """ | ||
| AbstractMultivariateProcess | ||
|
|
||
| Abstract type for multivariate temporal point processes. | ||
|
|
||
| To implement a multivariate process, one must subtype `AbstractMultivariateProcess` and provide | ||
| implementations for the methods below. | ||
| - `mark_distribution(pp, t, h, d)` | ||
| - `ground_intensity(pp, t, h, d)` | ||
| - `integrated_ground_intensity(pp, t, h, d)` | ||
| - `ground_intensity_bound(pp, t, h, d)` | ||
| - `fit(Type{pp}, h)` | ||
| - `simulate(pp, h)` | ||
| In all the cases, `pp` is the point process being implemented, `t` is the instant in | ||
| which the function will be evaluated, `h` is the history up to `t` and `d` is the dimension. | ||
| Other methods should be implemented if permance is an issue. | ||
| The process is expected to have a field `mark_dist::Vector{<:AbstractMarkDistribution}`. If this | ||
| field is not present, `Base.ndims(pp)` must also be implemented. | ||
| """ | ||
| abstract type AbstractMultivariateProcess <: AbstractPointProcess end | ||
|
|
||
| Base.ndims(pp::AbstractMultivariateProcess) = length(pp.mark_dist) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This assumes there is a mark_dist field but IndependentMultivariate does not have one?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, |
||
|
|
||
| function mark_distribution(pp::AbstractMultivariateProcess, t, h::History) | ||
| return [mark_distribution(pp, t, h, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function ground_intensity(pp::AbstractMultivariateProcess, t, h::History) | ||
| return [ground_intensity(pp, t, h, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function integrated_ground_intensity(pp::AbstractMultivariateProcess, h::History, a, b) | ||
| return [integrated_ground_intensity(pp, h, a, b, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function ground_intensity_bound(pp::AbstractMultivariateProcess, t, h::History) | ||
| return [ground_intensity_bound(pp, t, h, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function intensity(pp::AbstractMultivariateProcess, m, t, h::History, d::Int) | ||
| return ground_intensity(pp, t, h, d) * densityof(pp.mark_dist[d], t, h, m) | ||
| end | ||
|
|
||
| function intensity(pp::AbstractMultivariateProcess, m, t, h::History) | ||
| return [intensity(pp, m, t, h, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function log_intensity(pp::AbstractMultivariateProcess, m, t, h::History, d::Int) | ||
| return log(intensity(pp, m, t, h, d)) | ||
| end | ||
|
|
||
| function log_intensity(pp::AbstractMultivariateProcess, m, t, h::History) | ||
| return [log_intensity(pp, m, t, h, d) for d in 1:ndims(pp)] | ||
| end | ||
|
|
||
| function time_change(h::History{T}, pp::AbstractMultivariateProcess) where {T} | ||
| tmin = typemax(T) | ||
| tmax = typemin(T) | ||
| transformed_times = [zeros(T, nb_events(h, d)) for d in 1:ndims(h)] | ||
| for d in 1:ndims(pp) | ||
|
Comment on lines
+59
to
+60
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A 3-dim process with a history whose keyword constructor computed
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but should we allow for |
||
| Λ(t) = integrated_ground_intensity(pp, h, min_time(h), t, d) | ||
| transformed_times[d] .= Λ.(event_times(h, d)) | ||
| new_tmin = Λ(min_time(h)) | ||
| tmin = new_tmin < tmin ? new_tmin : tmin | ||
| new_tmax = Λ(max_time(h)) | ||
| tmax = new_tmax > tmax ? new_tmax : tmax | ||
| end | ||
| transformed_marks = [collect(event_marks(h, d)) for d in 1:ndims(h)] | ||
| return History(transformed_times, tmin, tmax, transformed_marks) | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does not filter by type. need something like:
or similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is shorter: