In [1]:
BELLOP = 'i1'
In [2]:
import matplotlib.pyplot as plt
import numpy as np
import json, csv
from functools import partial
#%config InlineBackend.figure_formats = ['svg']
In [3]:
import os
EXPORTDIR = 'data_export'
FIGUREDIR = 'figures'
os.makedirs(EXPORTDIR, exist_ok=True)
os.makedirs(FIGUREDIR, exist_ok=True)
def path_fig(filename):
    return os.path.join(FIGUREDIR, filename)
SAVEFIG_KWARGS = {'metadata':{'CreationDate':None}}
def path_export(filename):
    return os.path.join(EXPORTDIR, filename)
In [4]:
from IPython.display import Markdown as md, display, HTML
import html
import warnings
def report_error(message):
    display(md('<b style="font-size:5rem; color:red; line-height:5rem">{}</b>'.format(
        html.escape(message)
    )))

display(md(f'# Results for {BELLOP.upper()}'))

Results for I1

In [5]:
FIELDS = [BELLOP,'cond_entropy','cond_entropy_bound']

bell_val_bounds = {}
entropies_bounds = {}

with open(path_export(f'witness_bounds_{BELLOP}.tsv'), 'w', newline='') as outfile:
    csvwr = csv.writer(outfile, delimiter='\t')
    csvwr.writerow(FIELDS)
    for bound in range(0, 105, 5):
        entropies, bell_val = [], []
        bound /= 100
        with open(f'out_bell/bound_witnesses_{BELLOP}.{bound:.2f}.jsonl') as f:
            last = None
            for l in f:
                d = json.loads(l)
                entropies.append(d['cond_entropy'])
                bell_val.append(d[BELLOP])
                last = d
            if last:
                csvwr.writerow((last[BELLOP], last['cond_entropy'], -bound))
        bell_val_bounds[-bound] = bell_val
        entropies_bounds[-bound] = entropies
In [6]:
fig = plt.figure(figsize=(8,7))
for bound, bell_val in reversed(bell_val_bounds.items()):
    plt.plot(bell_val, label=str(bound))
