Cannot copy PointMass random variables

When I try to copy a PointMass random variable I get an Error:

import tensorflow as tf
import edward as ed

norm = ed.models.Normal(tf.zeros(1), tf.ones(1))
ed.copy(norm)

pm = ed.models.PointMass(tf.zeros(1))
ed.copy(pm)

TypeError: __init__() takes at least 2 arguments (4 given)

It seems that for RandomVariable that are directly derived from tensorflow distributions rv._args and rv._kwargs refer to the arguments needed for recreating them, while for PointMass rv._kwargs contains the arguments of super(PointMass, self).init in the constructor and the params argument needed for creating a copy is missing entirely.

Is there a reason why random_variables.py doesn’t use the copy() method which could then be easily implemented in PointMass and other classes that derive from RandomVariable?

Good catch. This relates to Github issue #610 and Confused by error message from inference.run() for LDA with KLqp. Looking into a fix now.

Is there a reason why random_variables.py doesn’t use the copy() method which could then be easily implemented in PointMass and other classes that derive from RandomVariable?

The copy() method in random variables only works for overwriting keyword arguments. However we’d like to overwrite both positional arguments and keyword arguments. This is because in order for inference to work properly, we require deep copies across all arguments to a random variable in ed.copy(). Maybe the copy() method in random variables could be improved to enable this.

1 Like

Fixed in a pull request (#658).

1 Like