这可能是一个初学者类型的问题:
我正在尝试使用 Beta-PERT 分布和 ecoinvent 3.10(截止)在 Brightway 2.5 中运行蒙特卡罗分析。然而,即使只运行 100 次迭代也需要很长时间。例如,只有 10 次迭代需要 7 分钟,而我的目标是运行 10,000 次迭代。我能够查明问题所在:只要 my_mc.lci() 在 for 循环内,由于库存的重复重新计算,该过程会显着减慢。然而,一旦我从 for 循环中删除 my_mc.lci(),我每次迭代都会得到相同的分数。我已经尝试了几乎所有可以在网上找到的解决方案,但似乎没有任何效果。有人有什么建议吗?多谢! (我在 Anaconda 中使用 Jupyter Notebook,Python v3.12.7)
#Presetting:
act2 = [x for x in eco_edit if 'carbon black production' in x ['name']
] [0]
heat_exchange= list(act2.technosphere()) [1]
act2.heat_exchange = heat_exchange
#Set up beta-pert distribution since it is not available in stats_arrays
def beta_pert_random(min_val, mode_val, max_val, size=1):
alpha = 1 + 4 * (mode_val - min_val) / (max_val - min_val)
beta_param = 1 + 4 * (max_val - mode_val) / (max_val - min_val)
return beta.rvs(alpha, beta_param, loc=min_val, scale=max_val - min_val, size=size)
#Defining Pert-parameters
min_heat = 0.1 # MJ
mode_heat = 1.5 # MJ (default)
max_heat = 10 # MJ
size = 1
demand = {act2.id: 1}
list_of_methods= [AF, CC, EP, ...]
CC_method = list_of_methods [1] #Climate change
#Set up characterization matrix which is calculated once
def get_C_matrix(demand, list_of_methods):
C_matrix = {}
sacrificial_LCA = bc.LCA(demand)
sacrificial_LCA.lci()
CC_method = list_of_methods[1]
sacrificial_LCA.switch_method(CC_method)
C_matrix[CC_method] = sacrificial_LCA.characterization_matrix
return C_matrix
#Monte Carlo Simulation:
my_iterations = 100
mc_scores = np.empty(shape=[my_iterations])
my_C_matrix = get_C_matrix(demand, list_of_methods)[CC_method]
for iteration in range(my_iterations):
random_heat = beta_pert_random(min_heat, mode_heat, max_heat, size)
heat_exchange['amount'] = random_heat [0]
heat_exchange.save()
my_mc = bc.LCA(demand, method=CC_method)
my_mc.lci()
my_mc.lcia()
next(my_mc)
mc_scores[iteration] = (my_C_matrix * my_mc.inventory).sum()
results = mc_scores.tolist()