def size_vs_error():
    #d, w = 25, 7
    #print("Sketch: d=%s w=%s (Cmp. size: %s%%)" % (d, w, (float(100*d*w)/1000)))

    # Setup the crypto
    G = EcGroup()
    sec = G.order().random()
    y = sec * G.generator()

    # Get some test data
    narrow_vals = 1000
    wide_vals = 200

    from numpy.random import laplace    
    from collections import defaultdict

    
    datapoints = defaultdict(list)
    sizes = defaultdict(list)

    eps = [0.5, 0.35, 0.25, 0.15, 0.1, 0.05, 0.025, 0.01]  #, 0.005, 0.001]
    for epsilon in eps:
        print epsilon

        for _ in range(40):
            vals = [gauss(300, 25) for _ in range (narrow_vals)]
            vals += [gauss(500, 200) for _ in range (wide_vals)]
            vals = sorted([int(v) for v in vals])

            median = vals[int(len(vals) / 2)]

            # Add each sample to the sketch
            # cs = CountSketchCt(d, w, y)
            cs = CountSketchCt.epsilondelta(epsilon, epsilon, y)
            sizes[epsilon] += [ float(100*cs.d*cs.w) / 1000 ]
            for x in vals:
                cs.insert("%s" % x)

            # Now use test the median function
            proto = get_median(cs, min_b = 0, max_b = 1000, steps = 20)

            plain = None
            no_decryptions = 0
            while True:
                v = proto.send(plain)
                if isinstance(v, int):
                    break
                no_decryptions += 1

                noise = 0
                plain = v.dec(sec) + noise

            print("Estimated median: %s\t\tAbs. Err: %s" % (v, abs(v - median)))
            datapoints[epsilon] += [ 100 * float(abs(v - median)) / median ] 

    lower_err, core_err, upper_err = analyze_series(eps, datapoints)
    lower_siz, core_siz, upper_siz = analyze_series(eps, sizes)

    import matplotlib.pyplot as plt

    eps_lab = range(len(eps))


    plt.plot(eps, core_err, label="Error (%)")
    plt.xscale('log')
    # v = v_issue / (len(cnt_issue)**0.5)
    plt.fill_between(x=eps, y1=lower_err, y2=upper_err, alpha=0.2, color="b")
    plt.xticks(eps, eps)


    plt.plot(eps, core_siz, label=r"Size (%)")
    # plt.yscale('log')
    # v = v_issue / (len(cnt_issue)**0.5)
    plt.fill_between(x=eps, y1=lower_siz, y2=upper_siz, alpha=0.2, color="b")
    # plt.xticks(eps_lab, eps)

    plt.xlabel(r'(epsilon, delta) parameter of Count-Sketch')
    plt.ylabel(r'%')
    plt.title(r'Median Estimation - Error vs. Size')
    # plt.axis([1, 10, 0, 1700])
    #plt.grid(True)
    plt.legend(loc="upper center")

    plt.savefig("Size.pdf")

    # plt.show()
    plt.close()
    # print core_err
dataset/ETHPy150Open gdanezis/petlib/examples/tormedian.py/size_vs_error/original