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


Python statistics.pvariance方法代码示例

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


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

示例1: DVOLA

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def DVOLA(df, n=30, price='Close'):
    """
    Daily Volatility
    Returns: list of floats = jhta.DVOLA(df, n=30, price='Close')
    Source: https://www.wallstreetmojo.com/volatility-formula/
    """
    dvola_list = []
    for i in range(len(df[price])):
        if i + 1 < n:
            dvola = float('NaN')
        else:
            start = i + 1 - n
            end = i + 1
            pvariance = statistics.pvariance(df[price][start:end])
            dvola = math.sqrt(pvariance)
        dvola_list.append(dvola)
    return dvola_list 
开发者ID:joosthoeks,项目名称:jhTAlib,代码行数:19,代码来源:volatility_indicators.py

示例2: pvariance

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def pvariance(self):
        return statistics.pvariance(self.price)

    # 方差 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:6,代码来源:QAAnalysis_dataframe.py

示例3: pvariance

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def pvariance(self):
        '返回DataStruct.price的方差 variance'
        res = self.price.groupby(level=1
                                 ).apply(lambda x: statistics.pvariance(x))
        res.name = 'pvariance'
        return res

    # 方差 
开发者ID:QUANTAXIS,项目名称:QUANTAXIS,代码行数:10,代码来源:base_datastruct.py

示例4: test_compare_to_variance

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def test_compare_to_variance(self):
        # Test that stdev is, in fact, the square root of variance.
        data = [random.uniform(-17, 24) for _ in range(1000)]
        expected = math.sqrt(statistics.pvariance(data))
        self.assertEqual(self.func(data), expected) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:7,代码来源:test_statistics.py

示例5: PVARIANCE

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def PVARIANCE(df, n, price='Close', mu=None):
    """
    Population variance of data
    Returns: list of floats = jhta.PVARIANCE(df, n, price='Close', mu=None)
    """
    pvariance_list = []
    if n == len(df[price]):
        start = None
        for i in range(len(df[price])):
            if df[price][i] != df[price][i]:
                pvariance = float('NaN')
            else:
                if start is None:
                    start = i
                end = i + 1
                pvariance = statistics.pvariance(df[price][start:end], mu)
            pvariance_list.append(pvariance)
    else:
        for i in range(len(df[price])):
            if i + 1 < n:
                pvariance = float('NaN')
            else:
                start = i + 1 - n
                end = i + 1
                pvariance = statistics.pvariance(df[price][start:end], mu)
            pvariance_list.append(pvariance)
    return pvariance_list 
开发者ID:joosthoeks,项目名称:jhTAlib,代码行数:29,代码来源:statistic_functions.py

示例6: test_plain

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def test_plain(self):
        f = lambda: (i * j for i in range(-1, 2, 1) for j in range(2, -2, -1))
        self.assertEqual(mean(f()), statistics.mean(f()))
        self.assertEqual(variance(f()), statistics.variance(f()))
        self.assertEqual(stdev(f()), statistics.stdev(f()))
        self.assertEqual(pvariance(f()), statistics.pvariance(f()))
        self.assertEqual(pstdev(f()), statistics.pstdev(f()))
        self.assertEqual(mode(f()), statistics.mode(f()))
        self.assertEqual(median(f()), statistics.median(f())) 
开发者ID:lschoe,项目名称:mpyc,代码行数:11,代码来源:test_statistics.py

示例7: test_statistics_error

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def test_statistics_error(self):
        self.assertRaises(statistics.StatisticsError, mean, [])
        self.assertRaises(statistics.StatisticsError, variance, [0])
        self.assertRaises(statistics.StatisticsError, stdev, [0])
        self.assertRaises(statistics.StatisticsError, pvariance, [])
        self.assertRaises(statistics.StatisticsError, pstdev, [])
        self.assertRaises(statistics.StatisticsError, mode, [])
        self.assertRaises(statistics.StatisticsError, median, []) 
