probsys / sppl

Probabilistic programming system for fast and exact symbolic inference
Apache License 2.0
76 stars 10 forks source link

Add size() for spe #113

Closed fsaad closed 3 years ago

fsaad commented 3 years ago

@Schaechtle

Schaechtle commented 3 years ago

Context: For for the whole-genome simulation we work with very large models. This does the trick:

def size(spe):
    if isinstance(spe, LeafSPE):
        return 1
    if isinstance(spe, BranchSPE):
        return 1  + sum(size(s) for s in spe.children)
    assert False, 'Unknown SPE type: %s' % (repr(spe),)