<jupyter_start><jupyter_text>This is a tutorial on `loss` mode scenario of `Plot` class.<jupyter_code># Necessary imports
import sys
import numpy as np

sys.path.insert(0, '../..')
from batchflow import plot
# Generate sample data

x = np.linspace(1, 100, 1000)

oscillation = lambda x: np.sin(x) / x + np.random.normal(scale=0.1, size=len(x))

y0 = -np.log(x) * .4 + oscillation(x)<jupyter_output><empty_output><jupyter_text>To display a single curve use `Plot` in `'loss'` mode.<jupyter_code>plot(
    data=y0,
    mode='loss',
    title='Simulated loss' 
)<jupyter_output><empty_output><jupyter_text>To change rolling mean window size specify it in `window` parameter.<jupyter_code>plot(
    data=y0,
    mode='loss',
    title='Simulated loss',
    window=100
)<jupyter_output><empty_output><jupyter_text>To modify mean of last `n` iterations (displayed in legend window), address `final_window` parameter.<jupyter_code>plot(
    data=y0,
    mode='loss',
    title='Simulated loss',
    final_window=200
)<jupyter_output><empty_output><jupyter_text>One migh wish to display several losses simultaneously.<jupyter_code>y1 = -np.log(x) * .6 + oscillation(x)<jupyter_output><empty_output><jupyter_text>To achieve that provide arrays in a list.<jupyter_code>plot(
    data=[y0, y1],
    mode='loss',
    title='Simulated loss',
)<jupyter_output><empty_output><jupyter_text>To display curves on separate plots use `combine='separate'`.<jupyter_code>plot(
    data=[y0, y1],
    mode='loss',
    combine='separate',
    title='Simulated loss',
)<jupyter_output><empty_output><jupyter_text>To display curves in ``'mixed'`` manner, i.e. with some curves overlaid and some displayed separately, use nested lists of arrays.If list has level 2 nestedness, outer level defines subplots order while inner one defines layers order.Note, that parameters should have same nestedness level.<jupyter_code>plot(
    data = [y0, y1, [y0, y1]],
    mode='loss',
    title='Simulated loss',
    color=['skyblue', 'sandybrown', ['skyblue', 'sandybrown']],
    linewidth=[1, 1, 2],
)<jupyter_output><empty_output><jupyter_text>Display learning rate alongside with loss values To display learning rate on the same plot with the loss simply provided it packed in the same tuple.Since learning rate often decays exponentially, it might be usefull to log corresponding axis.<jupyter_code>lr = np.full(len(x), 1e-3)
for i in range(0, len(x), 100):
    lr[i:] /= 10
    
plot(
    data=(y0, lr),
    mode='loss',
    log_lr=True
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1282051282051282, 'fraction_numerical': 0.01775147928994083, 'mean_word_length': 5.200488997555012, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '149999', 'license': 'Apache-2.0', 'n_tokens_mistral': 907, 'n_tokens_neox': 862, 'n_words': 240, 'path': 'examples/plot/04_loss.ipynb', 'repo_name': 'analysiscenter/dataset', 'size': '2535'}