我不知道如何设置BW2,以便在对数正态分布参数的MC模拟中获得负值,例如模拟负排放。示例:
from brightway2 import *
import numpy as np
mydb = Database('mydb')
mydb.write({
('mydb', 'Some activity'): {
'name': 'Some activity',
'unit': 'kWh',
'exchanges': [{
'input': ('mydb', 'Carbon dioxide'),
'amount': 20, # positive!
'unit': 'kg',
'type': 'biosphere',
'uncertainty type' : 2,
'loc' : np.log(20),
'scale' : 1.01
}]
},
('mydb', 'Carbon dioxide'): {'name': 'Carbon dioxide', 'unit': 'kg', 'type': 'biosphere'}
})
exc = list(mydb.get('Some activity').exchanges())[0]
exc.as_dict()
exc.random_sample(n=10)
这很管用。我得到:
Out[8]:
array([ 25.20415107, 17.48476344, 16.98842921, 3.79548038,
12.54165042, 27.93752377, 7.57070571, 43.22285015,
48.44984804, 13.83083672]) # everything fine
现在让我们假设我想要得到相同的值,但为负:array([ -25.20415107, -17.48476344, etc. ...
,因为我假设我的二氧化碳吸收量为-20千克二氧化碳。如果我写'amount': -20
,我会得到一个奇怪的结果:
Out[9]:
array([ 0.73060359, 36.69825867, 5.71416558, 10.78119397,
16.24447705, 2.96507057, 6.73564118, 19.24411117,
7.23110067, 126.42690714])
我知道对数正态分布不可能是负的,但我所期望的是,分布是基于‘loc’和‘scale’信息的正值计算出来的,然后根据‘amount’信息进行反转。这对于在负排放清单上执行MC是必要的。有什么线索吗?谢谢
有两个问题阻碍了预期的行为:
amount
字段中给出负值是不够的;RNG代码在stats_arrays库中,您必须将negative
字段设置为True
(see docs)。你知道吗brightway2-data
中有一个bug,在7e3341c和2.4.6版本中修复,它阻止了键negative
在exchange.uncertainty
中使用。你知道吗通常,从其他格式导入数据时,
negative
字段会自动设置,例如SimaPro CSV、Ecospold 1。此外,当数据库被处理为参数数组时,negative
字段也是来自amount field
的always set。这种情况下的区别是,您直接从stats_arrays
调用函数,而不是通过brightway2-calc
。你知道吗在最新安装中添加
negative
字段:产生预期行为:
相关问题 更多 >
编程相关推荐