Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement g3a_otherfood_table #203

Open
lentinj opened this issue Oct 30, 2024 · 0 comments
Open

Implement g3a_otherfood_table #203

lentinj opened this issue Oct 30, 2024 · 0 comments

Comments

@lentinj
Copy link
Collaborator

lentinj commented Oct 30, 2024

Pumping a table of abundance from a model into another is hard(tm):

st <- g3_stock("x", 1:19)

oth_table <- expand.grid(
    year = 1991:2020,
    step = 1:4,
    length = 1:19 )
oth_table$value <- floor(runif(nrow(oth_table), 1e3, 1e4))

lookup_array <- function(tbl_name, tbl) {
    tbl_arr <- g3_array_agg(gadget3:::g3_distribution_preview(oth_table))

    out <- gadget3:::call_to_formula(substitute(
        arr[,step = g3_idx(cur_step), year = g3_idx(cur_year - start_year + 1)],
        list(arr = as.symbol(tbl_name)) ), list())
    environment(out)[[tbl_name]] <- tbl_arr
    return(out)
}

actions <- list(
  g3a_time(2000, 2005, c(3,3,3,3)),
  g3a_otherfood(st, lookup_array("oth_abund", oth_table), force_lengthvector = FALSE ),
  NULL)
full_actions <- c(actions, list(
    g3a_report_detail(actions) ))
model_fn <- g3_to_r(full_actions)
model_cpp <- g3_to_tmb(full_actions)

attr(model_cpp, 'parameter_template') |>
    identity() -> params.in
nll <- model_fn(params.in) ; r <- attributes(nll) ; nll <- as.vector(nll)

print(r$detail_x__num)

gadget3:::ut_tmb_r_compare2(model_fn, model_cpp, params.in)

What would be nice is a g3a_otherfood_table(), which munges the input table into an array as we do with likelihood data, and then fills the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant