/usr/lib/python2.7/dist-packages/openopt/solvers/UkrOpt/ShorEllipsoid_oo.py is in python-openopt 0.38+svn1589-1.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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | if __name__ == '__main__':
import sys, os.path as pth
sys.path.insert(0,pth.split(pth.split(pth.split(pth.split(pth.realpath(pth.dirname(__file__)))[0])[0])[0])[0])
from openopt import NSP
from numpy import ones, arange
N = 4
p = NSP(lambda x: abs(x).sum(), ones([N,1]), maxFunEvals = 1e6, plot = False)
p.r0 = N
r = p.solve('ShorEllipsoid')
from numpy import diag, ones, inf, any, copy, sqrt
from openopt.kernel.baseSolver import baseSolver
class ShorEllipsoid(baseSolver):
__name__ = 'ShorEllipsoid'
__license__ = "BSD"
__authors__ = "Dmitrey"
__alg__ = "Naum Z. Shor modificated method of ellipsoids"
iterfcnConnected = True
#__optionalDataThatCanBeHandled__ = ['A', 'Aeq', 'b', 'beq', 'lb', 'ub', 'c', 'h']
def __init__(self): pass
def __solver__(self, p):
#if p.useScaling: p.err('ShorEllipsoid + scaling isn''t implemented yet')
n = p.n
B = diag(ones(n))
x0 = copy(p.x0)
########################
# Shor MME engine #
# //by Dmitrey Kroshko #
# //icq 275976670(inviz) #
########################
x = x0.copy()
xPrev = x0.copy()
xf = x0.copy()
xk = x0.copy()
p.xk = x0.copy()
if not hasattr(p, 'r0'): p.err('ShorEllipsoid solver requires r0')
r = p.r0
f = p.f(x)
fk = f
ff = f
p.fk = fk
g = p.df(x)
p._df = g
p.iterfcn()
if p.istop:
p.xf = x
p.ff = f
#r.advanced.ralg.hs = hs
return
multiplier_R = sqrt(1.+1./n**2)
beta = multiplier_R - 1. / n
alfa = 1. / beta
for k in range(p.maxIter):
BTG = p.matmult(B.T, g.reshape(-1,1))
dzeta_k = (BTG / p.norm(BTG))
hk = r*beta/n
x -= hk * p.matmult(B, dzeta_k).flatten()
B += p.matmult(B, p.matmult((1-alfa)*dzeta_k, dzeta_k.T))
r *= multiplier_R
f = p.f(x)
g = p.df(x)
xk = x.copy()
fk = f
if fk < ff:
ff, xf = fk, xk.copy()
p.fk = fk
p.xk = xk
p._df = g#CHECK ME! - MODIFIED!!
p.iterfcn()
if p.istop:
p.xf = xf
p.ff = ff
#p.advanced.ralg.hs = max(norm(xPrev - x), hsmin)
p._df = g
return
|