In [ ]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from pyunlocbox import functions, solvers
plt.rcParams['figure.figsize'] = (17, 5)
In [ ]:
f1 = functions.norm_l2(y=[4, 5, 6, 7])
f2 = functions.dummy()
solver = solvers.forward_backward()
ret = solvers.solve([f1, f2], [0., 0, 0, 0], solver, atol=1e-5)
ret['sol']
In [ ]:
plt.semilogy(np.array(ret['objective'])[:, 0], '.-');
In [ ]:
class myfunc(functions.func):
def __init__(self, myparam=1, **kwargs):
self.myparam = myparam
super(myfunc, self).__init__(**kwargs)
def _eval(self, x):
return 0 # Function evaluated at x.
def _grad(self, x):
return x # Gradient evaluated at x, if available.
def _prox(self, x, T):
return x # Proximal operator evaluated at x, if available.
In [ ]:
f = myfunc(myparam=2)
f.cap([0, 0])
Likewise, you can implement your owns solvers and acceleration schemes by sub-classing pyunlocbox.solvers.solver and pyunlocbox.acceleration.accel.
Try to follow one of our tutorials.
In [ ]:
# Your code here.
Or try anything that goes through your mind! Look at the reference guide to know more about the API.
In [ ]:
# Your code here.
If you miss a package, you can install it with:
In [ ]:
%pip install numpy