Functional coverage tree: Difference between revisions
Content added Content deleted
m (→Python: Composition of pure functions: (str.isspace() in lieu of `re`)) |
m (→Python: Composition of pure functions: Tidying) |
||
Line 1,606: | Line 1,606: | ||
# TWO COMPUTATIONS BY TRAVERSAL |
# TWO COMPUTATIONS BY TRAVERSAL |
||
withResidueShares(1.0)( |
withResidueShares(1.0)( |
||
foldTree( |
foldTree(weightedCoverage)( |
||
# TREE FROM PARSE OF OUTLINE TEXT |
# TREE FROM PARSE OF OUTLINE TEXT |
||
Line 1,624: | Line 1,624: | ||
# WEIGHTED COVERAGE, AND SHARE OF TOTAL RESIDUE ----------- |
# WEIGHTED COVERAGE, AND SHARE OF TOTAL RESIDUE ----------- |
||
# weightedCoverage :: Tree Dict -> |
# weightedCoverage :: Tree Dict -> |
||
def weightedCoverage(node): |
|||
'''The weighted coverage of a |
|||
node in a coverage tree. |
|||
''' |
|||
nodeRoot = root(node) |
|||
return nodeRoot['coverage'] * nodeRoot['weight'] |
|||
# weightedTreeAverage :: Tree Dict -> |
|||
# [Tree Dict] -> Tree Dict |
# [Tree Dict] -> Tree Dict |
||
def |
def weightedCoverage(x): |
||
'''The weighted |
'''The weighted coverage of a tree node, |
||
as a function of the weighted averages |
as a function of the weighted averages |
||
of its children. |
of its children. |
||
''' |
''' |
||
def go(xs): |
def go(xs): |
||
cws = [(r['coverage'], r['weight']) for r in [root(x) for x in xs]] |
|||
totalWeight = reduce(lambda a, x: a + x[1], cws, 0) |
|||
return Node(dict( |
return Node(dict( |
||
x, **{ |
x, **{ |
||
'coverage': round( |
'coverage': round(reduce( |
||
lambda a, cw: a + (cw[0] * cw[1]), |
|||
cws, x['coverage'] |
|||
) / (totalWeight if 0 < totalWeight else 1), 5) |
|||
) / ( |
|||
reduce( |
|||
lambda a, node: root(node)['weight'] + a, |
|||
xs, 0 |
|||
) or 1 |
|||
) |
|||
), 5) |
|||
} |
} |
||
))(xs) |
))(xs) |