Defining distribution parameters externally then creating the BN

The engine.
Post Reply
lom
Posts: 2
Joined: Tue Jan 21, 2025 2:57 pm

Defining distribution parameters externally then creating the BN

Post by lom »

Hi,
I have a continuous Bayesian network created in Python - with my nodes created using the CustomPDF distribution. Is there a way to enter the parameters of my CustomPDF function as lists from a CSV file? I would like to be able to update the values externally.
Thanks.
piotr [BayesFusion]
Site Admin
Posts: 67
Joined: Mon Nov 06, 2017 6:41 pm

Re: Defining distribution parameters externally then creating the BN

Post by piotr [BayesFusion] »

At the moment there is no dedicated function to update part of the equation of the node definition. You can write a function in Python to which you pass the list of parameters you want to include in the CustomPDF function and the name of the node, and which will return its definition.

Code: Select all

import pysmile
import pysmile_license

import csv

def convert_csv_to_string(file_path):
    numbers = []
    
    with open(file_path, newline='', encoding='utf-8') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            numbers.append(row['x'])
            numbers.append(row['y'])

    return ",".join(numbers)
    

net = pysmile.Network()
net.add_node(pysmile.NodeType.EQUATION, "Eq_node")
custom_pdf_params = convert_csv_to_string("file_with_parameters.csv")
net.set_node_equation("Eq_node", f"Eq_node=CustomPDF({custom_pdf_params})")
net.update_beliefs()
eq_node_values = net.get_node_value("Eq_node")
Post Reply