causalincentives / pycid

Library for graphical models of decision making, based on pgmpy and networkx
Apache License 2.0
96 stars 13 forks source link

Possible interface change: specifying a model with a dictionary #47

Closed tom4everitt closed 2 years ago

tom4everitt commented 3 years ago

The current add_cpds method is quite complex, and so is the way we extend TabularCPD by not calling super.__init__ in __init__. There should be a better way of doing this. The following is a proposal for how.

Instead of using add_cpds, we could define our own method add_model, which takes a dictionary {variable: function/dictionary/list} as input. For example:

cid.add_model({
'S' : {-1: 0.5, 1:0.5},
'D': [-1, 1],
'U': lambda s, d: s * d
})

It is the responsibility of CausalBayesianNetwork to derive TabularCPDs and add them to BayesianModel, with the help of modified versions StochasticFunctionCPD etc.

Why this is better:

Implementation:

edlanglois commented 3 years ago

I am thinking something like:

cid.parameterize('S', {-1: 0.5, 1:0.5})
cid.parameterize('D', [-1, 1])
cid.parameterize('U', lambda s, d: s * d)
...
cid.parameterize('Y',  lambda x: {x: 0.9}, domain=[0, 1])
tom4everitt commented 3 years ago

Started work on this in this branch https://github.com/causalincentives/pycid/tree/new_interface

tom4everitt commented 2 years ago

implemented, closing this issue