-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjectives.py
47 lines (32 loc) · 1.09 KB
/
objectives.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'''
This module contains the following:
Sparse Quadric
Max-k-sum-squared
SkewedQuartic
'''
import numpy as np
class SparseQuadric(object):
'''An implementation of the sparse quadric function.'''
def __init__(self, d, s):
self.s = s
self.dim = d
def __call__(self,x):
return np.dot(x[0:self.s],x[0:self.s])
class MaxK(object):
'''An implementation of the max-k-squared-sum function.'''
def __init__(self, d, s):
#self.dim = d
self.s = s
def __call__(self, x):
Max_IDX = np.abs(x).argsort()[-self.s:]
return np.dot(x[Max_IDX],x[Max_IDX])
class SkewedQuartic(object):
'''An implementation of the sparse quadric function.'''
def __init__(self, d, s):
self.dim = d
self.s = s
Diagonal = np.concatenate((np.ones(s),np.zeros(d-s)))
self.B = np.diag(Diagonal)
self.BB= np.dot(self.B.T, self.B)
def __call__(self, x):
return np.dot(np.dot(x.T,self.BB),x) + 0.1*np.sum(np.power(np.dot(self.B,x),3)) + 0.01*np.sum(np.power(np.dot(self.B,x),4))