Renaming an ACSetTransformation? #927
-
Hi everyone, I'm trying to replicate what I get from defining a UWD by hand with one where I create it using Catlab's imperative interface. My code is below - and it works - but what I would like is to get the same transition names for the automated version as for the hand-written one. using AlgebraicPetri,AlgebraicPetri.TypedPetri
using Catlab, Catlab.CategoricalAlgebra, Catlab.Programs
using Catlab.WiringDiagrams, Catlab.Graphics
epi_transitions = LabelledPetriNet(
[:Pop],
:infection=>((:Pop, :Pop)=>(:Pop, :Pop)),
:recovery=>(:Pop=>:Pop)
)
## Manual definition
risk_uwd = @relation () where (H::Pop, L::Pop) begin
infection(H,H,H,H) # Within H infection
infection(H,L,H,L) # Infection of S_H by I_L
infection(L,H,L,H) # Infection of S_L by I_H
infection(L,L,L,L) # Within L infection
recovery(H,H) # H recovery
recovery(L,L) # L recovery
end
risk_acst = oapply_typed(epi_transitions, risk_uwd, [:HH, :HL, :LH, :LL, :H, :L])
risk_lpn = dom(risk_acst)
tnames(risk_lpn)
## Automated
function make_risk_groups()
# Start with a blank UWD with 2 populations
uwd = RelationDiagram(repeat([:Pop], 2))
names = ["H","L"]
## Build junctions (just a `Dict`) and update the UWD
junctions = Dict(begin
variable = Symbol(names[i])
junction = add_junction!(uwd, :Pop, variable=variable)
set_junction!(uwd, port, junction, outer=true)
variable => junction
end for (i, port) in enumerate(ports(uwd, outer=true)))
pairs = collect(Iterators.product(keys(junctions), keys(junctions)))
tnames = Vector{Symbol}(undef,0)
## Cycle through pairs and add boxes for infection
for pair in pairs
ins_outs = (pair[1],pair[2],pair[1],pair[2])
box = add_box!(uwd, [junction_type(uwd, junctions[p]) for p in ins_outs], name=:infection)
for (rgn, port) in zip(ins_outs, ports(uwd, box))
set_junction!(uwd, port, junctions[rgn])
end
push!(tnames,Symbol("$(pair[1])$(pair[2])"))
end
## Generate an ACSet transformation using the above `epi_transitions`
act = oapply_typed(epi_transitions, uwd, tnames)
## Add recovery within groups
act = add_reflexives(act, repeat([[:recovery]], 2), epi_transitions)
return act
end
risk_automated_acst = make_risk_groups()
risk_automated_lpn = dom(risk_automated_acst)
tnames(risk_automated_lpn) Actually, what I'd really like to do is to specify a model that doesn't have the reflexives, and add them later. The reason for this is that I want to have a model that just has infection - the reflexives only make sense when I have to combine with another model i.e. to start with something like this: risk_uwd = @relation () where (H::Pop, L::Pop) begin
infection(H,H,H,H) # Within H infection
infection(H,L,H,L) # Infection of S_H by I_L
infection(L,H,L,H) # Infection of S_L by I_H
infection(L,L,L,L) # Within L infection
end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi Simon, you're right that the argument in I agree with your last statement that one should generally not represent the reflexive transitions until right before one does a stratification, so hopefully the autogenerated names are not a real problem? If they are, we could make a |
Beta Was this translation helpful? Give feedback.
-
Ok let me know if this works for you
|
Beta Was this translation helpful? Give feedback.
Ok let me know if this works for you