# Cannot copy PointMass random variables

**URL:** <https://discourse.edwardlib.org/t/cannot-copy-pointmass-random-variables/145>\
**Category:** General\
**Created:** [May 24, 2017, 5:56pm UTC](https://discourse.edwardlib.org/t/cannot-copy-pointmass-random-variables/145 "2017-05-24T17:56:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkusSchmaus](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@MarkusSchmaus](https://discourse.edwardlib.org/u/MarkusSchmaus)\
**Post date:** [May 24, 2017, 5:56pm UTC](https://discourse.edwardlib.org/t/cannot-copy-pointmass-random-variables/145/1 "2017-05-24T17:56:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![dustin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/dustin/32/134_2.png) [@dustin](https://discourse.edwardlib.org/u/dustin)\
**Post date:** [May 29, 2017, 4:02am UTC](https://discourse.edwardlib.org/t/cannot-copy-pointmass-random-variables/145/2 "2017-05-29T04:02:01Z")

</div>

Good catch. This relates to [Github issue #610](https://github.com/blei-lab/edward/issues/610) and [Confused by error message from inference.run() for LDA with KLqp](https://discourse.edwardlib.org/t/confused-by-error-message-from-inference-run-for-lda-with-klqp/119). 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.

---

<div class="post-metadata">

**Author:** ![dustin](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/dustin/32/134_2.png) [@dustin](https://discourse.edwardlib.org/u/dustin)\
**Post date:** [May 29, 2017, 4:58am UTC](https://discourse.edwardlib.org/t/cannot-copy-pointmass-random-variables/145/3 "2017-05-29T04:58:08Z")

</div>

Fixed in a [pull request (#658)](https://github.com/blei-lab/edward/pull/658).
