1 #ifndef TMVA_TEST_DNN_UTILITY 2 #define TMVA_TEST_DNN_UTILITY 20 template <
typename AArchitecture>
23 int nlayers = rand() % 5 + 1;
25 std::vector<EActivationFunction> ActivationFunctions
28 for (
int i = 0; i < nlayers; i++) {
29 int width = rand() % 20 + 1;
31 ActivationFunctions[rand() % ActivationFunctions.size()];
38 template <
typename AMatrix>
46 for (
size_t i = 0; i <
m; i++) {
47 for (
size_t j = 0; j <
n; j++) {
58 template <
typename AMatrix>
69 for (
size_t i = 0; i <
m; i++) {
70 for (
size_t j = 0; j <
n; j++) {
71 X(i,j) = rand.
Gaus(0.0, sigma);
78 template <
typename AMatrix>
86 template <
typename AMatrix>
93 for (
size_t i = 0; i <
m; i++) {
94 for (
size_t j = 0; j <
n; j++) {
102 template <
typename AMatrix,
typename F>
109 for (
size_t i = 0; i <
m; i++) {
110 for (
size_t j = 0; j <
n; j++) {
119 template <
typename AMatrix,
typename F>
129 for (
size_t i = 0; i <
m; i++) {
130 for (
size_t j = 0; j <
n; j++) {
131 Z(i,j) =
f(
X(i,j),
Y(i,j));
138 template <
typename AMatrix,
typename AFloat,
typename F>
147 for (
size_t i = 0; i <
m; i++) {
148 for (
size_t j = 0; j <
n; j++) {
149 result =
f(result,
X(i,j));
158 template <
typename AMatrix,
typename AFloat,
typename F>
167 for (
size_t i = 0; i <
m; i++) {
168 for (
size_t j = 0; j <
n; j++) {
169 result =
f(result,
X(i,j));
172 return result / (AFloat) (m * n);
179 template <
typename AFloat>
189 if ((std::abs(x) > 1
e-10) && (std::abs(y) > 1
e-10)) {
201 if ((std::abs(x) > 1
e-5) && (std::abs(y) > 1
e-5)) {
212 template <
typename AMatrix>
218 using AFloat = decltype(
X(0,0));
224 AFloat maximumError = 0.0;
226 for (
size_t i = 0; i <
m; i++) {
227 for (
size_t j = 0; j <
n; j++) {
229 maximumError = std::max(error, maximumError);
238 template <
typename F,
typename AFloat>
241 return f(dx) -
f(0.0 - dx);
246 template <
typename AFloat>
249 std::ostringstream out{};
void randomMatrix(AMatrix &X)
Fill matrix with random, Gaussian-distributed values.
auto maximumRelativeError(const AMatrix &X, const AMatrix &Y) -> decltype(X(0, 0))
Compute the maximum, element-wise relative error of the matrices X and Y normalized by the element of...
void applyMatrix(AMatrix &X, F f)
Apply functional to each element in the matrix.
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
void constructRandomLinearNet(TNet< AArchitecture > &net)
Construct a random linear neural network with up to five layers.
void identityMatrix(AMatrix &X)
Set matrix to the identity matrix.
void AddLayer(size_t width, EActivationFunction f, Scalar_t dropoutProbability=1.0)
Add a layer of the given size to the neural net.
AFloat reduceMean(F f, AFloat start, const AMatrix &X)
Apply function to matrix element-wise and compute the mean of the resulting element values...
std::string print_error(AFloat &e)
Color code error.
This is the base class for the ROOT Random number generators.
AFloat finiteDifference(F f, AFloat dx)
Numerically compute the derivative of the functional f using finite differences.
void zipWithMatrix(AMatrix &Z, F f, const AMatrix &X, const AMatrix &Y)
Combine elements of two given matrices into a single matrix using the given function f...
Generic neural network class.
VecExpr< UnaryOp< Fabs< T >, VecExpr< A, T, D >, T >, T, D > fabs(const VecExpr< A, T, D > &rhs)
void randomBatch(AMatrix &X)
Generate a random batch as input for a neural net.
void copyMatrix(AMatrix &X, const AMatrix &Y)
Generate a random batch as input for a neural net.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Abstract ClassifierFactory template that handles arbitrary types.
AFloat relativeError(const AFloat &x, const AFloat &y)
Compute the relative error of x and y normalized by y.
EActivationFunction
Enum that represents layer activation functions.
AFloat reduce(F f, AFloat start, const AMatrix &X)
Generate a random batch as input for a neural net.