• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ema_logging.debug函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中expWorkbench.ema_logging.debug函数的典型用法代码示例。如果您正苦于以下问题:Python debug函数的具体用法?Python debug怎么用?Python debug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: _handle_outcomes

 def _handle_outcomes(self, fns):                  
     for key, value in fns.iteritems():
         if key in self.normal_handling: # voor "normale" globals werkt dit
             with open(value) as fh:    
                 result = fh.readline()
                 result = result.strip()
                 result = result.split()
                 result = [float(entry) for entry in result]
                 self.output[key] = np.asarray(result)
         elif key in self.once_handling:
             with open(value) as fh:
                 result = fh.readline() # lees line die bestaat uit nullen en een list 
                 result = result.strip() #spaties weghalen
                 result = result.strip('[')# haakje weghalen, welke alleen in de lijst nog zitten eventueel
                 result = result.strip(']')# haakje weghalen, welke alleen in de lijst nog zitten eventueel
                 result = result.split() # splitsen op elementen: nullen en een list
                 results = np.zeros((self.run_length*10)) # lege array maken
                 for j, entry in enumerate(result):                           
                      if entry:
                         entry = float(entry)
                      else:
                         entry = 0                            
                      results[j] = entry
                 self.output[key] = results
         else:
             raise CaseError('no hander specified for {}'.format(key), {})
           
     for value in fns.values():
         ema_logging.debug('value: {}'.format(value))
           
         try:
             os.remove(value)
         except WindowsError:
             pass
开发者ID:rluteijn,项目名称:msc_thesis,代码行数:34,代码来源:Model_interface.py


示例2: experiment_generator

def experiment_generator(sampled_unc, model_structures, policies, sampler):
    '''
    
    generator function which yields experiments
    
    '''
    
    # experiment is made up of case, policy, and msi
    # to get case, we need msi
    
    for msi in model_structures:
        debug("generating designs for model %s" % (msi.name))
        
        samples = [sampled_unc[unc.name] for unc in msi.uncertainties if\
                   sampled_unc.has_key(unc.name)]
        uncertainties = [unc.name for unc in msi.uncertainties if\
                         sampled_unc.has_key(unc.name)]
        for policy in policies:
            debug("generating designs for policy %s" % (policy['name']))
            designs = sampler.generate_designs(samples)
            for design in designs:
                experiment = {uncertainties[i]: design[i] for i in\
                                range(len(uncertainties))}
                experiment['policy'] = policy
                experiment['model'] = msi.name
                yield experiment
开发者ID:rjplevin,项目名称:EMAworkbench,代码行数:26,代码来源:model_ensemble.py


示例3: make_name

def make_name(ind):
    keys  = sorted(ind.keys())
    try:
        keys.pop(keys.index('name'))
    except ValueError:
        ema_logging.debug("value error in make name, field 'name' not in list")
    
    name = ""
    for key in keys:
        name += " "+str(ind[key])
    return name
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:11,代码来源:ema_optimization.py


示例4: __store_result

 def __store_result(self, result):
     for outcome in self.outcomes:
         try:
             outcome_res = result[outcome]
         except KeyError:
             ema_logging.debug("%s not in msi" % outcome)
         else:
             try:
                 self.results[outcome][self.i-1, ] = outcome_res
             except KeyError: 
                 shape = np.asarray(outcome_res).shape
                 shape = list(shape)
                 shape.insert(0, self.nr_experiments)
                 self.results[outcome] = np.empty(shape)
                 self.results[outcome][:] = np.NAN
                 self.results[outcome][self.i-1, ] = outcome_res
开发者ID:canerhamarat,项目名称:EMAworkbench,代码行数:16,代码来源:callbacks.py


示例5: run_model

    def run_model(self, case):
        
        for key, value in self.defaults.items():
            case[key] = value
        
        replications = defaultdict(list)
        
        for i in range(self.nr_replications):
            ema_logging.debug('running replication {}'.format(i))
            self._run_case(case)
 
            for key, value in self.output.items():
                replications[key].append(value)
        
        for key, value in replications.items():
            data = np.asarray(value)
            self.output[key+'_mean'] = np.mean(data, axis=0)
            self.output[key+'_std'] = np.std(data, axis=0)    
