|
12 | 12 | exe = ProcessPoolExecutor() |
13 | 13 |
|
14 | 14 |
|
15 | | -def hide_observation(lineages: list, percentage: float) -> list: |
| 15 | +def hide_observation(lineages: list, percentage: float, rng=None) -> list: |
16 | 16 | """Taking a list of lineages and the percentage of cells want to be masked, it marks those x% negative.""" |
| 17 | + rng = np.random.default_rng(rng) |
17 | 18 | new_lineages = deepcopy(lineages) |
18 | 19 | for new_lineage in new_lineages: |
19 | 20 | for cell in new_lineage.output_lineage: |
20 | | - if bernoulli.rvs(p=percentage, size=1): |
| 21 | + if bernoulli.rvs(p=percentage, size=1, random_state=rng): |
21 | 22 | # negate the cell observations to mask them |
22 | 23 | cell.obs = [-1 * o for o in cell.obs] |
23 | 24 | new_lineage.obs = np.array([cell.obs for cell in new_lineage.output_lineage]) |
24 | 25 |
|
25 | 26 | return new_lineages |
26 | 27 |
|
27 | 28 |
|
28 | | -def crossval(train_populations: list, num_states: np.ndarray): |
| 29 | +def crossval(train_populations: list, num_states: np.ndarray, rng=None): |
29 | 30 | """Perform cross validation for the experimental data which runs in parallel for all states. |
30 | 31 | :param train_populations: the populations after applying hide_observation. This includes the list of list of lineages. |
31 | 32 | :param hidden_indexes: is a list of list of np.arrays for each lineage, |
32 | 33 | filled with zeros and ones. ones refer to the index of those cells that have been hidden. |
33 | 34 | :param hidden_obs: list of list of tuples of observations that have been masked in the train_lineage. |
34 | 35 | :param num_states: is a range of states we want to run the cross validation for. |
35 | 36 | """ |
| 37 | + rng = np.random.default_rng(rng) |
36 | 38 | # fit training data by parallel. |
37 | 39 |
|
38 | 40 | # save the tHMMobj for each number of states that is being run |
39 | 41 | LLs = [] |
40 | 42 | for k in num_states: |
41 | | - tHMMobj_list, _, gamma_list = Analyze_list(train_populations, k) |
| 43 | + tHMMobj_list, _, gamma_list = Analyze_list(train_populations, k, rng=rng) |
42 | 44 |
|
43 | 45 | Logls = 0 |
44 | 46 | # calculate the log likelihood of hidden observations |
|
0 commit comments