Skip to content

Commit

Permalink
switched operators to be classes instead of functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Niru Maheswaranathan committed Sep 16, 2015
1 parent 1e3b7a9 commit 3f09f7b
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 266 deletions.
6 changes: 3 additions & 3 deletions proxalgs/core.py
Expand Up @@ -53,7 +53,7 @@ def __init__(self, objfun, **kwargs):
def __str__(self):
return "Optimizer object with %i objectives." % len(self.objectives)

def add_regularizer(self, proxfun, **kwargs):
def add_regularizer(self, proxfun, *args, **kwargs):
"""
Add a regularizer from the operators module to the list of objectives
Expand All @@ -72,14 +72,14 @@ def add_regularizer(self, proxfun, **kwargs):
# if proxfun is a string, grab the corresponding function from operators.py
if isinstance(proxfun, str):
try:
self.objectives.append(lambda theta, rho: getattr(operators, proxfun)(theta.copy(), float(rho), **kwargs))
self.objectives.append(getattr(operators, proxfun)(*args, **kwargs))

except AttributeError as e:
print(str(e) + '\n' + 'Could not find the function ' + proxfun + ' in the operators module!')

# if proxfun is a function, add it as its own proximal operator
elif hasattr(proxfun, '__call__'):
self.objectives.append(lambda theta, rho: proxfun(theta.copy(), float(rho)))
self.objectives.append(proxfun)

# type of proxfun must be a string or a function
else:
Expand Down

0 comments on commit 3f09f7b

Please sign in to comment.