koder aka kdanilov | 6c49106 | 2015-04-09 22:33:13 +0300 | [diff] [blame] | 1 | import math |
| 2 | import itertools |
| 3 | from numpy.polynomial.chebyshev import chebfit, chebval |
| 4 | |
| 5 | |
| 6 | def med_dev(vals): |
| 7 | med = sum(vals) / len(vals) |
| 8 | dev = ((sum(abs(med - i) ** 2.0 for i in vals) / len(vals)) ** 0.5) |
| 9 | return med, dev |
| 10 | |
| 11 | |
| 12 | def round_deviation(med_dev): |
| 13 | med, dev = med_dev |
| 14 | |
| 15 | if dev < 1E-7: |
| 16 | return med_dev |
| 17 | |
| 18 | dev_div = 10.0 ** (math.floor(math.log10(dev)) - 1) |
| 19 | dev = int(dev / dev_div) * dev_div |
| 20 | med = int(med / dev_div) * dev_div |
| 21 | return (type(med_dev[0])(med), |
| 22 | type(med_dev[1])(dev)) |
| 23 | |
| 24 | |
| 25 | def groupby_globally(data, key_func): |
| 26 | grouped = {} |
| 27 | grouped_iter = itertools.groupby(data, key_func) |
| 28 | |
| 29 | for (bs, cache_tp, act, conc), curr_data_it in grouped_iter: |
| 30 | key = (bs, cache_tp, act, conc) |
| 31 | grouped.setdefault(key, []).extend(curr_data_it) |
| 32 | |
| 33 | return grouped |
| 34 | |
| 35 | |
| 36 | def approximate_curve(x, y, xnew, curved_coef): |
| 37 | """returns ynew - y values of some curve approximation""" |
| 38 | return chebval(xnew, chebfit(x, y, curved_coef)) |
| 39 | |
| 40 | |
| 41 | def approximate_line(x, y, xnew, relative_dist=False): |
| 42 | """returns ynew - y values of linear approximation""" |
| 43 | |
| 44 | |
| 45 | def difference(y, ynew): |
| 46 | """returns average and maximum relative and |
| 47 | absolute differences between y and ynew""" |
| 48 | |
| 49 | |
| 50 | def calculate_distribution_properties(data): |
| 51 | """chi, etc""" |
| 52 | |
| 53 | |
| 54 | def minimal_measurement_amount(data, max_diff, req_probability): |
| 55 | """ |
| 56 | should returns amount of measurements to get results (avg and deviation) |
| 57 | with error less, that max_diff in at least req_probability% cases |
| 58 | """ |