当前位置: 首页>>代码示例>>Python>>正文


Python ModelEnsemble.parallel方法代码示例

本文整理汇总了Python中expWorkbench.ModelEnsemble.parallel方法的典型用法代码示例。如果您正苦于以下问题:Python ModelEnsemble.parallel方法的具体用法?Python ModelEnsemble.parallel怎么用?Python ModelEnsemble.parallel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在expWorkbench.ModelEnsemble的用法示例。


在下文中一共展示了ModelEnsemble.parallel方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: maxmin_optimize

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def maxmin_optimize():
    ema_logging.log_to_stderr(ema_logging.INFO)
 
    model = TestModel("", 'simpleModel') #instantiate the model
    ensemble = ModelEnsemble() #instantiate an ensemble
    ensemble.set_model_structure(model) #set the model on the ensemble
    ensemble.parallel = True
    ensemble.processes = 12
    
    def obj_function1(outcomes):
        return outcomes['y']
    
    policy_levers = { "L1": (0,1),
                      "L2": (0,1)}
    
    
    
    results = ensemble.perform_maximin_optimization(obj_function1 = obj_function1, 
                                                policy_levers = policy_levers,
                                                minimax1='minimize',
                                                nrOfGenerations1=50,
                                                nrOfPopMembers1=200,
                                                minimax2 = "maximize",                                   
                                                nrOfGenerations2 = 50,
                                                nrOfPopMembers2 = 100,
                                                )

    graph_errorbars_raw(results['stats'])
    plt.show()
开发者ID:,项目名称:,代码行数:31,代码来源:

示例2: test_optimization

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def test_optimization():
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    model = FluModel(r'..\data', "fluCase")
    ensemble = ModelEnsemble()
    
    ensemble.set_model_structure(model)
    ensemble.parallel=True
#    ensemble.processes = 12
        
    stats, pop  = ensemble.perform_outcome_optimization(obj_function = obj_function_multi,
                                                    reporting_interval=10, 
                                                    weights=(MAXIMIZE, MAXIMIZE),
                                                    pop_size=100,
                                                    nr_of_generations=5,
                                                    crossover_rate=0.5,
                                                    mutation_rate=0.05)
    res = stats.hall_of_fame.keys
    
    x = [entry.values[0] for entry in res]
    y = [entry.values[1] for entry in res]
    
    print len(x), len(y)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.scatter(x,y)
    ax.set_ylabel("deceased population")
    ax.set_xlabel("infected fraction")
    
    plt.show()
开发者ID:,项目名称:,代码行数:33,代码来源:

示例3: perform_experiments

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def perform_experiments():
    ema_logging.log_to_stderr(level=ema_logging.INFO)
    model = SalinizationModel(r"C:\workspace\EMA-workbench\models\salinization", "verzilting")
    model.step = 4
    
    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model)
    
    ensemble.parallel = True
    nr_of_experiments = 10000
    results = ensemble.perform_experiments(nr_of_experiments)
    return results
开发者ID:canerhamarat,项目名称:EMAworkbench,代码行数:14,代码来源:salinization_example.py

示例4: test_optimization

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def test_optimization():
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    model = FluModel(r'..\data', "fluCase")
    ensemble = ModelEnsemble()
    
    ensemble.set_model_structure(model)
    ensemble.parallel=True
        
    stats, pop  = ensemble.perform_outcome_optimization(obj_function = obj_function_multi,
                                                    reporting_interval=100, 
                                                    weights=(MAXIMIZE, MAXIMIZE),
                                                    pop_size=100,
                                                    nr_of_generations=20,
                                                    crossover_rate=0.5,
                                                    mutation_rate=0.05,
                                                    caching=False)
    res = stats.hall_of_fame.keys
    
    print len(stats.tried_solutions.values())
开发者ID:bram32,项目名称:EMAworkbench,代码行数:22,代码来源:test_outcome_optimization.py

示例5: test_tree

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def test_tree():
    
    log_to_stderr(level= INFO)
        
    model = FluModel(r'..\..\models\flu', "fluCase")
    ensemble = ModelEnsemble()
    ensemble.parallel = True
    ensemble.set_model_structure(model)
    
    policies = [{'name': 'no policy',
                 'file': r'\FLUvensimV1basecase.vpm'},
                {'name': 'static policy',
                 'file': r'\FLUvensimV1static.vpm'},
                {'name': 'adaptive policy',
                 'file': r'\FLUvensimV1dynamic.vpm'}
                ]
    ensemble.add_policies(policies)
    
    results = ensemble.perform_experiments(10)
   
    a_tree = tree(results, classify)
开发者ID:bram32,项目名称:EMAworkbench,代码行数:23,代码来源:test_orange_functions.py

示例6: test_feature_selection

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def test_feature_selection():
    log_to_stderr(level= INFO)
        
    model = FluModel(r'..\..\models\flu', "fluCase")
    ensemble = ModelEnsemble()
    ensemble.parallel = True
    ensemble.set_model_structure(model)
    
    policies = [{'name': 'no policy',
                 'file': r'\FLUvensimV1basecase.vpm'},
                {'name': 'static policy',
                 'file': r'\FLUvensimV1static.vpm'},
                {'name': 'adaptive policy',
                 'file': r'\FLUvensimV1dynamic.vpm'}
                ]
    ensemble.add_policies(policies)
    
    results = ensemble.perform_experiments(5000)
   
    results = feature_selection(results, classify)
    for entry in results:
        print entry[0] +"\t" + str(entry[1])