开发者ID:lschoe,项目名称:mpyc,代码行数:10,代码来源:test_statistics.py

示例8: test_secint

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def test_secint(self):
        secint = mpc.SecInt()
        y = [1, 3, -2, 3, 1, -2, -2, 4] * 5
        random.shuffle(y)
        x = list(map(secint, y))
        self.assertEqual(mpc.run(mpc.output(mean(x))), round(statistics.mean(y)))
        self.assertEqual(mpc.run(mpc.output(variance(x))), round(statistics.variance(y)))
        self.assertEqual(mpc.run(mpc.output(variance(x, mean(x)))), round(statistics.variance(y)))
        self.assertEqual(mpc.run(mpc.output(stdev(x))), round(statistics.stdev(y)))
        self.assertEqual(mpc.run(mpc.output(pvariance(x))), round(statistics.pvariance(y)))
        self.assertEqual(mpc.run(mpc.output(pstdev(x))), round(statistics.pstdev(y)))
        self.assertEqual(mpc.run(mpc.output(mode(x))), round(statistics.mode(y)))
        self.assertEqual(mpc.run(mpc.output(median(x))), round(statistics.median(y)))
        self.assertEqual(mpc.run(mpc.output(median_low(x))), round(statistics.median_low(y)))
        self.assertEqual(mpc.run(mpc.output(median_high(x))), round(statistics.median_high(y))) 
开发者ID:lschoe,项目名称:mpyc,代码行数:17,代码来源:test_statistics.py

示例9: test_secfxp

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def test_secfxp(self):
        secfxp = mpc.SecFxp()
        x = [1, 1, 2, 2, 3, 4, 4, 4, 6] * 5
        random.shuffle(x)
        x = list(map(secfxp, x))
        self.assertAlmostEqual(mpc.run(mpc.output(mean(x))).signed(), 3, delta=1)
        self.assertAlmostEqual(mpc.run(mpc.output(median(x))).signed(), 3)
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))).signed(), 4)

        x = [1, 1, 1, 1, 2, 2, 3, 4, 4, 4, 4, 5, 6, 6, 6] * 100
        random.shuffle(x)
        x = list(map(lambda a: a * 2**-4, x))
        x = list(map(secfxp, x))
        self.assertAlmostEqual(mpc.run(mpc.output(mean(x))).signed(), (2**-4) * 10/3, delta=1)

        y = [1.75, 1.25, -0.25, 0.5, 1.25, -3.5] * 5
        random.shuffle(y)
        x = list(map(secfxp, y))
        self.assertAlmostEqual(float(mpc.run(mpc.output(mean(x)))), statistics.mean(y), 4)
        self.assertAlmostEqual(float(mpc.run(mpc.output(variance(x)))), statistics.variance(y), 2)
        self.assertAlmostEqual(float(mpc.run(mpc.output(stdev(x)))), statistics.stdev(y), 3)
        self.assertAlmostEqual(float(mpc.run(mpc.output(pvariance(x)))), statistics.pvariance(y), 2)
        self.assertAlmostEqual(float(mpc.run(mpc.output(pstdev(x)))), statistics.pstdev(y), 3)
        self.assertAlmostEqual(float(mpc.run(mpc.output(median(x)))), statistics.median(y), 4)

        x = list(map(secfxp, [1.0]*10))
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))).signed(), 1)
        k = mpc.options.sec_param
        mpc.options.sec_param = 1  # force no privacy case
        self.assertAlmostEqual(mpc.run(mpc.output(mode(x))).signed(), 1)
        mpc.options.sec_param = k 
开发者ID:lschoe,项目名称:mpyc,代码行数:33,代码来源:test_statistics.py