开发者ID:quaquel,项目名称:greeven_etal_2016,代码行数:18,代码来源:generating_experiments.py


示例6: __call__

 def __call__(self, case, policy, name, result):
     '''
     Method responsible for storing results. The implementation in this
     class only keeps track of how many runs have been completed and 
     logging this. 
     
     :param case: the case to be stored
     :param policy: the name of the policy being used
     :param name: the name of the model being used
     :param result: the result dict
     
     '''
     
     self.i+=1
     debug(str(self.i)+" cases completed")
     
     if self.i % self.reporting_interval == 0:
         info(str(self.i)+" cases completed")
开发者ID:canerhamarat,项目名称:EMAworkbench,代码行数:18,代码来源:callbacks.py


示例7: experiment_generator_predef_cases

def experiment_generator_predef_cases(designs, model_structures, policies):
    '''
    
    generator function which yields experiments
    
    '''
    
    # experiment is made up of case, policy, and msi
    # to get case, we need msi
    
    for msi in model_structures:
        debug("generating designs for model %s" % (msi.name))

        for policy in policies:
            debug("generating designs for policy %s" % (policy['name']))
            for experiment in designs:
                experiment['policy'] = copy.deepcopy(policy)
                experiment['model'] = msi.name
                yield experiment
开发者ID:rjplevin,项目名称:EMAworkbench,代码行数:19,代码来源:model_ensemble.py


示例8: model_init

 def model_init(self, policy, kwargs):
     '''
     :param policy: policy to be run, in the default implementation, this
                    argument is ignored. Extent :meth:`model_init` to
                    specify how this argument should be used. 
     :param kwargs: keyword arguments to be used by :meth:`model_init`
     
     '''
     
     if not self.xl:
         try:
             ema_logging.debug("trying to start Excel")
             self.xl = win32com.client.Dispatch("Excel.Application")
             ema_logging.debug("Excel started") 
         except com_error as e:
             raise EMAError(str(e))
     ema_logging.debug("trying to open workbook")
     self.wb = self.xl.Workbooks.Open(self.working_directory + self.workbook)
     ema_logging.debug("workbook opened")
     ema_logging.debug(self.working_directory)
开发者ID:bram32,项目名称:EMAworkbench,代码行数:20,代码来源:excel.py


示例9: model_init

 def model_init(self, policy, kwargs):
     try:
         self.modelFile = policy['file']
     except:
         logging.debug("no policy specified")
     super(EnergyTrans, self).model_init(policy, kwargs)
开发者ID:JBeek,项目名称:EMAworkbench,代码行数:6,代码来源:EnergyTransExample_withnewmonitors.py


示例10: pairs_lines

