Code
def LearnMLParams(self, cases):
""" Learn and set the parameters of the network to the ML estimate
contained in cases.
Warning: this is destructive, it does not take any prior parameters
into account. Assumes that all evidence is specified.
"""
for v in self.BNet.v.values():
if v.distribution.isAdjustable:
v.distribution.initializeAugmentedEq() # sets all a_ij and b_ij to equivalent sample size #momo
v.distribution.initializeCounts()
v.distribution.normalize(dim=v.name) # set the initial Pr's to a_ij/(a_ij+b_ij)
for case in cases:
assert(set(case.keys()) == set(self.BNet.v.keys())), "Not all values of 'case' are set"
for v in self.BNet.v.values():
if v.distribution.isAdjustable:
v.distribution.incrCounts(case)
v.distribution.setAugmentedAndCounts() #added
for v in self.BNet.v.values():
if v.distribution.isAdjustable:
v.distribution.setAugmentedAndCounts() #added
v.distribution.normalize(dim=v.name)