/usr/share/pyshared/openopt/solvers/UkrOpt/PolytopProjection.py is in python-openopt 0.38+svn1589-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | from openopt import QP
from numpy import dot, asfarray, ones, zeros, max
from numpy.linalg import norm
def PolytopProjection(data, T = 1.0, isProduct = False, solver = None):
if solver is None:
solver = 'cvxopt_qp'
#data = float128(data)
if isProduct:
H = data
n = data.shape[0]
m = len(T)
else:
H = dot(data, data.T)
n, m = data.shape
#print H.shape
#print 'PolytopProjection: n=%d, m=%d, H.shape[0]= %d, H.shape[1]= %d ' %(n, m, H.shape[0], H.shape[1])
#T = abs(dot(H, ones(n)))
f = -asfarray(T) *ones(n)
p = QP(H, f, lb = zeros(n), iprint = -1, maxIter = 150)
xtol = 1e-6
if max(T) < 1e5*xtol: xtol = max(T)/1e5
r = p._solve(solver, ftol = 1e-16, xtol = xtol, maxIter = 10000)
sol = r.xf
if isProduct:
return r.xf
else:
s = dot(data.T, r.xf)
return s.flatten(), r.xf
|