Belle II Software development
|
The class uses a neural network to find a probability distribution of arrival times for a sextet of APX25 signal samples. More...
#include <NNWaveFitter.h>
Public Types | |
typedef std::pair< double, double > | nnBoundsType |
Bounds type used to hold network parameter bounds used in training the network. | |
Public Member Functions | |
NNWaveFitter (std::string xmlData="") | |
Constructor constructs the wavefitter from data in xml file. | |
void | setNetwrok (const std::string &xmlData) |
Set proper network definition file. | |
std::shared_ptr< nnFitterBinData > | getFit (const apvSamples &samples, double tau) |
Fitting method Send data and get rseult structure. | |
const NNWaveFitTool & | getFitTool () const |
Get a handle to a NNWaveFit object. | |
const nnFitterBinData & | getBinCenters () const |
Get bin times of the network output. | |
const nnFitterBins & | getBins () const |
Get bins of netwrok output. | |
nnBoundsType | getWaveWidthBounds () const |
Get width bounds Width bounds are minimum and maximum width used in training the network. | |
nnBoundsType | getAmplitudeBounds () const |
Get amplitude bounds. | |
nnBoundsType | getTimeShiftBounds () const |
Get time shift bounds. | |
bool | isValid () const |
Is this fitter working? Return false if the fitter was not initialized properly. | |
bool | checkCoefficients (const std::string &dumpname, double tol=1.0e-10) |
Check NN data against a dump from Python. | |
Private Types | |
typedef std::function< double(double)> | activationType |
Activation functions type. | |
typedef std::map< size_t, std::pair< Eigen::MatrixXd, Eigen::VectorXd > > | networkWeightsType |
We use map to store network layers since we don't know if we'll be reading them in correct order. | |
typedef std::vector< Eigen::VectorXd > | layerStatesType |
Storage for internal states. | |
Private Member Functions | |
Eigen::VectorXd | softmax (const Eigen::VectorXd &input) |
Softmax function, normalization for the network's output layer. | |
int | readNetworkData (const std::string &xmlFileName) |
The method that actually reads the xml file. | |
Private Attributes | |
activationType | relu |
Rectifier activation. | |
activationType | sigmoid |
Sigmoid activation. | |
bool | m_isValid |
true if fitter was properly initialized | |
std::size_t | m_nLayers |
number of NN layers, read from xml | |
nnFitterBinData | m_binCenters |
centers of NN time bins | |
nnFitterBins | m_bins |
NN time bin boundaries. | |
layerStatesType | m_layerStates |
vectors of layer states | |
std::vector< std::size_t > | m_layerSizes |
NN layer sizes. | |
networkWeightsType | m_networkCoefs |
NN weights and intercepts. | |
activationType | m_activation |
Network activation function. | |
nnBoundsType | m_amplitudeBounds |
Amplitude range of the network. | |
nnBoundsType | m_waveWidthBounds |
Waveform width range of the network. | |
nnBoundsType | m_timeShiftBounds |
Time shift range of the network. | |
TauEncoder | m_tauCoder |
Tau encoder class instance to scale tau values. | |
WaveformShape | m_wave |
Wave function used in training the network. | |
std::shared_ptr< NNWaveFitTool > | m_fitTool |
FitterTool object allowing calculations on network fits. | |
The class uses a neural network to find a probability distribution of arrival times for a sextet of APX25 signal samples.
The input to the network are sample S/N ratios, i.e., we expect sigma^2 = 1, plus width of the waveform from calibration data. The network(s) is currently trained using Python's scikit-learn package and results are saved in a PMML-like xml file. The NNWaveFitter reads the contents of this xml and on request provides the following data to the calling routine:
The network is a multiclass classifier and the time bin probabilities are its main output. Time and amplitude are calculated from this distribution. The probability distribution is useful by itself in background suppression and u/v hit pairing.
The input xml file has, with a few extensions, the official PMML format (http://dmg.org), which can be created and read by most machine learning libraries.
The fitter generates a NNWaveFit object to aid in computations with bin probabilities, such as shifting, multiplication, calculations of time shift, amplitude and their errors.
Definition at line 61 of file NNWaveFitter.h.
|
private |
Activation functions type.
Definition at line 143 of file NNWaveFitter.h.
|
private |
Storage for internal states.
Definition at line 177 of file NNWaveFitter.h.
|
private |
We use map to store network layers since we don't know if we'll be reading them in correct order.
Definition at line 174 of file NNWaveFitter.h.
typedef std::pair<double, double> nnBoundsType |
Bounds type used to hold network parameter bounds used in training the network.
Also, this is the range guaranteed network applicability.
Definition at line 70 of file NNWaveFitter.h.
NNWaveFitter | ( | std::string | xmlData = "" | ) |
Constructor constructs the wavefitter from data in xml file.
xmlData | string containing the network definition xml tree |
Definition at line 260 of file NNWaveFitter.cc.
bool checkCoefficients | ( | const std::string & | dumpname, |
double | tol = 1.0e-10 |
||
) |
Check NN data against a dump from Python.
dumpname | Filename of a text dump of network coefficients. |
tol | Tolerance for float comparisons |
Definition at line 192 of file NNWaveFitter.cc.
|
inline |
Get amplitude bounds.
Definition at line 121 of file NNWaveFitter.h.
|
inline |
Get bin times of the network output.
Definition at line 104 of file NNWaveFitter.h.
|
inline |
Get bins of netwrok output.
Definition at line 109 of file NNWaveFitter.h.
std::shared_ptr< nnFitterBinData > getFit | ( | const apvSamples & | samples, |
double | tau | ||
) |
Fitting method Send data and get rseult structure.
If the fitter is not properly initialized, empty structure with valid = false will be returned, no warning - warning is only given for unsuccessful initialization.
samples | Array of 6 apv samples |
tau | The wave width for the current strip (unencoded ns) |
Definition at line 267 of file NNWaveFitter.cc.
|
inline |
Get a handle to a NNWaveFit object.
The object provides a set of tools to maniulate probabilities and calculate things from probability distributions.
Definition at line 98 of file NNWaveFitter.h.
|
inline |
Get time shift bounds.
Definition at line 126 of file NNWaveFitter.h.
|
inline |
Get width bounds Width bounds are minimum and maximum width used in training the network.
The bounds are used to encode width on input to the fitter.
Definition at line 116 of file NNWaveFitter.h.
|
inline |
Is this fitter working? Return false if the fitter was not initialized properly.
Definition at line 131 of file NNWaveFitter.h.
|
private |
The method that actually reads the xml file.
Counting things in NN:
xmlFileName | Name of the source xml file with network data |
Layers: input (hidden layers) output = n_hidden_lyaers + 2 = m_nLayers 0,1,2,... m_nLayers - 1. Layer sizes: input is 6, output is given by time binning in training, so we know terms 0 and m_nLayers - 1, and we can even establish hidden layer sizes beforehand from the repr of the classifier! Weights are about connections between layers, so we have w01, w12,.. w(m_nLayers-2)(m_nLayers-1) so we denote w1, w2, ... w(m_nLayers - 1) Intercepts are related to neurons where connections converge and activation is applied. So we have i1,...i(m_nLayers - 1).
Definition at line 36 of file NNWaveFitter.cc.
void setNetwrok | ( | const std::string & | xmlData | ) |
Set proper network definition file.
xmlData | string containing the network definition xml tree |
Definition at line 251 of file NNWaveFitter.cc.
|
inlineprivate |
Softmax function, normalization for the network's output layer.
This is a strange softmax that maps zero values back to zero, but this is what scikit-learn returns.
Definition at line 155 of file NNWaveFitter.h.
|
private |
Network activation function.
Definition at line 187 of file NNWaveFitter.h.
|
private |
Amplitude range of the network.
Definition at line 188 of file NNWaveFitter.h.
|
private |
centers of NN time bins
Definition at line 182 of file NNWaveFitter.h.
|
private |
NN time bin boundaries.
Definition at line 183 of file NNWaveFitter.h.
|
private |
FitterTool object allowing calculations on network fits.
Definition at line 193 of file NNWaveFitter.h.
|
private |
true if fitter was properly initialized
Definition at line 180 of file NNWaveFitter.h.
|
private |
NN layer sizes.
Definition at line 185 of file NNWaveFitter.h.
|
private |
vectors of layer states
Definition at line 184 of file NNWaveFitter.h.
|
private |
NN weights and intercepts.
Definition at line 186 of file NNWaveFitter.h.
|
private |
number of NN layers, read from xml
Definition at line 181 of file NNWaveFitter.h.
|
private |
Tau encoder class instance to scale tau values.
Definition at line 191 of file NNWaveFitter.h.
|
private |
Time shift range of the network.
Definition at line 190 of file NNWaveFitter.h.
|
private |
Wave function used in training the network.
Definition at line 192 of file NNWaveFitter.h.
|
private |
Waveform width range of the network.
Definition at line 189 of file NNWaveFitter.h.
|
private |
Rectifier activation.
Definition at line 145 of file NNWaveFitter.h.
|
private |
Sigmoid activation.
Definition at line 148 of file NNWaveFitter.h.