Можно scipy.optimize найти оптимальные входные значения, когда несколько продуктов Задействованы?
Вот что я попробовал, предполагая, что существует всего два продукта (на самом деле у меня несколько тысяч таких продуктов):
Код: Выделить всё
import numpy as np
import scipy
from scipy.optimize import minimize
Код: Выделить всё
Product1_InputB = np.array([0.5])
Product1_InputC = np.array([1])
Product1_InputD = np.array([1])
Product1_InputE = np.array([0.08])
Product1_InputF = np.array([20])
Product2_InputB = np.array([0.5])
Product2_InputC = np.array([1])
Product2_InputD = np.array([2])
Product2_InputE = np.array([0.1])
Product2_InputF = np.array([30])
Код: Выделить всё
def Neg_Product1_Output(Product1_InputA):
return -1 * ((2.71828**((Product1_InputA-Product1_InputB)*(0.5*Product1_InputC-1.5*Product1_InputD)))/(1+(2.71828**((Product1_InputA-Product1_InputB)*(0.5*Product1_InputC-1.5*Product1_InputD))))*(Product1_InputA-Product1_InputB))
def Neg_Product2_Output(Product2_InputA):
return -1 * ((2.71828**((Product2_InputA-Product2_InputB)*(0.5*Product2_InputC-1.5*Product2_InputD)))/(1+(2.71828**((Product2_InputA-Product2_InputB)*(0.5*Product2_InputC-1.5*Product2_InputD))))*(Product2_InputA-Product2_InputB))
def Neg_Total_Output(Product1_InputA,Product2_InputA):
return Neg_Product1_Output + Neg_Product2_Output
Код: Выделить всё
def constraint(Product1_InputA, Product2_InputA):
return (((Product1_InputA - Product1_InputE) * Neg_Product1_Output) + ((Product2_InputA - Product2_InputE) * Neg_Product2_Output)) / Neg_Total_Output - 2
con = {'type':'ineq', 'fun': constraint}
Product1_InputA_Initial_Guess = np.array([3])
Product1_InputA_Initial_Guess = np.asarray([3])
Product2_InputA_Initial_Guess = np.array([1])
Product2_InputA_Initial_Guess = np.asarray([1])
Product1_bound = [(0.3,4)]
Product2_bound = [(0.3,4)]
Код: Выделить всё
optimized_results = minimize(Neg_Total_Output,Product1_InputA_Initial_Guess,bounds=Product1_bound,constraints=con)
Код: Выделить всё
Product1_InputA_Optimal = optimized_results.x
Product1_InputA_Optimal
Код: Выделить всё
TypeError: constraint() missing 1 required positional argument: 'Product2_InputA'
Подробнее здесь: https://stackoverflow.com/questions/785 ... e-involved