Dear Community,
I am following the PDF version of the tutorial for SMILE wrappers, specifically for the Python language.
I tried to simulate a network with continuous variables only.
1. In this sample code, I first simulate a dataset based on a predefined formula as follows:
C = Normal(0, 1)
epsilon_A = Normal(0, 1)
A = 20 * C + epsilon_A
B = Normal(1, 1)
D = A + B
2. I tried structured learning from a simulated dataset and checked what the output network structure looks like.
3. I use the predefined network and simulated dataset for parameter learning.
4. I double checked and found that the learned parameter is wrong.
```
<nodes>
<equation id="A">
<definition>A=0</definition>
</equation>
<equation id="C">
<parents>A</parents>
<definition>C=A</definition>
</equation>
<equation id="B">
<definition>B=0</definition>
</equation>
<equation id="D">
<parents>A B</parents>
<definition>D=A+B</definition>
</equation>
</nodes>
```
My questions
(1) I want to define an empty network with continuous variables only in the following structure:
* C -> A
* A -> D
* B -> D
Is the following code for construct this network correct?
```
def create_cont_node(net, id, name, x_pos, y_pos):
handle = net.add_node(pysmile.NodeType.EQUATION, id)
net.set_node_name(handle, name)
net.set_node_position(handle, x_pos, y_pos, 85, 55)
return handle
cont_net = pysmile.Network()
A = create_cont_node(cont_net, "A", "A", 10, 20)
B = create_cont_node(cont_net, "B", "B", 10, 30)
C = create_cont_node(cont_net, "C", "C", 10, 40)
D = create_cont_node(cont_net, "D", "D", 10, 50)
cont_net.add_arc(C, A)
cont_net.add_arc(A, D)
cont_net.add_arc(B, D)
cont_net.write_file("./simulated_data/predefined_cont_net.xdsl")
```
(2)
I tried to learn parameter for the predefined network structure. Why is the parameter learned wrong?
Please check the file "./simulated_data/simulated_data_em_cont.xdsl"
```
<nodes>
<equation id="C">
<definition>C=Normal(-0.000420899,1.00017)</definition>
</equation>
<equation id="A">
<parents>C</parents>
<definition>A=C</definition>
</equation>
<equation id="B">
<definition>B=Normal(1.00357,0.999576)</definition>
</equation>
<equation id="D">
<parents>B C</parents>
<definition>D=1*B+1*C+Normal(3.32259e-09,7.18578e-07)</definition>
</equation>
</nodes>
```
Many thanks.
All related code and data are attached.
Help needed for my example of simulate continuous model and parameter learning. Parameter learning wrong.
-
- Posts: 8
- Joined: Tue Jun 10, 2025 3:51 pm
Help needed for my example of simulate continuous model and parameter learning. Parameter learning wrong.
- Attachments
-
- continuous_model.zip
- (105.54 KiB) Downloaded 42 times
-
- Site Admin
- Posts: 1457
- Joined: Mon Nov 26, 2007 5:51 pm
Re: Help needed for my example of simulate continuous model and parameter learning. Parameter learning wrong.
You have found a bug in SMILE. Depending on the order of node creation, the equations created by the continuous parameter learning may be incorrect. If you modify your program to create nodes in the C,A,B,D order, the equation will be correct.I tried to learn parameter for the predefined network structure. Why is the parameter learned wrong?
We have already fixed the problem. If you want to use a pre-release version of SMIILE, let me know; indicate which operating system and Python version you're using.
-
- Posts: 8
- Joined: Tue Jun 10, 2025 3:51 pm
Re: Help needed for my example of simulate continuous model and parameter learning. Parameter learning wrong.
Code: Select all
cont_net = pysmile.Network()
# Here the node is not added in order ABCD, but CABD
C = create_cont_node(cont_net, "C", "C", 10, 40)
A = create_cont_node(cont_net, "A", "A", 10, 20)
B = create_cont_node(cont_net, "B", "B", 10, 30)
D = create_cont_node(cont_net, "D", "D", 10, 50)
cont_net.add_arc(C, A)
cont_net.add_arc(A, D)
cont_net.add_arc(B, D)
cont_net.write_file("./simulated_data/predefined_cont_net.xdsl")
Yes, I want to use the pre-release version of SMILE. How to get access to it?
I am using Manjaro Linux with kernel version 6.12.28-1-MANJARO. Python 3.11.