Core

Utilities function to train models & others

source

is_plateau

 is_plateau (array:numpy.ndarray, w_size:int=3, delta:float=0.01,
             verbose:bool=True)

Detect if a plateau is reached when array diffs between last w_size below delta

Type Default Details
array np.ndarray 1D array to test
w_size int 3 Last elements to consider
delta float 0.01 Threshold indicating plateau
verbose bool True Display last w_size array’s elements

For instance:

loss = np.array([2.3, 2, 1, 0.5])
print(f'Array (loss): {loss}')
print(f'Has reached a plateau? {is_plateau(loss, delta=0.01)}')
pd.DataFrame(loss).plot();
Array (loss): [2.3 2.  1.  0.5]
Last pairs diff: [0.3 1.  0.5]
Has reached a plateau? False

loss = np.array([2.3, 2, 1, 0.5, 0.4])
print(f'Array (loss): {loss}')
print(f'Has reached a plateau? {is_plateau(loss, delta=0.01)}')
pd.DataFrame(loss).plot();
Array (loss): [2.3 2.  1.  0.5 0.4]
Last pairs diff: [1.  0.5 0.1]
Has reached a plateau? False

loss = np.array([2.3, 2, 1, 0.5, 0.4, 0.38, 0.37])
print(f'Array (loss): {loss}')
print(f'Has reached a plateau? {is_plateau(loss, delta=0.015)}')
pd.DataFrame(loss).plot();
Array (loss): [2.3  2.   1.   0.5  0.4  0.38 0.37]
Last pairs diff: [0.1  0.02 0.01]
Has reached a plateau? False

loss = np.array([2.3, 2, 1, 0.5, 0.4, 0.38, 0.37, 0.369, 0.369])
print(f'Array (loss): {loss}')
print(f'Has reached a plateau? {is_plateau(loss, delta=0.015)}')
pd.DataFrame(loss).plot();
Array (loss): [2.3   2.    1.    0.5   0.4   0.38  0.37  0.369 0.369]
Last pairs diff: [0.01  0.001 0.   ]
Has reached a plateau? True


source

load_dumps

 load_dumps (src_dir)

Load all .pickle file in specified directory

dumps = load_dumps(Path('test/lc'))
test_eq(len(dumps), 2)