当我尝试在目标表达式中使用math.log函数时,会弹出此错误。有人能帮我理解a如何添加我需要优化的公式吗
model_MPL+=samples*(math.log(beta_var)-beta_var*math.log(alfa_var))+suma
我试图复制Excel的解算器,以优化weibull分布的alpha和beta参数
data = np.array([509,660,386,753,811,613,848,725,315,872,487,512])
def func_aplicada(x):
return (beta_last -1)*math.log(x)-(x/alfa)**beta_last
alfa = 688.916073521629
beta_last = 3.979166666666667
suma=0
samples=data.shape[0]
for i in range(0,samples):
suma += func_aplicada(data[i])
print('Cantidad de muestras = ',samples, '/ sumaacum =',suma)
import pulp as pl
model_MPL = pl.LpProblem("MPL", pl.LpMaximize)
beta_var = pl.LpVariable("beta_var",beta_last*0.5 , beta_last*1.5)
alfa_var = pl.LpVariable("alfa_var", alfa*0.5, alfa*1.5)
model_MPL += alfa_var>=0.1
model_MPL += beta_var>=0.1
model_MPL += samples * (math.log(beta_var) - beta_var * math.log(alfa_var)) + suma
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-52-08c6614fb718> in <module>
22 model_MPL += beta_var>=0.1
23
---> 24 model_MPL += samples * (math.log(beta_var) - beta_var * math.log(alfa_var)) + suma
TypeError: must be real number, not LpVariable
我认为你需要在目标函数中使用lpSum
如错误所示
alpha_var
和beta_var
属于LpVariable
类型,但您需要有数值调用
alpha_var.value()
以获取LpVariable的值相关问题 更多 >
编程相关推荐