Node tag plugin
GraphPPL provides a built-in plugin to mark factor nodes with a specific tag for later analysis or debugging purposes.
GraphPPL.NodeTagPlugin — TypeNodeTagPluginA plugin that adds an tag property to the factor node. This field can be used to find a node given its tag with the GraphPPL.by_nodetag filter.
The plugin allows to specify the tag in the where { ... } block during the node construction. Here how it works:
@model function submodel(y, x, z)
y ~ Normal(x, z) where { tag = "from submodel" }
end
@model function mainmodel()
x ~ Normal(0.0, 1.0)
z ~ Normal(0.0, 1.0)
y ~ submodel(x = x, z = z)
endIn 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.NodeTagPlugin plugin.
model = GraphPPL.create_model(
GraphPPL.with_plugins(
mainmodel(),
GraphPPL.PluginsCollection(GraphPPL.NodeTagPlugin())
)
)After, we can fetch all the nodes with a specific tag using the GraphPPL.by_nodetag function.
GraphPPL.by_nodetag — Functionby_nodetag(tag)A filter predicate that can be used to find a node given its tag in a model.
labels = collect(filter(GraphPPL.by_nodetag("from submodel"), model))
foreach(labels) do label
println(GraphPPL.getname(label))
endDistributions.Normal