Reading temporal arcs and small bug in SMILE wrapper documentation

The engine.
Post Reply
Marijn Peppelman
Posts: 23
Joined: Mon Jul 08, 2019 3:14 pm

Reading temporal arcs and small bug in SMILE wrapper documentation

Post by Marijn Peppelman »

Hello.

I'm trying to read, from an existing model, which arcs exist.
Reading normal arcs is no problem, indeed the tutorial has included hot to access that, but I'm having some trouble figuring out how to determine which temporal arcs exist.
However, I'm running into some trouble when trying to determine which temporal arcs exist in the non-unrolled, 2-timeslice DBN.

When i try to use Network.get_temporal_parents(node, i) I either seem to get an error if a node has no arcs of order i:
SMILEException: pysmile.Network.get_temporal_parents(int, int) raised exception!
errno = -2
Or I get a list of TemporalInfo objects returned, and i can't seem to figure out how to parse/access those



Also, in the SMILE wrappers documentation, section 5.12.3 Temporal beliefs is a subsection of 5.12, continuous models, but i suspect it is supposed to be a subsection of 5.11, Dynamic Bayesian Networks, considering it starts with "For plate nodes in the DBN,"


Kind regards,
piotr [BayesFusion]
Site Admin
Posts: 63
Joined: Mon Nov 06, 2017 6:41 pm

Re: Reading temporal arcs and small bug in SMILE wrapper documentation

Post by piotr [BayesFusion] »

TemporalInfo is a class that contains three fields - handle, id and order.
Fields could be accesed by:

Code: Select all

parentArr = net.get_temporal_parents(node, order)
parentArr[0].handle 
parentArr[0].id 
parentArr[0].order
(with assumption, that temporal arcs exists, so parentArr is not empty)

Exception is raised when node is not part of temporal plate. Check if node temporal type == PLATE (net.get_node_temporal_type(node) == Network.NodeTemporalType.PLATE).

I hope I helped,
Piotr
Marijn Peppelman
Posts: 23
Joined: Mon Jul 08, 2019 3:14 pm

Re: Reading temporal arcs and small bug in SMILE wrapper documentation

Post by Marijn Peppelman »

This has indeed been very helpful, thank you very much.

One last question, is there a way to get all temporal arcs instantly, without iterating over every temporal order value, or a method that tells me which temporal order values contain arcs?
It's not a huge issue if there isn't, but mainly from a performance standpoint, I'd prefer not to have to check every possible order in range(1, X) given X time slices.

I'm likely dealing with semi-randomly generated arcs/networks, and i can't guarantee beforehand that they won't exist beyond a certain order value
piotr [BayesFusion]
Site Admin
Posts: 63
Joined: Mon Nov 06, 2017 6:41 pm

Re: Reading temporal arcs and small bug in SMILE wrapper documentation

Post by piotr [BayesFusion] »

Unfortunately, there is no function that returns all temporal arcs in Network, but you can narrow down the search area and iterate nodes placed on Temporal Plate by net.get_temporal_children(node) - it should be slightly faster than net.get_temporal_parents(node, order).
Marijn Peppelman
Posts: 23
Joined: Mon Jul 08, 2019 3:14 pm

Re: Reading temporal arcs and small bug in SMILE wrapper documentation

Post by Marijn Peppelman »

After digging a bit though the available methods, for future reference, for the PySMILE wrapper there is a function net.get_max_temporal_order() which returns the maximum temporal order of arcs that exists in the network, and a function net.get_max_node_temporal_order(node) (i believe node can be either the handle or node id) that returns the maximum temporal order for the given node.

As i mentioned earlier, in the naive case of using a for loop over all the orders to search for an arc with net.get_temporal_parents(node, order), the value returned here can be used to restrict the amount of orders searched, possibly optimizing the search a bit (especially for a large amount of time slices).

So something like:

Code: Select all

temporal_arcs = []
for node in net.get_all_nodes():
	if net.get_node_temporal_type(node) == pysmile.NodeTemporalType.PLATE:
		for order in range( net.get_max_node_temporal_order(node) ):
			temporal_arcs.append( net.get_temporal_parents(node, order) )
return temporal_arcs
Post Reply