我有以下课程:
class Optimization_problem():
def __init__(self, **args):
if 'function' in args:
self.function = args['function']
if 'gradient' in args:
self.gradient = args['gradient']
else:
def deriv(x):
return nd.Gradient(self.function)(x)
self.gradient= deriv
if 'acc' in args:
self.acc = args['acc']
我想创建一个Optmization_method从上面的类继承属性的类,以便我可以执行以下操作:
f = lambda x: 100 * (x[1] - x[0] ** 2) ** 2 + (1 - x[0]) ** 2
problem = Optimization_problem(function=f, acc=1.e-3)
method = Optimization_method(problem) # I want to be able to do this
我已经尝试了以下但它不起作用。
class Optimization_method(Optimization_problem):
def __init__(self, **args):
Optimization_problem.__init__(self, **args)
#methods......
largeQ
相关分类