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

predict, simulate and genFLQuant #143

Open
colinpmillar opened this issue Mar 19, 2025 · 2 comments
Open

predict, simulate and genFLQuant #143

colinpmillar opened this issue Mar 19, 2025 · 2 comments
Assignees

Comments

@colinpmillar
Copy link
Member

There are some nice things in the package that are not exported, also with some overlap. Some effort could be put into reducing the code replication and simplifying the use interface.

example of hidden functionality, the function FLa4a:::predict.stkpars could be exported as a method on a4aStkParams class.

fit0 <- sca(ple4, ple4.index)
stk_submodel <- stkmodel(fit)

FLa4a:::predict.stkpars(stk_submodel)$ny1
An object of class "FLQuant"
, , unit = unique, season = all, area = unique

    year
age  1957
  1      NA
  2  277659
  3  510240
  4  807496
  5  946944
  6  738763
  7  369066
  8  122659
  9   30208
  10   6407
stk_submodel_sim <- simulate(stk_submodel, nsim = 100)
FLa4a:::predict.stkpars(stk_submodel_sim)$ny1
An object of class "FLQuant"
iters:  100

, , unit = unique, season = all, area = unique

    year
age  1957
  1      NA(    NA)
  2  277463(  8331)
  3  510797( 44575)
  4  811887(110382)
  5  964181(160899)
  6  742286(124788)
  7  360544( 74975)
  8  115474( 27940)
  9   27037(  9828)
  10   5529(  2749)

units:  1000
@colinpmillar colinpmillar self-assigned this Mar 19, 2025
@colinpmillar
Copy link
Member Author

Continuing this, the function genFLQuant has some similarities to predict.stkpars, and doing some code cleaning would make things more streamlined / cleaner

@colinpmillar
Copy link
Member Author

Further notes: genFLQuant, combines simulate and predict.

These three things provide the same result

res <- microbenchmark::microbenchmark(
  FLa4a:::predict.stkpars(simulate(stkmodel(fit0), nsim = 100, seed = 12342))$harvest[, "2017"],
  harvest(simulate(fit0, nsim = 100, seed = 12342))[, "2017"],
  genFLQuant(stkmodel(fit0), nsim = 100, seed = 12342, type = "response")$harvest[, "2017"], times <- 1000L
)

ggplot2::autoplot(res)

Image

But, i think genFLQuant returns also stock.n, and catch.n, as does simulate(fit). So perhaps makes sense. Anyway, would be good to clean this up a bit.

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