-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
[FR] Allow as_draws_dt for data.table #348
Comments
Would it make sense to have a backend option for draws_df that applies the draws_df class on top of a data frame? Or would the semantics of data table break something in that case... |
Sorry I'm not sure I understand. For reference I'd like to be able to call something like the below which currently errors # Run pathfinder
fit <- mod$pathfinder(data=data_list, seed=1234, refresh = 0)
# create a set of draws that is a `draws_dt` object.
path_draws_dt = init$draws(format = "dt")
path_draws_dt[, lw := lp__ - lp_approx__]
path_draws_dt[, pareto_weight := pareto_smooth(exp(lw - max(lw)), tail = "right")[["x"]]]
# This line not possible
path_draws_dt[, posterior_draws :=
weight_draws(.SD, weights = pareto_weight, log = FALSE)] I think to cast the data.table I'm using to a
|
Ah, sorry I wasn't clear. The current draws_df class is: class(as_draws_df(example_draws()))
## [1] "draws_df" "draws" "tbl_df" "tbl" "data.frame" i.e., it uses tibble as its base class. However, S3 is not like classical OOP in that there's no reason we cannot also create objects with a class of However, if that leads to a bunch of corner cases, then probably a separate If we went ahead with this I suspect we would only want data.table as a Suggests level dependency. Curious what @paul-buerkner thinks. |
I would not be opposed to it. After all, one core principle of posterior is that we allow and support different formats because that represents the reality of its users wanting to interact with their draws differently. Why not have a data.table kind format then. And if we can reuse code from draws_df that this is of course great too. |
Cool. I made a quick attempt at implementing this and quickly realized that if we want the format to allow data.table's specialized selection syntax with The upshot is there may not be much code-sharing with draws_df unless we put work into some refactoring, so it may take a bit of work to implement. |
In other words, we would just need another draws format to make this work? That would be okay for me :-) |
Yeah, exactly :). That comment was just a lament that the implementation will take more than a half hour of work, heh. |
I put the "quick" implementation on the This version doesn't allow data.table selection semantics, which we presumably want (else why the format). A starting point for such an implementation could be to change this value to Lines 1 to 4 in 80daa13
And then begin re-implementing stuff ;). I probably don't have the time to do that at the moment since I'd have to go and learn data.table semantics first. Maybe someone already familiar with data.table would be the right person? (@SteveBronder? ;) ) |
I'm working on a few things in cmdstanr right now but I think eventually I can find time for this |
My workflow is pretty data.table based. It would be nice to have a format like
draws_df
that uses the data.table backend.I think this would be semi copy-paste heavy wrt
draws_df
. Though it would let a few function that work over groups be a bit faster by using the data.table backend.imo I don't care much about performance though, I just like the data.table scheme for parsing data
The text was updated successfully, but these errors were encountered: