Equation Nodes SMILE

The engine.
Post Reply
Danny
Posts: 4
Joined: Sun Jun 20, 2021 2:14 pm

Equation Nodes SMILE

Post by Danny »

Good afternoon,

I am using SMILE with Python and inference with general chance nodes is fine but for some reason as soon as I introduce equation nodes inference fails to run. Even using the tutorial code, the pythin script runs with no output or response. Is there something I can try to debug this? Thanks in advance.

Best Wishes,
Danny
Danny
Posts: 4
Joined: Sun Jun 20, 2021 2:14 pm

Re: Equation Nodes SMILE

Post by Danny »

PS. I cannot seem to use any of the tutorial code either which indicates an unusual error as I can inference does work with the starting VentureBN example. For added clarity, the custom BN that I created and the Python code I wrote to infer with it is pasted below.
SpeedBN.xdsl
(2.11 KiB) Downloaded 253 times
----------------------------------------------------------------------------
import pysmile

class HazardDetection():
def __init__(self):
self.net = pysmile.Network() #init network object
self.net.read_file("test2.xdsl"); # read network file
#self.net.read_file("hazardbn.xdsl"); # read network file
self.distances = []
#self.time = []

def update_evidence(self, node_id, outcome_id):
if outcome_id is not None:
self.net.set_evidence(node_id, outcome_id)
else:
self.net.clear_evidence(node_id)
self.net.update_beliefs()

def get_belief(self, node_id):
beliefs = self.net.get_node_value(node_id) # get posterior beliefs
dict_output = {}
for i in range(0, len(beliefs)):
dict_output[self.net.get_outcome_id(node_id, i)] = '{:.3g}'.format(beliefs) # compile probabilities by iterating over returned array
print(self.net.get_outcome_id(node_id, i))
print(beliefs)
return dict_output


hazard_detection = HazardDetection()
hazard_detection.update_evidence("SpeedLimit", "30")
hazard_detection.update_evidence("EVSpeed", "15")
belief = hazard_detection.get_belief("SpeedCheck")
print(belief)
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: Equation Nodes SMILE

Post by shooltz[BayesFusion] »

You need to call set_cont_evidence (instead of set_evidence) on the continuous nodes. Please refer to SMILE Wrappers manual, section 5.12.2 titled "Continuous Inference". Below you can find the fixed code which I was able to run (I also fixed the problem with the format specifier in get_belief method).

Code: Select all

import pysmile
import pysmile_license

class HazardDetection():
    def __init__(self):
        self.net = pysmile.Network() #init network object
        self.net.read_file("SpeedBN.xdsl"); # read network file
        self.distances = []

    def update_evidence(self, node_id, outcome_id):
        if outcome_id is not None:
            self.net.set_cont_evidence(node_id, outcome_id)
        else:
            self.net.clear_evidence(node_id)
        self.net.update_beliefs()

    def get_belief(self, node_id):
        beliefs = self.net.get_node_value(node_id) # get posterior beliefs
        dict_output = {}
        for i in range(0, len(beliefs)):
            dict_output[self.net.get_outcome_id(node_id, i)] = '{:.3g}'.format(beliefs[i]) # compile probabilities by iterating over returned array
        return dict_output

hazard_detection = HazardDetection()
hazard_detection.update_evidence("SpeedLimit", 30)
hazard_detection.update_evidence("EVSpeed", 15)
belief = hazard_detection.get_belief("SpeedCheck")
print(belief)
Post Reply