# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/25_training.core.ipynb.

# %% ../nbs/25_training.core.ipynb 3
from __future__ import annotations
import numpy as np
import pandas as pd

# %% auto 0
__all__ = ['is_plateau']

# %% ../nbs/25_training.core.ipynb 5
def is_plateau(array:np.ndarray, # 1D array to test
               w_size:int=3, # Moving average window size
               delta:float=0.01, # Threshold indicating plateau  
               verbose:bool=True # Display mean's evolution
              ):
    '''Detect if a plateau is reached'''  
    if len(array) < w_size:
        return False
    prev_mean = np.mean(array[-(w_size+1):-1])
    new_mean = np.mean(array[-w_size:])
    if verbose:
        print(f'Previous mean: {prev_mean:.3f}')
        print(f'New mean: {new_mean:.3f}')
        print(f'Is means difference: {prev_mean - new_mean:.3f} < {delta:.3f}')
    return True if (prev_mean - new_mean) < delta else False
