-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathTwinPlane2.py
38 lines (33 loc) · 1.04 KB
/
TwinPlane2.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
#!/usr/bin/env python
import numpy as np
from numpy import linalg
from cvxopt import solvers,matrix
#__copyright__ = ""
#__license__ = "GPL"
# __version__ = "1.1"
# __maintainer__ = "Arnav Kansal"
# __email__ = "[email protected]"
# __status__ = "Production"
def Twin_plane_2(L,N,C2,Epsi2,regulz2):
NtN = np.dot(N.T,N)
# for regularization we add identity matrix with wt. before inversion
NtN = NtN + regulz2*(np.identity(NtN.shape[0]))
NtNLt = linalg.solve(NtN,L.T)
LtNtNLt = np.dot(L,NtNLt)
LtNtNLt = (LtNtNLt+(LtNtNLt.T))/2
m1 = L.shape[0]
e1 = -np.ones((m1,1))
solvers.options['show_progress'] = False
vlb = np.zeros((m1,1))
vub = C2*(np.ones((m1,1)))
# x<=vub
# x>=vlb -> -x<=-vlb
# cdx<=vcd
cd = np.vstack((np.identity(m1),-np.identity(m1)))
vcd = np.vstack((vub,-vlb))
gamma = solvers.qp(matrix(LtNtNLt,tc='d'),matrix(e1,tc='d'),matrix(cd,tc='d'),matrix(vcd,tc='d'))#,matrix(0.0,(1,m1)),matrix(0.0))#,None,matrix(x0))
gammasol = np.array(gamma['x'])
z = -np.dot(NtNLt,gammasol)
w2 = z[:len(z)-1]
b2 = z[len(z)-1]
return [w2,b2]