Hi,
"set explicit targets in the network if you're only interested in the subset of node probabilities"
print_posteriors() function is like below:
Code: Select all
def print_posteriors(net, node_handle):
node_id = net.get_node_id(node_handle)
if net.is_evidence(node_handle):
print(f"{node_id} has evidence set ({net.get_evidence_id(node_handle)})")
else :
posteriors = net.get_node_value(node_handle)
for i in range(0, len(posteriors)):
print(f"P({node_id}={net.get_outcome_id(node_handle, i)})={posteriors[i]}")
When I run print_posteriors(net, 0), it is only for target variable with node_handle 0
I want to clarify that it looks like it is not that I did not set explicit targets that cause memory issue.
It is the update_beliefs() function call that reports out of memory error.
Below is my test on a small network:
Code: Select all
manipulate_net = pysmile.Network()
# load the network with learned parameters.
manipulate_net.read_file("./simulated_data/simulated_data_em_cont.xdsl")
# If I call print_posteriors only for target 2, it will reports error
Code: Select all
print_posteriors(manipulate_net, 2)
Code: Select all
---------------------------------------------------------------------------
SMILEException Traceback (most recent call last)
Cell In[33], line 1
----> 1 print_posteriors(manipulate_net, 2)
Cell In[22], line 6, in print_posteriors(net, node_handle)
4 print(f"{node_id} has evidence set ({net.get_evidence_id(node_handle)})")
5 else :
----> 6 posteriors = net.get_node_value(node_handle)
7 for i in range(0, len(posteriors)):
8 print(f"P({node_id}={net.get_outcome_id(node_handle, i)})={posteriors[i]}")
SMILEException: SMILE Error 1 in function Network.GetValue
I must firstly update_beliefs() and then print_posteriors only for target variable.
Code: Select all
manipulate_net.update_beliefs()
print_posteriors(manipulate_net, 2)
Then it gives correct result:
Code: Select all
P(T=T___0)=0.54084
P(T=T___1)=0.45916
Below is the situation on a real world network
If I run
Code: Select all
hybrid_net_with_para.update_beliefs()
print_posteriors(hybrid_net_with_para, 1)
The hybrid_net.update_beliefs() that cause it to have -42 error.
Code: Select all
SMILEException Traceback (most recent call last)
Cell In[144], line 1
----> 1 hybrid_net.update_beliefs()
2 posteriors = hybrid_net.get_node_value(1)
SMILEException: SMILE Error -42 in function Network.UpdateBeliefs
(2)
(2.1)
Could you please point me to some tutorial with sample code or document to do "approximate sampling inference (EPIS)"?
(2.2)
I found that SMILE wrapper document lacks lots of information. Did I missed anything, any other document resource?
I have read the EPIS related material in the GeNIe document. But I cannot find any documentation in the wrapper document about how to set EPIS.
In the Network methods list I found two methods get_bayesian_algorithm() and set_bayesian_algorithm()
I use get_bayesian_algorithm() to get current algorithm, it prints <BayesianAlgorithmType.LAURITZEN: 0>.
Could you please show me how to set it to EPIS?
Thank you very much.