argmin-rs / argmin

Numerical optimization in pure Rust
http://argmin-rs.org
Apache License 2.0
972 stars 76 forks source link

Request to add Polars (dataframe) backend #351

Open humphreylee opened 1 year ago

humphreylee commented 1 year ago

Would it be possible to add Polars (dataframe) as backend? Thanks.

itrumper commented 1 year ago

Can you explain a bit more about what you mean by "backend"? Do you want to use the dataframes as your Param, Gradient, or Output types in the problem?

If so, you can always implement the trait bounds from the solver on those types, and argmin should happily optimize with them. I recently just learned about this capability (see discussion).

stefan-k commented 1 year ago

Would it be possible to add Polars (dataframe) as backend?

I haven't used Polars yet, therefore I can't really comment on this. This requires someone with Polars expertise.

If so, you can always implement the trait bounds from the solver on those types, and argmin should happily optimize with them.

That's true; however in that case you would be implementing a foreign trait on a foreign type which is prohibited by the orphan rule. To circumvent this limitation the newtype pattern is necessary. Note that this isn't really prohibiting, just a bit of an annoyance. Therefore ideally third-party backends should be supported in argmin-math, because then the traits aren't foreign.

humphreylee commented 1 year ago

Can you explain a bit more about what you mean by "backend"? Do you want to use the dataframes as your Param, Gradient, or Output types in the problem?

If so, you can always implement the trait bounds from the solver on those types, and argmin should happily optimize with them. I recently just learned about this capability (see discussion).

Probably "backend" is not the correct term. What I meant is can Polars support be added similar to ndarray or nalgebra? My data (CSV) is a mix of strings and numbers, which is happily handled in dataframe (in R or Julia). The data is not pure numbers. Instead of doing multiple conversion (CSV -> polars -> ndarray / nalgebra), would love to see argmin{} handle directly Polars data format. Just a suggestion.