bodkan / demografr

Fast and simple simulation-based population genetic inference in R
https://bodkan.net/demografr
Other
26 stars 1 forks source link

Add plot_specification preliminary #4

Open currocam opened 2 months ago

currocam commented 2 months ago

First iteration to try to solve #2

Description

I have implemented a first iteration of how that smart plotting function could look like (that I've named plot_specification). These are my thoughts:

  1. It would be nice to just rely on the AST to figure out proper values. However, I think that approach could grow in complexity very quickly. For example, users could specify split times as a function of other parameters. An intermediate approach could be to first rely on the AST to reduce the number of parameters to look at and brute force a valid combination of parameters.

That's what I do in this first preliminary version. First I identify Ne parameters and assign them an arbitrary value and then brute-force a valid combination of split times.

  1. The brute-forced valid combination of split times can look very ugly/uninformative when plotting it. One uninformative sequence of events would be [1, 2, 1e5, 1e10]. One option could be to shrink those values to [1, 2, 3, 4] for better visualization. I implemented that for the simplest case with no gene flow and forward direction.

  2. As you said, introducing the dummy values is annoying. However, I think it can be less annoying if, in the case the function fails, it prints the necessary snippet of code to manually edit. I implemented a preliminary version of that.

Sampling from priors

I think that a third option could be to request the user to introduce the list of priors. This would make it easier to implement the "brute-force" solution. Moreover, it could provide additional value as it could help checking whether the priors are misspecified. For example, if no valid combination was found after generating a reasonably high value of combinations by sampling from the priors, I think it is very likely that there is something odd with the priors. I've implemented a very simplistic version of that feature, such that combinations are obtained by sampling from the priors of the specified parameters.

bodkan commented 1 month ago

Awesome job, thanks so much!

I wrote a longer reply here, so I'm linking to that comment in case you didn't get a notification from there. As I said, I hope to take a dive into demografr soon after I finish some important (and rather complex/annoying) refactoring of slendr which will allow demografr to do its thing much easier. My hope is very much to finish demografr within the next few months, so the development should pick up the pace fairly soon.