Skip to content

Commit 62b1e1f

Browse files
committed
ruff fixes hopefully passes the linter, but weird stuff going on in the broadcast documentation
1 parent ef345e7 commit 62b1e1f

File tree

8 files changed

+57
-55
lines changed

8 files changed

+57
-55
lines changed

bayesflow/adapters/transforms/as_set.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
class AsSet(ElementwiseTransform):
77
"""
8-
The `.as_set(["x", "y"])` transform indicates that both `x` and `y` are treated as sets.
9-
That is, their values will be treated as *exchangable* such that they will imply the same inference regardless of the values' order.
10-
This would be useful in a linear regression context where we can index the observations in arbitrary order and always get the same regression line.
8+
The `.as_set(["x", "y"])` transform indicates that both `x` and `y` are treated as sets.
9+
That is, their values will be treated as *exchangable* such that they will imply the same inference regardless of
10+
the values' order. This would be useful in a linear regression context where we can index the observations in
11+
arbitrary order and always get the same regression line.
12+
13+
Useage:
1114
12-
Useage:
13-
1415
adapter = (
1516
bf.Adapter()
1617
.as_set(["x", "y"])

bayesflow/adapters/transforms/concatenate.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212

1313
@serializable(package="bayesflow.adapters")
1414
class Concatenate(Transform):
15-
"""Concatenate multiple arrays into a new key. Used to specify how data variables should be treated by the network.
15+
"""Concatenate multiple arrays into a new key. Used to specify how data variables should be treated by the network.
1616
17-
Parameters:
17+
Parameters:
1818
keys: Input a list of strings, where the strings are the names of data variables.
19-
into: A string telling network how to use the variables named in keys.
19+
into: A string telling network how to use the variables named in keys.
2020
-options: "inference_variables", "summary_variables", "inference_conditions"
21-
axis: integer specifing along which axis to concatonate the keys. The last axis is used by default.
21+
axis: integer specifing along which axis to concatonate the keys. The last axis is used by default.
2222
23-
Example:
24-
Suppose you have a simulator that generates variables beta, sigma from priors and then observation variables "x" and "y".
25-
We can then use concatonate in the following way
23+
Example:
24+
Suppose you have a simulator that generates variables beta, sigma from priors and then observation
25+
variables "x" and "y". We can then use concatonate in the following way
2626
2727
adapter = (
2828
bf.Adapter()

bayesflow/adapters/transforms/constrain.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,34 @@
1616
@serializable(package="bayesflow.adapters")
1717
class Constrain(ElementwiseTransform):
1818
"""
19-
Constrains neural network predictions of a data variable to specificied bounds.
20-
21-
Parameters:
22-
String containing the name of the data variable to be transformed e.g. "sigma". See examples below.
19+
Constrains neural network predictions of a data variable to specificied bounds.
2320
24-
Named Parameters:
21+
Parameters:
22+
String containing the name of the data variable to be transformed e.g. "sigma". See examples below.
23+
24+
Named Parameters:
2525
lower: Lower bound for named data variable.
2626
upper: Upper bound for named data variable.
27-
method: Method by which to shrink the network predictions space to specified bounds. Choose from
27+
method: Method by which to shrink the network predictions space to specified bounds. Choose from
2828
- Double bounded methods: sigmoid, expit, (default = sigmoid)
2929
- Lower bound only methods: softplus, exp, (default = softplus)
3030
- Upper bound only methods: softplus, exp, (default = softplus)
31-
3231
3332
34-
Examples:
35-
Let sigma be the standard deviation of a normal distribution, then sigma should always be greater than zero.
3633
37-
Useage:
34+
Examples:
35+
Let sigma be the standard deviation of a normal distribution, then sigma should always be greater than zero.
36+
37+
Useage:
3838
adapter = (
3939
bf.Adapter()
4040
.constrain("sigma", lower=0)
4141
)
4242
43-
Suppose p is the parameter for a binomial distribution where p must be in [0,1] then we would constrain the neural network to estimate p in the following way
43+
Suppose p is the parameter for a binomial distribution where p must be in [0,1] then we would constrain the
44+
neural network to estimate p in the following way
4445
45-
Usage:
46+
Usage:
4647
adapter = (
4748
bf.Adapter()
4849
.constrain("p", lower=0, upper=1, method = "sigmoid")

bayesflow/adapters/transforms/convert_dtype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
@serializable(package="bayesflow.adapters")
1212
class ConvertDType(ElementwiseTransform):
1313
"""
14-
Default transform used to convert all floats from float64 to float32 to be in line with keras framework.
14+
Default transform used to convert all floats from float64 to float32 to be in line with keras framework.
1515
"""
16+
1617
def __init__(self, from_dtype: str, to_dtype: str):
1718
super().__init__()
1819

bayesflow/adapters/transforms/drop.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@
1111

1212
@serializable(package="bayesflow.adapters")
1313
class Drop(Transform):
14-
"""
15-
Transform to drop variables from further calculation.
14+
"""
15+
Transform to drop variables from further calculation.
16+
17+
Parameters:
18+
keys: list of strings, containing names of data variables that should be dropped
1619
17-
Parameters:
18-
keys: list of strings, containing names of data variables that should be dropped
19-
20-
Example:
20+
Example:
2121
2222
>>> import bayesflow as bf
23-
>>> a = [1,2,3,4]
24-
>>> b = [[1,2],[3,4]]
25-
>>> c = [[5,6,7,8]]
26-
>>> dat = dict(a=a,b=b,c=c)
23+
>>> a = [1, 2, 3, 4]
24+
>>> b = [[1, 2], [3, 4]]
25+
>>> c = [[5, 6, 7, 8]]
26+
>>> dat = dict(a=a, b=b, c=c)
2727
>>> dat
2828
{'a': [1, 2, 3, 4], 'b': [[1, 2], [3, 4]], 'c': [[5, 6, 7, 8]]}
29-
>>> drop = bf.adapters.transforms.Drop(("b","c"))
29+
>>> drop = bf.adapters.transforms.Drop(("b", "c"))
3030
>>> drop.forward(dat)
3131
{'a': [1, 2, 3, 4]}
3232
"""

bayesflow/adapters/transforms/elementwise_transform.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
@serializable(package="bayesflow.adapters")
66
class ElementwiseTransform:
7-
87
"""Base class on which other transforms are based"""
98

109
def __call__(self, data: np.ndarray, inverse: bool = False, **kwargs) -> np.ndarray:

bayesflow/adapters/transforms/keep.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,36 @@
1212
@serializable(package="bayesflow.adapters")
1313
class Keep(Transform):
1414
"""
15-
Name the data parameters that should be kept for futher calculation.
15+
Name the data parameters that should be kept for futher calculation.
1616
17-
Parameters:
17+
Parameters:
1818
19-
cls: tuple containing the names of kept data variables as strings.
19+
cls: tuple containing the names of kept data variables as strings.
2020
21-
Useage:
21+
Useage:
2222
2323
Two moons simulator generates data for priors alpha, r and theta as well as observation data x.
24-
We are interested only in theta and x, to keep only theta and x we should use the following;
24+
We are interested only in theta and x, to keep only theta and x we should use the following;
2525
2626
adapter = (
2727
bf.adapters.Adapter()
2828
29-
# drop data from unneeded priors alpha, and r
29+
# drop data from unneeded priors alpha, and r
3030
.keep(("theta", "x"))
3131
)
3232
33-
Example:
34-
>>> a = [1,2,3,4]
35-
>>> b = [[1,2],[3,4]]
36-
>>> c = [[5,6,7,8]]
37-
>>> dat = dict(a=a,b=b,c =c)
38-
# Here we want to only keep elements b and c
39-
>>> keeper = bf.adapters.transforms.Keep(("b","c"))
33+
Example:
34+
>>> a = [1, 2, 3, 4]
35+
>>> b = [[1, 2], [3, 4]]
36+
>>> c = [[5, 6, 7, 8]]
37+
>>> dat = dict(a=a, b=b, c=c)
38+
# Here we want to only keep elements b and c
39+
>>> keeper = bf.adapters.transforms.Keep(("b", "c"))
4040
>>> keeper.forward(dat)
4141
{'b': [[1, 2], [3, 4]], 'c': [[5, 6, 7, 8]]}
4242
4343
"""
44+
4445
def __init__(self, keys: Sequence[str]):
4546
self.keys = keys
4647

bayesflow/adapters/transforms/to_array.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@
1313
class ToArray(ElementwiseTransform):
1414
"""
1515
Checks provided data for any non-arrays and converts them to numpy arrays.
16-
This ensures all data is in a format suitable for training.
16+
This ensures all data is in a format suitable for training.
1717
18-
Example:
18+
Example:
1919
>>> ta = bf.adapters.transforms.ToArray()
20-
>>> a = [1,2,3,4]
20+
>>> a = [1, 2, 3, 4]
2121
>>> ta.forward(a)
2222
array([1, 2, 3, 4])
23-
>>> b = [[1,2],[3,4]]
23+
>>> b = [[1, 2], [3, 4]]
2424
>>> ta.forward(b)
2525
array([[1, 2],
2626
[3, 4]])
2727
"""
2828

29-
3029
def __init__(self):
3130
super().__init__()
3231
self.original_type = None

0 commit comments

Comments
 (0)