<jupyter_start><jupyter_text>The block maxima methodThis notebook continues with a subset of the dataset of the notebook about the `Dataset` object.There are two main approaches in extreme value theory: the peaks over threshold approach and the block maxima approach.In this notebook, the block maxima approach will be illustrated.To make the plotting less crowded, we will take a subset of the original dataset by reducing `N_DATAPOINTS`.<jupyter_code>from evt.dataset import Dataset
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from scipy.stats import pareto, norm

N_DATAPOINTS = 10000  # number of datapoints in the example set
NORMAL_STD = 5  # standard deviation of the normal distribution
PARETO_SHAPE = 2.5  # shape parameter of the Pareto distribution
EXAMPLE_NAME = 'Values'  # for nicer plots
EXAMPLE_INDEX_NAME = 'Index'

np.random.seed(0)  # enforce deterministic behaviour

series = pd.Series(
    norm.rvs(scale=NORMAL_STD, size=N_DATAPOINTS) + pareto.rvs(PARETO_SHAPE, size=N_DATAPOINTS),
    name=EXAMPLE_NAME
)
series.index.name = EXAMPLE_INDEX_NAME

dataset = Dataset(series)<jupyter_output><empty_output><jupyter_text>Let's start by examining the block maxima of the subset of our dataset.<jupyter_code>from evt.methods.block_maxima import BlockMaxima

N_SAMPLES_PER_BLOCK = 500

block_maxima = BlockMaxima(dataset, N_SAMPLES_PER_BLOCK)<jupyter_output><empty_output><jupyter_text>The block maxima are stored in the `self.block_maxima` attribute.<jupyter_code>block_maxima.block_maxima<jupyter_output><empty_output><jupyter_text>Visually inspect the block maxima using plotting functions of the block maxima object.<jupyter_code>fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))

block_maxima.plot_block_maxima(ax1)
block_maxima.plot_block_maxima_boxplot(ax2)

fig.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07116104868913857, 'fraction_numerical': 0.011235955056179775, 'mean_word_length': 6.6016260162601625, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '340365', 'license': 'MIT', 'n_tokens_mistral': 637, 'n_tokens_neox': 614, 'n_words': 180, 'path': 'tutorial/2_block_maxima.ipynb', 'repo_name': 'spmvg/evt', 'size': '1869'}