-
Notifications
You must be signed in to change notification settings - Fork 3
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
Refactor with method hierarchy #78
Changes from all commits
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 |
---|---|---|
@@ -1,24 +1,41 @@ | ||
abstract type AbstractLatentProcess end | ||
abstract type AbstractLatentProcessArg end | ||
|
||
struct RandomWalkLatentProcess{D <: Sampleable, S <: Sampleable} <: AbstractLatentProcess | ||
init_prior::D | ||
var_prior::S | ||
end | ||
|
||
struct RandomWalkLatentProcessArg <: AbstractLatentProcessArg end | ||
|
||
function default_rw_priors() | ||
return (:var_RW_prior => truncated(Normal(0.0, 0.05), 0.0, Inf), | ||
:init_rw_value_prior => Normal()) |> Dict | ||
end | ||
|
||
function generate_latent_process(latent_process::AbstractLatentProcess, n; kwargs...) | ||
@info "No concrete implementation for generate_latent_process is defined." | ||
function latent_process(lp::AbstractLatentProcess, n; | ||
kwargs...) | ||
return latent_process( | ||
AbstractLatentProcessArg(), n; var_prior = lp.var_prior, init_prior = lp.init_prior) | ||
end | ||
|
||
function latent_process(lp::AbstractLatentProcess, n; kwargs...) | ||
@info "No concrete implementation for latent_process is defined." | ||
return nothing | ||
end | ||
|
||
@model function generate_latent_process(latent_process::RandomWalkLatentProcess, n) | ||
function latent_process(lp::RandomWalkLatentProcess, n) | ||
return latent_process( | ||
RandomWalkLatentProcessArg(), n; var_prior = lp.var_prior, | ||
init_prior = lp.init_prior | ||
) | ||
end | ||
|
||
@model function latent_process(lp::RandomWalkLatentProcessArg, n; | ||
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. It feels like the point of the above is to lower down to this function; but you can get the same effect by specifying the fields of I'd avoid that by having |
||
var_prior::ContinuousDistribution, init_prior::ContinuousDistribution) | ||
ϵ_t ~ MvNormal(ones(n)) | ||
σ²_RW ~ latent_process.var_prior | ||
rw_init ~ latent_process.init_prior | ||
σ²_RW ~ var_prior | ||
rw_init ~ init_prior | ||
σ_RW = sqrt(σ²_RW) | ||
rw = Vector{eltype(ϵ_t)}(undef, n) | ||
|
||
|
@@ -28,7 +45,3 @@ end | |
end | ||
return rw, (; σ_RW, rw_init) | ||
end | ||
|
||
# function random_walk_process(; latent_process_priors = default_rw_priors()) | ||
# LatentProcess(random_walk, latent_process_priors) | ||
# 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.
I think defining a type hierarchy for the underlying priors and an auxiliary type hierarchy that is initimately connected to it is overkill.
For example, you can dispatch on the type of the first type without using it if you want to.