deepnn¶
Documentation for the functions in the machine_learning.deepnn module:
- machine_learning.deepnn.train_dnn(training_set, settings, savefig=True, figname='', trained_filenames=('deepnn.json', 'deepnn.h5'))[source]¶
Trains a Keras deep neural network.
- Parameters:
training_set (2D numpy.array[float]) – 2D numpy array with flag={0,1} as last column for training the DNN.
settings (utilities.import_datasets.DnnSettings class instance) – DnnSettings instance with the settings for the generation of the DNN.
savefig (bool) – If
True, saves the history plot of the training.figname (str) – If
savefig==True, saves the loss history figure with this name.trained_filenames (tuple[str]) – Two element tuple containing respectively the name of the .json of the file where to save the DNN and the .h5 where to store its weigths.
- Returns:
Trained deep neural network.
- Return type:
keras.models.Model
- machine_learning.deepnn.eval_dnn(dnn, eval_set, flag_data=True, savefig=True, plot_opt=[], figname='')[source]¶
Evaluates a given keras deep neural network on a given dataset.
- Parameters:
dnn (keras.models.Model) – Trained deep neural network to be used in the evaluation.
eval_set (2D numpy.array[float]) – 2D numpy array to evaluate.
flag_data (bool) – If
Trueassumes the eval_set array has no flag column at the end, otherwise it strips away the last column before evaluation.savefig (bool) – If
Truesaves the histogram of the evaluation results of the given set.plot_opt (tuple[str] or list[str]) – Three-element tuple or list, containing the name of the plot, the color of the histogram and its label (in this order).
figname (str) – If savefig=``True``, saves the evaluation figure with this name.
- Returns:
Predictions of the of the eval_set’s events.
- Return type:
numpy.array[float]
- machine_learning.deepnn.dnn(source=('root', ('/home/docs/checkouts/readthedocs.org/user_builds/cmepda-pikclassifier/checkouts/latest/utilities/../data/root_files/B0PiPi_MC.root', '/home/docs/checkouts/readthedocs.org/user_builds/cmepda-pikclassifier/checkouts/latest/utilities/../data/root_files/B0sKK_MC.root', '/home/docs/checkouts/readthedocs.org/user_builds/cmepda-pikclassifier/checkouts/latest/utilities/../data/root_files/Bhh_data.root')), root_tree='tree;1', vars=('M0_Mpipi', 'M0_MKK', 'M0_MKpi', 'M0_MpiK', 'M0_p', 'M0_pt', 'M0_eta', 'h1_thetaC0', 'h1_thetaC1', 'h1_thetaC2', 'h2_thetaC0', 'h2_thetaC1', 'h2_thetaC2'), n_mc=560000, n_data=50000, test_split=0.2, settings=<utilities.dnn_settings.DnnSettings object>, efficiency=0.9, error_optimization=True, load=False, trained_filenames=('deepnn.json', 'deepnn.h5'), savefigs=False, figpath='', fignames=('', '', '', ''))[source]¶
Trains or loads a deep neural network and uses it to estimate the fraction ‘f’ of Kaons in the mixed dataset. To do that, an evaluation of the dnn on the “testing dataset” with a fixed value of efficiency is required
- Parameters:
source (tuple[{'root','txt'}, tuple[str]]) – Two element tuple containing the options for how to build the datasets for the DNN and the relative paths. The first item can be either ‘txt’ or ‘root’. In case it is built from txt, the second element of source must be a tuple containing two .txt paths, one relative to the training set and the other to the data set to be evaluated. The .txt files must be in a format compatible with numpy’s loadtxt() and savetxt() methods. In case it is built from root the second element of source must be a tuple containing three .root file paths, for the “background” set (flag=0), the “signal” set (flag=1) and the data one, in this order.
root_tree (str) – In case of ‘root’ source, the name of the tree from which to load variables.
vars (tuple[str]) – In case of ‘root’ source, tuple containing the names of the features to load for the DNN.
n_mc (int) – In case of ‘root’ source, number of events to take from the root files for the training set.
n_data (int) – In case of ‘root’ source, number of events to take from the root file for the mixed set.
test_split (float) – Fraction of the training array that is used for the testing
settings (utilities.import_datasets.DnnSettings class instance) – DnnSettings instance with the settings for the generation of the DNN.
load (bool) – If
True, instead of training a new DNN, it loads it from the files given in “trained_model”.trained_filenames (tuple[str]) – Two element tuple containing respectively the name of the .json and .h5 files from which to load the DNN structure and weights, if
load==True.efficiency (float) – Sensitivity required from the test
error_optimization (bool) – Performs error optimization instead of using a fixed efficiency value
savefigs (bool) – If
True, saves the training history (if the DNN was not loaded) and the histograms of the evaluation results on the training and mixed datasets.figpath (str) – Path where to save the figures (in case
savefigs==True)fignames (tuple[str]) – Four element tuple containing the figure names (in case
savefigs==True) for: DNN training history figure, evaluated training species figures, evaluated mixed dataset figure.
- Returns:
Estimated signal fraction (with uncertainties), parameters of the test algorithm and arrays containing the DNN evaluation of the testing array (divided for the two species)
- Return type:
tuple[float], tuple[float], tuple[numpy.array[float]]