gummy.create() with covariance matrix mutates input matrix
nluetts opened this issue · 2 comments
nluetts commented
Hi,
I noticed that gummy.create()
mutates its input covariance matrix.
This leads to unexpected behavior:
from metrolopy import gummy
import numpy as np
val = [1., 2.]
cov = np.array([[0.3, 0.1], [0.1, 0.2]])
print("cov before gummy creation:\n", cov)
print()
a, b = gummy.create(val, covariance_matrix=cov)
print("cov after gummy creation:\n", cov)
print()
print("a + b after first gummy creation ", a + b)
a, b = gummy.create(val, covariance_matrix=cov)
print("a + b after second gummy creation ", a + b)
cov before gummy creation:
[[0.3 0.1]
[0.1 0.2]]
cov after gummy creation:
[[1. 0.40824829]
[0.40824829 1. ]]
a + b after first gummy creation 3.00(84)
a + b after second gummy creation 3.0(17)
I think this line is the problem:
Line 381 in 2230edc
Is the mutation necessary?
A workaround is to pass a deepcopy of the covariance matrix.
hvparks commented
Good catch, the matrix should not be mutated. I will change this line to create a new matrix instead.
hvparks commented
Version 0.5.6 has now been released which fixes this bug.