AlgebraicJulia / AlgebraicJulia/ASKEM-demos

High level stratification doesn't work with more than two cities

Ouverte
#23 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Jupyter Notebook
Étoiles
8
Forks
1
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

I wanted to make an example of SIRD stratified by a large number of cities/regions. Initially I tried to use the high-level `StrataSpec` formulation, but for more than two cities, the resulting pullback has the wrong transitions. It does not have all the city transitions for each (allowed) state and instead has many combo (disease,city) transitions (e.g. an infected susceptible person in one city spontaneously becomes an infected susceptible person in another city). I made a function to generate the multi-city model. As in the demo, the two-city form is correct, but for more than two it fails.
Hard coding three cities (not using the generate function) also fails, while using the low-level formulation on a generated multi-city model does work. The example below is the high-level formulation of three cities.
```
using Catlab.CategoricalAlgebra
using Catlab.Present, Catlab.Theories
using AlgebraicPetri
using AlgebraicPetri: Graph
include("Oct2022Demo.jl");

types′ = LabelledPetriNet([:Pop],
:infect=>((:Pop, :Pop)=>(:Pop, :Pop)),
:disease=>(:Pop=>:Pop),
:strata=>(:Pop=>:Pop))
types = map(types′, Name=name->nothing)

SIRD = LabelledPetriNet([:S, :I, :R, :D],
:inf => ((:S,:I) => (:I,:I)),
:recover => (:I=>:R),
:death => (:I=>:D));
AlgebraicPetri.Graph(SIRD)

SIRD_typed = homomorphism(SIRD, types;
initial=(T=[1,2,2],I=[1,2,3,3],O=[1,2,3,3]),
type_components=(Name=x->nothing,))
@assert is_natural(SIRD_typed)

function makeMultiCity(n)
lstates = []
ltrans = []
for ii in 1:n
push!(lstates,Symbol("City"*string(ii)))
end
for ii in 1:n
for jj in 1:n
if ii != jj
push!(ltrans,Symbol("travel"*string(ii)*string(jj)) => ((lstates[ii])=>(lstates[jj])))
end
end
end
MultiCity = LabelledPetriNet(lstates,ltrans...)
end

num_cities = 3
MultiCity = makeMultiCity(num_cities)
MultiCity_typed = homomorphism(MultiCity, types;
initial=(T=repeat([3],ns(MultiCity)),), type_components=(Name=x->nothing,))
@assert is_natural(MultiCity_typed)
AlgebraicPetri.Graph(MultiCity)

l_trans_per_state_SIRD = repeat([[:strata]],3)
push!(l_trans_per_state_SIRD,[])
SIRD_MC_ss = StrataSpec(SIRD_typed, l_trans_per_state_SIRD)
l_trans_per_state_MC = []
for ii in 1:num_cities
push!(l_trans_per_state_MC,[:disease,:infect])
end
MultiCity_ss = StrataSpec(MultiCity_typed, l_trans_per_state_MC)
mdl_SIRD_MC, obsSIRD_MC = stratify(SIRD_MC_ss, MultiCity_ss, types′);

AlgebraicPetri.Graph(mdl_SIRD_MC)
```

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.