Skip to content
Snippets Groups Projects
Commit 63489817 authored by Michele Nottoli's avatar Michele Nottoli
Browse files

Converted diff coefficients to normal coefficients.

parent 8685c877
No related branches found
No related tags found
No related merge requests found
Pipeline #2065 failed
...@@ -76,22 +76,13 @@ class DiffFitting(AbstractFitting): ...@@ -76,22 +76,13 @@ class DiffFitting(AbstractFitting):
if self.options["regularization"] > 0.0: if self.options["regularization"] > 0.0:
a += np.identity(len(b))*self.options["regularization"] a += np.identity(len(b))*self.options["regularization"]
coefficients = np.linalg.solve(a, b) coefficients = np.linalg.solve(a, b)
return np.array(coefficients, dtype=np.float64)
def linear_combination(self, vectors: List[np.ndarray], # Convert diff coefficients to normal coefficients (like in
coefficients: np. ndarray) -> np.ndarray: # least square fitting)
"""Given a set of vectors (or matrices) and the corresponding coefficients = np.concatenate((coefficients, [1.0 - np.sum(coefficients)]))
coefficients, build their linear combination."""
if len(vectors) == 1: return coefficients
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
class LeastSquare(AbstractFitting): class LeastSquare(AbstractFitting):
...@@ -158,6 +149,8 @@ class QuasiTimeReversible(AbstractFitting): ...@@ -158,6 +149,8 @@ class QuasiTimeReversible(AbstractFitting):
a += np.identity(len(b))*self.options["regularization"] a += np.identity(len(b))*self.options["regularization"]
coefficients = np.linalg.solve(a, b) coefficients = np.linalg.solve(a, b)
# Convert quasi time reversible coefficients to normal
# coefficients (like in least square fitting)
if q == 1: if q == 1:
full_coefficients = np.concatenate(([-1.0], coefficients)) full_coefficients = np.concatenate(([-1.0], coefficients))
elif q%2 == 0: elif q%2 == 0:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment