- edited description
Add a "clone" method
Currently, Lea instances cannot be duplicated while keeping their dependency relationships. Consider for example the following CPT, where obs1
is an observation that depends on an unknown hypothesis, among H1 or H2:
hyp = pmf({'H1': 0.50, 'H2': 0.50})
obs1 = hyp.switch({ 'H1': pmf({'A': 0.50, 'B': 0.50}),
'H2': pmf({'A': 0.75, 'B': 0.25})} )
We want to see how the likelihood of each hypothesis evolves as new observation obs2
is made. The approach obs2 = obs1.new()
is wrong because it makes the marginalization and build a new independent random variable. Currently, the only way to define obs2
is to redo the CPT construct:
obs2 = hyp.switch({ 'H1': pmf({'A': 0.50, 'B': 0.50}),
'H2': pmf({'A': 0.75, 'B': 0.25})} )
By doing so, obs1
and obs2
share the same hypothesis hyp
. We can then make make valid queries as:
print (hyp.given(obs1=='A',obs2=='A'))
# -> H1 : 0.3076923076923077
H2 : 0.6923076923076923
To avoid redoing the same statement over and over, it could be nice to have a clone
method, which makes the job:
obs2 = obs1.clone((hyp,))
The argument is an iterable specifying the variables that we want to share between the orignal instance and the cloned instance. This has the advantage of having an explicit statement of the dependencies between the two variables, which makes the model more understandable.
Similarly to the new
method, an optional argument should allow building up n clones at a time:
obs1to10 = obs1.clone((hyp,),10)
Comments (9)
-
reporter -
reporter Add Lea.clone method and associated private methods (refs
#48)→ <<cset 4af1d3eb8310>>
-
reporter - edited description
-
reporter - changed status to open
-
reporter Correct doc (refs
#48)→ <<cset 566992d43a57>>
-
reporter -
assigned issue to
-
assigned issue to
-
reporter - changed status to closed
-
reporter Add Lea.clone method and associated private methods (refs
#48)→ <<cset 690667a5e96e>>
-
reporter Correct doc (refs
#48)→ <<cset 87aee9ad7aea>>
- Log in to comment