probability icon indicating copy to clipboard operation
probability copied to clipboard

copy.deepcopy TransformedDistribution fails

Open pipme opened this issue 3 years ago • 3 comments

import tensorflow_probability as tfp
import copy

tfd =tfp.distributions
tfb = tfp.bijectors
log_normal = tfd.TransformedDistribution(
distribution=tfd.Normal(loc=0., scale=1.),
bijector=tfb.Exp(),
name='LogNormalTransformedDistribution')

copy.deepcopy(log_normal)

The above raises TypeError: missing a required argument: 'distribution'.

Versions: tensorflow-probability==0.17.0, tensorflow==2.9.1.

pipme avatar Sep 04 '22 13:09 pipme

can you use log_normal.copy()?

csuter avatar Sep 06 '22 15:09 csuter

actually, this isn't a deep copy. it will reuse the parameters passed to the log_normal constructor. maybe it will suffice for your use case, though.

csuter avatar Sep 06 '22 15:09 csuter

Hi, thanks. The log_normal is an attribute of a class instance that need to be deep copied. A workaround may be using log_normal.copy() and writing a custom deepcopy method.

But any chance we can directly make a deepcopy of a TransformedDistribution instance? In 0.15.0 I was able to do that.

pipme avatar Sep 06 '22 20:09 pipme