Skip to content

Commit 0c08eb4

Browse files
committed
Merge branch 'main' of github.com:JonasTurnwald/fredipy
2 parents 96ba16f + d950a43 commit 0c08eb4

9 files changed

Lines changed: 37 additions & 37 deletions

examples/basic_breit_wigner.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"data = {\n",
8484
" 'x': p,\n",
8585
" 'y': G_err,\n",
86-
" 'dy': err**2}"
86+
" 'cov_y': err**2}"
8787
]
8888
},
8989
{
@@ -327,7 +327,7 @@
327327
"obs_direct = {\n",
328328
" 'x': w_direct,\n",
329329
" 'y': rho_direct,\n",
330-
" 'dy': 0.1**2}"
330+
" 'cov_y': 0.1**2}"
331331
]
332332
},
333333
{
@@ -420,7 +420,7 @@
420420
"obs_deriv = {\n",
421421
" 'x': w_deriv,\n",
422422
" 'y': rho_deriv,\n",
423-
" 'dy': 0.1**2}"
423+
" 'cov_y': 0.1**2}"
424424
]
425425
},
426426
{
@@ -622,7 +622,7 @@
622622
"data2d = {\n",
623623
" 'x': p_data,\n",
624624
" 'y': G + err * np.random.randn(len(G)),\n",
625-
" 'dy': err**2}"
625+
" 'cov_y': err**2}"
626626
]
627627
},
628628
{

examples/gaussian_mixture_model.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
"data = {\n",
115115
" 'x': matsubara_mesh,\n",
116116
" 'y': noised_eucl,\n",
117-
" 'dy': noise_amplitude**2 }"
117+
" 'cov_y': noise_amplitude**2 }"
118118
]
119119
},
120120
{

fredipy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
__all__ = ["models", "constraints", "operators", "integrators", "util", "kernels"]
1010

11-
__version__ = "0.1.0"
11+
__version__ = "0.2.0"

fredipy/constraints.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ def __init__(
2929
----------
3030
op : operator that acts on the GP, see Operator module.
3131
data : data dictionary or List or np.ndarray. \
32-
If input is List Dictionary needs position 'x' and value 'y' entries and optionally some error 'dy'. \
33-
If input is List or np.ndarray needs [**x**, **y**, **dy**] entries, where dy is optional.
32+
If input is List Dictionary, needs position 'x' and value 'y' entries and optionally some error 'cov_y'. \
33+
If input is List or np.ndarray, needs [**x**, **y**, **cov_y**] entries, where cov_y is optional.
3434
x : position of the data, List or np.ndarray or number.
3535
y : value of the data, List or np.ndarray or number, must have the same length as x.
36-
dy : error of the data, List or np.ndarray or number or None.
36+
cov_y : covariance of the data, List or np.ndarray or number or None.
3737
"""
3838
self.op = op
3939

4040
if isinstance(data, dict):
4141
x, y = make_column_vector(data['x']), make_column_vector(data['y'])
42-
dy = np.array(data['dy'] if 'dy' in data else 0.)
42+
cov_y = np.array(data['cov_y'] if 'cov_y' in data else 0.)
4343

4444
if isinstance(data, list) or isinstance(data, np.ndarray):
4545
x, y = make_column_vector(data[0]), make_column_vector(data[1])
46-
dy = np.array(data[2] if len(data) > 2 else 0.)
46+
cov_y = np.array(data[2] if len(data) > 2 else 0.)
4747

4848
len_y = y.shape[0]
4949
assert x.shape[0] == len_y, \
5050
f'Length of x/y must match, have {x.shape[0], len(y)}.'
5151

52-
assert (dy.shape == (len_y, len_y) or dy.shape == (len_y,) or dy.shape == (len_y, 1) or
53-
dy.shape == (1, len_y) or dy.shape == (1,) or dy.shape == ()), \
54-
f'Error matrix must be a matrix of shape (len(y), len(y)), a vector with len(y) or a number, \
55-
have {dy.shape} with y having length {len_y}.'
52+
assert (cov_y.shape == (len_y, len_y) or cov_y.shape == (len_y,) or cov_y.shape == (len_y, 1) or
53+
cov_y.shape == (1, len_y) or cov_y.shape == (1,) or cov_y.shape == ()), \
54+
f'Covariance must be a matrix of shape (len(y), len(y)), a vector with len(y) or a number, \
55+
have {cov_y.shape} with y having length {len_y}.'
5656

57-
if not dy.shape == (len(y), len(y)):
58-
dy = dy * np.eye(len(y))
57+
if not cov_y.shape == (len(y), len(y)):
58+
cov_y = cov_y * np.eye(len(y))
5959

60-
self.x, self.y, self.dy = x, y, dy
60+
self.x, self.y, self.cov_y = x, y, cov_y
6161
self._op = None
6262
self._args: Tuple = tuple()
6363
self._x = None

fredipy/integrators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(
9797
) -> None:
9898

9999
self.w = make_column_vector(np.linspace(w_min, w_max, int_n+1))
100-
self.dw = self.w[1] - self.w[0]
100+
self.dw = (self.w[1] - self.w[0]).item()
101101
self.w = self.w[:-1] + 0.5 * self.dw # midpoint rule
102102

103103
def doubleIntegrationSymmetric(
@@ -116,7 +116,7 @@ def doubleIntegrationSymmetric(
116116
constraint(make_row_vector(self.w), x=make_column_vector(np.array([p[i, 0]])))
117117
@ kernel(np.c_[self.w, p[i, 1:] * ones_w], np.c_[self.w, p[j, 1:] * ones_w])
118118
@ constraint(make_column_vector(self.w), x=make_row_vector(np.array([p[j, 0]])))
119-
)
119+
).item()
120120

121121
return tmp + tmp.T - np.diag(tmp.diagonal())
122122

@@ -258,7 +258,7 @@ def __init__(
258258
if int_n % 2 == 0:
259259
int_n = int_n + 1
260260
self.w = make_column_vector(np.linspace(w_min, w_max, int_n))
261-
self.dw = self.w[1] - self.w[0]
261+
self.dw = (self.w[1] - self.w[0]).item()
262262
# construct array of alternating prefactors
263263
self.prefactors = np.empty_like(self.w)
264264
self.prefactors[::2] = 2
@@ -286,7 +286,7 @@ def doubleIntegrationSymmetric(
286286
@ kernel(np.c_[self.w, p[i, 1:] * ones_w], np.c_[self.w, p[j, 1:] * ones_w])
287287
@ (self.prefactors
288288
* constraint(make_row_vector(self.w), x=make_column_vector(np.array([p[j, 0]])))).T
289-
)
289+
).item()
290290

291291
return tmp + tmp.T - np.diag(tmp.diagonal())
292292

fredipy/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def __init__(
5353
self.OpKer = OpKer
5454

5555
self.y = np.concatenate([c.y for c in self.constraints])
56-
self.dy = sp.linalg.block_diag(*[c.dy for c in self.constraints])
56+
self.cov_y = sp.linalg.block_diag(*[c.cov_y for c in self.constraints])
5757

5858
# for caching intermediate results
5959
self._posterior_cache: Dict[str, np.ndarray] = {}
@@ -203,7 +203,7 @@ def _maybe_prepare_posterior(self) -> None:
203203
OpKerOp = self.OpKerOp(
204204
self.kernel, self.constraints)
205205
OpKerOp_cholesky = np.linalg.cholesky(
206-
OpKerOp + self.dy)
206+
OpKerOp + self.cov_y)
207207
alpha = sp.linalg.solve_triangular(
208208
OpKerOp_cholesky.T,
209209
sp.linalg.solve_triangular(

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
66
name = "fredipy"
77
authors = [
88
{name = "Jonas Turnwald", email = "jonas.turnwald@tu-darmstadt.de"},
9-
{name = "Julian M. Urban", email = "tbd@tbd.com"}, # DO EMAILS!
9+
{name = "Julian M. Urban", email = "jurban@mit.edu"}, # DO EMAILS!
1010
{name = "Nicolas Wink", email = "tbd@tbd.com"}
1111
]
1212
classifiers = [
@@ -41,4 +41,4 @@ include = ["fredipy"]
4141
exclude = ["tests*", "docs", "examples", "archive"]
4242

4343
[tool.setuptools.dynamic]
44-
version = {attr = "fredipy.__version__"}
44+
version = {attr = "fredipy.__version__"}

tests/test_data_input.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_single_datapoint_integrator(x: Any) -> None:
5151
data = {
5252
'x': x,
5353
'y': x,
54-
'dy': 0.1}
54+
'cov_y': 0.1}
5555

5656
kernel = fp.kernels.RadialBasisFunction(0.5, 0.3)
5757

@@ -83,7 +83,7 @@ def test_single_datapoint_identity(x: Any) -> None:
8383
data = {
8484
'x': x,
8585
'y': x,
86-
'dy': 0.1}
86+
'cov_y': 0.1}
8787

8888
kernel = fp.kernels.RadialBasisFunction(0.5, 0.3)
8989
constraints = [fp.constraints.LinearEquality(fp.operators.Identity(), data)]
@@ -96,21 +96,21 @@ def test_single_datapoint_identity(x: Any) -> None:
9696
assert len(_rho) == 1
9797

9898

99-
@pytest.mark.parametrize("dy", [
100-
rng.rand(3, 3),
99+
@pytest.mark.parametrize("cov_y", [
100+
rng.rand(3, 3) + 0.1 * np.eye(3),
101101
[0.1, 0.2, 0.3],
102102
0.1,
103103
np.array([0.1, 0.2, 0.3]),
104104
np.array([0.1, 0.2, 0.3]).reshape(-1, 1),
105105
np.array([0.1, 0.2, 0.3]).reshape(1, -1)
106106
])
107-
def test_multiple_dy_inputs(dy: Any) -> None:
107+
def test_multiple_cov_y_inputs(cov_y: Any) -> None:
108108
x = np.array([1, 2, 3])
109109
y = np.array([1, 2, 3])
110110
data = {
111111
'x': x,
112112
'y': y,
113-
'dy': dy
113+
'cov_y': cov_y
114114
}
115115

116116
kernel = fp.kernels.RadialBasisFunction(0.5, 0.3)
@@ -122,7 +122,7 @@ def test_multiple_dy_inputs(dy: Any) -> None:
122122

123123

124124
@pytest.mark.parametrize("data_input", [
125-
{'x': [1, 2, 3], 'y': [1, 2, 3], 'dy': [0.1, 0.2, 0.3]},
125+
{'x': [1, 2, 3], 'y': [1, 2, 3], 'cov_y': [0.1, 0.2, 0.3]},
126126
[[1, 2, 3], [1, 2, 3], [0.1, 0.2, 0.3]],
127127
np.array([[1, 2, 3], [1, 2, 3], [0.1, 0.2, 0.3]])
128128
])

tests/test_reconstruction.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_reconstruction_BW_1d() -> None:
5252
data = {
5353
'x': p,
5454
'y': G + err * rng.randn(len(G)),
55-
'dy': err * np.ones_like(p)}
55+
'cov_y': err**2 * np.ones_like(p)}
5656

5757
# setting up the model
5858
kernel = fp.kernels.RadialBasisFunction(0.5, 0.3)
@@ -88,7 +88,7 @@ def test_reconstruction_BW_1d_uv_asymptotics() -> None:
8888
data = {
8989
'x': p,
9090
'y': G + err * rng.randn(len(G)),
91-
'dy': err * np.ones_like(p)}
91+
'cov_y': err**2 * np.ones_like(p)}
9292

9393
def uv_asymptotics(x): return 1 / x**3
9494

@@ -125,7 +125,7 @@ def test_standard_interpolation_1D() -> None:
125125
data = {
126126
'x': p,
127127
'y': G_data,
128-
'dy': err}
128+
'cov_y': err**2}
129129

130130
kernel = fp.kernels.RadialBasisFunction(3., 0.4)
131131
identity_op = fp.operators.Identity()
@@ -152,7 +152,7 @@ def test_dressing_1D() -> None:
152152
data = {
153153
'x': p,
154154
'y': G_data,
155-
'dy': err * np.ones_like(p)}
155+
'cov_y': err**2 * np.ones_like(p)}
156156

157157
# setting up the model
158158
kernel = fp.kernels.RadialBasisFunction(0.3, 0.5)

0 commit comments

Comments
 (0)