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

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_mchsh_+1 min_mchsh_+1 max_entr_-1 min_entr_-1 max_mchsh_-1 min_mchsh_-1
0 -1.00 -1.0000000 -1.0000000 3.8284269 3.8284267 -1.0000000 -1.0000000 3.8284269 3.8284268
1 -0.95 -0.9499944 -0.9499944 3.8126800 3.8126798 -0.9500067 -0.9500068 3.8126846 3.8126844
2 -0.90 -0.8999938 -0.8999938 3.7922511 3.7922508 -0.9000072 -0.9000072 3.7922569 3.7922567
3 -0.85 -0.8499936 -0.8499936 3.7689509 3.7689506 -0.8500074 -0.8500074 3.7689577 3.7689574
4 -0.80 -0.7999934 -0.7999934 3.7432887 3.7432886 -0.8000076 -0.8000076 3.7432963 3.7432961
5 -0.75 -0.7499934 -0.7499934 3.7155226 3.7155223 -0.7500077 -0.7500078 3.7155309 3.7155304
6 -0.70 -0.6999933 -0.6999933 3.6858021 3.6858020 -0.7000077 -0.7000077 3.6858113 3.6858109
7 -0.65 -0.6499933 -0.6499934 3.6542216 3.6542210 -0.6500077 -0.6500077 3.6542309 3.6542306
8 -0.60 -0.5999934 -0.5999934 3.6208372 3.6208363 -0.6000076 -0.6000076 3.6208470 3.6208469
9 -0.55 -0.5499935 -0.5499935 3.5856826 3.5856822 -0.5500074 -0.5500074 3.5856924 3.5856922
10 -0.50 -0.4999937 -0.4999937 3.5487715 3.5487709 -0.5000072 -0.5000073 3.5487817 3.5487809
11 -0.45 -0.4499938 -0.4499938 3.5101025 3.5101023 -0.4500070 -0.4500070 3.5101134 3.5101123
12 -0.40 -0.3999940 -0.3999943 3.4696640 3.4696623 -0.4000068 -0.4000070 3.4696749 3.4696710
13 -0.35 -0.3499942 -0.3499943 3.4274307 3.4274286 -0.3500065 -0.3500065 3.4274411 3.4274406
14 -0.30 -0.2999944 -0.2999944 3.3833676 3.3833675 -0.3000063 -0.3000063 3.3833783 3.3833782
15 -0.25 -0.2499947 -0.2499947 3.3374302 3.3374299 -0.2500059 -0.2500059 3.3374413 3.3374396
16 -0.20 -0.1999950 -0.1999951 3.2895629 3.2895610 -0.2000055 -0.2000056 3.2895724 3.2895708
17 -0.15 -0.1499953 -0.1499953 3.2396964 3.2396950 -0.1500053 -0.1500053 3.2397072 3.2397060
18 -0.10 -0.0999962 -0.0999962 3.1877540 3.1877539 -0.1000049 -0.1000049 3.1877647 3.1877632
19 -0.05 -0.0499959 -0.0499959 3.1336441 3.1336409 -0.0500045 -0.0500046 3.1336536 3.1336512
20 0.00 0.0000038 0.0000037 3.0772579 3.0772508 -0.0000041 -0.0000041 3.0772669 3.0772647
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 mchsh_max_diff_+1 s_max_diff_-1 mchsh_max_diff_-1 s_max_diff mchsh_max_diff
0 -1.00 8.68073e-09 2.12742e-07 6.23263e-09 1.50265e-07 8.68073e-09 2.12742e-07
1 -0.95 2.35519e-09 1.64784e-07 7.08986e-08 2.89445e-07 1.23646e-05 4.83092e-06
2 -0.90 4.14880e-10 3.31380e-07 5.97343e-08 2.14890e-07 1.34001e-05 6.12973e-06
3 -0.85 2.64226e-09 3.16964e-07 2.73703e-09 3.09687e-07 1.38113e-05 7.08325e-06
4 -0.80 6.00231e-12 7.81976e-08 3.19875e-08 1.85435e-07 1.42121e-05 7.72893e-06
5 -0.75 9.28804e-10 2.78562e-07 9.39562e-08 5.14800e-07 1.43276e-05 8.58158e-06
6 -0.70 8.63165e-12 1.92697e-07 7.79710e-13 3.72495e-07 1.44132e-05 9.32723e-06
7 -0.65 6.46278e-08 6.44790e-07 2.58937e-11 2.71053e-07 1.44014e-05 9.91003e-06
8 -0.60 7.81129e-08 9.36139e-07 2.21722e-11 8.15520e-08 1.42677e-05 1.06628e-05
9 -0.55 1.40713e-10 3.88591e-07 1.28510e-08 2.24103e-07 1.39838e-05 1.02291e-05
10 -0.50 3.32429e-10 5.45235e-07 1.07981e-07 7.69242e-07 1.36008e-05 1.07554e-05
11 -0.45 7.10625e-11 1.27253e-07 5.35073e-10 1.15815e-06 1.32321e-05 1.10777e-05
12 -0.40 3.94196e-07 1.67572e-06 2.65159e-07 3.90120e-06 1.30768e-05 1.25647e-05
13 -0.35 9.12665e-08 2.02754e-06 5.11263e-08 4.70294e-07 1.23656e-05 1.24577e-05
14 -0.30 3.44028e-11 1.23078e-07 1.74864e-10 8.91602e-08 1.18779e-05 1.08106e-05
15 -0.25 9.67681e-12 3.10413e-07 7.56414e-08 1.69444e-06 1.12399e-05 1.13421e-05
16 -0.20 9.19577e-08 1.83221e-06 9.01927e-08 1.56223e-06 1.06514e-05 1.13760e-05
17 -0.15 3.53602e-08 1.33924e-06 1.39889e-10 1.21745e-06 1.00211e-05 1.21994e-05
18 -0.10 7.45071e-10 9.25359e-08 8.13659e-11 1.51765e-06 8.71223e-06 1.07761e-05
19 -0.05 1.78472e-08 3.19090e-06 5.17107e-08 2.39256e-06 8.69578e-06 1.27451e-05
20 0.00 8.34544e-08 7.06795e-06 1.70809e-10 2.16322e-06 7.96305e-06 1.60698e-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_mchsh_-1 max_mchsh_+1 max_mchsh_is_-1
0 -1.00 3.82842691 3.82842695 False
1 -0.95 3.81268464 3.81267997 True
2 -0.90 3.79225693 3.79225113 True
3 -0.85 3.76895768 3.76895092 True
4 -0.80 3.74329633 3.74328868 True
5 -0.75 3.71553088 3.71552257 True
6 -0.70 3.68581128 3.68580215 True
7 -0.65 3.65423088 3.65422162 True
8 -0.60 3.62084697 3.62083724 True
9 -0.55 3.58569244 3.58568260 True
10 -0.50 3.54878169 3.54877148 True
11 -0.45 3.51011342 3.51010247 True
12 -0.40 3.46967489 3.46966400 True
13 -0.35 3.42744109 3.42743066 True
14 -0.30 3.38337828 3.38336760 True
15 -0.25 3.33744128 3.33743025 True
16 -0.20 3.28957241 3.28956286 True
17 -0.15 3.23970721 3.23969635 True
18 -0.10 3.18776472 3.18775403 True
19 -0.05 3.13365363 3.13364408 True
20 0.00 3.07726687 3.07725787 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]:
mchsh cond_entropy cond_entropy_bound
0 3.03961715 -2.59148258e-12 -0.00
1 3.10034910 -5.00000000e-02 -0.05
2 3.15847460 -1.00000000e-01 -0.10
3 3.21411578 -1.50000000e-01 -0.15
4 3.26737867 -2.00000000e-01 -0.20
5 3.31835509 -2.50000000e-01 -0.25
6 3.36712400 -3.00000000e-01 -0.30
7 3.41375248 -3.50000000e-01 -0.35
8 3.45829641 -4.00000000e-01 -0.40
9 3.50080076 -4.50000000e-01 -0.45
10 3.54129948 -5.00000000e-01 -0.50
11 3.57981499 -5.50000000e-01 -0.55
12 3.61635697 -6.00000000e-01 -0.60
13 3.65092027 -6.50000000e-01 -0.65
14 3.68348140 -7.00000000e-01 -0.70
15 3.71399250 -7.50000000e-01 -0.75
16 3.74237050 -8.00000000e-01 -0.80
17 3.76847590 -8.50000000e-01 -0.85
18 3.79206451 -9.00000000e-01 -0.90
19 3.81264331 -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]:
mchsh_p1 cond_entropy_p1 s_bound apx_p1 mchsh_m1 cond_entropy_m1 apx_m1
0 3.8284270962 -0.9999999897 -1.00 1 3.8284270960 -0.9999999896 -1
1 3.8126411939 -0.9499943574 -0.95 1 3.8126411939 -0.9499943575 -1
2 3.7920617365 -0.8999937670 -0.90 1 3.7920617364 -0.8999937668 -1
3 3.7684727294 -0.8499936521 -0.85 1 3.7684727294 -0.8499936520 -1
4 3.7423668408 -0.7999933017 -0.80 1 3.7423668408 -0.7999933017 -1
5 3.7139886217 -0.7499934280 -0.75 1 3.7139886217 -0.7499934280 -1
6 3.6834773040 -0.6999935170 -0.70 1 3.6834773041 -0.6999935171 -1
7 3.6509159093 -0.6499935138 -0.65 1 3.6509159092 -0.6499935138 -1
8 3.6163523853 -0.5999935546 -0.60 1 3.6163523854 -0.5999935547 -1
9 3.5798102959 -0.5499937410 -0.55 1 3.5798103262 -0.5499937819 -1
10 3.5412950562 -0.4999944066 -0.50 1 3.5412950562 -0.4999944066 -1
11 3.5007959861 -0.4499942533 -0.45 1 3.5007959861 -0.4499942533 -1
12 3.4582917896 -0.3999946958 -0.40 1 3.4582916628 -0.3999945480 -1
13 3.4137479236 -0.3499950086 -0.35 1 3.4137479254 -0.3499950106 -1
14 3.3671194615 -0.2999952473 -0.30 1 3.3671194615 -0.2999952474 -1
15 3.3183506577 -0.2499955575 -0.25 1 3.3183506581 -0.2499955579 -1
16 3.2673743900 -0.1999958976 -0.20 1 3.2673744094 -0.1999959165 -1
17 3.2141119059 -0.1499964487 -0.15 1 3.2141119058 -0.1499964487 -1
18 3.1584706464 -0.0999965209 -0.10 1 3.1584706466 -0.0999965211 -1
19 3.1003455982 -0.0499970583 -0.05 1 3.1003455986 -0.0499970586 -1
20 3.0396136254 0.0000028380 0.00 1 3.0396138709 0.0000026372 -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]:
mchsh_p1 cond_entropy_p1 s_bound apx mchsh_m1 cond_entropy_m1 cond_entropy_bound
0 3.8126411939 -0.9499943574 -0.95 1 3.8126433142 -9.5000000000e-01 -0.95
1 3.7920617365 -0.8999937670 -0.90 1 3.7920645062 -9.0000000000e-01 -0.90
2 3.7684727294 -0.8499936521 -0.85 1 3.7684758957 -8.5000000000e-01 -0.85
3 3.7423668408 -0.7999933017 -0.80 1 3.7423704959 -8.0000000000e-01 -0.80
4 3.7139886217 -0.7499934280 -0.75 1 3.7139924979 -7.5000000001e-01 -0.75
5 3.6834773040 -0.6999935170 -0.70 1 3.6834813980 -7.0000000000e-01 -0.70
6 3.6509159093 -0.6499935138 -0.65 1 3.6509202663 -6.5000000000e-01 -0.65
7 3.6163523853 -0.5999935546 -0.60 1 3.6163569692 -6.0000000001e-01 -0.60
8 3.5798102959 -0.5499937410 -0.55 1 3.5798149941 -5.5000000000e-01 -0.55
9 3.5412950562 -0.4999944066 -0.50 1 3.5412994818 -5.0000000001e-01 -0.50
10 3.5007959861 -0.4499942533 -0.45 1 3.5008007559 -4.5000000000e-01 -0.45
11 3.4582917896 -0.3999946958 -0.40 1 3.4582964084 -4.0000000001e-01 -0.40
12 3.4137479236 -0.3499950086 -0.35 1 3.4137524762 -3.5000000001e-01 -0.35
13 3.3671194615 -0.2999952473 -0.30 1 3.3671239954 -3.0000000000e-01 -0.30
14 3.3183506577 -0.2499955575 -0.25 1 3.3183550885 -2.5000000001e-01 -0.25
15 3.2673743900 -0.1999958976 -0.20 1 3.2673786657 -2.0000000000e-01 -0.20
16 3.2141119059 -0.1499964487 -0.15 1 3.2141157753 -1.5000000000e-01 -0.15
17 3.1584706464 -0.0999965209 -0.10 1 3.1584746033 -1.0000000000e-01 -0.10
18 3.1003455982 -0.0499970583 -0.05 1 3.1003490961 -5.0000000000e-02 -0.05
19 3.0396136254 0.0000028380 0.00 1 3.0396171495 -2.5914825841e-12 -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.0000001471 -0.0000001842 -1.00
1 -0.95 0.0000387797 0.0000434458 -0.95
2 -0.90 0.0001893915 0.0001951898 -0.90
3 -0.85 0.0004781864 0.0004849527 -0.85
4 -0.80 0.0009218353 0.0009294860 -0.80
5 -0.75 0.0015339524 0.0015422554 -0.75
6 -0.70 0.0023248442 0.0023339788 -0.70
7 -0.65 0.0033057104 0.0033149756 -0.65
8 -0.60 0.0044848568 0.0044945835 -0.60
9 -0.55 0.0058723023 0.0058821428 -0.55
10 -0.50 0.0074764283 0.0074866385 -0.50
11 -0.45 0.0093064824 0.0093174329 -0.45
12 -0.40 0.0113722126 0.0113831015 -0.40
13 -0.35 0.0136827387 0.0136931689 -0.35
14 -0.30 0.0162481344 0.0162588219 -0.30
15 -0.25 0.0190795882 0.0190906199 -0.25
16 -0.20 0.0221884714 0.0221980152 -0.20
17 -0.15 0.0255844474 0.0255953076 -0.15
18 -0.10 0.0292833853 0.0292940689 -0.10
19 -0.05 0.0332984772 0.0333080314 -0.05
20 0.00 0.0376442431 0.0376532450 0.00