Calibration Results Processing Script

This script is designed to process and sort calibration results stored in .pkl files within the current directory. It identifies files ending with '.pkl', sorts them based on specific criteria extracted from their filenames, and then loads and evaluates the calibration results from each file using the pickle module. It prints the optimized alphaML parameter if the calibration was successful or indicates failure otherwise.

import pickle as pkl
import os
 
calibResultFiles = filter(lambda x: x.endswith(".pkl"), os.listdir("."))
sortedCalibFiles = sorted(calibResultFiles, key=lambda x: (x.split('-')[0][-1], float(x.split('+')[1].split('_')[0])))
for file in sortedCalibFiles:
    with open(file, 'rb') as f:
        calibResults = pkl.load(f)
 
    if calibResults.success:
        print(f"For {file} calibrated alphaML is {calibResults.x[2]:0.3f}")
    else:
        print(f"For {file} calibration FAILED!")