Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Brightway2蒙特卡罗模拟中的负对数正态结果_Python_Brightway - Fatal编程技术网

Python Brightway2蒙特卡罗模拟中的负对数正态结果

Python Brightway2蒙特卡罗模拟中的负对数正态结果,python,brightway,Python,Brightway,我不知道如何设置BW2,以便在对数正态分布参数的MC模拟中获得负值,例如模拟负排放。例如: from brightway2 import * import numpy as np mydb = Database('mydb') mydb.write({ ('mydb', 'Some activity'): { 'name': 'Some activity', 'unit': 'kWh', 'exchanges': [{

我不知道如何设置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
现在让我们假设我想要得到相同的值,但为负值:
数组([-25.20415107,-17.48476344,等等…
,因为我假设我的二氧化碳吸收量为-20千克。如果我写
“数量”:-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是必要的。有什么线索吗?谢谢预防预期行为的ems:

array([ -3.24683872,  -5.01873359, -31.54532003, -40.59523805,
       -54.00447092,  -6.11459063, -41.5250442 ,  -8.05295075,
       -31.46077832, -29.8769442 ])
  • 仅在
    金额
    字段中给出负值是不够的;RNG代码在库中,您必须将
    负值
    字段设置为
    ()
  • brightway2数据
    中存在一个错误,已在中修复并发布,该错误阻止键
    负数
    用于
    交换。不确定性
  • 通常,当从其他格式导入数据时,
    负值
    字段会自动设置,例如,此外,当数据库被处理为参数数组时,
    负值
    字段也来自
    金额字段
    。这种情况下的区别在于,您是从
    统计数组
    中调用函数直接,而不是通过
    brightway2 calc

    在最新安装上添加
    字段:

    from brightway2 import *
    import numpy as np
    projects.set_current("SO 45935773")
    bw2setup()
    
    mydb = Database('mydb')
    gwp = ('IPCC 2013', 'climate change', 'GWP 100a')
    co2 = get_activity(('biosphere3', '349b29d1-3e58-4c66-98b9-9d1a076efd2e'))
    
    mydb.write({
        ('mydb', 'Some activity'): {
            'name': 'Some activity',
            'unit': 'kWh',
            'exchanges': [{
                'input': co2.key,
                'amount': -20, # negative
                'negative': True,
                'unit': 'kg',
                'type': 'biosphere', 
                'uncertainty type' : 2,
                'loc' : np.log(20), 
                'scale' : 1.01 
            }]
        }
    })
    
    exc = list(mydb.get('Some activity').exchanges())[0]
    exc.random_sample(n=10)  
    
    产生预期的行为:

    array([ -3.24683872,  -5.01873359, -31.54532003, -40.59523805,
           -54.00447092,  -6.11459063, -41.5250442 ,  -8.05295075,
           -31.46077832, -29.8769442 ])
    

    非常好,感谢您的帮助和信息。在您的答案到达之前,我实际上正在与“否定”选项作斗争。我用我的brightway版本测试了您的代码,但正如您所预期的那样,它不起作用。然后我更新了brightway,代码按照预期工作和行为(我得到了否定的结果).我用LCIA方法、从Simapro CSV导入的文件等确认了一个更复杂的案例。即使没有手动指定“负”为真,情况也很好。谢谢。