Better __repr__ for scipy.stats distributions

I'm using various rv_continuous distributions as priors for a Bayesian analysis package I'm writing. Part of the GUI functionality is to produce code fragments from the GUI state to encourage scientific reproducibility. i.e. set up the analysis objects in a GUI, then output code that could be run from a script. I'm making a lot of use of __repr__ to produce text that can be used to build the objects. However, I'm stalled at recreating the scipy.stats distributions, and would like to propose that the __repr__ of these classes be improved to a point where the repr can be used to reproduce the distribution. e.g instead of:
from scipy.stats import norm print(repr(norm(0, 1))) <scipy.stats._distn_infrastructure.rv_frozen object at 0x1a17c8f898>
one would get: norm(0, 1) This would require that all the initialisation variables be accessible from the object (which I think was discussed recently if I remember rightly). Would others find this useful? Andrew. -- _____________________________________ Dr. Andrew Nelson _____________________________________

On Wed, 30 Jan 2019 07:54:17 +1100, Andrew Nelson wrote:
... would like to propose that the __repr__ of these classes be improved to a point where the repr can be used to reproduce the distribution.
e.g instead of:
from scipy.stats import norm print(repr(norm(0, 1))) <scipy.stats._distn_infrastructure.rv_frozen object at 0x1a17c8f898>
one would get: norm(0, 1)
That seems like a very reasonable request. `scikit-learn` does something similar: In [6]: br = linear_model.BayesianRidge() In [7]: br Out[7]: BayesianRidge(alpha_1=1e-06, alpha_2=1e-06, compute_score=False, copy_X=True, fit_intercept=True, lambda_1=1e-06, lambda_2=1e-06, n_iter=300, normalize=False, tol=0.001, verbose=False) The only concern I can see may be about the internal state of the RNG that keeps changing after values are generated. Stéfan
participants (2)
-
Andrew Nelson
-
Stefan van der Walt