inst/tree_sampling/tree-sample-test.R

## SKG
## 2/4/20
## Calculating likelhood  and making trees
##


## Generate partition list
part_list <- generate_part_list(n = 25)
g_weight_list <- get_weight_list(part_list)


K <- 100
inf_params <- c("beta_0" = -2, "beta_1" = 1.5)
max_size <- 26
smear_pos_prob <- .5

forest <- simulate_flip_til_failure(K = K,
                                    inf_params = inf_params,
                                    smear_pos_prob = smear_pos_prob,
                                    max_size = max_size)

bark <- summarize_clusters(forest)


## Make samples of data


expect_equal(length(out), 1)
n_trials <- 1000


cluster_summary <- bark

n <- cluster_summary$n
n_pos <- cluster_summary$n_pos
n_vec <- rep(n, each = n_trials)
n_pos_vec <- rep(n_pos, each = n_trials)
par <- c("beta_1" = 1, "beta_0" = 0)
one_init <- TRUE



## Sample trees of n people with n_pos
sampled_trees <- simulate_many_cond_bp(K = length(n_vec),
                                       n_vec = n_vec, n_pos_vec = n_pos_vec,
                                       part_list = part_list,
                                       g_weight_list = g_weight_list,
                                       one_init = one_init)

out <- loglike_cluster_summary(par = par,
                               cluster_summary = cluster_summary,
                               part_list = part_list,
                               g_weight_list = g_weight_list,
                               sampled_trees = sampled_trees,
                               one_init = one_init,
                               return_neg = FALSE,
                               n_trials = n_trials)

out2 <- optim(par = par, fn = loglike_cluster_summary,
             cluster_summary = cluster_summary,
             part_list = part_list,
             g_weight_list = g_weight_list,
             sampled_trees = sampled_trees,
             one_init = one_init,
             return_neg = TRUE,
             n_trials = n_trials)
skgallagher/TBornotTB documentation built on April 21, 2020, 1:19 p.m.