當前位置: 首頁>>代碼示例>>Python>>正文


Python statistics.pstdev方法代碼示例

本文整理匯總了Python中statistics.pstdev方法的典型用法代碼示例。如果您正苦於以下問題:Python statistics.pstdev方法的具體用法?Python statistics.pstdev怎麽用?Python statistics.pstdev使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在statistics的用法示例。


在下文中一共展示了statistics.pstdev方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: diagnosticity

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def diagnosticity(evaluations):
    """Return the diagnosticity of a piece of evidence given its evaluations against a set of hypotheses.

    :param evaluations: an iterable of iterables of Eval for a piece of evidence
    """
    # The "diagnosticity" needs to capture how well the evidence separates/distinguishes the hypotheses. If we don't
    # show a preference between consistent/inconsistent, STDDEV captures this intuition OK. However, in the future,
    # we may want to favor evidence for which hypotheses are inconsistent. Additionally, we may want to calculate
    # "marginal diagnosticity" which takes into the rest of the evidence.
    # (1) calculate the consensus for each hypothesis
    # (2) map N/A to neutral because N/A doesn't help determine consistency of the evidence
    # (3) calculate the population standard deviation of the evidence. It's more reasonable to consider the set of
    #     hypotheses at a given time to be the population of hypotheses than as a "sample" (although it doesn't matter
    #     much because we're comparing across hypothesis sets of the same size)
    na_neutral = map(mean_na_neutral_vote, evaluations)  # pylint: disable=bad-builtin
    try:
        return statistics.pstdev(filter(None.__ne__, na_neutral))  # pylint: disable=bad-builtin
    except statistics.StatisticsError:
        return 0.0 
開發者ID:twschiller,項目名稱:open-synthesis,代碼行數:21,代碼來源:metrics.py

示例2: sharpRatio

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def sharpRatio(
        _returns: DataStruct,
        _factor: int = 252,
        _risk_free: float = 0.0,
        _fund_index: str = 'fund'
) -> float:
    fund = _returns[_fund_index]
    tmp_list = [
        a / b - 1.0 - _risk_free for a, b in zip(
            fund[1:], fund[:-1]
        )
    ]
    return statistics.mean(
        tmp_list
    ) / statistics.pstdev(
        tmp_list
    ) * math.sqrt(_factor) 
開發者ID:ppaanngggg,項目名稱:ParadoxTrading,代碼行數:19,代碼來源:Functions.py

示例3: _addOne

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        price_value = _data_struct[self.use_key][0]
        if self.last_price is not None:
            chg_rate = price_value / self.last_price - 1
            self.buf.append(chg_rate)

            std_value = statistics.pstdev(self.buf) * self.factor
            if self.smooth > 1 and len(self.data):
                last_std_value = self.data[self.ret_key][-1]
                std_value = (
                    (self.smooth - 1) * last_std_value + std_value
                ) / self.smooth

            self.data.addDict({
                self.idx_key: index_value,
                self.ret_key: std_value,
            })
        self.last_price = price_value 
開發者ID:ppaanngggg,項目名稱:ParadoxTrading,代碼行數:21,代碼來源:Volatility.py

示例4: debias

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def debias(fragments):
    if CLI_ARGS.debias is not None:
        for debias in CLI_ARGS.debias:
            grouped = engroup(fragments, lambda f: f.meta[debias])
            if UNKNOWN in grouped:
                fragments = grouped[UNKNOWN]
                del grouped[UNKNOWN]
            else:
                fragments = []
            counts = list(map(lambda f: len(f), grouped.values()))
            mean = statistics.mean(counts)
            sigma = statistics.pstdev(counts, mu=mean)
            cap = int(mean + CLI_ARGS.debias_sigma_factor * sigma)
            counter = Counter()
            for group, group_fragments in progress(grouped.items(), desc='De-biasing "{}"'.format(debias)):
                if len(group_fragments) > cap:
                    group_fragments.sort(key=lambda f: f.quality)
                    counter[group] += len(group_fragments) - cap
                    group_fragments = group_fragments[-cap:]
                fragments.extend(group_fragments)
            if len(counter.keys()) > 0:
                logging.info('Dropped for de-biasing "{}":'.format(debias))
                for group, count in counter.most_common():
                    logging.info(' - "{}": {}'.format(group, count))
    return fragments 
開發者ID:mozilla,項目名稱:DSAlign,代碼行數:27,代碼來源:export.py

示例5: calculate_time_differences_std

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def calculate_time_differences_std(timestamp_list):
    if len(timestamp_list) == 1:
        time_differences_std = 0.0
    else:
        timestamp_differences = get_timestamp_differences(timestamp_list)
        time_differences_std = statistics.pstdev(timestamp_differences)
    return time_differences_std 
開發者ID:MKLab-ITI,項目名稱:news-popularity-prediction,代碼行數:9,代碼來源:temporal.py

示例6: update_time_difference_std

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def update_time_difference_std(timestamp_differences):
    """
    Time difference standard deviation update.

    Input:  - timestamp_differences: The list of all action timestamp differences.

    Output: - time_difference_std: The time difference standard deviation.
    """
    time_difference_std = statistics.pstdev(timestamp_differences)
    return time_difference_std 
開發者ID:MKLab-ITI,項目名稱:news-popularity-prediction,代碼行數:12,代碼來源:temporal.py

示例7: stdev

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def stdev(arr):
    """
    Compute the standard deviation.
    """
    if sys.version_info >= (3, 0):
        import statistics
        return statistics.pstdev(arr)
    else:
        # Dependency on NumPy
        try:
            import numpy
            return numpy.std(arr, axis=0)
        except ImportError:
            return 0. 
