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 is unique for every factor node.
The plugin sets a field in the GraphPPL.NodeData
for every factor node that acts as a unique identified. Here how it works:
@model function submodel(y, x, z)
y ~ Normal(x, z)
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 discern between them using only the NodeData
. 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 node ids.
labels = collect(filter(GraphPPL.as_node(), model))
foreach(labels) do label
println(GraphPPL.getextra(model[label], :id))
end
4
8
10