Skip to content

Commit

Permalink
allow None bounds in constrain_coefs
Browse files Browse the repository at this point in the history
  • Loading branch information
lbluque committed May 4, 2022
1 parent 253f899 commit 69dcb4b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions sparselm/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np


def constrain_coefficients(indices, high, low=0.0):
def constrain_coefficients(indices, high=None, low=None):
"""Constrain a fit method to keep coefficients within a specified range.
Decorator to enforce that a fit method fitting a cluster expansion that
Expand All @@ -30,8 +30,14 @@ def your_fit_method(X, y):
"""

indices = np.array(indices)
high = high * np.ones(len(indices)) if isinstance(high, float) else np.array(high)
low = low * np.ones(len(indices)) if isinstance(low, float) else np.array(low)
if high is not None:
high = high * np.ones(len(indices)) if isinstance(high, float) else np.array(high)
else:
high = np.inf * np.ones(len(indices))
if low is not None:
low = low * np.ones(len(indices)) if isinstance(low, float) else np.array(low)
else:
low = -np.inf * np.ones(len(indices))

def decorate_fit_method(fit_method):
"""Decorate a fit method to constrain "dielectric constant".
Expand Down

0 comments on commit 69dcb4b

Please sign in to comment.