From b3ea4f5643d9f98a80cd77189cee71f7f8d0fa6b Mon Sep 17 00:00:00 2001 From: darcones Date: Mon, 16 Sep 2024 15:44:00 +0200 Subject: [PATCH] Undoing expansion definition. Modifying deepcopy --- docs/examples/bias.py | 12 ++++++------ probeye/inference/solver.py | 2 +- .../inference/bias/test_likelihood_models.py | 6 +++--- tests/unit_tests/inference/bias/test_solver.py | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/examples/bias.py b/docs/examples/bias.py index 26919c85..5e34c140 100644 --- a/docs/examples/bias.py +++ b/docs/examples/bias.py @@ -95,11 +95,7 @@ class LinearModel(ForwardModelBase): def __init__(self, name): super().__init__(name) self.pce_order = 1 - self.bias_dist = chaospy.Normal(0.0, 1.0) - - # generate the polynomial chaos expansion - self.expansion = chaospy.generate_expansion(self.pce_order, self.bias_dist) - + def interface(self): self.parameters = ["a", "b"] self.input_sensors = Sensor("x") @@ -116,6 +112,10 @@ def response(self, inp: dict) -> dict: # define the distribution for the bias term b_dist = chaospy.Normal(0.0, b) + + # generate the polynomial chaos expansion + expansion = chaospy.generate_expansion(self.pce_order, bias_dist) + # generate quadrature nodes and weights sparse_quads = chaospy.generate_quadrature( self.pce_order, b_dist, rule="Gaussian" @@ -127,7 +127,7 @@ def response(self, inp: dict) -> dict: # fit the polynomial chaos expansion fitted_sparse = chaospy.fit_quadrature( - self.expansion, sparse_quads[0], sparse_quads[1], sparse_evals + expansion, sparse_quads[0], sparse_quads[1], sparse_evals ) return {"y": fitted_sparse, "dist": b_dist} diff --git a/probeye/inference/solver.py b/probeye/inference/solver.py index e59bdd15..ab87a508 100644 --- a/probeye/inference/solver.py +++ b/probeye/inference/solver.py @@ -31,7 +31,7 @@ def __init__( ): # attributes from arguments - self.problem = cp.deepcopy(problem) + self.problem = cp.copy(problem) self.show_progress = show_progress self.seed = seed diff --git a/tests/unit_tests/inference/bias/test_likelihood_models.py b/tests/unit_tests/inference/bias/test_likelihood_models.py index 899d2d0a..fa4256ef 100644 --- a/tests/unit_tests/inference/bias/test_likelihood_models.py +++ b/tests/unit_tests/inference/bias/test_likelihood_models.py @@ -30,8 +30,6 @@ def __init__(self, name): super().__init__(name) self.pce_order = 1 - self.b_dist = chaospy.Normal(0.0, 1.0) - self.expansion = chaospy.generate_expansion(self.pce_order, self.b_dist) def interface(self): self.parameters = ["a", "b"] @@ -49,6 +47,8 @@ def response(self, inp: dict) -> dict: # define the distribution for the bias term b_dist = chaospy.Normal(0.0, b) + expansion = chaospy.generate_expansion(self.pce_order, b_dist) + # generate quadrature nodes and weights sparse_quads = chaospy.generate_quadrature( self.pce_order, b_dist, rule="Gaussian" @@ -59,7 +59,7 @@ def response(self, inp: dict) -> dict: ) # fit the polynomial chaos expansion fitted_sparse = chaospy.fit_quadrature( - self.expansion, sparse_quads[0], sparse_quads[1], sparse_evals + expansion, sparse_quads[0], sparse_quads[1], sparse_evals ) return {"y": fitted_sparse, "dist": b_dist} diff --git a/tests/unit_tests/inference/bias/test_solver.py b/tests/unit_tests/inference/bias/test_solver.py index 9ee21940..83e19430 100644 --- a/tests/unit_tests/inference/bias/test_solver.py +++ b/tests/unit_tests/inference/bias/test_solver.py @@ -26,8 +26,6 @@ def __init__(self, name): super().__init__(name) self.pce_order = 1 - self.b_dist = chaospy.Normal(0.0, 1.0) - self.expansion = chaospy.generate_expansion(self.pce_order, self.b_dist) def interface(self): self.parameters = ["a", "b"] @@ -45,6 +43,8 @@ def response(self, inp: dict) -> dict: # define the distribution for the bias term b_dist = chaospy.Normal(0.0, b) + expansion = chaospy.generate_expansion(self.pce_order, b_dist) + # generate quadrature nodes and weights sparse_quads = chaospy.generate_quadrature( self.pce_order, b_dist, rule="Gaussian" @@ -55,7 +55,7 @@ def response(self, inp: dict) -> dict: ) # fit the polynomial chaos expansion fitted_sparse = chaospy.fit_quadrature( - self.expansion, sparse_quads[0], sparse_quads[1], sparse_evals + expansion, sparse_quads[0], sparse_quads[1], sparse_evals ) return {"y": fitted_sparse, "dist": b_dist}