diff --git a/doc/sampling.rst b/doc/sampling.rst index 3914c4a..85b2aaf 100644 --- a/doc/sampling.rst +++ b/doc/sampling.rst @@ -50,3 +50,9 @@ Base classes .. autoclass:: sparse_ir.sampling.DecomposedMatrix :members: + +.. autoclass:: sparse_ir.sampling.SplitDecomposedMatrix + :members: + +.. autoclass:: sparse_ir.sampling.ConditioningWarning + :members: diff --git a/src/sparse_ir/sampling.py b/src/sparse_ir/sampling.py index e1fd569..fac169a 100644 --- a/src/sparse_ir/sampling.py +++ b/src/sparse_ir/sampling.py @@ -26,7 +26,12 @@ def evaluate(self, al, axis=None): def fit(self, ax, axis=None): """Fit basis coefficients from the sparse sampling points""" - return self.matrix.lstsq(ax, axis) + matrix = self.matrix + if self.basis.is_well_conditioned and not (matrix.cond <= 1e8): + warn(f"Sampling matrix is poorly conditioned " + f"(kappa = {matrix.cond:.2g})", ConditioningWarning) + + return matrix.lstsq(ax, axis) @property def cond(self): @@ -68,9 +73,6 @@ def __init__(self, basis, sampling_points=None): self._sampling_points = sampling_points self._matrix = DecomposedMatrix(matrix) - if basis.is_well_conditioned and self._matrix.cond > 1e8: - warn(f"Sampling matrix is poorly conditioned " - f"(kappa = {self._matrix.cond:.2g})", ConditioningWarning) @property def basis(self): return self._basis @@ -125,10 +127,6 @@ def __init__(self, basis, sampling_points=None, *, positive_only=False): else: self._matrix = DecomposedMatrix(matrix) - if basis.is_well_conditioned and self._matrix.cond > 1e8: - warn(f"Sampling matrix is poorly conditioned " - f"(kappa = {self._matrix.cond:.2g})", ConditioningWarning) - @property def basis(self): return self._basis @@ -314,6 +312,13 @@ def cond(self): class ConditioningWarning(RuntimeWarning): + """Warns about a poorly conditioned problem. + + This warning is issued if the library detects a poorly conditioned fitting + problem. This essentially means there is a high degree of ambiguity in how + to choose the solution. One must therefore expect to lose significant + precision in the parameter values. + """ pass