From 63489817bff2070179bd8b3b7ab3699af8c4b396 Mon Sep 17 00:00:00 2001 From: Michele Nottoli <michele.nottoli@gmail.com> Date: Mon, 4 Mar 2024 13:11:14 +0100 Subject: [PATCH] Converted diff coefficients to normal coefficients. --- gext/fitting.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/gext/fitting.py b/gext/fitting.py index 41fc250..dac86d6 100644 --- a/gext/fitting.py +++ b/gext/fitting.py @@ -76,22 +76,13 @@ class DiffFitting(AbstractFitting): if self.options["regularization"] > 0.0: a += np.identity(len(b))*self.options["regularization"] coefficients = np.linalg.solve(a, b) - return np.array(coefficients, dtype=np.float64) - def linear_combination(self, vectors: List[np.ndarray], - coefficients: np. ndarray) -> np.ndarray: - """Given a set of vectors (or matrices) and the corresponding - coefficients, build their linear combination.""" - if len(vectors) == 1: - raise ValueError("DiffFitting does not work for one vector") - result = np.zeros(vectors[0].shape, dtype=np.float64) - diff_vectors = [] - for i in range(1,len(vectors)): - diff_vectors.append(vectors[i-1]-vectors[-1]) - for coeff, vector in zip(coefficients, diff_vectors): - result += vector*coeff - result=result+vectors[-1] - return result + # Convert diff coefficients to normal coefficients (like in + # least square fitting) + coefficients = np.concatenate((coefficients, [1.0 - np.sum(coefficients)])) + + return coefficients + class LeastSquare(AbstractFitting): @@ -158,6 +149,8 @@ class QuasiTimeReversible(AbstractFitting): a += np.identity(len(b))*self.options["regularization"] coefficients = np.linalg.solve(a, b) + # Convert quasi time reversible coefficients to normal + # coefficients (like in least square fitting) if q == 1: full_coefficients = np.concatenate(([-1.0], coefficients)) elif q%2 == 0: -- GitLab