<jupyter_start><jupyter_text>LPPUFv1 LR Attack<jupyter_code>import numpy as np
import pandas as pd
import seaborn as sns

import pypuf.batch
results = pypuf.batch.FilesystemResultCollection('results/v1/lr')
data = pd.DataFrame(results.load_all())

# fix a bug where the p-value was included as the last axis
data['correlation'] = data.apply(lambda row: row['correlation'][:, :, 0] if len(row['correlation'].shape) == 3 else row['correlation'], axis=1)
# fix a bug where the p-value was included as the last axis
data['correlation_unrelated'] = data.apply(lambda row: row['correlation_unrelated'][:, :, 0] if not np.isnan(row['correlation_unrelated']).any() and len(row['correlation_unrelated'].shape) == 3 else row['correlation_unrelated'], axis=1)

# compute max correlation (by abs val)
data['correlation_max'] = data.apply(lambda row: np.max(np.abs(row['correlation'])), axis=1)
data['correlation_unrelated_max'] = data.apply(lambda row: np.max(np.abs(row['correlation_unrelated'])), axis=1)

# unpack accuracy
data['accuracy'] = data.apply(lambda row: row['accuracy'][0], axis=1)
data['LP-PUF Layer 3 Weights'] = data['correlation_max']
data['Unrelated XOR Arbiter PUF'] = data['correlation_unrelated_max']

melted_data = data[data.iloc[0].parameters + ['LP-PUF Layer 3 Weights', 'Unrelated XOR Arbiter PUF']].melt(
    id_vars=data.iloc[0].parameters,
    var_name='Correlation with',
    value_name='correlation',
    value_vars=['LP-PUF Layer 3 Weights', 'Unrelated XOR Arbiter PUF'],
)
sns.catplot(
    x='N', 
    y='correlation', 
    row='m', 
    #col='noisiness_2', 
    hue='Correlation with', 
    data=melted_data[melted_data['m'].isin([2, 4])],
    kind='box',
    aspect=3/1,
    height=2.5,
)
sns.catplot(
    x='m', 
    y='accuracy', 
    row='noisiness_1', 
    col='noisiness_2', 
    hue='N', 
    data=data,
    kind='box',
    aspect=3/1,
    height=2.5,
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16579497907949792, 'fraction_numerical': 0.015690376569037656, 'mean_word_length': 5.211038961038961, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '364773', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 725, 'n_tokens_neox': 683, 'n_words': 147, 'path': 'LPPUFv1 LR Attack.ipynb', 'repo_name': 'nils-wisiol/LP-PUF', 'size': '1912'}