def pairs_lines(results, 
                outcomes_to_show = [],
                group_by = None,
                grouping_specifiers = None,
                ylabels = {},
                legend=True,
                **kwargs):
    '''
    
    Generate a `R style pairs <http://www.stat.psu.edu/~dhunter/R/html/graphics/html/pairs.html>`_ 
    lines multiplot. It shows the behavior of two outcomes over time against
    each other. The origin is denoted with a circle and the end is denoted
    with a '+'. 
    
    :param results: return from perform_experiments.
    :param outcomes_to_show: list of outcome of interest you want to plot. If 
                             empty, all outcomes are plotted.
    :param group_by: name of the column in the cases array to group results by.
                     Alternatively, `index` can be used to use indexing arrays 
                     as the basis for grouping.
    :param grouping_specifiers: set of categories to be used as a basis for 
                                grouping by. Grouping_specifiers is only 
                                meaningful if group_by is provided as well. In
                                case of grouping by index, the grouping 
                                specifiers should be in a dictionary where the
                                key denotes the name of the group. 
    :param ylabels: ylabels is a dictionary with the outcome names as keys, the 
                    specified values will be used as labels for the y axis. 
    :param legend: boolean, if true, and there is a column specified for 
                   grouping, show a legend.
    :param point_in_time: the point in time at which the scatter is to be made.
                          If None is provided, the end states are used. 
                          point_in_time should be a valid value on time
    :rtype: a `figure <http://matplotlib.sourceforge.net/api/figure_api.html>`_ instance
            and a dict with the individual axes.
    
    '''
    
    #unravel return from run_experiments   
    debug("making a pars lines plot")
    
    prepared_data = prepare_pairs_data(results, outcomes_to_show, group_by, 
                                       grouping_specifiers, None)
    outcomes, outcomes_to_show, grouping_labels = prepared_data
    
    grid = gridspec.GridSpec(len(outcomes_to_show), len(outcomes_to_show))                             
    grid.update(wspace = 0.1,
                hspace = 0.1)
    
    #the plotting
    figure = plt.figure()
    axes_dict = {}
    
    if group_by and legend:
        make_legend(grouping_labels, figure)
     
    combis = [(field1, field2) for field1 in outcomes_to_show\
                               for field2 in outcomes_to_show]
    
    for field1, field2 in combis:
        i = outcomes_to_show.index(field1)
        j = outcomes_to_show.index(field2)
        ax = figure.add_subplot(grid[i,j])
        axes_dict[(field1, field2)] = ax

        if group_by:
            for x, entry in enumerate(grouping_labels):
                data1 = outcomes[entry][field1]
                data2 = outcomes[entry][field2]
                color = COLOR_LIST[x]
                if i==j: 
                    color = 'white'
                simple_pairs_lines(ax, data1, data2, color)
        else:
            data1 = outcomes[field1]
            data2 = outcomes[field2]
            color = 'b'
            if i==j: 
                color = 'white'
            simple_pairs_lines(ax, data1, data2, color)
        do_text_ticks_labels(ax, i, j, field1, field2, ylabels, 
                             outcomes_to_show)
            

    return figure, axes_dict
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:85,代码来源:pairs_plotting.py


示例11: perform_experiments


#.........这里部分代码省略.........
            nr_of_exp =self.sampler.deterimine_nr_of_designs(sampled_unc)\
                      *len(self._policies)*len(self._msis)
            experiments = self._generate_experiments(sampled_unc)
        elif type(cases) == types.ListType:
            unc_dict = self.determine_uncertainties()[1]
            unc_names = cases[0].keys()
            sampled_unc = {name:[] for name in unc_names}
            nr_of_exp = len(cases)*len(self._policies)*len(self._msis)
            experiments = self._generate_experiments(cases)
        else:
            raise EMAError("unknown type for cases")
        uncertainties = [unc_dict[unc] for unc in sorted(sampled_unc)]

        # identify the outcomes that are to be included
        overview_dict, element_dict = self._determine_unique_attributes("outcomes")
        if which_outcomes==UNION:
            outcomes = element_dict.keys()
        elif which_outcomes==INTERSECTION:
            outcomes = overview_dict[tuple([msi.name for msi in self._msis])]
            outcomes = [outcome.name for outcome in outcomes]
        else:
            raise ValueError("incomplete value for which_outcomes")
         
        info(str(nr_of_exp) + " experiment will be executed")
                
        #initialize the callback object
        callback = callback(uncertainties, 
                            outcomes, 
                            nr_of_exp,
                            reporting_interval=reporting_interval,
                            **kwargs)

        if self.parallel:
            info("preparing to perform experiment in parallel")
            
            if not self._pool:
                self._make_pool(model_kwargs)
            info("starting to perform experiments in parallel")

            self._pool.run_experiments(experiments, callback)
        else:
            info("starting to perform experiments sequentially")

            def cleanup(modelInterfaces):
                for msi in modelInterfaces:
                    msi.cleanup()
                    del msi

            
            msi_initialization_dict = {}
            msis = {msi.name: msi for msi in self._msis}
            job_counter = itertools.count()
            
            cwd = os.getcwd() 
            for experiment in experiments:
                case_id = job_counter.next()
                policy = experiment.pop('policy')
                msi = experiment.pop('model')
                
                # check whether we already initialized the model for this 
                # policy
                if not msi_initialization_dict.has_key((policy['name'], msi)):
                    try:
                        debug("invoking model init")
                        msis[msi].model_init(copy.deepcopy(policy),\
                                             copy.deepcopy(model_kwargs))
                    except (EMAError, NotImplementedError) as inst:
                        exception(inst)
                        cleanup(self._msis)
                        raise
                    except Exception:
                        exception("some exception occurred when invoking the init")
                        cleanup(self._msis)
                        raise 
                    debug("initialized model %s with policy %s" % (msi, policy['name']))
                    #always, only a single initialized msi instance
                    msi_initialization_dict = {(policy['name'], msi):msis[msi]}
                msi = msis[msi]

                case = copy.deepcopy(experiment)
                try:
                    debug("trying to run model")
                    msi.run_model(case)
                except CaseError as e:
                    warning(str(e))
                    
                debug("trying to retrieve output")
                result = msi.retrieve_output()
                msi.reset_model()
                
                debug("trying to reset model")
                callback(case_id, experiment, policy, msi.name, result)
                
            cleanup(self._msis)
            os.chdir(cwd)
       
        results = callback.get_results()
        info("experiments finished")
        
        return results
