From 7f5d92870a71444858ef316fc2ba46b848d3a953 Mon Sep 17 00:00:00 2001 From: "James P. Fairbanks" Date: Tue, 2 Jan 2024 15:36:59 -0500 Subject: [PATCH 1/2] WIP: initial guess at regnet support --- src/regnets.jl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/regnets.jl diff --git a/src/regnets.jl b/src/regnets.jl new file mode 100644 index 0000000..5ad82b8 --- /dev/null +++ b/src/regnets.jl @@ -0,0 +1,36 @@ +using SyntacticModels +using SyntacticModels.SyntacticModelsBase +using SyntacticModels.AMR +using ACSets.ADTs +using MLStyle + +@as_record Properties <: AbstractTerm + rate_constant::String +end + +@as_record struct Edge <: AbstractTerm + id::String + source::String + target::String + properties::Properties + sign::Bool +end + +@as_record struct Vertex <: AbstractTerm + id::String + name::String + grounding::Any + initial::String + rate_constant::String + sign::Bool +end + +@data struct RegNet <: AbstractTerm + Edgelist(vertices::Vector{Vertex}, edges::Vector{Edge}) +end + +@as_record struct RegNetModel <: AbstractTerm + header::Header + model::RegNet + parameters::Vector{AMR.Parameter} +end From a4fa9616923c5089c064077f70e19d322200f1ca Mon Sep 17 00:00:00 2001 From: "James P. Fairbanks" Date: Tue, 2 Jan 2024 16:42:05 -0500 Subject: [PATCH 2/2] wip: writing lotka volterra example by hand --- src/regnets.jl | 89 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-) diff --git a/src/regnets.jl b/src/regnets.jl index 5ad82b8..c3f8ce8 100644 --- a/src/regnets.jl +++ b/src/regnets.jl @@ -1,10 +1,11 @@ using SyntacticModels using SyntacticModels.SyntacticModelsBase using SyntacticModels.AMR +import SyntacticModels.AMR: nounit using ACSets.ADTs using MLStyle -@as_record Properties <: AbstractTerm +@as_record struct Properties <: AbstractTerm rate_constant::String end @@ -12,8 +13,8 @@ end id::String source::String target::String - properties::Properties sign::Bool + properties::Properties end @as_record struct Vertex <: AbstractTerm @@ -25,7 +26,7 @@ end sign::Bool end -@data struct RegNet <: AbstractTerm +@data RegNet <: AbstractTerm begin Edgelist(vertices::Vector{Vertex}, edges::Vector{Edge}) end @@ -34,3 +35,85 @@ end model::RegNet parameters::Vector{AMR.Parameter} end + + +vertices = [ + Vertex("R", + "Rabbits", + nothing, + "R0", + "alpha", + true), + Vertex("W", + "Wolves", + nothing, + "W0", + "gamma", + false) +] + +edges = [ + Edge( + "wolf_eats_rabbit", + "W", + "R", + false, + Properties("beta")), + Edge( + "rabbit_feeds_wolf", + "R", + "W", + true, + Properties("delta")) +] + +parameters = [ + Parameter( + :R0, + "Initial rabbit population", + nounit, + 2., + PointMass(2) + ), + Parameter( + :W0, + "Initial wolf population", + nounit, + 1., + Uniform(.9,1.1) + ), + Parameter( + :alpha, + "Maximum per capita prey growth rate", + nounit, + 0.667, + PointMass(.667) + ), + Parameter( + :beta, + "Effect of predators on prey", + nounit, + 1.333, + PointMass(1.333) + ), + Parameter( + :gamma, + "Effect of prey on predators", + nounit, + 1., + PointMass(1) + ), + Parameter( + :delta, + "Maximum per capita predator death rate", + nounit, + 1., + PointMass(1.0) + ) +] + +rnm = RegNetModel( + Header("Lotka Volterra", "https://raw.githubusercontent.com/DARPA-ASKEM/Model-Representations/regnet_v0.2/regnet/regnet_schema.json", "regnet", "Lotka Volterra model", "0.1"), + Edgelist(vertices, edges), + parameters +)