MCPcopy Create free account
hub / github.com/CyberPoint/libpgm / next

Method next

libpgm/tablecpdfactorization.py:386–425  ·  view source on GitHub ↗
(current)

Source from the content-addressed store, hash-verified

384
385 # define function to create the next instantiation
386 def next(current):
387 for node in order:
388 # multiply all relevant factors together
389 relevantfactors = []
390 for factor in self.factorlist:
391 if (factor.scope.count(node) > 0):
392 factorcopy = factor.copy()
393 relevantfactors.append(factorcopy)
394 for j in range(1, len(relevantfactors)):
395 relevantfactors[0].multiplyfactor(relevantfactors[j])
396
397 # reduce to leave only the one node
398 for othernode in order:
399 if (othernode != node and relevantfactors[0].scope.count(othernode) > 0):
400 relevantfactors[0].reducefactor(othernode, current[othernode])
401
402 # renormalize
403 summ = 0
404 for val in relevantfactors[0].vals:
405 summ += val
406 for x in range(len(relevantfactors[0].vals)):
407 relevantfactors[0].vals[x] /= summ
408
409 # convert random number
410 val = random.random()
411 lboundary = 0
412 uboundary = 0
413 for x in range(len(relevantfactors[0].vals)):
414 uboundary += relevantfactors[0].vals[x]
415 if (lboundary <= val and val < uboundary):
416 rindex = x
417 # print s, val
418 break
419 else:
420 lboundary = uboundary
421
422 # modify result
423 current[node] = self.bn.Vdata[node]["vals"][rindex]
424
425 return current
426
427 # run next() function n times
428 for u in range(n-1):

Callers

nothing calls this directly

Calls 3

copyMethod · 0.80
multiplyfactorMethod · 0.80
reducefactorMethod · 0.80

Tested by

no test coverage detected