开发者ID:rjplevin,项目名称:EMAworkbench,代码行数:101,代码来源:model_ensemble.py


示例12: test_callback_call_union

def test_callback_call_union():
    # there are actually 3 cases that should be tested here
    # union unc, intersection outcomes
    # intersection unc, union outcomes
    # union unc, union outcomes
    
    # case 1 union unc, intersection outcomes
#    debug('----------- case 1 -----------')
#    nr_experiments = 10
#    uncs = [ParameterUncertainty((0,1), "a"),
#           ParameterUncertainty((0,1), "b")]
#    outcomes = [Outcome("test", time=True)]
#    callback = DefaultCallback(uncs, outcomes, nr_experiments=nr_experiments)
#    
#    policy = {"name": "none"}
#    name = "test"
#    
#    for i in range(nr_experiments):
#        if i % 2 == 0:
#            case = {uncs[0].name: np.random.rand(1)}
#        else: 
#            case = {uncs[1].name: np.random.rand(1)}
#        result = {outcome.name: np.random.rand(10) for outcome in outcomes}
#    
#        callback(case, policy, name, result)
#    
#    results = callback.get_results()
#    debug("\n"+str(results[0]))

    
    debug('----------- case 2 -----------')
#    nr_experiments = 10
#    uncs = [ParameterUncertainty((0,1), "a"),
#           ParameterUncertainty((0,1), "b")]
#    outcomes = [Outcome("test 1", time=True), 
#                Outcome("test 2", time=True)]
#    callback = DefaultCallback(uncs, outcomes, nr_experiments=nr_experiments)
#    
#    policy = {"name": "none"}
#    name = "test"
#    
#    for i in range(nr_experiments):
#        case = {unc.name: random.random()for unc in uncs}
#        if i % 2 == 0:
#            result = {outcomes[0].name: np.random.rand(10)}
#        else: 
#            result = {outcomes[1].name: np.random.rand(10)}
#    
#        callback(case, policy, name, result)
#    


  
    debug('----------- case 3 -----------')
    nr_experiments = 10
    uncs = [ParameterUncertainty((0,1), "a"),
           ParameterUncertainty((0,1), "b")]
    outcomes = [Outcome("test 1", time=True), 
                Outcome("test 2", time=True)]
    callback = DefaultCallback(uncs, outcomes, nr_experiments=nr_experiments)
    
    policy = {"name": "none"}
    name = "test"
    
    for i in range(nr_experiments):
        if i % 2 == 0:
            case = {uncs[0].name: random.random()}
            result = {outcomes[0].name: np.random.rand(10)}
        else: 
            case = {uncs[1].name: random.random()}
            result = {outcomes[1].name: np.random.rand(10)}
    
        callback(case, policy, name, result)
    
    results = callback.get_results()
    debug("\n"+str(results[0]))
    for key, value in results[1].iteritems():
        debug("\n" + str(key) + "\n" + str(value))   
开发者ID:epruyt,项目名称:EMAworkbench,代码行数:78,代码来源:test_callback.py


示例13: test_callback_store_results