开发者ID:bram32,项目名称:EMAworkbench,代码行数:24,代码来源:test_orange_functions.py

示例7: test_optimization

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
def test_optimization():
    ema_logging.log_to_stderr(ema_logging.INFO)
    
    model = FluModel(r'../models', "fluCase")
    ensemble = ModelEnsemble()
    
    ensemble.set_model_structure(model)
    ensemble.parallel=True
    
    pop_size = 8
    nr_of_generations = 10
    eps = np.array([1e-3, 1e6])

    stats, pop  = ensemble.perform_outcome_optimization(obj_function = obj_function_multi,
                                                    algorithm=epsNSGA2,
                                                    reporting_interval=100, 
                                                    weights=(MAXIMIZE, MAXIMIZE),
                                                    pop_size=pop_size,          
                                                    nr_of_generations=nr_of_generations,
                                                    crossover_rate=0.8,
                                                    mutation_rate=0.05,
                                                    eps=eps)
    fn = '../data/test optimization save.bz2'
开发者ID:epruyt,项目名称:EMAworkbench,代码行数:25,代码来源:test_outcome_optimization.py

示例8: CaseError

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
            raise CaseError("run not completed", case) 

def obj_func(outcomes):
    outcome = outcomes['total fraction new technologies']
    zeros = np.zeros((outcome.shape[0], 1))
    zeros[outcome[:,-1]>0.6] = 1
    value = np.sum(zeros)/zeros.shape[0] 
    return value,

if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
    model = EnergyTrans(r"..\data", "ESDMAElecTrans")
       
    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model)
    ensemble.parallel = True
    
    policy_levers = {'Trigger subsidy T2': {'type':'range', 'values':(0,1)},
                   'Trigger subsidy T3': {'type':'range', 'values':(0,1)},
                   'Trigger subsidy T4': {'type':'range', 'values':(0,1)},
                   'Trigger addnewcom': {'type':'list', 'values':[0, 0.25, 0.5, 0.75, 1]}}
    
    stats_callback, pop   = ensemble.perform_robust_optimization(cases=10,
                                               reporting_interval=100,
                                               obj_function=obj_func,
                                               policy_levers=policy_levers,
                                               weights = (MAXIMIZE,),
                                               nr_of_generations=100,
                                               pop_size=10,
                                               crossover_rate=0.5, 
                                               mutation_rate=0.02,
开发者ID:,项目名称:,代码行数:33,代码来源:

示例9: model_init

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
    def model_init(self, policy, kwargs):
        '''initializes the model'''
        
        try:
            self.model_file = policy['file']
        except KeyError:
            ema_logging.warning("key 'file' not found in policy")
        super(FluModel, self).model_init(policy, kwargs)
        
if __name__ == "__main__":
    ema_logging.log_to_stderr(ema_logging.INFO)
        
    model = FluModel(r'..\..\models\flu', "fluCase")
    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model)
    
    #add policies
    policies = [{'name': 'no policy',
                 'file': r'\FLUvensimV1basecase.vpm'},
                {'name': 'static policy',
                 'file': r'\FLUvensimV1static.vpm'},
                {'name': 'adaptive policy',
                 'file': r'\FLUvensimV1dynamic.vpm'}
                ]
    ensemble.add_policies(policies)

    ensemble.parallel = True #turn on parallel processing

    results = ensemble.perform_experiments(1000)
    
    save_results(results, r'./data/1000 flu cases.bz2')
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:33,代码来源:flu_vensim_example.py

示例10: ParameterUncertainty

# 需要导入模块: from expWorkbench import ModelEnsemble [as 别名]
# 或者: from expWorkbench.ModelEnsemble import parallel [as 别名]
                     ParameterUncertainty((0.45,0.55),
                                          "tH"),
                     ParameterUncertainty((0.1,0.3),
                                          "kk")]
    
    #specification of the outcomes
    outcomes = [Outcome("B4:B1076", time=True),  #we can refer to a range in the normal way
                Outcome("P_t", time=True)] # we can also use named range
    
    #name of the sheet
    sheet = "Sheet1"
    
    #relative path to the Excel file
    workbook = r'\excel example.xlsx'
    

if __name__ == "__main__":    
    ema_logging.log_to_stderr(level=ema_logging.INFO)
    
    model = ExcelModel(r"./models/excelModel", "predatorPrey")
    
    ensemble = ModelEnsemble()
    ensemble.set_model_structure(model) 

    ensemble.parallel = True #turn on parallel computing
    ensemble.processes = 2 #using only 2 cores 
    
    #run 100 experiments
    nr_experiments = 100
    results = ensemble.perform_experiments(nr_experiments) 
开发者ID:epruyt,项目名称:EMAworkbench,代码行数:32,代码来源:excel_example.py


注:本文中的expWorkbench.ModelEnsemble.parallel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。