Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)))
# Publishing in SONAR: http://docs.codehaus.org/pages/viewpage.action?pageId=229743270
import datetime
import json
import os.path
import statistics
import sys
import csv
from docopt import docopt
from utilities import VERSION
STATS_LAMBDAS = {"AVG": statistics.mean,
"MEDIAN": statistics.median,
"MEDIANHIGH": statistics.median_high,
"MEDIANLOW": statistics.median_low,
"MEDIANGROUPED": statistics.median_grouped,
"MODE": statistics.mode,
"STDEV": statistics.pstdev,
"VARIANCE": statistics.pvariance}
def metric_name_for_sorting(metric_name):
if ":" not in metric_name:
return metric_name
else:
parts = metric_name.split(":")
return parts[-1] + parts[0]
def process_csv_metrics (cmdline_arguments, max_values_allowed_by_metric):
violation_count = 0
highest_values_found_by_metric = {}
last_processed_metric = "" # fix for #21, to reuse values
#Topic ----
# importing the statistics module
import statistics
#%%Median is often referred to as the robust measure of central location and is less affected by the presence of outliers in data.
#statistics module in Python allows three options to deal with median / middle elements in a data set, which are median(), median_low() and median_high().
#The low median is always a member of the data set. When the number of data points is odd, the middle value is returned. When it is even, the smaller of the two middle values is returned.
#%%%
# simple list of a set of integers
set1 = [1, 3, 3, 4, 5, 7]
set1
# Note: low median will always be a member of the data-set.
# Print low median of the data-set
print("Low median of the data-set is % s " % (statistics.median_low(set1)))
# lie within the data-set
print("Median of the set is % s" % (statistics.median(set1)))
print("Low median of the data-set is % s " % (statistics.median_high(set1)))
#%%%
refactored_index = bin_max_index[0].max()
# special case: refactor maximum index, when there are multiple equal maximum values in histogram
max_histo_value = hist[refactored_index]
all_max_indices = []
for hist_index, hist_value in enumerate(hist):
if hist_value == max_histo_value:
all_max_indices.append(hist_index)
# adapt the index for special case, take the middle value in the distribution
# my_custom_median_index = np.where(all_max_indices == np.median(all_max_indices))
new_refactored_index = int(stats.median_low(all_max_indices))
# additional condition for setting breakpoint
if refactored_index != new_refactored_index:
refactored_index = new_refactored_index
values_in_this_bin = []
for index_ad, ad in enumerate(assigned_digits):
ad -= 1
if ad == refactored_index:
values_in_this_bin.append(original_values[index_ad])
mean_val = np.mean(values_in_this_bin)
final_mean = int(np.round(mean_val))
return final_mean
def sortSubListsAndMedian(A):
sortedList = []
medianList = []
for smallList in A:
sortedList.append(sorted(smallList))
medianList.append(statistics.median_low(smallList))
return sortedList, medianList
def median_low(text):
"""
Finds the low median of a space-separated list of numbers.
Example::
/median low 33 54 43 65 43 62
"""
return format_output(statistics.median_low(parse_numeric_list(text)))
def get_median_low(self):
"""See :py:func:`statistics.median_low`.
Examples
--------
>>> from iteration_utilities import Iterable
>>> Iterable(range(10)).get_median_low()
4
"""
return self._get_iter(statistics.median_low, 0)