From ae73647df65fb9970e8a8a08e0783a30f7f57863 Mon Sep 17 00:00:00 2001 From: Samuel Brand <48288458+SamuelBrand1@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:55:36 +0000 Subject: [PATCH] Issue 529: Create null Latent model (#530) * Null Latent model * Null Latent model * fix doctest --- .../src/EpiLatentModels/EpiLatentModels.jl | 3 ++- EpiAware/src/EpiLatentModels/models/Null.jl | 24 +++++++++++++++++++ EpiAware/test/EpiLatentModels/models/Null.jl | 8 +++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 EpiAware/src/EpiLatentModels/models/Null.jl create mode 100644 EpiAware/test/EpiLatentModels/models/Null.jl diff --git a/EpiAware/src/EpiLatentModels/EpiLatentModels.jl b/EpiAware/src/EpiLatentModels/EpiLatentModels.jl index 1cff8d8be..1dabab681 100644 --- a/EpiAware/src/EpiLatentModels/EpiLatentModels.jl +++ b/EpiAware/src/EpiLatentModels/EpiLatentModels.jl @@ -15,7 +15,7 @@ using Turing, Distributions, DocStringExtensions, LinearAlgebra, SparseArrays, OrdinaryDiffEq #Export models -export FixedIntercept, Intercept, RandomWalk, AR, HierarchicalNormal +export FixedIntercept, Intercept, RandomWalk, AR, HierarchicalNormal, Null #Export ODE definitions export SIRParams, SEIRParams @@ -38,6 +38,7 @@ include("models/Intercept.jl") include("models/RandomWalk.jl") include("models/AR.jl") include("models/HierarchicalNormal.jl") +include("models/Null.jl") include("odemodels/SIRParams.jl") include("odemodels/SEIRParams.jl") include("modifiers/DiffLatentModel.jl") diff --git a/EpiAware/src/EpiLatentModels/models/Null.jl b/EpiAware/src/EpiLatentModels/models/Null.jl new file mode 100644 index 000000000..064d43320 --- /dev/null +++ b/EpiAware/src/EpiLatentModels/models/Null.jl @@ -0,0 +1,24 @@ +@doc raw" +A null model struct. This struct is used to indicate that no latent variables are to be generated. +" +struct Null <: AbstractTuringLatentModel end + +@doc raw" +Generates `nothing` as latent variables for the given `latent_model` of type `Null`. + +# Example +```jldoctest +using EpiAware +null = Null() +null_mdl = generate_latent(null, 10) +isnothing(null_mdl()) + +# output + +true + +``` +" +@model function EpiAwareBase.generate_latent(latent_model::Null, n) + return nothing +end diff --git a/EpiAware/test/EpiLatentModels/models/Null.jl b/EpiAware/test/EpiLatentModels/models/Null.jl new file mode 100644 index 000000000..305760702 --- /dev/null +++ b/EpiAware/test/EpiLatentModels/models/Null.jl @@ -0,0 +1,8 @@ +@testitem "Null Model Tests" begin + # Test that Null can be instantiated + @test Null() isa Null + + # Test that generate_latent returns nothing + null = Null() + @test isnothing(generate_latent(null, 10)()) +end