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


Python six.viewvalues方法代码示例

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


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

示例1: calculate_cum_reward

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def calculate_cum_reward(policy):

    """Calculate cumulative reward with respect to time.

        Parameters
        ----------
        policy: bandit object
            The bandit algorithm you want to evaluate.

        Return
        ---------
        cum_reward: dict
            The dict stores {history_id: cumulative reward} .

        cum_n_actions: dict
            The dict stores
            {history_id: cumulative number of recommended actions}.
    """
    cum_reward = {-1: 0.0}
    cum_n_actions = {-1: 0}
    for i in range(policy.history_storage.n_histories):
        reward = policy.history_storage.get_history(i).rewards
        cum_n_actions[i] = cum_n_actions[i - 1] + len(reward)
        cum_reward[i] = cum_reward[i - 1] + sum(six.viewvalues(reward))
    return cum_reward, cum_n_actions 
开发者ID:ntucllab,项目名称:striatum,代码行数:27,代码来源:rewardplot.py

示例2: this_is_okay

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def this_is_okay():
    d = {}
    iterkeys(d)
    six.iterkeys(d)
    six.itervalues(d)
    six.iteritems(d)
    six.iterlists(d)
    six.viewkeys(d)
    six.viewvalues(d)
    six.viewlists(d)
    itervalues(d)
    future.utils.iterkeys(d)
    future.utils.itervalues(d)
    future.utils.iteritems(d)
    future.utils.iterlists(d)
    future.utils.viewkeys(d)
    future.utils.viewvalues(d)
    future.utils.viewlists(d)
    six.next(d)
    builtins.next(d) 
开发者ID:PyCQA,项目名称:flake8-bugbear,代码行数:22,代码来源:b301_b302_b305.py

示例3: _add_mark_rule

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def _add_mark_rule(src_ip, environment):
    """Add an environment mark for all traffic coming from an IP.

    :param ``str`` src_ip:
        Source IP to be marked
    :param ``str`` environment:
        Environment to use for the mark
    """
    assert environment in _SET_BY_ENVIRONMENT, \
        'Unknown environment: %r' % environment

    target_set = _SET_BY_ENVIRONMENT[environment]
    _LOGGER.debug('Add %s ip %s to ipset %s', environment, src_ip, target_set)
    iptables.add_ip_set(target_set, src_ip)

    # Check that the IP is not marked in any other environment
    other_env_sets = {
        env_set for env_set in six.viewvalues(_SET_BY_ENVIRONMENT)
        if env_set != target_set
    }
    for other_set in other_env_sets:
        if iptables.test_ip_set(other_set, src_ip) is True:
            raise Exception('%r is already in %r' % (src_ip, other_set)) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:25,代码来源:network_service.py

示例4: CaptureFrameLocals

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def CaptureFrameLocals(self, frame):
    """Captures local variables and arguments of the specified frame.

    Args:
      frame: frame to capture locals and arguments.

    Returns:
      (arguments, locals) tuple.
    """
    # Capture all local variables (including method arguments).
    variables = {n: self.CaptureNamedVariable(n, v, 1,
                                              self.default_capture_limits)
                 for n, v in six.viewitems(frame.f_locals)}

    # Split between locals and arguments (keeping arguments in the right order).
    nargs = frame.f_code.co_argcount
    if frame.f_code.co_flags & inspect.CO_VARARGS: nargs += 1
    if frame.f_code.co_flags & inspect.CO_VARKEYWORDS: nargs += 1

    frame_arguments = []
    for argname in frame.f_code.co_varnames[:nargs]:
      if argname in variables: frame_arguments.append(variables.pop(argname))

    return (frame_arguments, list(six.viewvalues(variables))) 
开发者ID:GoogleCloudPlatform,项目名称:cloud-debug-python,代码行数:26,代码来源:capture_collector.py

示例5: viewflatvalues

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def viewflatvalues(self):
        ''' Return view of flattened values '''
        return six.viewvalues(self.flattened()) 
开发者ID:sassoftware,项目名称:python-esppy,代码行数:5,代码来源:xdict.py

示例6: _exp4p_score

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def _exp4p_score(self, context):
        """The main part of Exp4.P.
        """
        advisor_ids = list(six.viewkeys(context))

        w = self._modelstorage.get_model()['w']
        if len(w) == 0:
            for i in advisor_ids:
                w[i] = 1
        w_sum = sum(six.viewvalues(w))

        action_probs_list = []
        for action_id in self.action_ids:
            weighted_exp = [w[advisor_id] * context[advisor_id][action_id]
                            for advisor_id in advisor_ids]
            prob_vector = np.sum(weighted_exp) / w_sum
            action_probs_list.append((1 - self.n_actions * self.p_min)
                                     * prob_vector
                                     + self.p_min)
        action_probs_list = np.asarray(action_probs_list)
        action_probs_list /= action_probs_list.sum()

        estimated_reward = {}
        uncertainty = {}
        score = {}
        for action_id, action_prob in zip(self.action_ids, action_probs_list):
            estimated_reward[action_id] = action_prob
            uncertainty[action_id] = 0
            score[action_id] = action_prob
        self._modelstorage.save_model(
            {'action_probs': estimated_reward, 'w': w})

        return estimated_reward, uncertainty, score 
开发者ID:ntucllab,项目名称:striatum,代码行数:35,代码来源:exp4p.py

