Skip to content
Snippets Groups Projects
Commit 8f37f70b authored by Askarpour, Zahra's avatar Askarpour, Zahra
Browse files

tangent point is one point before the last one

parent 8ef9b9b0
No related branches found
No related tags found
No related merge requests found
Pipeline #2062 failed
"""Main module containing the Extrapolator class.""" """module containing the Extrapolator class."""
from typing import Optional from typing import Optional
import numpy as np import numpy as np
...@@ -21,6 +21,7 @@ class Extrapolator: ...@@ -21,6 +21,7 @@ class Extrapolator:
"fitting": "diff", "fitting": "diff",
"allow_partially_filled": True, "allow_partially_filled": True,
"store_overlap": True, "store_overlap": True,
"tangent": "first",
} }
def __init__(self, nelectrons: int, nbasis: int, natoms: int, **kwargs): def __init__(self, nelectrons: int, nbasis: int, natoms: int, **kwargs):
...@@ -41,7 +42,9 @@ class Extrapolator: ...@@ -41,7 +42,9 @@ class Extrapolator:
if self.options["store_overlap"]: if self.options["store_overlap"]:
self.overlaps = CircularBuffer(self.options["nsteps"], self.overlaps = CircularBuffer(self.options["nsteps"],
(self.nbasis, self.nbasis)) (self.nbasis, self.nbasis))
if self.options["tangent"]=="one_before_last":
self.coeffs=CircularBuffer(self.options["nsteps"],
(self.nelectrons//2, self.nbasis))
self.tangent: Optional[np.ndarray] = None self.tangent: Optional[np.ndarray] = None
def set_options(self, **kwargs): def set_options(self, **kwargs):
...@@ -101,12 +104,17 @@ class Extrapolator: ...@@ -101,12 +104,17 @@ class Extrapolator:
coeff = self._normalize(coeff, overlap) coeff = self._normalize(coeff, overlap)
# if it is the first time we load data, set the tangent point # if it is the first time we load data, set the tangent point
if self.tangent is None: if self.tangent is None and self.options["tangent"] is not "one_before_last":
self._set_tangent(coeff) self._set_tangent(coeff)
# push the new data to the corresponding vectors # push the new data to the corresponding vectors
self.gammas.push(self._grassmann_log(coeff))
self.descriptors.push(self._compute_descriptor(coords)) self.descriptors.push(self._compute_descriptor(coords))
if self.options["tangent"]=="one_before_last":
cropped_coeff = self._crop_coeff(coeff)
self.coeffs.push(cropped_coeff)
else:
self.gammas.push(self._grassmann_log(coeff))
if self.options["store_overlap"]: if self.options["store_overlap"]:
self.overlaps.push(overlap) self.overlaps.push(overlap)
...@@ -141,9 +149,21 @@ class Extrapolator: ...@@ -141,9 +149,21 @@ class Extrapolator:
# use the fitting coefficients and the previous gammas to # use the fitting coefficients and the previous gammas to
# extrapolate a new gamma # extrapolate a new gamma
gammas = self.gammas.get(n)
if self.options["tangent"]=="one_before_last":
coeffs=self.coeffs.get(n)
self._set_tangent(coeffs[-1])
gammas=[]
for i in range(len(coeffs)):
gammas.append(self._grassmann_log(coeffs[i]))
print('maxgamma_last', np.max(gammas[-1]))
else:
gammas = self.gammas.get(n)
print('maxgamm', np.max(gammas[0]))
gamma = self.fitting_calculator.linear_combination(gammas, fit_coefficients) gamma = self.fitting_calculator.linear_combination(gammas, fit_coefficients)
if self.options["verbose"]: if self.options["verbose"]:
fit_descriptor = self.fitting_calculator.linear_combination( fit_descriptor = self.fitting_calculator.linear_combination(
prev_descriptors, fit_coefficients) prev_descriptors, fit_coefficients)
...@@ -179,10 +199,13 @@ class Extrapolator: ...@@ -179,10 +199,13 @@ class Extrapolator:
def _set_tangent(self, c: np.ndarray): def _set_tangent(self, c: np.ndarray):
"""Set the tangent point.""" """Set the tangent point."""
if self.tangent is None: if self.options["tangent"]="one_before_last"
self.tangent = c self.tangent = c
else: else:
raise ValueError("Resetting the tangent.") if self.tangent is None:
self.tangent = c
else:
raise ValueError("Resetting the tangent.")
def _grassmann_log(self, coeff: np.ndarray) -> np.ndarray: def _grassmann_log(self, coeff: np.ndarray) -> np.ndarray:
"""Map from the manifold to the tangent plane.""" """Map from the manifold to the tangent plane."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment