當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。