-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 252: Composing complex models (#296)
* add prefixing to ConcatLatentModels * start working on concatlatentmodels * fix concat constructor * add tests for ConcatLatentModels * add draft ascertainment method * work on tests * use latent_model not latentmodel * use latent_model not latentmodel * fix Ascertainment constructors * add tests for prefix_submodel * start to add helper strucs * add tests and constructors for Prefix wrappers around prefix_submodel * reduce custom code by using Prefix constructors * switch stackobservation models to using new prefixwrapper * fix ascertaiment to use latent models * fix testing issues related to prefix_submodel * fix final tests
- Loading branch information
Showing
27 changed files
with
358 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
@doc raw" | ||
Generate a submodel with an optional prefix. A lightweight wrapper around the `@submodel` macro from DynamicPPL.jl. | ||
# Arguments | ||
- `model::AbstractModel`: The model to be used. | ||
- `fn::Function`: The Turing @model function to be applied to the model. | ||
- `prefix::String`: The prefix to be used. If the prefix is an empty string, the submodel is created without a prefix. | ||
# Returns | ||
- `submodel`: The returns from the submodel are passed through. | ||
# Examples | ||
```julia | ||
using EpiAware | ||
submodel = prefix_submodel(CombineLatentModels([FixedIntercept(0.1), AR()]), generate_latent, \"Test\", 10) | ||
rand(submodel) | ||
``` | ||
" | ||
@model function prefix_submodel( | ||
model::AbstractModel, fn::Function, prefix::String, kwargs...) | ||
if prefix == "" | ||
@submodel submodel = fn(model, kwargs...) | ||
else | ||
@submodel prefix=eval(prefix) submodel=fn(model, kwargs...) | ||
end | ||
return submodel | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
EpiAware/src/EpiLatentModels/modifiers/PrefixLatentModel.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@doc raw" | ||
Generate a latent model with a prefix. A lightweight wrapper around `EpiAwareUtils.prefix_submodel`. | ||
# Constructors | ||
- `PrefixLatentModel(model::M, prefix::P)`: Create a `PrefixLatentModel` with the latent model `model` and the prefix `prefix`. | ||
- `PrefixLatentModel(; model::M, prefix::P)`: Create a `PrefixLatentModel` with the latent model `model` and the prefix `prefix`. | ||
# Examples | ||
```julia | ||
using EpiAware | ||
latent_model = PrefixLatentModel(model = HierarchicalNormal(), prefix = \"Test\") | ||
mdl = generate_latent(latent_model, 10) | ||
rand(mdl) | ||
``` | ||
" | ||
@kwdef struct PrefixLatentModel{M <: AbstractTuringLatentModel, P <: String} <: | ||
AbstractTuringLatentModel | ||
"The latent model" | ||
model::M | ||
"The prefix for the latent model" | ||
prefix::P | ||
end | ||
|
||
@model function EpiAwareBase.generate_latent(latent_model::PrefixLatentModel, n) | ||
@submodel submodel = prefix_submodel( | ||
latent_model.model, generate_latent, latent_model.prefix, n) | ||
return submodel | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.