示例10: variance

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def variance(data, xbar=None):
    """Return the sample variance of data, an iterable of at least two numbers.

    If the optional second argument xbar is given, it should be the mean of data.
    If it is missing or None (the default), the mean is automatically calculated.

    Use this function when your data is a sample from a population. To calculate
    the variance from the entire population, see pvariance().

    Raises StatisticsError if data has fewer than two values.
    """
    return _var(data, xbar, 1) 
开发者ID:lschoe,项目名称:mpyc,代码行数:14,代码来源:statistics.py

示例11: pstdev

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def pstdev(data, mu=None):
    """Return the population standard deviation (square root of the population variance).

    See pvariance() for arguments and other details.
    """
    return _std(data, mu, 0) 
开发者ID:lschoe,项目名称:mpyc,代码行数:8,代码来源:statistics.py

示例12: _var

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def _var(data, m, correction):
    if iter(data) is data:
        x = list(data)
    else:
        x = data
    n = len(x)
    if n < 1 + correction:
        if correction:
            e = 'variance requires at least two data points'
        else:
            e = 'pvariance requires at least one data point'
        raise statistics.StatisticsError(e)

    stype = type(x[0])  # all elts of x assumed of same type
    if issubclass(stype, sectypes.SecureFiniteField):
        raise TypeError('secure fixed-point or integer type required')

    if issubclass(stype, sectypes.SecureInteger):
        if m is None:
            s = runtime.sum(x)
            y = [a * n - s for a in x]  # TODO: runtime.scalar_mul(n,x) for public (int) n
            d = n**2 * (n - correction)
        else:
            y = runtime.vector_sub(x, [m] * n)  # TODO: runtime.vector_sub(x,y) for scalar y
            d = n - correction
        return (runtime.in_prod(y, y) + d//2) // d

    if issubclass(stype, sectypes.SecureFixedPoint):
        if m is None:
            m = mean(x)
        y = runtime.vector_sub(x, [m] * n)
        d = n - correction
        return runtime.in_prod(y, y) / d

    if correction:
        return statistics.variance(x, m)

    return statistics.pvariance(x, m) 
开发者ID:lschoe,项目名称:mpyc,代码行数:40,代码来源:statistics.py

示例13: variance

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def variance(lst):
    return statistics.pvariance(lst) 
开发者ID:TuringApp,项目名称:Turing,代码行数:4,代码来源:stats.py

示例14: time_testcase_statistics

# 需要导入模块: import statistics [as 别名]
# 或者: from statistics import pvariance [as 别名]
def time_testcase_statistics(
    testcase: typing.Callable,
    *args: typing.Any,
    runs: int = 10,
    sleep: float = 0,
    **kwargs: typing.Any,
) -> None:
    """
    Take multiple measurements about the run-time of a testcase and return/display statistics.

    :param testcase: Testcase to call.
    :param args,\\ kwargs: Arguments to pass to the testcase.
    :param int runs: How many samples to take.
    :param float sleep: How much time to sleep in between the runs.  Example
        use:  Maybe the board does not discharge quick enough so it can cause
        troubles when the subsecuent testcase run tries to boot again the board
    """

    elapsed_times = []

    for n in range(runs):
        elapsed_time, _ = time_testcase(testcase, *args, **kwargs)
        elapsed_times.append(elapsed_time)
        time.sleep(sleep)

    results = TimingResults(
        statistics.mean(elapsed_times),
        statistics.harmonic_mean(elapsed_times),
        statistics.median(elapsed_times),
        statistics.pvariance(elapsed_times),
        statistics.pstdev(elapsed_times),
    )

    tbot.log.message(
        f"""\
    Timing Results:
        {tbot.log.c('mean').green}: {results.mean}
        {tbot.log.c('harmonic mean').green}: {results.harmonic_mean}
        {tbot.log.c('median').green}: {results.median}
        {tbot.log.c('variance').green}: {results.pvariance}
        {tbot.log.c('standard deviation').green}: {results.pstdev}
    """
    ) 
开发者ID:Rahix,项目名称:tbot,代码行数:45,代码来源:__init__.py


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