/usr/share/pyshared/openopt/kernel/NLLSP.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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | from baseProblem import NonLinProblem
from numpy import sum, dot, asfarray
import NLP
class NLLSP(NonLinProblem):
_optionalData = ['lb', 'ub', 'A', 'Aeq', 'b', 'beq', 'c', 'h']
showGoal = False
goal = 'minimum'
probType = 'NLLSP'
allowedGoals = ['minimum', 'min']
isObjFunValueASingleNumber = False
expectedArgs = ['f', 'x0']
def __init__(self, *args, **kwargs):
NonLinProblem.__init__(self, *args, **kwargs)
def objFuncMultiple2Single(self, fv):
return (fv ** 2).sum()
def nllsp2nlp(self, solver, **solver_params):
ff = lambda x: sum(asfarray(self.f(x))**2)
p = NLP.NLP(ff, self.x0)
#p = NLP.NLP(FF, self.x0)
self.inspire(p, sameConstraints=True)
if self.userProvided.df:
p.df = lambda x: dot(2*asfarray(self.f(x)), asfarray(self.df(x,useSparse=False)))
p.f = ff
def nllsp_iterfcn(*args, **kwargs):
p.primalIterFcn(*args, **kwargs)
p.xk = self.xk
p.fk = p.f(p.xk)
p.rk = self.rk
# TODO: add nNaNs
if self.istop != 0:
p.istop = self.istop
elif p.istop != 0:
self.istop = p.istop
p.primalIterFcn, p.iterfcn = self.iterfcn, nllsp_iterfcn
self.iprint = -1
p.show = False
r = p.solve(solver, **solver_params)
#r.ff = ff(r.xf)
return r
|