= Solution
Initialize all \b[eight] leaves, not seven: every observed base contributes a one-hot vector in the order A, C, G, T. The reference to $L-1$ leaf rows in the prose is inconsistent with its eight-leaf tree.
``
def initialise_prob(leafList):
alphabet = {base: j for j, base in enumerate("ACGT")}
result = np.zeros((2*len(leafList)-1, 4), dtype=float)
for i, base in enumerate(leafList):
result[i, alphabet[base]] = 1.
return result
leaves = ["G", "A", "T", "G", "G", "G", "C", "G"]
prob = initialise_prob(leaves)
print(prob[:len(leaves)])
``
The initialized leaf rows are:
``
0 0 1 0
1 0 0 0
0 0 0 1
0 0 1 0
0 0 1 0
0 0 1 0
0 1 0 0
0 0 1 0
``
The remaining seven internal-node rows initially contain zeros. Their eventual entries are conditional <likelihoods> of descendant observations given the ancestral base, rather than normalized <posterior probabilities> of that ancestral base.
Back to article page