Beispiel #1
0
import sys
from distance import squared_distance
from ioutils import read_strings
from strutils import words

if __name__ == "__main__":
    x = float(sys.argv[1])
    y = float(sys.argv[2])
    z = float(sys.argv[3])
    array = read_strings()
    res = []

    def closest(x, y, z, v1, v2):
        if squared_distance([x, y, z], v1) < squared_distance([x, y, z], v2):
            return v1
        return v2

    for line in array:
        [xi, yi, zi] = words(line)[0:3]
        [xi, yi, zi] = [float(xi), float(yi), float(zi)]
        if res == []:
            res = [xi, yi, zi]
        else:
            res = closest(x, y, z, res, [xi, yi, xi])

    print(res)
Beispiel #2
0
    parser = argparse.ArgumentParser(
        description='generate transition matrix given in stdin')
    parser.add_argument(
        'move_to_other_page_prob',
        type=float,
        help=
        'the probality for moving to another page through link instead of staying on the same page'
    )
    parser.add_argument(
        '--ignore-multiple-links',
        help='if multiple links present (from one to anotgher) ignore them',
        action='store_true')
    args = parser.parse_args()
    LOOP_PROBAB = 1 - args.move_to_other_page_prob
    TRANS_PROB = args.move_to_other_page_prob
    inp = read_strings()
    n = int(inp[0])
    links = as_tuples(inp[1:])
    if args.ignore_multiple_links:
        links = list(set(links))  #unique

    lnk_cnts = link_counts(n, links)
    # print(lnk_cnts)
    # print(degrees_vec(lnk_cnts))
    # print(loop_equi_probab(5,LOOP_PROBAB))
    # print(link_probab(lnk_cnts,TRANS_PROB))
    trns_matr = transition_matrix(n, links, LOOP_PROBAB)
    trns_matr = [normalize(row) for row in trns_matr]

    print(trns_matr)
    for line in lines:
        dig = int(leading_digit(line))
        freqs[dig] += 1
        count += 1
    freqs_array = [freqs[k] for k in range(0, 10)]
    freqs_array = [f / count for f in freqs_array]
    return freqs_array


def fake_benford():
    "Numbers from 1 to 1000"
    r = random.random() * 3
    return str(10**r)


if __name__ == "__main__":
    lines = read_strings()
    freqs_array = get_benford_dist(lines)
    print(freqs_array)

    plt.plot(range(1, 10), freqs_array[1:])

    theoritical_freq = [log(1 + 1 / d, 10) for d in range(1, 10)]
    plt.plot(range(1, 10), theoritical_freq)

    fake_lines = [fake_benford() for i in range(10000)]
    freqs_array = get_benford_dist(fake_lines)
    plt.plot(range(1, 10), freqs_array[1:])

    plt.show()
Beispiel #4
0
import sys
from Interval import Interval
from ioutils import read_strings

if __name__ == "__main__":
    x = float(sys.argv[1])
    strs = read_strings()
    for s in strs:
        flts = [float(x) for x in s.split()]
        intrvl = Interval(flts[0], flts[1])
        if x in intrvl:
            print(intrvl)