Skip to content
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

Problem wiring a simple SEIR model #7

Open
sdwfrost opened this issue Jun 19, 2023 · 7 comments
Open

Problem wiring a simple SEIR model #7

sdwfrost opened this issue Jun 19, 2023 · 7 comments

Comments

@sdwfrost
Copy link

For some reason, the following code for an SEIR model wires E to R, rather than I to R. Can anyone spot where I'm going wrong?

using AlgebraicPetri,AlgebraicPetri.TypedPetri
using Catlab, Catlab.CategoricalAlgebra, Catlab.Programs
using Catlab.WiringDiagrams, Catlab.Graphics
using AlgebraicDynamics.UWDDynam


epi_transitions = LabelledPetriNet(
  [:Pop],
  :infection=>((:Pop, :Pop)=>(:Pop, :Pop)),
  :progression=>(:Pop=>:Pop),
  :recovery=>(:Pop=>:Pop)
)

seir_uwd = @relation () where (S::Pop, E::Pop, I::Pop, R::Pop) begin
    infection(S, I, E, I)
    progression(E, I)
    recovery(I, R)
end
seir_acst = oapply_typed(epi_transitions, seir_uwd, [, , ])
seir_lpn = dom(seir_acst)
Graph(seir_lpn)
@jpfairbanks
Copy link
Member

It looks like you specified it right. I'm digging in now.

@jpfairbanks
Copy link
Member

I do not know why this fixed it, but this code makes the correct answer.

using AlgebraicPetri,AlgebraicPetri.TypedPetri
using Catlab, Catlab.CategoricalAlgebra, Catlab.Programs
using Catlab.WiringDiagrams, Catlab.Graphics
using AlgebraicDynamics.UWDDynam
using Catlab.Graphics.Graphviz

epi_transitions = LabelledPetriNet(
  [:Pop],
  :infection=>((:Pop, :Pop)=>(:Pop, :Pop)),
  :progression=>(:Pop=>:Pop),
  :recovery=>(:Pop=>:Pop)
)

seir_uwd = @relation () where (S::Pop, I::Pop, E::Pop, R::Pop) begin
    infection(S, I, E, I)
    progression(E, I)
    recovery(I, R)
end
to_graphviz(seir_uwd, box_labels=:name, junction_labels=:variable)
seir_acst = oapply_typed(epi_transitions, seir_uwd, [, , ])
seir_lpn = dom(seir_acst)
Graph(seir_lpn)

The change was to reorder the arguments in the UWD.

seir_uwd = @relation () where **(S::Pop, I::Pop, E::Pop, R::Pop)** begin
    infection(S, I, E, I)
    progression(E, I)
    recovery(I, R)
end

The fact that this fixed it, makes me suspicious that there is a deeper bug.

@sdwfrost
Copy link
Author

Your fix lists the symbols in the order they appear in the rules. This sounds like a bug/undocumented feature!

@epatters
Copy link
Member

Yeah, this looks like a bug. It shouldn't matter how you order the outer ports in the UWD.

@sdwfrost
Copy link
Author

I was trying to look into this further, but the following code for drawing the UWD doesn't display labels - is this a config thing on my side?

using Catlab, Catlab.CategoricalAlgebra, Catlab.Programs
using Catlab.WiringDiagrams, Catlab.Graphics

seir_uwd = @relation (S, I, E, R)  begin
    infection(S, I, E, I)
    progression(E, I)
    recovery(I, R)
end
to_graphviz(seir_uwd)

@epatters
Copy link
Member

You want

to_graphviz(seir_uwd, box_labels=:name)

or

to_graphviz(seir_uwd, box_labels=:name, junction_labels=:variable)

depending on whether you also want junction labels.

@sdwfrost
Copy link
Author

Thanks @epatters! The UWD displays correctly (I wired to R), so it's this bit of the code where things get rewired:

seir_acst = oapply_typed(epi_transitions, seir_uwd, [, , ])
seir_lpn = dom(seir_acst)
Graph(seir_lpn)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants