Skip to content

Commit

Permalink
Update growth_model.R
Browse files Browse the repository at this point in the history
  • Loading branch information
elena-buscaroli committed Dec 16, 2024
1 parent 5fee616 commit e7c00fd
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions R/growth_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,18 @@ run_py_growth = function(rates.df,

input.clone = pop_df.cl %>%
dplyr::filter(Identity == cluster) %>%
dplyr::select(-Frequency) %>%
dplyr::mutate(Population=ifelse((Generation == 0 & clonal), 1, Population)) %>%
tidyr::pivot_wider(id_cols="Generation", names_from="Lineage", values_from="Population") %>%

## Run with population size
# dplyr::select(-Frequency) %>%
# dplyr::mutate(Population=ifelse((Generation == 0 & clonal), 1, Population)) %>%
# tidyr::pivot_wider(id_cols="Generation", names_from="Lineage", values_from="Population") %>%

## Run with re-scaled population size
dplyr::mutate(Frequency=Frequency * 1000) %>%
dplyr::select(-Population) %>%
dplyr::mutate(Frequency=ifelse((Generation == 0 & clonal), 1, Frequency)) %>%
tidyr::pivot_wider(id_cols="Generation", names_from="Lineage", values_from="Frequency") %>%

dplyr::arrange(Generation)

times = input.clone$Generation
Expand All @@ -189,6 +198,10 @@ run_py_growth = function(rates.df,
times = torch$tensor(times)$int()$unsqueeze(as.integer(1))
y = torch$tensor(y %>% as.matrix())

# Remove ######
print(times)
print(y)

p.rate.exp = p.rate.log = NULL

x.reg = py_pkg$explogreg$Regression(times, y)
Expand All @@ -198,6 +211,9 @@ run_py_growth = function(rates.df,
losses.exp = x.reg$train(regr="exp", p_rate=p.rate.exp, steps=as.integer(steps), random_state=as.integer(random_state))
p.exp = x.reg$get_learned_params()
ll.exp = x.reg$compute_log_likelihood() %>% setNames(nm=lineages)

# Remove ######
print(p.exp)
}

if (grepl("log", growth_model)) { # log training
Expand Down

0 comments on commit e7c00fd

Please sign in to comment.