-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathequipartition.py
More file actions
55 lines (42 loc) · 1.55 KB
/
equipartition.py
File metadata and controls
55 lines (42 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import argparse
import math
import numpy
from fit import read_stats
def main(args):
x_data, y_data = read_stats(sys.stdin, args.xmin, args.xmax,
normalize=False, swap=args.swap)
x_min = numpy.min(x_data)
x_max = numpy.max(x_data)
total = y_data.sum()
s = 0.0
j = 1
for i in range(len(x_data)):
p = y_data[i]
x = x_data[i]
s += p
if s*args.n > j*total:
j += 1
print(x, end=' ')
print("")
return 0
if __name__ == "__main__":
class MyFormatter(argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter):
pass
parser = argparse.ArgumentParser(
description="""Finds equiprobabilistic partitions.
Author: Gábor Borbély, License: MIT
Contact: http://math.bme.hu/~borbely/indexeng""",
formatter_class=MyFormatter)
parser.add_argument('-m', "--max", dest='xmax', type=int, default=100,
help='maximum sentence length')
parser.add_argument("-min", "--min", dest='xmin', type=int, default=1,
help='minimum sentence length')
parser.add_argument('-s', '--swap', dest='swap', default=False,
help='swap columns in input', action='store_true')
parser.add_argument('-n', dest='n', default=10,
help='number of bins', type=int)
exit(main(parser.parse_args()))