To reproduce the problem, download the files contained in this public folder: https://pandora.infn.it/public/335590
Folder contents:
symptoms.npz (data)
tX.pkl (input sklearn scaler)
saved_model (keras sequential model)
CompiledModel_sim10-2016MU_latest.so (compiled pipeline)
The following lines allow to reproduce the problem, in particular, all the instances contained in symptoms.npz produce quantile and absolute errors greater than $10^{-3}$.
import pickle
import ctypes
import numpy as np
import pandas as pd
from tensorflow import keras
from scipy.stats import percentileofscore as pos
# Symptomatic data
npz_file = np.load("/path/to/symptoms.npz")
x = npz_file["x"].astype(np.float32)
print(x.shape) # (80, 4)
# Python output
with open("/path/to/tX.pkl", "rb") as file:
x_scaler = pickle.load(file)
x_prep = x_scaler.transform(x)
model = keras.models.load_model("/path/to/saved_model")
ismuon_py = model.predict(x_prep)
# C output
dll = ctypes.CDLL("/path/to/CompiledModel_sim10-2016MU_latest.so")
float_p = ctypes.POINTER(ctypes.c_float)
ismuon_c = []
for input_row in x:
in_f = input_row.astype(ctypes.c_float)
out_f = np.empty(1, dtype=ctypes.c_float)
getattr(dll, f"isMuon_pion_pipe")(
out_f.ctypes.data_as(float_p),
in_f.ctypes.data_as(float_p),
)
ismuon_c.append(out_f)
# Numerical instability
ismuon_py = ismuon_py.flatten()
ismuon_c = np.array(ismuon_c).flatten()
ismuon_err_df = pd.DataFrame()
ismuon_q_err_py = pos(ismuon_py, ismuon_py)
ismuon_q_err_c = pos(ismuon_py, ismuon_c)
ismuon_err_df["q_err_isMuon"] = (ismuon_q_err_py - ismuon_q_err_c) / 1e2
ismuon_err_df["abs_err_isMuon"] = abs(ismuon_py - ismuon_c)
err_counts = np.count_nonzero(
(abs(ismuon_err_df["q_err_isMuon"]) > 0.001)
& (ismuon_err_df["abs_err_isMuon"] > 0.001)
)
print(err_counts) # 80
To reproduce the problem, download the files contained in this public folder: https://pandora.infn.it/public/335590
Folder contents:
symptoms.npz(data)tX.pkl(input sklearn scaler)saved_model(keras sequential model)CompiledModel_sim10-2016MU_latest.so(compiled pipeline)The following lines allow to reproduce the problem, in particular, all the instances contained in$10^{-3}$ .
symptoms.npzproduce quantile and absolute errors greater than