question regarding the multidimensional arrays represented as flat array

The engine.
Post Reply
BayesFusionUser123
Posts: 8
Joined: Tue Jun 10, 2025 3:51 pm

question regarding the multidimensional arrays represented as flat array

Post by BayesFusionUser123 »

Dear Community,

I am following the PDF version of the tutorial for SMILE wrappers, specifically for the Python language.

In Tutorial 1, after adding arcs, it redirected to a tutorial "Multidimensional arrays". In this section, how to understand the following statement? It says " The order of the coordinates reflects the order in which the arcs to the node were created. The most significant (leftmost) coordinate will represent the state of the first parent. The state of the node itself corresponds to the least significant (rightmost) coordinate."

In Tutorial 1, the arcs are added in this order:

Code: Select all

net.add_arc(e, s)
net.add_arc(s, f)
net.add_arc("Economy", "Forecast")
For forecase node, in tutorial 1's python code I can see:

Code: Select all

  forecastDef = [
            0.70, # P(Forecast=G|Success=S,Economy=U)
            0.29, # P(Forecast=M|Success=S,Economy=U)
            0.01, # P(Forecast=P|Success=S,Economy=U)
        
            0.65, # P(Forecast=G|Success=S,Economy=F)
            0.30, # P(Forecast=M|Success=S,Economy=F)
            0.05, # P(Forecast=P|Success=S,Economy=F)
        
            0.60, # P(Forecast=G|Success=S,Economy=D)
            0.30, # P(Forecast=M|Success=S,Economy=D)
            0.10, # P(Forecast=P|Success=S,Economy=D)
        
            0.15,  # P(Forecast=G|Success=F,Economy=U)
            0.30, # P(Forecast=M|Success=F,Economy=U)
            0.55, # P(Forecast=P|Success=F,Economy=U)
        
            0.10, # P(Forecast=G|Success=F,Economy=F)
            0.30, # P(Forecast=M|Success=F,Economy=F)
            0.60, # P(Forecast=P|Success=F,Economy=F)
        
            0.05, # P(Forecast=G|Success=F,Economy=D)
            0.25, # P(Forecast=G|Success=F,Economy=D)
            0.70  # P(Forecast=G|Success=F,Economy=D)
        ]

So for the "forecast" node, the first parent is s (success), the second parent is e (economy).

My understanding:

In the Python code, we can see that the order of numbers in the flat array can be see as:

We have three nested for loops,
The first parent "success" is in the first for loop, the second parent "economy" is in the second for loop, the node "forecast" is in the third for loop.

Code: Select all

for tmp_s in ["S", "F"]:
    for tmp_e in ["U", "F", "D"]:
       for tmp_f in ["G", "M", "P"]:
           print("P(Forcast=%s|Success=%s,Economy=%s)" % (tmp_f, tmp_s, tmp_e))
But, how to understand this statement "The order of the coordinates reflects the order in which the arcs to the node were created. The most significant (leftmost) coordinate will represent the state of the first parent. The state of the node itself corresponds to the least significant (rightmost) coordinate." in this case?

What is the leftmost coordinate? What is the rightmost coordinate?
Last edited by BayesFusionUser123 on Fri Jun 13, 2025 8:27 pm, edited 1 time in total.
shooltz[BayesFusion]
Site Admin
Posts: 1457
Joined: Mon Nov 26, 2007 5:51 pm

Re: question regarding the multidimensional arrays represented as flat array

Post by shooltz[BayesFusion] »

But, how to understand this statement "The order of the coordinates reflects the order in which the arcs to the node were created. The most significant (leftmost) coordinate will represent the state of the first parent. The state of the node itself corresponds to the least significant (rightmost) coordinate." in this case?
The coordinates are the linear integer array. The forecast node requires three values in this coordinate array to index its CPT. It has two parents, so there are two elements in the coordinates representing the parents, and one element representing the outcome of the forecast node.

The first (leftmost) element of the coordinates is for the success node. The arc from success to forecast was created first, before the arc from economy to forecast.

The second element of the coordinates is for the economy node. The arc from economy to forecast was created second.

The third (rightmost) element of the coordinates is for the forecast node itself.
Post Reply