我正在尝试校准一个模型,该模型包含12个未知参数,但只有5个参数作为输入。我正在为它构建一个类,例如:
class model:
def __init__(self,input_1,input_2,input_3,...):
self.input_1=input_1
self.input_2=input_2
self.input_3=input_3
.
.
. #Only inputs here, no pmts
Then I've defined the functions as:
def integral(self, input_1, pmt1, pm2, pm3.... )
integral,err= quad(f(input,pmt1,pmt2,pmt3)) #I'm simplifying here, the function is longer
return integral
def model_price(self,input_1,input_2,input_3):
price = pm3 + self.integral(self)/input_3
return price
def loss_function(self):
err = (self.input_1 - self.model_price)
pen = 0
return err + pen
def minimization(self,x0,bnds):
params = {"pm1": {"x0": 0.0746, "lbub": [1e-4,4.9]}, #1
"pmt2": {"x0": 0.3369, "lbub": [1e-4,4]}, #2
"pm3": {"x0": 0.3369, "lbub": [1e-4,4]}, #3
....
}
x0 = [param["x0"] for key, param in params.items()]
bnds = [param["lbub"] for key, param in params.items()]
results =minimize(self.loss_function(), x0, tol = 1e-3, method='SLSQP', options={'maxiter': 1e3 }, bounds=bnds)
return results
当我尝试使用但不起作用时,我尝试在函数外部传递x0和bounds。我总是得到:
TypeError: integral() missing 12 required positional arguments: 'pmt1, pmt2, pmt3,
1条答案
按热度按时间kdfy810k1#
错误消息非常清楚,您正在尝试使用单个参数调用方法
integral
,而您需要传递12个参数。因此,您需要
self.integral(arg1, … , arg12)
而不是self.integral(self)