Coverage for bmm_multitask_learning/coalescent/parameters_cov.py: 0%
26 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-13 13:33 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-13 13:33 +0000
1import numpy as np
3from .coalescent_inference import CoalescentTree
6def optimal_cov(coalesce_tree: CoalescentTree, dim):
7 """
8 retunrns samples from covariance matrix
9 for InverseWishart distribution parameters update
10 """
11 sample_mean = np.zeros((dim, ), dtype=float)
12 overall_items = 0
14 # compute sample mean
15 for item in coalesce_tree.iterate_over():
16 parent = item.parent
17 if parent is not None:
18 overall_items += 1
19 dt = item.t - parent.t
20 D_i = item.mean - parent.mean
21 x_i = D_i / np.sqrt(dt)
22 sample_mean += x_i
23 sample_mean /= overall_items
26 # compute samples
27 samples = []
29 for item in coalesce_tree.iterate_over():
30 parent = item.parent
31 if parent is not None:
32 dt = item.t - parent.t
33 D_i = item.mean - parent.mean
34 x_i = D_i / np.sqrt(dt)
35 samples.append(x_i - sample_mean)
37 return np.array(samples)
40def optimal_R(s_leaves, weights):
41 y = np.exp(- s_leaves) * weights # n x d
42 return y