示例7: _exp3_probs

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def _exp3_probs(self):
        """Exp3 algorithm.
        """
        w = self._model_storage.get_model()['w']
        w_sum = sum(six.viewvalues(w))

        probs = {}
        n_actions = self._action_storage.count()
        for action_id in self._action_storage.iterids():
            probs[action_id] = ((1 - self.gamma) * w[action_id]
                                / w_sum
                                + self.gamma / n_actions)

        return probs 
开发者ID:ntucllab,项目名称:striatum,代码行数:16,代码来源:exp3.py

示例8: __iter__

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def __iter__(self):
        return iter(six.viewvalues(self._actions)) 
开发者ID:ntucllab,项目名称:striatum,代码行数:4,代码来源:action.py

示例9: required_estimates_fields

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def required_estimates_fields(columns):
    """
    Compute the set of resource columns required to serve
    `columns`.
    """
    # We also expect any of the field names that our loadable columns
    # are mapped to.
    return metadata_columns.union(viewvalues(columns)) 
开发者ID:enigmampc,项目名称:catalyst,代码行数:10,代码来源:earnings_estimates.py

示例10: everything_else_is_wrong

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def everything_else_is_wrong():
    d = None  # note: bugbear is no type checker
    d.iterkeys()
    d.itervalues()
    d.iteritems()
    d.iterlists()  # Djangoism
    d.viewkeys()
    d.viewvalues()
    d.viewitems()
    d.viewlists()  # Djangoism
    d.next()
    d.keys().next() 
开发者ID:PyCQA,项目名称:flake8-bugbear,代码行数:14,代码来源:b301_b302_b305.py

示例11: get_column_names

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def get_column_names():
        """
        List names of columns as they should appear in the CSV.
        """
        return six.viewvalues(BuildLearnerProgramReport.field_names_to_columns) 
开发者ID:edx,项目名称:edx-analytics-pipeline,代码行数:7,代码来源:program_reports.py

示例12: __contains__

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def __contains__(self, other):
        '''Returns True if the `other` register is a sub-part of `self`.'''
        return other in six.viewvalues(self.__children__) 
开发者ID:arizvisa,项目名称:ida-minsc,代码行数:5,代码来源:_interface.py

示例13: synchronize

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def synchronize(self):
        """Cleanup state resource.
        """
        for app_unique_name in six.viewkeys(self._devices.copy()):
            if not self._devices[app_unique_name].get('stale', False):
                continue

            # This is a stale device, destroy it.
            self.on_delete_request(app_unique_name)

        # Reset the container environment sets to the IP we have now cleaned
        # up.  This is more complex than expected because multiple environment
        # can be merged in the same set in _SET_BY_ENVIRONMENT.
        container_env_ips = {}
        for set_name in set(_SET_BY_ENVIRONMENT.values()):
            key = sorted(
                [
                    env for env in _SET_BY_ENVIRONMENT
                    if _SET_BY_ENVIRONMENT[env] == set_name
                ]
            )
            container_env_ips[tuple(key)] = set()

        for set_envs, set_ips in six.viewitems(container_env_ips):
            for device in six.viewvalues(self._devices):
                if device['environment'] not in set_envs:
                    continue
                set_ips.add(device['ip'])

        for set_envs, set_ips in six.viewitems(container_env_ips):
            iptables.atomic_set(
                _SET_BY_ENVIRONMENT[set_envs[0]],
                set_ips,
                set_type='hash:ip',
                family='inet', hashsize=1024, maxelem=65536
            )

        # It is now safe to clean up all remaining vIPs without resource.
        self._vips.garbage_collect()

        # Read bridge status
        self._bridge_mtu = netdev.dev_mtu(self._TMBR_DEV) 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:44,代码来源:network_service.py

示例14: priv_utilization_queue

# 需要导入模块: import six [as 别名]
# 或者: from six import viewvalues [as 别名]
def priv_utilization_queue(self):
        """Returns tuples for sorted by global utilization.

        Apps in the queue are ordered by priority, insertion order.

        Adding or removing maintains invariant that apps utilization
        monotonically increases as well.

        Returns local prioritization queue in a tuple where first element is
        utilization ratio, so that this queue is suitable for merging into
        global priority queue.
        """
        def _app_key(app):
            """Compares apps by priority, state, global index
            """
            return (-app.priority, 0 if app.server else 1,
                    app.global_order, app.name)

        prio_queue = sorted(six.viewvalues(self.apps), key=_app_key)

        acc_demand = zero_capacity()
        available = self.reserved + np.finfo(float).eps
        util_before = utilization(acc_demand, self.reserved, available)

        for app in prio_queue:
            acc_demand = acc_demand + app.demand
            util_after = utilization(acc_demand, self.reserved, available)
            # Priority 0 apps are treated specially - utilization is set to
            # max float.
            #
            # This ensures that they are at the end of the all queues.
            if app.priority == 0:
                util_before = _MAX_UTILIZATION
                util_after = _MAX_UTILIZATION

            # All things equal, already scheduled applications have priority
            # over pending.
            pending = 0 if app.server else 1
            if util_after <= self.max_utilization - 1:
                rank = self.rank
                if util_before < 0:
                    rank -= self.rank_adjustment
            else:
                rank = _UNPLACED_RANK

            entry = (rank, util_before, util_after, pending, app.global_order,
                     app)

            util_before = util_after
            yield entry 
开发者ID:Morgan-Stanley,项目名称:treadmill,代码行数:52,代码来源:__init__.py


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