Node ID plugin
GraphPPL provides a built-in plugin to mark factor nodes with a specific ID for later analysis or debugging purposes.
GraphPPL.NodeIdPlugin
— TypeNodeIdPlugin
A plugin that adds an id
property to the factor node. This field can be used to find a node given its id
with the GraphPPL.by_nodeid
filter.
The plugin allows to specify the id
in the where { ... }
block during the node construction. Here how it works:
@model function submodel(y, x, z)
y ~ Normal(x, z) where { id = "from submodel" }
end
@model function mainmodel()
x ~ Normal(0.0, 1.0)
z ~ Normal(0.0, 1.0)
y ~ submodel(x = x, z = z)
end
In this example we have created three Normal
factor nodes and would like to access the one which has been created within the submodel
. To do that, we need to instantiate our model with the GraphPPL.NodeIdPlugin
plugin.
model = GraphPPL.create_model(
GraphPPL.with_plugins(
mainmodel(),
GraphPPL.PluginsCollection(GraphPPL.NodeIdPlugin())
)
)
After, we can fetch all the nodes with a specific id using the GraphPPL.by_nodeid
function.
GraphPPL.by_nodeid
— Functionby_nodeid(id)
A filter predicate that can be used to find a node given its id
in a model.
labels = collect(filter(GraphPPL.by_nodeid("from submodel"), model))
foreach(labels) do label
println(GraphPPL.getname(label))
end
Distributions.Normal