<jupyter_start><jupyter_text>Visualization Notebook<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

import sys
sys.path.append('../GA_2021_05_17/')
from Prepare_Data_Functions import load_df, subtract_baseline, normalize_df, delete_rows
sys.path.append('../GP_BUCB_2021_05_19/')
TARGET = load_df(r'target_spectra.xlsx')
TARGET = subtract_baseline(TARGET, 'A2')
TARGET = normalize_df(TARGET)
TARGET = TARGET.drop(['A2'], axis = 1)
TARGET = np.array(TARGET)

wavelength = TARGET[:,0]
TARGET = TARGET[:,1]
def plot_batch(Results, actions, wavelength, target, batch_num):
    
    fig, ax = plt.subplots(figsize=(8,6), nrows=1, ncols=1)
    fontsize = 16
    
    # formatting loop
    ax.tick_params(direction='out', width=2, length=8)
    ax.tick_params(direction='out', which='minor', width=1, length=5)
    ax.set_yticks([])
        
    ax.set_xticks(np.arange(300, 801, 50))
    ax.tick_params(axis='x', labelsize=fontsize+2)
    ax.set_xlabel("Wavelength", fontsize=fontsize+6)

    # target
    ax.plot(wavelength, target, 'k-', linewidth=3, label="Target")
    for i, spectrum in enumerate(Results):
        # normalize
        action = actions[i]
        action = action / np.sum(action)
        spectrum = spectrum - np.min(spectrum)
        spectrum = spectrum/np.max(spectrum)
        ax.plot(wavelength, spectrum, '-', c=action, alpha=0.4)
        
    # setting legend as batch label
    legend = ax.legend([f'Batch {batch_num}'], fontsize=fontsize+4, handlelength=0,
                        handletextpad=0, fancybox=True,)
    for item in legend.legendHandles:
        item.set_visible(False)

    plt.subplots_adjust(hspace=0.0, wspace=0.05)
    plt.show()
%%javascript
 IPython.OutputArea.prototype._should_scroll = function(lines) {
   return false;
 }
for i in range(1,11):
    Results = pd.read_excel(f'Iteration_{i}.xlsx')
    actions = pd.read_csv(f'Batch_{i}.csv')
     
    Results = np.array(Results)
    wavelength = Results[:,0].T
    Results = Results[:,1:].T

    # 'red-stock', 'green-stock', 'blue-stock'
    actions = actions.iloc[:, 0:3]
    actions = np.array(actions)
    
    plot_batch(Results[:-1], actions, wavelength, TARGET, i)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14330497089117777, 'fraction_numerical': 0.026869682042095836, 'mean_word_length': 3.7230443974630023, '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': '340053', 'license': 'MIT', 'n_tokens_mistral': 816, 'n_tokens_neox': 776, 'n_words': 149, 'path': 'In-lab experiments/GP_BUCB_2021_05_19/Visualization.ipynb', 'repo_name': 'REAL-Pipetting/REinforced-Automaton-Learning-REAL-Pipetting', 'size': '2233'}