andrew-edwards / EDMsimulate

An R package for simulating fish populations for empirical dynamic modeling
1 stars 1 forks source link

Can't quite get the parallel call to multiview_embedding working #17

Open andrew-edwards opened 1 year ago

andrew-edwards commented 1 year ago

Got the infrastructure set up for mve, but in fit_models() can't quite get the call right. Latest commit is a585423. Have commented out what I thought should work, and added dummy results to not give an error. So res <- sim_and_fit_realisations(M=2)
works. [UPDATE: Andy broke it with a commit today (10/10/23), but it's tied in with #18)].

Don't forget to update pbsEDM; I updated it today.

Think it's just the arguments - does end up being a vector of list of lists, or something.

Also haven't added in the fit_mve_full_series results yet (added to the help), need to do that once fixed error.

Almost there I think. browser() in fit_models() doesn't seem to work with parallel though.

andrew-edwards commented 1 year ago

This runs okay:

set.seed(42)
h_simulated <- 0.1095 + sample(1:180) * 0.001 # has mean of 0.2
simulated_4 <- EDMsimulate::salmon_sim(h_t = h_simulated)
mve_args_manual = list(lags = list(R_t = 0:1, S_t = 0:3))
R_switch_manual <- "R_t"
fit_mve_manual <- do.call(pbsEDM::multiview_embedding,
                     c(list(data = simulated_4,
                            response = R_switch_manual),
                       mve_args_manual))

Think it's therefore to do with the all_sims argument in fit_models.

andrew-edwards commented 12 months ago

But this did not run okay [does now, see next comment], with constant (default) h_t (which is what my default is using in sim_and_fit_realisations():

set.seed(42)
simulated_5 <- EDMsimulate::salmon_sim()  # Back to default h_t, not noisy,
                                        # to see if that's an issue. Shouldn't be but it is.
mve_args_manual = list(lags = list(R_t = 0:1, S_t = 0:3))
R_switch_manual <- "R_t"
fit_mve_manual_5 <- do.call(pbsEDM::multiview_embedding,
                     c(list(data = simulated_5,
                            response = R_switch_manual),
                       mve_args_manual))

Think it is to do with R_t and S_t being highly correlated when h_t is constant, and if that happens I'd put in something to not test those lags, which I think is causing the issue. Looking into it...

andrew-edwards commented 12 months ago

Above commit 093372a in pbsEDM ensures the code chunk above now runs.

Last commit above (ef3d..) has some TODO's that need addressing.

andrew-edwards commented 12 months ago

This, based on Carrie's report, almost works:

out <- EDMsimulate::sim_and_fit_realisations(salmon_sim_args =
                                               list(sigma_nu = 1,
                                                    omega = 0.4),
                                             target_hr = 0.2,
                                             sigma_ou = 0.05,
                                             larkin_fit = TRUE,
                                             ricker_fit = TRUE,
                                             R_switch = "R_t",#"R_prime_t",#"R_t",#
                                             M = 2)

Pretty sure the parallel computations work. Note default run_stan = FALSE so not doing full stan.

andrew-edwards commented 12 months ago

Problem, I think, is that