Bayesian Object Oriented Programming in Pyro

My name is harish and i am currently in @osazuwa class trying to implement Avi Pfeffer’s Bayesian Object Oriented Programming using Pyro instead of Figaro.

The way, we are trying to make it work is to make an unique trace variable for each class instantiation. But in some cases, logically we need to refer to the same trace variable. Pyro returns a "RuntimeError: Multiple sample sites named ‘something_that_is_not_unique’. How can i re-use the same trace variable ?

In the above image, we are having trouble with creating trace variables for connection class as the people who have already been connected should be represented only once.

def model():
    persons = conn.execute("SELECT * from Persons")
    for person in persons:
        exec('%s = Person(%d)' % (person[1], person[0]))
    posts = conn.execute("SELECT * from Posts")
    for post in posts:
        exec('%s = Post(%s, %d)' % (post[1], post[2], post[0]))

Each class members that are random variables has its pyro.sample statements in class definitions.

With the data saved in table, this equates to
Amy = Person(1) # Uses the trace variable 'p1' for pyro.sample
Bryan = Person(2) # Uses the trace variable 'p2' for pyro.sample

Post1 = Post(Amy, 1) # Uses the trace variable 'post1' for pyro.sample
Post2 = Post(Amy,2) # Uses the trace variable 'post2' for pyro.sample


With this set up, we are able to condition using pyro.condition and use an inference algorithm, as to generate a sample, the trace variables are all unique.

But when we add comments, inherently the connection might not be unique for each comment.

# Now, a connection is formed between Amy and Brian automatically, 
# with a RV defining their relationship with trace variable 
# name 'Amy_Brian'
Comment1 = Comment(1,Post1, 'Brian') 

 # This is where error occurs.
#  When this is called. I generate the same trace variable named 
# 'Amy_Brian' and when i try to generate samples i get an runtime error ,
# Multiple sample sites named 'Amy_Brian'
Comment2 = Comment(2, Post2, 'Brian')

How do i tell pyro that its the same thing and you need generate sample only once, which is what i thought would happen if i have the same trace variable.

The code needs a set up to be reproducible (as the data comes in from a RDS). Please let me know if more information is needed or if code could be shared in some way.


Hi @mancunian1792, could you provide some background, and ideally some code for the actual objects? I’m not familiar with Bayesian Object Oriented Programming, so it’s quite not clear to me what you’re trying to do.