def test_callback_store_results():
    nr_experiments = 3
    uncs = [ParameterUncertainty((0,1), "a"),
           ParameterUncertainty((0,1), "b")]
    outcomes = [Outcome("test", time=True)]
    case = {unc.name:random.random() for unc in uncs}
    policy = {'name':'none'}
    name = "test"

    # case 1 scalar shape = (1)
    debug('----------- case 1 -----------')
    callback = DefaultCallback(uncs, 
                               [outcome.name for outcome in outcomes], 
                               nr_experiments=nr_experiments)
    result = {outcomes[0].name: 1}
    callback(case, policy, name, result)
    
    results = callback.get_results()
    for key, value in results[1].iteritems():
        debug("\n" + str(key) + "\n" + str(value))

    # case 2 time series shape = (1, nr_time_steps)
    debug('----------- case 2 -----------')
    callback = DefaultCallback(uncs, 
                               [outcome.name for outcome in outcomes], 
                               nr_experiments=nr_experiments)
    result = {outcomes[0].name: np.random.rand(10)}
    callback(case, policy, name, result)
    
    results = callback.get_results()
    for key, value in results[1].iteritems():
        debug("\n" + str(key) + "\n" + str(value))


    # case 3 maps etc. shape = (x,y)
    debug('----------- case 3 -----------')
    callback = DefaultCallback(uncs, 
                               [outcome.name for outcome in outcomes], 
                               nr_experiments=nr_experiments)
    result = {outcomes[0].name: np.random.rand(2,2)}
    callback(case, policy, name, result)
    
    results = callback.get_results()
    for key, value in results[1].iteritems():
        debug("\n" + str(key) + "\n" + str(value))


    # case 4 maps etc. shape = (x,y)
    debug('----------- case 4 -----------')
    callback = DefaultCallback(uncs, 
                               [outcome.name for outcome in outcomes], 
                               nr_experiments=nr_experiments)
    result = {outcomes[0].name: np.random.rand(2,2, 2)}
    callback(case, policy, name, result)
开发者ID:epruyt,项目名称:EMAworkbench,代码行数:54,代码来源:test_callback.py


示例14: pairs_scatter

def pairs_scatter(results, 
                  outcomes_to_show = [],
                  group_by = None,
                  grouping_specifiers = None,
                  ylabels = {},
                  legend=True,
                  point_in_time=-1,
                  filter_scalar=True,
                  **kwargs):
    '''
    
    Generate a `R style pairs <http://www.stat.psu.edu/~dhunter/R/html/graphics/html/pairs.html>`_ 
    scatter multiplot. In case of time-series data, the end states are used.
    
    :param results: return from perform_experiments.
    :param outcomes_to_show: list of outcome of interest you want to plot. If 
                             empty, all outcomes are plotted.
    :param group_by: name of the column in the cases array to group results by.
                     Alternatively, `index` can be used to use indexing arrays 
                     as the basis for grouping.
    :param grouping_specifiers: set of categories to be used as a basis for 
                                grouping by. Grouping_specifiers is only 
                                meaningful if group_by is provided as well. In
                                case of grouping by index, the grouping 
                                specifiers should be in a dictionary where the
                                key denotes the name of the group. 
    :param ylabels: ylabels is a dictionary with the outcome names as keys, the 
                    specified values will be used as labels for the y axis. 
    :param legend: boolean, if true, and there is a column specified for 
                   grouping, show a legend.
    :param point_in_time: the point in time at which the scatter is to be made.
                          If None is provided, the end states are used. 
                          point_in_time should be a valid value on time
    :param filter_scalar: boolean, remove the non-time-series outcomes.  
                          Defaults to True.
    :rtype: a `figure <http://matplotlib.sourceforge.net/api/figure_api.html>`_ instance
            and a dict with the individual axes.
    

    .. note:: the current implementation is limited to seven different 
          categories in case of column, categories, and/or discretesize.
          This limit is due to the colors specified in COLOR_LIST. 
    '''
    
    debug("generating pairwise scatter plot")
   
    prepared_data = prepare_pairs_data(results, outcomes_to_show, group_by, 
                                       grouping_specifiers, point_in_time,
                                       filter_scalar)
    outcomes, outcomes_to_show, grouping_labels = prepared_data
   
    grid = gridspec.GridSpec(len(outcomes_to_show), len(outcomes_to_show))                             
    grid.update(wspace = 0.1,
                hspace = 0.1)    
    
    
    #the plotting
    figure = plt.figure()
    axes_dict = {}
    
    if group_by and legend:
        make_legend(grouping_labels, figure, legend_type='scatter')
     
    combis = [(field1, field2) for field1 in outcomes_to_show\
                               for field2 in outcomes_to_show]
    
    for field1, field2 in combis:
        i = outcomes_to_show.index(field1)
        j = outcomes_to_show.index(field2)
        ax = figure.add_subplot(grid[i,j])
        axes_dict[(field1, field2)] = ax

        if group_by:
            for x, group in enumerate(grouping_labels):
                y_data = outcomes[group][field1]
                x_data = outcomes[group][field2]
                
                facecolor = COLOR_LIST[x]
                edgecolor = 'k'
                if i==j: 
                    facecolor = 'white'
                    edgecolor = 'white'
                ax.scatter(x_data, y_data, 
                           facecolor=facecolor, edgecolor=edgecolor)
        else:
            y_data = outcomes[field1]
            x_data = outcomes[field2]

            facecolor = 'b'
            edgecolor = 'k'
            if i==j: 
                facecolor = 'white'
                edgecolor = 'white'
            ax.scatter(x_data, y_data, 
                       facecolor=facecolor, edgecolor=edgecolor)
        do_text_ticks_labels(ax, i, j, field1, field2, ylabels, 
                             outcomes_to_show)

    return figure, axes_dict
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:99,代码来源:pairs_plotting.py


