In [1]:
BELLOP = 'bc3'
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 BC3

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_bc3_+1 min_bc3_+1 max_entr_-1 min_entr_-1 max_bc3_-1 min_bc3_-1
0 -1.00 -1.0000000 -1.0000000 5.1961523 5.1961522 -1.0000000 -1.0000000 5.1961523 5.1961522
1 -0.95 -0.9499920 -0.9499922 5.1704215 5.1704213 -0.9500091 -0.9500092 5.1704317 5.1704315
2 -0.90 -0.8999924 -0.8999925 5.1378757 5.1378753 -0.9000088 -0.9000088 5.1378870 5.1378869
3 -0.85 -0.8499928 -0.8499932 5.1012173 5.1012168 -0.8500082 -0.8500085 5.1012291 5.1012286
4 -0.80 -0.7999931 -0.7999932 5.0611832 5.0611828 -0.8000078 -0.8000080 5.0611955 5.0611949
5 -0.75 -0.7499935 -0.7499936 5.0181403 5.0181397 -0.7500074 -0.7500078 5.0181530 5.0181523
6 -0.70 -0.6999937 -0.6999944 4.9723006 4.9722994 -0.7000071 -0.7000074 4.9723127 4.9723121
7 -0.65 -0.6499940 -0.6499942 4.9237912 4.9237901 -0.6500068 -0.6500072 4.9238043 4.9238022
8 -0.60 -0.5999942 -0.5999945 4.8726916 4.8726905 -0.6000064 -0.6000066 4.8727043 4.8727028
9 -0.55 -0.5499949 -0.5499950 4.8190436 4.8190434 -0.5500061 -0.5500063 4.8190563 4.8190554
10 -0.50 -0.4999948 -0.4999954 4.7628636 4.7628609 -0.5000058 -0.5000059 4.7628758 4.7628753
11 -0.45 -0.4499951 -0.4499954 4.7041466 4.7041442 -0.4500054 -0.4500056 4.7041586 4.7041578
12 -0.40 -0.3999954 -0.3999960 4.6428707 4.6428670 -0.4000051 -0.4000052 4.6428822 4.6428814
13 -0.35 -0.3499956 -0.3499959 4.5789967 4.5789938 -0.3500048 -0.3500050 4.5790084 4.5790063
14 -0.30 -0.2999959 -0.2999962 4.5124713 4.5124670 -0.3000045 -0.3000046 4.5124828 4.5124807
15 -0.25 -0.2499962 -0.2499965 4.4432265 4.4432249 -0.2500041 -0.2500043 4.4432375 4.4432314
16 -0.20 -0.1999965 -0.1999967 4.3711783 4.3711664 -0.2000038 -0.2000042 4.3711894 4.3711807
17 -0.15 -0.1499968 -0.1499970 4.2962279 4.2962208 -0.1500035 -0.1500041 4.2962384 4.2962290
18 -0.10 -0.0999970 -0.0999977 4.2182586 4.2182231 -0.1000032 -0.1000040 4.2182684 4.2182398
19 -0.05 -0.0499971 -0.0499976 4.1371388 4.1370442 -0.0500030 -0.0500035 4.1371484 4.1370570
20 0.00 0.0000033 0.0000027 4.0558397 4.0558208 -0.0000035 -0.0000040 4.0558515 4.0558359
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 bc3_max_diff_+1 s_max_diff_-1 bc3_max_diff_-1 s_max_diff bc3_max_diff
0 -1.00 2.16800e-09 1.64712e-07 2.96836e-09 1.68846e-07 3.14728e-09 1.79101e-07
1 -0.95 1.72903e-07 2.43562e-07 6.43567e-08 1.90017e-07 1.71182e-05 1.04036e-05
2 -0.90 1.16160e-07 3.37797e-07 1.67085e-08 1.68369e-07 1.64493e-05 1.16907e-05
3 -0.85 4.37017e-07 5.29709e-07 2.59558e-07 5.26543e-07 1.56688e-05 1.23176e-05
4 -0.80 1.23534e-07 4.27385e-07 2.39084e-07 5.52545e-07 1.49488e-05 1.27070e-05
5 -0.75 1.02456e-07 6.03708e-07 3.56023e-07 6.44462e-07 1.42836e-05 1.32560e-05
6 -0.70 7.22721e-07 1.17582e-06 2.84079e-07 5.63330e-07 1.36835e-05 1.32924e-05
7 -0.65 2.36320e-07 1.12232e-06 4.65002e-07 2.11005e-06 1.32662e-05 1.41715e-05
8 -0.60 2.19240e-07 1.05773e-06 1.50963e-07 1.47616e-06 1.23484e-05 1.37218e-05
9 -0.55 1.02412e-07 1.55131e-07 2.27473e-07 8.73303e-07 1.14686e-05 1.28214e-05
10 -0.50 6.27719e-07 2.76571e-06 9.65711e-08 4.46135e-07 1.10807e-05 1.48899e-05
11 -0.45 3.26934e-07 2.39498e-06 1.20990e-07 8.16519e-07 1.04918e-05 1.44332e-05
12 -0.40 6.38202e-07 3.70066e-06 1.28233e-07 7.81918e-07 9.89349e-06 1.51951e-05
13 -0.35 2.95288e-07 2.90352e-06 2.47529e-07 2.05629e-06 9.41540e-06 1.46054e-05
14 -0.30 3.13422e-07 4.27868e-06 1.62562e-07 2.07428e-06 8.70033e-06 1.57818e-05
15 -0.25 2.78525e-07 1.58889e-06 1.90770e-07 6.09283e-06 8.12048e-06 1.26008e-05
16 -0.20 1.95988e-07 1.18233e-05 4.15207e-07 8.69833e-06 7.75991e-06 2.29791e-05
17 -0.15 2.00615e-07 7.04893e-06 5.41752e-07 9.36880e-06 7.31285e-06 1.75659e-05
18 -0.10 7.16648e-07 3.55832e-05 7.56757e-07 2.85420e-05 6.97777e-06 4.53251e-05
19 -0.05 4.31702e-07 9.45949e-05 4.77602e-07 9.14423e-05 6.37623e-06 1.04252e-04
20 0.00 6.30479e-07 1.89259e-05 5.60664e-07 1.56522e-05 7.32440e-06 3.07211e-05
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_bc3_-1 max_bc3_+1 max_bc3_is_-1
0 -1.00 5.19615233 5.19615234 False
1 -0.95 5.17043168 5.17042152 True
2 -0.90 5.13788703 5.13787567 True
3 -0.85 5.10122911 5.10121732 True
4 -0.80 5.06119547 5.06118319 True
5 -0.75 5.01815299 5.01814034 True
6 -0.70 4.97231270 4.97230059 True
7 -0.65 4.92380427 4.92379122 True
8 -0.60 4.87270426 4.87269160 True
9 -0.55 4.81905627 4.81904360 True
10 -0.50 4.76287577 4.76286365 True
11 -0.45 4.70415861 4.70414657 True
12 -0.40 4.64288221 4.64287072 True
13 -0.35 4.57900839 4.57899668 True
14 -0.30 4.51248277 4.51247127 True
15 -0.25 4.44323749 4.44322648 True
16 -0.20 4.37118942 4.37117827 True
17 -0.15 4.29623837 4.29622785 True
18 -0.10 4.21826838 4.21825864 True
19 -0.05 4.13714843 4.13713878 True
20 0.00 4.05585153 4.05583974 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]:
bc3 cond_entropy cond_entropy_bound
0 4.05270931 -2.63122857e-14 -0.00
1 4.13714239 -5.00000000e-02 -0.05
2 4.21826518 -1.00000000e-01 -0.10
3 4.29623406 -1.50000000e-01 -0.15
4 4.37118424 -2.00000000e-01 -0.20
5 4.44323210 -2.50000000e-01 -0.25
6 4.51247692 -3.00000000e-01 -0.30
7 4.57900213 -3.50000000e-01 -0.35
8 4.64287608 -4.00000000e-01 -0.40
9 4.70415231 -4.50000000e-01 -0.45
10 4.76286928 -5.00000000e-01 -0.50
11 4.81904947 -5.50000000e-01 -0.55
12 4.87269754 -6.00000000e-01 -0.60
13 4.92379722 -6.50000000e-01 -0.65
14 4.97230600 -7.00000000e-01 -0.70
15 5.01814622 -7.50000000e-01 -0.75
16 5.06118899 -8.00000000e-01 -0.80
17 5.10122271 -8.50000000e-01 -0.85
18 5.13788100 -9.00000000e-01 -0.90
19 5.17042628 -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]:
bc3_p1 cond_entropy_p1 s_bound apx_p1 bc3_m1 cond_entropy_m1 apx_m1
0 5.1961523515 -0.9999999817 -1.00 1 5.1961523542 -0.9999999830 -1
1 5.1704215739 -0.9499921704 -0.95 1 5.1704215612 -0.9499921493 -1
2 5.1378756835 -0.8999923574 -0.90 1 5.1378756835 -0.8999923574 -1
3 5.1012173386 -0.8499930181 -0.85 1 5.1012173386 -0.8499930181 -1
4 5.0611835678 -0.7999934843 -0.80 1 5.0611835680 -0.7999934845 -1
5 5.0181403477 -0.7499934005 -0.75 1 5.0181403477 -0.7499934005 -1
6 4.9723000681 -0.6999937141 -0.70 1 4.9723000681 -0.6999937142 -1
7 4.9237913048 -0.6499940622 -0.65 1 4.9237913048 -0.6499940622 -1
8 4.8726917412 -0.5999944646 -0.60 1 4.8726917412 -0.5999944646 -1
9 4.8190434531 -0.5499945261 -0.55 1 4.8190434531 -0.5499945261 -1
10 4.7628637933 -0.4999952342 -0.50 1 4.7628637933 -0.4999952343 -1
11 4.7041464825 -0.4499951464 -0.45 1 4.7041464825 -0.4499951464 -1
12 4.6428705492 -0.3999955815 -0.40 1 4.6428705492 -0.3999955815 -1
13 4.5789973680 -0.3499963592 -0.35 1 4.5789973680 -0.3499963592 -1
14 4.5124720092 -0.2999963950 -0.30 1 4.5124720092 -0.2999963950 -1
15 4.4432267527 -0.2499962176 -0.25 1 4.4432267526 -0.2499962176 -1
16 4.3711791553 -0.1999965413 -0.20 1 4.3711791069 -0.1999965081 -1
17 4.2962291657 -0.1499967984 -0.15 1 4.2962291657 -0.1499967984 -1
18 4.2182604867 -0.0999970463 -0.10 1 4.2182604867 -0.0999970463 -1
19 4.1371388499 -0.0499978634 -0.05 1 4.1371388498 -0.0499978633 -1
20 4.0527054394 0.0000022467 0.00 1 4.0527054394 0.0000022467 -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]:
bc3_p1 cond_entropy_p1 s_bound apx bc3_m1 cond_entropy_m1 cond_entropy_bound
0 5.1704215739 -0.9499921704 -0.95 1 5.1704262789 -9.5000000001e-01 -0.95
1 5.1378756835 -0.8999923574 -0.90 1 5.1378810022 -9.0000000000e-01 -0.90
2 5.1012173386 -0.8499930181 -0.85 1 5.1012227099 -8.5000000000e-01 -0.85
3 5.0611835678 -0.7999934843 -0.80 1 5.0611889932 -8.0000000000e-01 -0.80
4 5.0181403477 -0.7499934005 -0.75 1 5.0181462176 -7.5000000000e-01 -0.75
5 4.9723000681 -0.6999937141 -0.70 1 4.9723060014 -7.0000000001e-01 -0.70
6 4.9237913048 -0.6499940622 -0.65 1 4.9237972219 -6.5000000000e-01 -0.65
7 4.8726917412 -0.5999944646 -0.60 1 4.8726975431 -6.0000000000e-01 -0.60
8 4.8190434531 -0.5499945261 -0.55 1 4.8190494653 -5.5000000001e-01 -0.55
9 4.7628637933 -0.4999952342 -0.50 1 4.7628692756 -5.0000000000e-01 -0.50
10 4.7041464825 -0.4499951464 -0.45 1 4.7041523070 -4.5000000000e-01 -0.45
11 4.6428705492 -0.3999955815 -0.40 1 4.6428760813 -4.0000000001e-01 -0.40
12 4.5789973680 -0.3499963592 -0.35 1 4.5790021294 -3.5000000000e-01 -0.35
13 4.5124720092 -0.2999963950 -0.30 1 4.5124769155 -3.0000000000e-01 -0.30
14 4.4432267527 -0.2499962176 -0.25 1 4.4432320959 -2.5000000000e-01 -0.25
15 4.3711791553 -0.1999965413 -0.20 1 4.3711842391 -2.0000000000e-01 -0.20
16 4.2962291657 -0.1499967984 -0.15 1 4.2962340609 -1.5000000000e-01 -0.15
17 4.2182604867 -0.0999970463 -0.10 1 4.2182651847 -1.0000000000e-01 -0.10
18 4.1371388499 -0.0499978634 -0.05 1 4.1371423947 -5.0000000000e-02 -0.05
19 4.0527054394 0.0000022467 0.00 1 4.0527093140 -2.6312285684e-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.0000000102 -0.0000000205 -1.00
1 -0.95 -0.0000000521 0.0000101079 -0.95
2 -0.90 -0.0000000105 0.0000113425 -0.90
3 -0.85 -0.0000000150 0.0000117729 -0.85
4 -0.80 -0.0000003777 0.0000119020 -0.80
5 -0.75 -0.0000000125 0.0000126399 -0.75
6 -0.70 0.0000005197 0.0000126363 -0.70
7 -0.65 -0.0000000837 0.0000129655 -0.65
8 -0.60 -0.0000001405 0.0000125236 -0.60
9 -0.55 0.0000001468 0.0000128130 -0.55
10 -0.50 -0.0000001436 0.0000119806 -0.50
11 -0.45 0.0000000896 0.0000121278 -0.45
12 -0.40 0.0000001658 0.0000116603 -0.40
13 -0.35 -0.0000006839 0.0000110180 -0.35
14 -0.30 -0.0000007390 0.0000107641 -0.30
15 -0.25 -0.0000002727 0.0000107392 -0.25
16 -0.20 -0.0000008899 0.0000102658 -0.20
17 -0.15 -0.0000013149 0.0000092021 -0.15
18 -0.10 -0.0000018505 0.0000078914 -0.10
19 -0.05 -0.0000000742 0.0000095832 -0.05
20 0.00 0.0031342991 0.0031460943 0.00