From 596d65b15bad262f1d9096e88527961f81ff47e2 Mon Sep 17 00:00:00 2001 From: Timothy Smith Date: Fri, 20 Oct 2023 14:04:14 -0600 Subject: [PATCH] Rename bias -> bias_factor (#46) --- xesn/esn.py | 18 +++++++++--------- xesn/lazyesn.py | 8 ++++---- xesn/optim.py | 8 ++++---- xesn/test/config-eager.yaml | 4 ++-- xesn/test/config-lazy.yaml | 4 ++-- xesn/test/esn.py | 8 ++++---- xesn/test/lazy.py | 2 +- xesn/test/optim.py | 6 +++--- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/xesn/esn.py b/xesn/esn.py index 41420af..6c3bbdf 100644 --- a/xesn/esn.py +++ b/xesn/esn.py @@ -41,7 +41,7 @@ def adjacency_factor(self): return self.adjacency_kwargs["factor"] @property - def bias(self): + def bias_factor(self): return self.bias_kwargs["factor"] def __init__(self, @@ -50,10 +50,10 @@ def __init__(self, n_reservoir, input_factor, adjacency_factor, - connectedness, - bias, + bias_factor, leak_rate, tikhonov_parameter, + connectedness, input_kwargs=None, adjacency_kwargs=None, bias_kwargs=None): @@ -104,20 +104,20 @@ def __init__(self, # Handle bias vector options self.bias_kwargs = { "distribution" : "uniform", - "factor" : bias, + "factor" : bias_factor, "random_seed" : None } if bias_kwargs is not None: self.bias_kwargs.update(bias_kwargs) - if self.bias_kwargs["factor"] != bias: - raise ValueError(f"ESN.__init__: conflicting bias factor given with options 'bias' and 'bias_kwargs[''factor'']'") + if self.bias_kwargs["factor"] != bias_factor: + raise ValueError(f"ESN.__init__: conflicting bias factor given with options 'bias_factor' and 'bias_kwargs[''factor'']'") # Check inputs try: - assert self.bias >= 0.0 + assert self.bias_factor >= 0.0 except AssertionError: - raise ValueError(f"ESN.__init__: bias must be non-negative, got {self.bias}") + raise ValueError(f"ESN.__init__: bias_factor must be non-negative, got {self.bias_factor}") try: assert self.connectedness < self.n_reservoir @@ -138,7 +138,7 @@ def __str__(self): f' {"n_reservoir:":<24s}{self.n_reservoir}\n'+\ '--- \n'+\ f' {"connectedness:":<24s}{self.connectedness}\n'+\ - f' {"bias:":<24s}{self.bias}\n'+\ + f' {"bias_factor:":<24s}{self.bias_factor}\n'+\ f' {"leak_rate:":<24s}{self.leak_rate}\n'+\ f' {"tikhonov_parameter:":<24s}{self.tikhonov_parameter}\n'+\ '--- \n'+\ diff --git a/xesn/lazyesn.py b/xesn/lazyesn.py index f4c1eac..0b9386f 100644 --- a/xesn/lazyesn.py +++ b/xesn/lazyesn.py @@ -58,10 +58,10 @@ def __init__(self, n_reservoir, input_factor, adjacency_factor, - connectedness, - bias, + bias_factor, leak_rate, tikhonov_parameter, + connectedness, overlap, persist, boundary=xp.nan, @@ -98,10 +98,10 @@ def __init__(self, n_reservoir=n_reservoir, input_factor=input_factor, adjacency_factor=adjacency_factor, - connectedness=connectedness, - bias=bias, + bias_factor=bias_factor, leak_rate=leak_rate, tikhonov_parameter=tikhonov_parameter, + connectedness=connectedness, input_kwargs=input_kwargs, adjacency_kwargs=adjacency_kwargs, bias_kwargs=bias_kwargs) diff --git a/xesn/optim.py b/xesn/optim.py index acc6ed0..7182d96 100644 --- a/xesn/optim.py +++ b/xesn/optim.py @@ -52,12 +52,12 @@ def transform(params, transformations): transformed_params (dict): with updated parameters based on transformations, or untouched if not specified Example: - >>> params = {"input_factor": 0.5, "adjacency_factor": 0.5, "bias": 0.5} + >>> params = {"input_factor": 0.5, "adjacency_factor": 0.5, "bias_factor": 0.5} >>> transforms = {"input_factor": "log", "adjacency_factor": "log10"} >>> transform(params, transforms) {'input_factor': -0.6931471805599453, 'adjacency_factor': -0.3010299956639812, - 'bias': 0.5} + 'bias_factor': 0.5} """ transformed_params = params.copy() @@ -96,12 +96,12 @@ def inverse_transform(transformed_params, transformations): transformed_params (dict): with updated parameters based on transformations, or untouched if not specified Example: - >>> params = {"input_factor": -0.69, "adjacency_factor": -0.3, "bias": 0.5} + >>> params = {"input_factor": -0.69, "adjacency_factor": -0.3, "bias_factor": 0.5} >>> transforms = {"input_factor": "log", "adjacency_factor": "log10"} >>> inverse_transform(params, transforms) {'input_factor': 0.5015760690660556, 'adjacency_factor': 0.5011872336272722, - 'bias': 0.5} + 'bias_factor': 0.5} """ params = transformed_params.copy() diff --git a/xesn/test/config-eager.yaml b/xesn/test/config-eager.yaml index 89d406b..2e4a742 100644 --- a/xesn/test/config-eager.yaml +++ b/xesn/test/config-eager.yaml @@ -35,7 +35,7 @@ esn: is_sparse : True random_seed : 1 # - bias : 0.5 + bias_factor : 0.5 bias_kwargs: distribution : uniform normalization : svd @@ -58,7 +58,7 @@ macro_training: parameters: input_factor : [1.e-2, 2.] adjacency_factor: [1.e-2, 2.] - bias : [0. , 2.] + bias_factor : [0. , 2.] transformations: input_factor : log10 adjacency_factor: log diff --git a/xesn/test/config-lazy.yaml b/xesn/test/config-lazy.yaml index 54b7c7c..14608a7 100644 --- a/xesn/test/config-lazy.yaml +++ b/xesn/test/config-lazy.yaml @@ -46,7 +46,7 @@ lazyesn: is_sparse : True random_seed : 1 # - bias : 0.5 + bias_factor : 0.5 bias_kwargs: distribution : uniform normalization : svd @@ -69,7 +69,7 @@ macro_training: parameters: input_factor : [1.e-2, 1e2] adjacency_factor: [1.e-2, 2.] - bias : [0. , 2.] + bias_factor : [0. , 2.] transformations: input_factor : log10 diff --git a/xesn/test/esn.py b/xesn/test/esn.py index d94ac8b..bfe71dd 100644 --- a/xesn/test/esn.py +++ b/xesn/test/esn.py @@ -14,7 +14,7 @@ class TestESN: n_reservoir = 100 n_train = 500 connectedness = 5 - bias = 0.1 + bias_factor = 0.1 leak_rate = 0.5 tikhonov_parameter = 1e-6 @@ -24,10 +24,10 @@ class TestESN: @property def kw(self): return {key: getattr(self, key) for key in [ - "n_input", "n_output", "n_reservoir", "connectedness", "bias", "leak_rate", "tikhonov_parameter", "input_factor", "adjacency_factor"]} + "n_input", "n_output", "n_reservoir", "connectedness", "bias_factor", "leak_rate", "tikhonov_parameter", "input_factor", "adjacency_factor"]} equal_list = ("n_input", "n_output", "n_reservoir") - close_list = ("input_factor", "adjacency_factor", "connectedness", "bias", "leak_rate", "tikhonov_parameter") + close_list = ("input_factor", "adjacency_factor", "connectedness", "bias_factor", "leak_rate", "tikhonov_parameter") class TestInit(TestESN): @@ -50,7 +50,7 @@ def test_basic(self): @pytest.mark.parametrize( "key, val, raises, error", [ - ("bias", -1., pytest.raises, ValueError), + ("bias_factor", -1., pytest.raises, ValueError), ("connectedness", 101, pytest.raises, ValueError), ("connectedness", 90, pytest.warns, RuntimeWarning), ], diff --git a/xesn/test/lazy.py b/xesn/test/lazy.py index 98fe394..230bace 100644 --- a/xesn/test/lazy.py +++ b/xesn/test/lazy.py @@ -21,7 +21,7 @@ class TestLazy(TestESN): overlap = {"x": 1, "time": 0} persist = True equal_list = ("overlap", "esn_chunks", "persist", "overlap", "n_reservoir", "boundary") - close_list = ("input_factor", "adjacency_factor", "connectedness", "bias", "leak_rate", "tikhonov_parameter") + close_list = ("input_factor", "adjacency_factor", "connectedness", "bias_factor", "leak_rate", "tikhonov_parameter") @property def kw(self): diff --git a/xesn/test/optim.py b/xesn/test/optim.py index f7073ac..9b03846 100644 --- a/xesn/test/optim.py +++ b/xesn/test/optim.py @@ -10,7 +10,7 @@ def transform_params(): params = { "input_factor" : 0.5, "adjacency_factor" : 0.5, - "bias" : 0.5} + "bias_factor" : 0.5} transforms ={ "input_factor" : "log10", @@ -38,7 +38,7 @@ def test_transform(transform_inputs, request): assert_allclose(np.array(ptest["input_factor"]), np.log10(np.array(params["input_factor"]))) assert_allclose(np.array(ptest["adjacency_factor"]), np.log(np.array(params["adjacency_factor"]))) - assert_allclose(np.array(ptest["bias"]), np.array(params["bias"])) + assert_allclose(np.array(ptest["bias_factor"]), np.array(params["bias_factor"])) @pytest.mark.parametrize( @@ -51,7 +51,7 @@ def test_inverse_transform(transform_inputs, request): assert_allclose(np.array(ptest["input_factor"]), 10.** np.array(params["input_factor"])) assert_allclose(np.array(ptest["adjacency_factor"]), np.exp(np.array(params["adjacency_factor"]))) - assert_allclose(np.array(ptest["bias"]), np.array(params["bias"])) + assert_allclose(np.array(ptest["bias_factor"]), np.array(params["bias_factor"])) @pytest.mark.parametrize( "transformer", (transform, inverse_transform)