示例15: pairs_density

def pairs_density(results, 
                  outcomes_to_show = [],
                  group_by = None,
                  grouping_specifiers = None,
                  ylabels = {},
                  point_in_time=-1,
                  log=True,
                  gridsize=50,
                  colormap='jet',
                  filter_scalar=True): 
    '''
    
    Generate a `R style pairs <http://www.stat.psu.edu/~dhunter/R/html/graphics/html/pairs.html>`_ 
    hexbin density multiplot. In case of time-series data, the end states are 
    used.
    
    hexbin makes hexagonal binning plot of x versus y, where x, y are 1-D 
    sequences of the same length, N. If C is None (the default), this is a 
    histogram of the number of occurences of the observations at (x[i],y[i]).
    For further detail see `matplotlib on hexbin <http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hexbin>`_
    
    :param results: return from perform_experiments.
    :param outcomes_to_show: list of outcome of interest you want to plot. If 
                             empty, all outcomes are plotted.
    :param group_by: name of the column in the cases array to group results by.
                     Alternatively, `index` can be used to use indexing arrays 
                     as the basis for grouping.
    :param grouping_specifiers: set of categories to be used as a basis for 
                                grouping by. Grouping_specifiers is only 
                                meaningful if group_by is provided as well. In
                                case of grouping by index, the grouping 
                                specifiers should be in a dictionary where the
                                key denotes the name of the group. 
    :param ylabels: ylabels is a dictionary with the outcome names as keys, the 
                    specified values will be used as labels for the y axis. 
    :param point_in_time: the point in time at which the scatter is to be made.
                          If None is provided, the end states are used. 
                          point_in_time should be a valid value on time
    :param log: boolean, indicating whether density should be log scaled. 
                Defaults to True.
    :param gridsize: controls the gridsize for the hexagonal binning
    :param cmap: color map that is to be used in generating the hexbin. For 
                 details on the available maps, 
                 see `pylab <http://matplotlib.sourceforge.net/examples/pylab_examples/show_colormaps.html#pylab-examples-show-colormaps>`_.
                 (Defaults = jet)
    :param filter_scalar: boolean, remove the non-time-series outcomes.  
                          Defaults to True.
    :rtype: a `figure <http://matplotlib.sourceforge.net/api/figure_api.html>`_ instance
            and a dict with the individual axes.
    
    '''
    debug("generating pairwise density plot")
    
    prepared_data = prepare_pairs_data(results, outcomes_to_show, group_by, 
                                       grouping_specifiers, point_in_time,
                                       filter_scalar)
    outcomes, outcomes_to_show, grouping_specifiers = prepared_data
   
    if group_by:
        #figure out the extents for each combination
        extents = determine_extents(outcomes, outcomes_to_show)
        
        axes_dicts = {}
        figures = []
        for key, value in outcomes.items():
            figure, axes_dict = simple_pairs_density(value, outcomes_to_show, 
                                       log, colormap, gridsize, ylabels,
                                       extents=extents, title=key)
            axes_dicts[key] = axes_dict
            figures.append(figure)
        
        # harmonize the color scaling across figures
        combis = [(field1, field2) for field1 in outcomes_to_show\
                           for field2 in outcomes_to_show]
        for combi in combis:
            vmax = -1
            for entry in axes_dicts.values():
                vmax =  max(entry[combi].collections[0].norm.vmax, vmax)
            for entry in axes_dicts.values():
                ax = entry[combi]
                ax.collections[0].set_clim(vmin=0, vmax=vmax)
            del vmax
            
        return figures, axes_dicts
    else:
        return simple_pairs_density(outcomes, outcomes_to_show, log, colormap, 
                                    gridsize, ylabels)
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:87,代码来源:pairs_plotting.py