開發者ID:bchretien,項目名稱:vim-profiler,代碼行數:16,代碼來源:vim-profiler.py

示例8: pstdev

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def pstdev(self):
        return statistics.pstdev(self.price)

    # 調和平均數 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:6,代碼來源:QAAnalysis_dataframe.py

示例9: pstdev

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def pstdev(self):
        '返回DataStruct.price的總體標準差 Population standard deviation'
        res = self.price.groupby(level=1).apply(lambda x: statistics.pstdev(x))
        res.name = 'pstdev'
        return res

    # 調和平均數 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:9,代碼來源:base_datastruct.py

示例10: calculate_everything

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def calculate_everything(arg):

    average = statistics.mean(arg)
    minimum = min(arg)
    maximum = max(arg)
    standard_deviation = statistics.pstdev(arg)
    return [average, minimum, maximum, standard_deviation] 
開發者ID:jbaltop,項目名稱:57_Challenges,代碼行數:9,代碼來源:36_2.py

示例11: zscores

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def zscores(original: Sequence[float]) -> List[float]:
    avg: float = mean(original)
    std: float = pstdev(original)
    if std == 0: # return all zeros if there is no variation
        return [0] * len(original)
    return [(x - avg) / std for x in original] 
開發者ID:davecom,項目名稱:ClassicComputerScienceProblemsInPython,代碼行數:8,代碼來源:kmeans.py

示例12: stats

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def stats(self):
        # Compute statistics
        ep_stats = self._episodes_stats()
        steps_stats = self._steps_stats(update_index=True)

        # Overall stats
        num_logs = len(self.all_rewards) // self.interval
        msg = '-' * 20 + ' ' + self.title + ' Log ' + str(num_logs) + ' ' + '-' * 20 + '\n'
        msg += 'Overall:' + '\n'
        msg += '- Steps: ' + str(self.num_steps) + '\n'
        msg += '- Episodes: ' + str(self.num_episodes) + '\n'

        # Episodes stats
        msg += 'Last ' + str(self.ep_interval) + ' Episodes:' + '\n'
        msg += '- Mean episode length: ' + '%.2f' % mean(ep_stats['episode_lengths'])
        msg += ' +/- ' + '%.2f' % pstdev(ep_stats['episode_lengths']) + '\n'
        msg += '- Mean episode reward: ' + '%.2f' % mean(ep_stats['episode_rewards'])
        msg += ' +/- ' + '%.2f' % pstdev(ep_stats['episode_rewards']) + '\n'

        # Steps stats
        msg += 'Last ' + str(self.interval) + ' Steps:' + '\n'
        msg += '- Episodes: ' + str(steps_stats['num_episodes']) + '\n'
        msg += '- Mean episode length: ' + '%.2f' % mean(steps_stats['episode_lengths'])
        msg += ' +/- ' + '%.2f' % pstdev(steps_stats['episode_lengths']) + '\n'
        msg += '- Mean episode reward: ' + '%.2f' % mean(steps_stats['episode_rewards'])
        msg += ' +/- ' + '%.2f' % pstdev(steps_stats['episode_rewards']) + '\n'
        for key in self.values.keys():
            msg += '- Mean ' + key + ': ' + '%.2f' % mean(steps_stats[key])
            msg += ' +/- ' + '%.2f' % pstdev(steps_stats[key]) + '\n'
        return msg, ep_stats, steps_stats 
開發者ID:learnables,項目名稱:cherry,代碼行數:32,代碼來源:logger_wrapper.py

示例13: _addOne

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])
        self.data.addDict({
            self.idx_key: index_value,
            self.ret_key: statistics.pstdev(self.buf),
        }) 
開發者ID:ppaanngggg,項目名稱:ParadoxTrading,代碼行數:9,代碼來源:STD.py

示例14: _addOne

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])

        if len(self.data) > self.period:
            const_std = statistics.pstdev(self.buf[-self.period:])
            self.dynamic_n *= const_std / self.prev_std
            self.dynamic_n = max(self.min_n, self.dynamic_n)
            self.dynamic_n = min(self.max_n, self.dynamic_n)
            tmp_n = int(round(self.dynamic_n))

            mean = statistics.mean(self.buf[-tmp_n:])
            std = statistics.pstdev(self.buf[-tmp_n:])

            self.data.addRow(
                [index_value, mean + self.rate * std,
                 mean, mean - self.rate * std],
                self.keys
            )

            self.prev_std = const_std
        else:
            if len(self.data) == self.period:
                self.prev_std = statistics.pstdev(self.buf)

            self.data.addRow(
                [index_value, None, None, None],
                self.keys
            ) 
開發者ID:ppaanngggg,項目名稱:ParadoxTrading,代碼行數:31,代碼來源:AdaBBands.py

示例15: _addOne

# 需要導入模塊: import statistics [as 別名]
# 或者: from statistics import pstdev [as 別名]
def _addOne(self, _data_struct: DataStruct):
        index_value = _data_struct.index()[0]
        self.buf.append(_data_struct.getColumn(self.use_key)[0])
        mean = statistics.mean(self.buf)
        std = statistics.pstdev(self.buf, mu=mean)
        self.data.addRow([
            index_value, mean + self.rate * std, mean, mean - self.rate * std
        ], self.keys) 
開發者ID:ppaanngggg,項目名稱:ParadoxTrading,代碼行數:10,代碼來源:BBands.py


注:本文中的statistics.pstdev方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。