Python statistics.pstdev() Examples
The following are 30
code examples of statistics.pstdev().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
statistics
, or try the search function
.
Example #1
Source File: export.py From DSAlign with Mozilla Public License 2.0 | 6 votes |
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
Example #2
Source File: Functions.py From ParadoxTrading with MIT License | 6 votes |
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)
Example #3
Source File: Volatility.py From ParadoxTrading with MIT License | 6 votes |
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
Example #4
Source File: metrics.py From open-synthesis with GNU General Public License v3.0 | 6 votes |
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
Example #5
Source File: test_statistics.py From mpyc with MIT License | 5 votes |
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()))
Example #6
Source File: test_statistics.py From rotest with MIT License | 5 votes |
def remove_anomalies(durations): """Return a list with less anomalies in the numeric values. Args: durations (list): list of numeric values. Returns: list. list with less anomalies. """ avg = (mean(durations) + median(durations)) / 2 deviation = pstdev(durations) cut_off = deviation * CUT_OFF_FACTOR lower_limit = avg - cut_off upper_limit = avg + cut_off return [x for x in durations if lower_limit < x < upper_limit]
Example #7
Source File: codespeedinfo.py From scrapy-bench with MIT License | 5 votes |
def uploadresult(test, w): commit = get_latest_commit('scrapy', 'scrapy') data = { 'commitid': commit['html_url'].rsplit('/', 1)[-1], 'branch': 'default', # Always use default for trunk/master/tip 'project': 'Scrapy-Bench', 'executable': 'bench.py', 'benchmark': test, 'environment': get_env(), 'result_value': statistics.mean(w), } data.update({ 'revision_date': current_date, # Optional. Default is taken either # from VCS integration or from current date 'result_date': current_date, # Optional, default is current date 'std_dev': statistics.pstdev(w), # Optional. Default is blank #'max': 4001.6, # Optional. Default is blank #'min': 3995.1, # Optional. Default is blank }) params = urllib.urlencode(data).encode("utf-8") response = "None" print("Saving result for executable %s, revision %s, benchmark %s" % ( data['executable'], data['commitid'], data['benchmark'])) f = urllib2.urlopen(CODESPEED_URL + 'result/add/', params) response = f.read() f.close() print("Server (%s) response: %s\n" % (CODESPEED_URL, response))
Example #8
Source File: vim-plugins-profile.py From vim-plugins-profile with GNU General Public License v3.0 | 5 votes |
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.
Example #9
Source File: SeriouslyCommands.py From Seriously with MIT License | 5 votes |
def D_fn(srs): a = srs.pop() if isinstance(a, collections.Iterable) and not isinstance(a, str): srs.push(pstdev(a)) elif isinstance(a, str): if len(a) == 1: srs.push(chr_cp437(ord_cp437(a)-1%256)) else: srs.push(a-1)
Example #10
Source File: Code Counter.py From PySimpleGUI with GNU Lesser General Public License v3.0 | 5 votes |
def display_stats(code_stats, window): """ display code stats in the window """ window['LINES'].update('{:,d}'.format(code_stats['lines'])) window['CHARS'].update('{:,d}'.format(code_stats['count'])) window['CPL'].update('{:,d}'.format(code_stats['char_per_line'])) window['MEAN'].update('{:,.0f}'.format(code_stats['mean'])) window['MEDIAN'].update('{:,.0f}'.format(code_stats['median'])) window['PSTDEV'].update('{:,.0f}'.format(code_stats['pstdev'])) window['MAX'].update('{:,d}'.format(code_stats['max'])) window['MIN'].update('{:,d}'.format(code_stats['min']))
Example #11
Source File: stats.py From Turing with MIT License | 5 votes |
def stand_dev(lst): return statistics.pstdev(lst)
Example #12
Source File: statistics.py From mpyc with MIT License | 5 votes |
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)
Example #13
Source File: test_statistics.py From mpyc with MIT License | 5 votes |
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
Example #14
Source File: test_statistics.py From mpyc with MIT License | 5 votes |
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)))
Example #15
Source File: test_statistics.py From mpyc with MIT License | 5 votes |
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, [])
Example #16
Source File: statistic_functions.py From jhTAlib with GNU General Public License v3.0 | 5 votes |
def PSTDEV(df, n, price='Close', mu=None): """ Population standard deviation of data Returns: list of floats = jhta.PSTDEV(df, n, price='Close', mu=None) """ pstdev_list = [] if n == len(df[price]): start = None for i in range(len(df[price])): if df[price][i] != df[price][i]: pstdev = float('NaN') else: if start is None: start = i end = i + 1 pstdev = statistics.pstdev(df[price][start:end], mu) pstdev_list.append(pstdev) else: for i in range(len(df[price])): if i + 1 < n: pstdev = float('NaN') else: start = i + 1 - n end = i + 1 pstdev = statistics.pstdev(df[price][start:end], mu) pstdev_list.append(pstdev) return pstdev_list
Example #17
Source File: BBands.py From ParadoxTrading with MIT License | 5 votes |
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)
Example #18
Source File: AdaBBands.py From ParadoxTrading with MIT License | 5 votes |
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 )
Example #19
Source File: STD.py From ParadoxTrading with MIT License | 5 votes |
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), })
Example #20
Source File: logger_wrapper.py From cherry with Apache License 2.0 | 5 votes |
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
Example #21
Source File: kmeans.py From ClassicComputerScienceProblemsInPython with Apache License 2.0 | 5 votes |
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]
Example #22
Source File: 36_2.py From 57_Challenges with MIT License | 5 votes |
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]
Example #23
Source File: base_datastruct.py From QUANTAXIS with MIT License | 5 votes |
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 # 调和平均数
Example #24
Source File: QAAnalysis_dataframe.py From QUANTAXIS with MIT License | 5 votes |
def pstdev(self): return statistics.pstdev(self.price) # 调和平均数
Example #25
Source File: vim-profiler.py From vim-profiler with GNU General Public License v3.0 | 5 votes |
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.
Example #26
Source File: temporal.py From news-popularity-prediction with Apache License 2.0 | 5 votes |
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
Example #27
Source File: temporal.py From news-popularity-prediction with Apache License 2.0 | 5 votes |
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
Example #28
Source File: Code Counter.py From PySimpleGUI with GNU Lesser General Public License v3.0 | 4 votes |
def clean_data(window): """ clean and parse the raw data """ raw = window.AllKeysDict['INPUT'].DefaultText.split('\n') # remove whitespace data = [row.strip() for row in raw if row.strip()] # remove hash comments stage1 = [] for row in data: if row.find('#') != -1: stage1.append(row[:row.find('#')]) else: stage1.append(row) # remove " multiline comments stage2 = [] ml_flag = False # multiline comment flag for row in stage1: if row.count(r'"""') == 0 and not ml_flag: # not a comment line stage2.append(row) elif row.count(r'"""') == 1 and not ml_flag: # starting comment line ml_flag = True stage2.append(row[:row.find('"""')]) elif row.count(r'"""') == 1 and ml_flag: # ending comment line ml_flag = False stage2.append(row[row.find('"""') + 1:]) else: continue # remove ' multiline comments stage3 = [] ml_flag = False # multiline comment flag for row in stage2: if row.count(r"'''") == 0 and not ml_flag: # not a comment line stage3.append(row) elif row.count(r"'''") == 1 and not ml_flag: # starting comment line ml_flag = True stage3.append(row[:row.find("'''")]) elif row.count(r"'''") == 1 and ml_flag: # ending comment line ml_flag = False stage3.append(row[row.find("'''") + 1:]) else: continue clean_code = [row for row in stage3 if row not in ('', "''", '""')] # row and character rounds / for calc stats, histogram, charts char_cnt = [len(row) for row in clean_code] # statistics if len(clean_code) == 0: char_per_line = 1 else: char_per_line = sum(char_cnt) // len(clean_code) code_stats = { 'lines': len(clean_code), 'char_per_line': char_per_line, 'count': sum(char_cnt), 'mean': stats.mean(char_cnt), 'median': stats.median(char_cnt), 'pstdev': stats.pstdev(char_cnt), 'min': min(char_cnt), 'max': max(char_cnt)} return clean_code, char_cnt, code_stats
Example #29
Source File: __init__.py From tbot with GNU General Public License v3.0 | 4 votes |
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} """ )
Example #30
Source File: bench.py From scrapy-bench with MIT License | 4 votes |
def calculator( test, arg, n_runs, only_result, upload_result=False, vmprof=False, workpath=os.getcwd()): w = [] command = 'python {}'.format(arg) if vmprof: command = 'python -m vmprof --web {}'.format(arg) for x in range(n_runs): if only_result: process = subprocess.Popen( command, cwd=workpath, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) process.wait() else: process = subprocess.Popen(command, cwd=workpath, shell=True) process.wait() with open(os.path.join(workpath, "Benchmark.txt")) as f: for line in f.readlines(): w.append(float(line)) click.secho( "\nThe results of the benchmark are (all speeds in items/sec) : \n", bold=True) click.secho( "\nTest = '{0}' Iterations = '{1}'\n".format(test, n_runs), bold=True) click.secho( "\nMean : {0} Median : {1} Std Dev : {2}\n".format( statistics.mean(w), statistics.median(w), statistics.pstdev(w)), bold=True) if upload_result: codespeedinfo.uploadresult(test, w) os.remove(os.path.join(workpath, "Benchmark.txt"))