示例16: run_interval

def run_interval(model,loop_index,interval,VOI,edges,ind_cons,
                 double_list,case):
    
    # Load the model.
    vensim.load_model(model)
    
    case = copy.deepcopy(case)
    set_lookups(case)
    
    for key,value in case.items():
        vensim.set_value(key,repr(value))
#        print key, repr(value), vensim.get_val(key), value-vensim.get_val(key)

    # We run the model in game mode.
    step = vensim.get_val(r'TIME STEP')
    start_interval = interval[0]*step
    end_interval = interval[1]*step
    venDLL.command('GAME>GAMEINTERVAL|'+str(start_interval))

    # Initiate the model to be run in game mode.
    venDLL.command("MENU>GAME")
    if start_interval > 0:
        venDLL.command('GAME>GAMEON')

    loop_on = 1
    loop_off = 0

    loop_turned_off = False
    while True:

        # Initiate the experiment of interest.
        # In other words set the uncertainties to the same value as in
        # those experiments.
        time = vensim.get_val(r'TIME')
        ema_logging.debug(time)
        
        if time ==(2000+step*interval[0]) and not loop_turned_off:
            loop_turned_off = True
            
            if loop_index != 0:
                
                # If loop elimination method is based on unique edge.
                if loop_index-1 < ind_cons:
                    constant_value = vensim.get_val(edges[int(loop_index-1)][0])
                    
                    if loop_off==1:
                        constant_value = 0
                    
                    vensim.set_value('value loop '+str(loop_index),
                                     constant_value)
                    vensim.set_value('switch loop '+str(loop_index),
                                     loop_off)
        
                # Else it is based on unique consecutive edges.
                else:
                    constant_value = vensim.get_val(edges[int(loop_index-1)][0])
                    
                    if loop_off==1:
                        constant_value = 0
                    
                    # Name of constant value used does not fit loop index minus 'start of cons'-index.
                    if loop_index-ind_cons in double_list:
                        vensim.set_value('value cons loop '+str(loop_index-ind_cons-1),
                                         constant_value)
                        vensim.set_value('switch cons loop '+str(loop_index-ind_cons-1),
                                         loop_off)
                    else:
                        vensim.set_value('value cons loop '+str(loop_index-ind_cons),
                                         constant_value)
                        vensim.set_value('switch cons loop '+str(loop_index-ind_cons),
                                         loop_off)
                        
            venDLL.command('GAME>GAMEINTERVAL|'+str(end_interval-start_interval))
            
        elif time ==(2000+step*interval[1]) and loop_turned_off:
            loop_turned_off = False
            if loop_index != 0:
                # If loop elimination method is based on unique edge.
                if loop_index-1 < ind_cons:
                    constant_value = 0
                    vensim.set_value('value loop '+str(loop_index),
                                     constant_value)
                    vensim.set_value('switch loop '+str(loop_index),
                                     loop_on)
        
                # Else it is based on unique consecutive edges.
                else:
                    constant_value = 0
                    # Name of constant value used does not fit loop index minus 'start of cons'-index.
                    if loop_index-ind_cons in double_list:
                        vensim.set_value('value cons loop '+str(loop_index-ind_cons-1),
                                         constant_value)
                        vensim.set_value('switch cons loop '+str(loop_index-ind_cons-1),
                                         loop_on)
                    else:
                        vensim.set_value('value cons loop '+str(loop_index-ind_cons),
                                         constant_value)
                        vensim.set_value('switch cons loop '+str(loop_index-ind_cons),
                                         loop_on)
            
