bat.utils.proj_lp
1import numpy as np 2 3def proj_lp(v, xi=0.1, p=2): 4 """ 5 Supports only p = 2 and p = Inf. 6 """ 7 if p == 2: 8 v = v * min(1, xi/np.linalg.norm(v.flatten('C'))) 9 # v = v / np.linalg.norm(v.flatten(1)) * xi 10 elif p == np.inf: 11 v = np.sign(v) * np.minimum(abs(v), xi) 12 else: 13 raise ValueError('Values of p different from 2 and Inf are currently not supported...') 14 15 return v
def
proj_lp(v, xi=0.1, p=2):
4def proj_lp(v, xi=0.1, p=2): 5 """ 6 Supports only p = 2 and p = Inf. 7 """ 8 if p == 2: 9 v = v * min(1, xi/np.linalg.norm(v.flatten('C'))) 10 # v = v / np.linalg.norm(v.flatten(1)) * xi 11 elif p == np.inf: 12 v = np.sign(v) * np.minimum(abs(v), xi) 13 else: 14 raise ValueError('Values of p different from 2 and Inf are currently not supported...') 15 16 return v
Supports only p = 2 and p = Inf.