plt.title(f'maximized {BELLOP.upper()}')
plt.xlabel('iterations (witness count)')
plt.ylabel(BELLOP.upper())
plt.grid()
plt.legend()
plt.show(fig)
fig.savefig(path_fig(f'witn_{BELLOP}_val.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [7]:
fig = plt.figure(figsize=(8,7))
for bound, entropies in entropies_bounds.items():
    plt.plot(entropies, label=str(bound))
plt.title(f'Entropies for maximized {BELLOP.upper()}')
plt.xlabel('iterations (witness count)')
plt.ylabel('conditional entropy')
plt.grid()
plt.legend()
plt.show(fig)
fig.savefig(path_fig(f'witn_{BELLOP}_entr.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)

Analiza wników seesaw z apkroksymacjami półokreślonymi entropii (apx $\pm$1)

In [8]:
def extract_by_keys(data, keys):
    return [ data[key] for key in keys ]

def read_data(path, extract_funcs):
    rows = []
    with open(path, 'r') as f:
        for line in f:
            try:
                row = []
                data = json.loads(line)
                for func in extract_funcs:
                    row += (
                            matrix_to_octave_str(value) if isinstance(value, list) else value
                            for value in func(data)
                            )
                rows.append(row)
            except json.JSONDecodeError as e:
                warnings.warn(f"Failed to decode line {len(rows)+1} in {path}: {e!r}")
                break
    return rows

def fields(bellop):
    return [bellop, 'cond_entropy','s_bound']

DATA_PATH_FMT = 'out_bell/{bellop}_seesaw_{bound}_{apx}.jsonl'
EXPECTED_ROWS = 100

incomplete_paths = []

def plot(bound, bellop=BELLOP):
    fig, ax = plt.subplots(figsize=(12, 7))
    ax.grid(True)
    handles = []
    stats = {'s_bound': bound}
    rowsum = 0
    for i, apx in enumerate((+1, -1)):
        data_path = DATA_PATH_FMT.format(bound=bound, apx=apx, bellop=bellop)
        try:
            rows = read_data(data_path,
                         [partial(extract_by_keys, keys=fields(bellop))])
        except FileNotFoundError as e:
            warnings.warn(f'{data_path}: {FileNotFoundError!r}')
            rows = []
        rowsum += len(rows)
        if len(rows) != EXPECTED_ROWS:
            incomplete_paths.append((data_path, len(rows)))
        if len(rows) == 0:
            report_error(f"Empty file: {data_path}")
            continue
        elif len(rows) < EXPECTED_ROWS:
            report_error(f"Only {len(rows)} lines read, but expected {EXPECTED_ROWS}: {data_path}")
        elif len(rows) > EXPECTED_ROWS:
            report_error(f"More lines ({len(rows)}) than expected ({EXPECTED_ROWS}): {data_path}")
        bell_vals, cond_entropy, s_bound = zip(*rows)
        if not (np.array(s_bound) == bound).all():
            print(s_bound, 'should be equal', bound)
        stats[f'max_entr_{apx:+}'], stats[f'min_entr_{apx:+}'] = max(cond_entropy), min(cond_entropy)
        stats[f'max_{bellop}_{apx:+}'], stats[f'min_{bellop}_{apx:+}'] = max(bell_vals), min(bell_vals)
        handles[i:i] = ax.plot(cond_entropy, bell_vals, '.', markersize=4., label=f'{bound} apx={apx}')
    lim = plt.ylim()
    ax.vlines(bound, -10, 10)
    plt.ylim(lim)
    ax.legend(handles=handles)
    ax.set_ylabel(bellop.upper())
    ax.set_xlabel('conditional entropy')
    if rowsum != 0:
        plt.show(fig)
    plt.close(fig)
    return stats
In [9]:
records = []
for b in np.linspace(-1,0,21).round(12):
    records.append(plot(b))
In [10]:
from pprint import pprint
pprint(incomplete_paths)
[]
In [11]:
if len(incomplete_paths) > 0:
       report_error('Incomplete files:')
print(' '.join(path for path, count in incomplete_paths))

In [12]:
import pandas as pd
stats = pd.DataFrame.from_records(records)
In [13]:
pd.set_option("precision", 7)
stats
Out[13]:
s_bound max_entr_+1 min_entr_+1 max_i1_+1 min_i1_+1 max_entr_-1 min_entr_-1 max_i1_-1 min_i1_-1
0 -1.00 -1.0000000 -1.0000000 6.1961523 6.1961520 -1.0000000 -1.0000000 6.1961521 6.1961519
1 -0.95 -0.9499929 -0.9499929 6.1677637 6.1677635 -0.9500082 -0.9500082 6.1677739 6.1677735
2 -0.90 -0.8999932 -0.8999932 6.1314705 6.1314703 -0.9000083 -0.9000083 6.1314821 6.1314820
3 -0.85 -0.8499929 -0.8499929 6.0904778 6.0904767 -0.8500081 -0.8500081 6.0904905 6.0904905
4 -0.80 -0.7999931 -0.7999932 6.0456912 6.0456893 -0.8000080 -0.8000080 6.0457046 6.0457045
5 -0.75 -0.7499932 -0.7499936 5.9975818 5.9975748 -0.7500079 -0.7500079 5.9975961 5.9975956
6 -0.70 -0.6999935 -0.6999935 5.9464447 5.9464446 -0.7000081 -0.7000081 5.9464601 5.9464600
7 -0.65 -0.6499936 -0.6499937 5.8924898 5.8924890 -0.6500078 -0.6500078 5.8925048 5.8925047
8 -0.60 -0.5999938 -0.5999938 5.8358762 5.8358752 -0.6000073 -0.6000074 5.8358910 5.8358825
9 -0.55 -0.5499937 -0.5499939 5.7767400 5.7767294 -0.5500073 -0.5500073 5.7767560 5.7767559
10 -0.50 -0.4999941 -0.4999944 5.7152135 5.7152123 -0.5000070 -0.5000073 5.7152291 5.7152139
11 -0.45 -0.4499939 -0.4499940 5.6514260 5.6514173 -0.4500068 -0.4500069 5.6514439 5.6514375
12 -0.40 -0.3999945 -0.3999945 5.5855404 5.5855402 -0.4000067 -0.4000067 5.5855590 5.5855407
13 -0.35 -0.3499941 -0.3499945 5.5177407 5.5176907 -0.3500068 -0.3500068 5.5177545 5.5177543
14 -0.30 -0.2999941 -0.2999942 5.4482516 5.4482332 -0.3000066 -0.3000074 5.4482717 5.4482690
15 -0.25 -0.2499941 -0.2499943 5.3773787 5.3773399 -0.2500066 -0.2500074 5.3773992 5.3773875
16 -0.20 -0.1999940 -0.1999941 5.3054550 5.3054238 -0.2000066 -0.2000071 5.3054643 5.3053078
17 -0.15 -0.1499939 -0.1499941 5.2328899 5.2325711 -0.1500068 -0.1500070 5.2329085 5.2326468
18 -0.10 -0.0999937 -0.0999941 5.1600951 5.1599284 -0.1000069 -0.1000077 5.1601158 5.1595873
19 -0.05 -0.0499935 -0.0499939 5.0874969 5.0871009 -0.0500071 -0.0500080 5.0875161 5.0870071
20 0.00 0.0000067 0.0000057 5.0154689 5.0152906 -0.0000074 -0.0000082 5.0154891 5.0151326
In [14]:
diffs = stats[["s_bound"]].copy()
for apx in +1, -1:
    diffs[f's_max_diff_{apx:+}'] = stats[f'max_entr_{apx:+}'] - stats[f'min_entr_{apx:+}']
    diffs[f'{BELLOP}_max_diff_{apx:+}'] = stats[f'max_{BELLOP}_{apx:+}'] - stats[f'min_{BELLOP}_{apx:+}']

def both_apx(fmtstr, bellop=BELLOP):
    return [fmtstr.format(apx=+1, bellop=bellop), fmtstr.format(apx=-1, bellop=bellop)]

diffs[f's_max_diff'] = (
    stats[both_apx('max_entr_{apx:+}')].max(axis=1)
    - stats[both_apx('min_entr_{apx:+}')].min(axis=1)
)
diffs[f'{BELLOP}_max_diff'] = (
    stats[both_apx('max_{bellop}_{apx:+}')].max(axis=1)
    - stats[both_apx('min_{bellop}_{apx:+}')].min(axis=1)
)
pd.set_option("precision", 5)
diffs
Out[14]:
s_bound s_max_diff_+1 i1_max_diff_+1 s_max_diff_-1 i1_max_diff_-1 s_max_diff i1_max_diff
0 -1.00 3.43183e-09 3.33582e-07 6.56328e-09 2.19094e-07 6.56328e-09 4.10845e-07
1 -0.95 4.14842e-09 1.89395e-07 1.83606e-08 4.00372e-07 1.53027e-05 1.04150e-05
2 -0.90 2.17557e-08 2.09072e-07 3.95010e-08 1.43925e-07 1.51363e-05 1.18365e-05
3 -0.85 1.35984e-08 1.08890e-06 6.63370e-11 8.24720e-08 1.51435e-05 1.38572e-05
4 -0.80 2.38245e-08 1.90523e-06 1.44011e-10 8.31136e-08 1.48804e-05 1.53325e-05
5 -0.75 3.81697e-07 7.01191e-06 1.86422e-09 5.34150e-07 1.46598e-05 2.13383e-05
6 -0.70 1.06039e-10 8.79235e-08 6.31379e-10 8.69390e-08 1.46559e-05 1.54820e-05
7 -0.65 1.08201e-08 7.56728e-07 3.78456e-10 9.08532e-08 1.41725e-05 1.57417e-05
8 -0.60 2.76501e-10 1.00981e-06 1.48319e-07 8.52077e-06 1.35644e-05 1.57709e-05
9 -0.55 2.02543e-07 1.05947e-05 6.70857e-11 9.13015e-08 1.36377e-05 2.66137e-05
10 -0.50 2.20693e-07 1.26325e-06 3.46784e-07 1.51014e-05 1.31596e-05 1.67661e-05
11 -0.45 1.21755e-07 8.67944e-06 1.20904e-07 6.41049e-06 1.30377e-05 2.65328e-05
12 -0.40 6.00689e-10 1.76537e-07 2.79148e-09 1.83296e-05 1.22191e-05 1.88538e-05
13 -0.35 4.53355e-07 4.99274e-05 4.84506e-10 2.07038e-07 1.27811e-05 6.37248e-05
14 -0.30 1.63003e-07 1.84062e-05 7.81404e-07 2.68763e-06 1.32753e-05 3.84829e-05
15 -0.25 2.48576e-07 3.88731e-05 8.66693e-07 1.17154e-05 1.33697e-05 5.93073e-05
16 -0.20 1.60435e-08 3.12328e-05 4.76099e-07 1.56486e-04 1.30710e-05 1.56486e-04
17 -0.15 1.79694e-07 3.18857e-04 1.47421e-07 2.61744e-04 1.30830e-05 3.37455e-04
18 -0.10 3.62136e-07 1.66762e-04 7.62755e-07 5.28515e-04 1.39376e-05 5.28515e-04
19 -0.05 3.80689e-07 3.96023e-04 8.66343e-07 5.09062e-04 1.44896e-05 5.09062e-04
20 0.00 9.30907e-07 1.78323e-04 7.89436e-07 3.56543e-04 1.48636e-05 3.56543e-04
In [15]:
fig, (ax, ax2) = plt.subplots(nrows=2, figsize=(12, 24), dpi=150)
hp1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_+1'], 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1'], '.-', label=f'max_{BELLOP}[apx=-1]')
ax.legend(handles=[hp1,hm1])
ax.grid(True)
ax2.grid(True)
h3diff, = ax2.plot(diffs['s_bound'], diffs[f'{BELLOP}_max_diff'], '+-b', label=f'max_{BELLOP}_diff')
hdiff, = ax2.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1']-stats[f'max_{BELLOP}_+1'], '.-g', label=f'max_{BELLOP}[apx=-1]-max_{BELLOP}[apx=+1]')
h2diff, = ax2.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1']-stats[f'min_{BELLOP}_+1'], 'x-r', label=f'max_{BELLOP}[apx=-1]-min_{BELLOP}[apx=+1]')
ax2.legend(handles=[hdiff,h2diff, h3diff])
plt.show(fig)
fig.savefig(path_fig(f'seesaw_apx_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [16]:
export = stats[['s_bound', f'max_{BELLOP}_-1', f'max_{BELLOP}_+1']].copy()
export[f'max_{BELLOP}_is_-1'] = export[[f'max_{BELLOP}_-1', f'max_{BELLOP}_+1']].max(axis=1) == export[f'max_{BELLOP}_-1']
pd.set_option("precision", 8)
export
Out[16]:
s_bound max_i1_-1 max_i1_+1 max_i1_is_-1
0 -1.00 6.19615211 6.19615230 False
1 -0.95 6.16777389 6.16776366 True
2 -0.90 6.13148210 6.13147047 True
3 -0.85 6.09049054 6.09047777 True
4 -0.80 6.04570462 6.04569119 True
5 -0.75 5.99759610 5.99758178 True
6 -0.70 5.94646005 5.94644466 True
7 -0.65 5.89250479 5.89248980 True
8 -0.60 5.83589100 5.83587624 True
9 -0.55 5.77675603 5.77674001 True
10 -0.50 5.71522905 5.71521355 True
11 -0.45 5.65144388 5.65142602 True
12 -0.40 5.58555903 5.58554036 True
13 -0.35 5.51775446 5.51774066 True
14 -0.30 5.44827166 5.44825158 True
15 -0.25 5.37739917 5.37737874 True
16 -0.20 5.30546432 5.30545502 True
17 -0.15 5.23290852 5.23288992 True
18 -0.10 5.16011578 5.16009513 True
19 -0.05 5.08751613 5.08749691 True
20 0.00 5.01548914 5.01546894 True
In [17]:
export.to_csv(path_export(f'seesaw_max_export_{BELLOP}.tsv'), sep='\t')

Porównanie

In [18]:
witness_bounds = pd.read_csv(path_export(f'witness_bounds_{BELLOP}.tsv'), sep='\t')
In [19]:
FIXEDM_FIELDS = fields(BELLOP)+['apx']
fixedm = read_data(f'out_bell/fixedm_{BELLOP}_entr_approx_states.jsonl', [partial(extract_by_keys, keys=FIXEDM_FIELDS)])
foundm = read_data(f'out_bell/foundm/fixedm_{BELLOP}_entr_approx_states.jsonl', [partial(extract_by_keys, keys=FIXEDM_FIELDS)])
In [20]:
witness_bounds
Out[20]:
i1 cond_entropy cond_entropy_bound
0 4.86573443 -5.19584376e-14 -0.00
1 4.96551650 -5.00000000e-02 -0.05
2 5.06125253 -1.00000000e-01 -0.10
3 5.15313319 -1.50000000e-01 -0.15
4 5.24132355 -2.00000000e-01 -0.20
5 5.32596591 -2.50000000e-01 -0.25
6 5.40718190 -3.00000000e-01 -0.30
7 5.48507401 -3.50000000e-01 -0.35
8 5.55972653 -4.00000000e-01 -0.40
9 5.63120591 -4.50000000e-01 -0.45
10 5.69956049 -5.00000000e-01 -0.50
11 5.76481939 -5.50000000e-01 -0.55
12 5.82699038 -6.00000000e-01 -0.60
13 5.88605616 -6.50000000e-01 -0.65
14 5.94196814 -7.00000000e-01 -0.70
15 5.99463581 -7.50000000e-01 -0.75
16 6.04390771 -8.00000000e-01 -0.80
17 6.08953414 -8.50000000e-01 -0.85
18 6.13108203 -9.00000000e-01 -0.90
19 6.16767984 -9.50000000e-01 -0.95
In [21]:
fixedm = pd.DataFrame.from_records(fixedm, columns=FIXEDM_FIELDS)
fixedm_p1, fixedm_m1 = fixedm[fixedm['apx']==+1], fixedm[fixedm['apx']==-1]
foundm = pd.DataFrame.from_records(foundm, columns=FIXEDM_FIELDS)
foundm_p1, foundm_m1 = foundm[foundm['apx']==+1], foundm[foundm['apx']==-1]

Łączenie DataFrame z samym sobą

In [22]:
pd.set_option("precision", 10)
fixedm_p1.merge(fixedm_m1, on='s_bound', suffixes=('_p1', '_m1'))
Out[22]:
i1_p1 cond_entropy_p1 s_bound apx_p1 i1_m1 cond_entropy_m1 apx_m1
0 6.1961523721 -0.9999999889 -1.00 1 6.1961523724 -0.9999999890 -1
1 6.1676752573 -0.9499931799 -0.95 1 6.1676750956 -0.9499929349 -1
2 6.1310765622 -0.8999930494 -0.90 1 6.1310765623 -0.8999930496 -1
3 6.0895279047 -0.8499928685 -0.85 1 6.0895279048 -0.8499928685 -1
4 6.0439011199 -0.7999930666 -0.80 1 6.0439011190 -0.7999930656 -1
5 5.9946289457 -0.7499932729 -0.75 1 5.9946289457 -0.7499932729 -1
6 5.9419610772 -0.6999934941 -0.70 1 5.9419610772 -0.6999934941 -1
7 5.8860491808 -0.6499939329 -0.65 1 5.8860491808 -0.6499939329 -1
8 5.8269830351 -0.5999939443 -0.60 1 5.8269830353 -0.5999939444 -1
9 5.7648120329 -0.5499942281 -0.55 1 5.7648119851 -0.5499941901 -1
10 5.6995531243 -0.4999944863 -0.50 1 5.6995531238 -0.4999944858 -1
11 5.6311985822 -0.4499947577 -0.45 1 5.6311986502 -0.4499948069 -1
12 5.5597195911 -0.3999952574 -0.40 1 5.5597195912 -0.3999952575 -1
13 5.4850671857 -0.3499955316 -0.35 1 5.4850671857 -0.3499955316 -1
14 5.4071755785 -0.2999960329 -0.30 1 5.4071755792 -0.2999960333 -1
15 5.3259594514 -0.2499961087 -0.25 1 5.3259592660 -0.2499959937 -1
16 5.2413171491 -0.1999962935 -0.20 1 5.2413171510 -0.1999962946 -1
17 5.1531271459 -0.1499966423 -0.15 1 5.1531271432 -0.1499966408 -1
18 5.0612469594 -0.0999970312 -0.10 1 5.0612467936 -0.0999969415 -1
19 4.9655116722 -0.0499975329 -0.05 1 4.9655116715 -0.0499975325 -1
20 4.8657291273 0.0000026007 0.00 1 4.8657291277 0.0000026005 -1
In [23]:
# i z innym df
fixedm_p1.merge(witness_bounds, left_on='s_bound', right_on='cond_entropy_bound', suffixes=('_p1', '_m1'))
Out[23]:
i1_p1 cond_entropy_p1 s_bound apx i1_m1 cond_entropy_m1 cond_entropy_bound
0 6.1676752573 -0.9499931799 -0.95 1 6.1676798446 -9.5000000001e-01 -0.95
1 6.1310765622 -0.8999930494 -0.90 1 6.1310820342 -9.0000000000e-01 -0.90
2 6.0895279047 -0.8499928685 -0.85 1 6.0895341378 -8.5000000000e-01 -0.85
3 6.0439011199 -0.7999930666 -0.80 1 6.0439077085 -8.0000000000e-01 -0.80
4 5.9946289457 -0.7499932729 -0.75 1 5.9946358090 -7.5000000000e-01 -0.75
5 5.9419610772 -0.6999934941 -0.70 1 5.9419681448 -7.0000000000e-01 -0.70
6 5.8860491808 -0.6499939329 -0.65 1 5.8860561631 -6.5000000001e-01 -0.65
7 5.8269830351 -0.5999939443 -0.60 1 5.8269903780 -6.0000000000e-01 -0.60
8 5.7648120329 -0.5499942281 -0.55 1 5.7648193889 -5.5000000000e-01 -0.55
9 5.6995531243 -0.4999944863 -0.50 1 5.6995604918 -5.0000000000e-01 -0.50
10 5.6311985822 -0.4499947577 -0.45 1 5.6312059123 -4.5000000000e-01 -0.45
11 5.5597195911 -0.3999952574 -0.40 1 5.5597265260 -4.0000000001e-01 -0.40
12 5.4850671857 -0.3499955316 -0.35 1 5.4850740051 -3.5000000001e-01 -0.35
13 5.4071755785 -0.2999960329 -0.30 1 5.4071818974 -3.0000000001e-01 -0.30
14 5.3259594514 -0.2499961087 -0.25 1 5.3259659112 -2.5000000000e-01 -0.25
15 5.2413171491 -0.1999962935 -0.20 1 5.2413235545 -2.0000000000e-01 -0.20
16 5.1531271459 -0.1499966423 -0.15 1 5.1531331925 -1.5000000000e-01 -0.15
17 5.0612469594 -0.0999970312 -0.10 1 5.0612525335 -1.0000000000e-01 -0.10
18 4.9655116722 -0.0499975329 -0.05 1 4.9655165035 -5.0000000000e-02 -0.05
19 4.8657291273 0.0000026007 0.00 1 4.8657344271 -5.1958437552e-14 -0.00

Wspólny wykres

In [24]:
fig, ax = plt.subplots(figsize=(12, 12), dpi=150)
hwitn, = ax.plot(witness_bounds['cond_entropy_bound'], witness_bounds[BELLOP], 'r-', marker=5, label=f'max_{BELLOP} with witness (fixed meas.)')
hfp1, = ax.plot(fixedm_p1['s_bound'], fixedm_p1[BELLOP], 'c-', marker=6, label=f'max_{BELLOP} apx=+1 fixed mesurements')
hfm1, = ax.plot(fixedm_m1['s_bound'], fixedm_m1[BELLOP], 'b-', marker=7, label=f'max_{BELLOP} apx=-1 fixed mesurements')
hp1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_+1'], 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(stats['s_bound'], stats[f'max_{BELLOP}_-1'], '.-', label=f'max_{BELLOP}[apx=-1]')
fndp1, = ax.plot(foundm_p1['s_bound'], foundm_p1[BELLOP], '|--', label=f'max_{BELLOP} apx=+1 found meas.')
fndm1, = ax.plot(foundm_m1['s_bound'], foundm_m1[BELLOP], '|--', label=f'max_{BELLOP} apx=-1 found meas.')

ax.legend(handles=[hp1,hm1, hwitn, hfp1,hfm1, fndp1, fndm1])
ax.grid(True)
plt.show(fig)
fig.savefig(path_fig(f'compare_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)
In [25]:
diffbase = fixedm_p1

def diff(df, key_eq, key_val):
    merged = diffbase.merge(df, left_on='s_bound', right_on=key_eq, suffixes=('_base', ''))
    return merged['s_bound'], merged[key_val]-merged[f'{BELLOP}_base' if BELLOP in df.columns else BELLOP]


fig, ax = plt.subplots(figsize=(12, 12), dpi=150)


hwitn, = ax.plot(*diff(witness_bounds, 'cond_entropy_bound', BELLOP), 'r-', marker=5, label=f'max_{BELLOP} with witness (fixed meas.)')
hfp1, = ax.plot(*diff(fixedm_p1, 's_bound', BELLOP), 'c-', marker=6, label=f'max_{BELLOP} apx=+1 fixed mesurements')
hfm1, = ax.plot(*diff(fixedm_m1, 's_bound', BELLOP), 'b-', marker=7, label=f'max_{BELLOP} apx=-1 fixed mesurements')
hp1, = ax.plot(*diff(stats, 's_bound', f'max_{BELLOP}_+1'), 'x-', label=f'max_{BELLOP}[apx=+1]')
hm1, = ax.plot(*diff(stats, 's_bound', f'max_{BELLOP}_-1'), '.-', label=f'max_{BELLOP}[apx=-1]')

from matplotlib.ticker import SymmetricalLogLocator
plt.yscale('symlog', linthresh=1e-4)
ax.yaxis.set_minor_locator(SymmetricalLogLocator(linthresh=1e-4, base=10, subs=range(2,10)))
ax.tick_params(which='minor', length=4)
ax.legend(handles=[hp1,hm1, hwitn, hfp1,hfm1])
ax.grid(True)
plt.title(f'Value minus corresponding value of [max_{BELLOP} apx=-1 fixed mesurements]')
plt.show(fig)
fig.savefig(path_fig(f'diff_fixedm_p1_{BELLOP}.pdf'), **SAVEFIG_KWARGS)
plt.close(fig)

^ UWAGA! Powyższy wykres: oś Y jest częściowo w skali logarytmicznej, a częściowo w liniowej! ^

In [26]:
# Seesaw difference to fixedm_p1
s_bound, seesaw_p1_diff = diff(stats, 's_bound', f'max_{BELLOP}_+1')
s_bound2, seesaw_m1_diff = diff(stats, 's_bound', f'max_{BELLOP}_-1')
pd.DataFrame({'s_bound':s_bound, 'seesaw_p1_diff':seesaw_p1_diff, 'seesaw_m1_diff':seesaw_m1_diff, 's_bound2':s_bound2})
Out[26]:
s_bound seesaw_p1_diff seesaw_m1_diff s_bound2
0 -1.00 -0.0000000675 -0.0000002592 -1.00
1 -0.95 0.0000884030 0.0000986286 -0.95
2 -0.90 0.0003939100 0.0004055375 -0.90
3 -0.85 0.0009498692 0.0009626375 -0.85
4 -0.80 0.0017900710 0.0018034982 -0.80
5 -0.75 0.0029528322 0.0029671586 -0.75
6 -0.70 0.0044835804 0.0044989745 -0.70
7 -0.65 0.0064406195 0.0064556044 -0.65
8 -0.60 0.0088932003 0.0089079614 -0.60
9 -0.55 0.0119279790 0.0119439980 -0.55
10 -0.50 0.0156604234 0.0156759263 -0.50
11 -0.45 0.0202274415 0.0202452949 -0.45
12 -0.40 0.0258207654 0.0258394427 -0.40
13 -0.35 0.0326734751 0.0326872724 -0.35
14 -0.30 0.0410760056 0.0410960823 -0.30
15 -0.25 0.0514192882 0.0514397224 -0.25
16 -0.20 0.0641378721 0.0641471722 -0.20
17 -0.15 0.0797627770 0.0797813747 -0.15
18 -0.10 0.0988481694 0.0988688167 -0.10
19 -0.05 0.1219852336 0.1220044535 -0.05
20 0.00 0.1497398078 0.1497600162 0.00