#.........这里部分代码省略.........
开发者ID:bram32,项目名称:EMAworkbench,代码行数:101,代码来源:scarcityExample.py


示例17: _run_optimization

    def _run_optimization(self, toolbox, generate_individual, 
                           evaluate_population, attr_list, keys, obj_function, 
                           pop_size, reporting_interval, weights, 
                           nr_of_generations, crossover_rate, mutation_rate,
                           levers, caching, **kwargs):
        '''
        Helper function that runs the actual optimization
                
        :param toolbox: 
        :param generate_individual: helper function for generating an 
                                    individual
        :param evaluate_population: helper function for evaluating the 
                                    population
        :param attr_list: list of attributes (alleles)
        :param keys: the names of the attributes in the same order as attr_list
        :param obj_function: the objective function
        :param pop_size: the size of the population
        :param reporting_interval: the interval for reporting progress, passed
                                   on to perform_experiments
        :param weights: the weights on the outcomes
        :param nr_of_generations: number of generations for which the GA will 
                                  be run
        :param crossover_rate: the crossover rate of the GA
        :param mutation_rate: the muation rate of the GA
        :param levers: a dictionary with param keys as keys, and as values
                       info used in mutation.
        
        '''
        # figure out whether we are doing single or multi-objective 
        # optimization
        #TODO raise error if not specified
        single_obj = True
        if len(weights) >1: 
            single_obj=False
        
        # Structure initializers
        toolbox.register("individual", 
                         generate_individual, 
                         creator.Individual, #@UndefinedVariable
                         attr_list, keys=keys) 
        toolbox.register("population", tools.initRepeat, list, 
                         toolbox.individual)
    
        # Operator registering
        toolbox.register("evaluate", obj_function)
        toolbox.register("crossover", tools.cxOnePoint)
        toolbox.register("mutate", mut_polynomial_bounded)
       
        if single_obj:
            toolbox.register("select", tools.selTournament)
        else:
            toolbox.register("select", tools.selNSGA2)

        # generate population
        # for some stupid reason, DEAP demands a multiple of four for 
        # population size in case of NSGA-2 
        pop_size = closest_multiple_of_four(pop_size)
        info("population size restricted to %s " % (pop_size))
        pop = toolbox.population(pop_size)
        
        debug("Start of evolution")
        
        # Evaluate the entire population
        evaluate_population(pop, reporting_interval, toolbox, self)
        
        if not single_obj:
            # This is just to assign the crowding distance to the individuals
            tools.assignCrowdingDist(pop)
    
        #some statistics logging
        stats_callback = NSGA2StatisticsCallback(weights=weights,
                                    nr_of_generations=nr_of_generations,
                                    crossover_rate=crossover_rate, 
                                    mutation_rate=mutation_rate, 
                                    pop_size=pop_size, 
                                    caching=caching)
        stats_callback(pop)
        stats_callback.log_stats(0)

        # Begin the generational process
        for gen in range(nr_of_generations):
            pop = self._run_geneneration(pop, crossover_rate, mutation_rate, 
                                          toolbox, reporting_interval, levers, 
                                          evaluate_population, keys, 
                                          single_obj, stats_callback, 
                                          caching, **kwargs)
            stats_callback(pop)
            stats_callback.log_stats(gen)    
        info("-- End of (successful) evolution --")

        return stats_callback, pop        
开发者ID:rahalim,项目名称:EMAworkbench,代码行数:91,代码来源:model_ensemble.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ema_logging.info函数代码示例发布时间:2022-05-24
下一篇:
Python expWorkbench.ModelEnsemble类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap