ROOT
master
Reference Guide
Loading...
Searching...
No Matches
DataLoader.cxx
Go to the documentation of this file.
1
// @(#)root/tmva/tmva/dnn:$Id$
2
// Author: Simon Pfreundschuh 06/06/17
3
4
/*************************************************************************
5
* Copyright (C) 2016, Simon Pfreundschuh *
6
* All rights reserved. *
7
* *
8
* For the licensing terms see $ROOTSYS/LICENSE. *
9
* For the list of contributors see $ROOTSYS/README/CREDITS. *
10
*************************************************************************/
11
12
/////////////////////////////////////////////////////////////
13
// Specializations of Copy functions for the DataLoader //
14
// specialized for the reference architecture. //
15
/////////////////////////////////////////////////////////////
16
17
#include "
TMVA/DNN/Architectures/Reference.h
"
18
#include "
TMVA/DataSetInfo.h
"
19
20
namespace
TMVA
{
21
namespace
DNN {
22
23
//______________________________________________________________________________
24
template
<>
25
void
TDataLoader<MatrixInput_t, TReference<Real_t>
>::CopyInput(
TMatrixT<Real_t>
&
matrix
,
IndexIterator_t
sampleIterator
)
26
{
27
const
TMatrixT<Real_t>
&
input
= std::get<0>(fData);
28
Int_t
m
=
matrix
.GetNrows();
29
Int_t
n
=
input
.GetNcols();
30
31
for
(
Int_t
i = 0; i <
m
; i++) {
32
Int_t
sampleIndex
= *
sampleIterator
;
33
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
34
matrix
(i,
j
) =
static_cast<
Real_t
>
(
input
(
sampleIndex
,
j
));
35
}
36
sampleIterator
++;
37
}
38
}
39
40
//______________________________________________________________________________
41
template
<>
42
void
TDataLoader<MatrixInput_t, TReference<Real_t>
>::CopyOutput(
TMatrixT<Real_t>
&
matrix
,
43
IndexIterator_t
sampleIterator
)
44
{
45
const
TMatrixT<Real_t>
&
output
= std::get<1>(fData);
46
Int_t
m
=
matrix
.GetNrows();
47
Int_t
n
=
output
.GetNcols();
48
49
for
(
Int_t
i = 0; i <
m
; i++) {
50
Int_t
sampleIndex
= *
sampleIterator
;
51
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
52
matrix
(i,
j
) =
static_cast<
Real_t
>
(
output
(
sampleIndex
,
j
));
53
}
54
sampleIterator
++;
55
}
56
}
57
58
//______________________________________________________________________________
59
template
<>
60
void
TDataLoader<MatrixInput_t, TReference<Real_t>
>::CopyWeights(
TMatrixT<Real_t>
&
matrix
,
61
IndexIterator_t
sampleIterator
)
62
{
63
const
TMatrixT<Real_t>
&weights = std::get<2>(fData);
64
Int_t
m
=
matrix
.GetNrows();
65
66
for
(
Int_t
i = 0; i <
m
; i++) {
67
Int_t
sampleIndex
= *
sampleIterator
;
68
matrix
(i, 0) =
static_cast<
Real_t
>
(weights(
sampleIndex
, 0));
69
sampleIterator
++;
70
}
71
}
72
73
//______________________________________________________________________________
74
template
<>
75
void
TDataLoader<MatrixInput_t, TReference<Double_t>
>::CopyInput(
TMatrixT<Double_t>
&
matrix
,
76
IndexIterator_t
sampleIterator
)
77
{
78
const
TMatrixT<Double_t>
&
input
= std::get<0>(fData);
79
Int_t
m
=
matrix
.GetNrows();
80
Int_t
n
=
input
.GetNcols();
81
82
for
(
Int_t
i = 0; i <
m
; i++) {
83
Int_t
sampleIndex
= *
sampleIterator
;
84
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
85
matrix
(i,
j
) =
static_cast<
Double_t
>
(
input
(
sampleIndex
,
j
));
86
}
87
sampleIterator
++;
88
}
89
}
90
91
//______________________________________________________________________________
92
template
<>
93
void
TDataLoader<MatrixInput_t, TReference<Double_t>
>::CopyOutput(
TMatrixT<Double_t>
&
matrix
,
94
IndexIterator_t
sampleIterator
)
95
{
96
const
TMatrixT<Double_t>
&
output
= std::get<1>(fData);
97
Int_t
m
=
matrix
.GetNrows();
98
Int_t
n
=
output
.GetNcols();
99
100
for
(
Int_t
i = 0; i <
m
; i++) {
101
Int_t
sampleIndex
= *
sampleIterator
;
102
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
103
matrix
(i,
j
) =
static_cast<
Double_t
>
(
output
(
sampleIndex
,
j
));
104
}
105
sampleIterator
++;
106
}
107
}
108
109
//______________________________________________________________________________
110
template
<>
111
void
TDataLoader<MatrixInput_t, TReference<Double_t>
>::CopyWeights(
TMatrixT<Double_t>
&
matrix
,
112
IndexIterator_t
sampleIterator
)
113
{
114
const
TMatrixT<Double_t>
&
output
= std::get<2>(fData);
115
Int_t
m
=
matrix
.GetNrows();
116
117
for
(
Int_t
i = 0; i <
m
; i++) {
118
Int_t
sampleIndex
= *
sampleIterator
;
119
matrix
(i, 0) =
static_cast<
Double_t
>
(
output
(
sampleIndex
, 0));
120
sampleIterator
++;
121
}
122
}
123
124
//______________________________________________________________________________
125
template
<>
126
void
TDataLoader<TMVAInput_t, TReference<Real_t>
>::CopyInput(
TMatrixT<Real_t>
&
matrix
,
IndexIterator_t
sampleIterator
)
127
{
128
// short-circuit on empty
129
if
(std::get<0>(fData).empty())
130
return
;
131
Event
*
event
=
nullptr
;
132
133
Int_t
m
=
matrix
.GetNrows();
134
Int_t
n
=
matrix
.GetNcols();
135
136
// Copy input variables.
137
138
for
(
Int_t
i = 0; i <
m
; i++) {
139
Int_t
sampleIndex
= *
sampleIterator
++;
140
event
= std::get<0>(fData)[
sampleIndex
];
141
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
142
matrix
(i,
j
) =
event
->GetValue(
j
);
143
}
144
}
145
}
146
147
//______________________________________________________________________________
148
template
<>
149
void
TDataLoader<TMVAInput_t, TReference<Real_t>
>::CopyOutput(
TMatrixT<Real_t>
&
matrix
,
IndexIterator_t
sampleIterator
)
150
{
151
// short-circuit on empty
152
if
(std::get<0>(fData).empty())
153
return
;
154
Event
*
event
=
nullptr
;
155
const
DataSetInfo
&
info
= std::get<1>(fData);
156
Int_t
m
=
matrix
.GetNrows();
157
Int_t
n
=
matrix
.GetNcols();
158
159
for
(
Int_t
i = 0; i <
m
; i++) {
160
Int_t
sampleIndex
= *
sampleIterator
++;
161
event
= std::get<0>(fData)[
sampleIndex
];
162
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
163
// Classification
164
if
(event->GetNTargets() == 0) {
165
if
(
n
== 1) {
166
// Binary.
167
matrix
(i,
j
) = (
info
.IsSignal(event)) ? 1.0 : 0.0;
168
}
else
{
169
// Multiclass.
170
matrix
(i,
j
) = 0.0;
171
if
(
j
==
static_cast<
Int_t
>
(event->GetClass())) {
172
matrix
(i,
j
) = 1.0;
173
}
174
}
175
}
else
{
176
matrix
(i,
j
) =
static_cast<
Real_t
>
(
event
->GetTarget(
j
));
177
}
178
}
179
}
180
}
181
182
//______________________________________________________________________________
183
template
<>
184
void
TDataLoader<TMVAInput_t, TReference<Real_t>
>::CopyWeights(
TMatrixT<Real_t>
&
matrix
,
IndexIterator_t
sampleIterator
)
185
{
186
// short-circuit on empty
187
if
(std::get<0>(fData).empty())
188
return
;
189
Event
*
event
=
nullptr
;
190
for
(
Int_t
i = 0; i <
matrix
.GetNrows(); i++) {
191
Int_t
sampleIndex
= *
sampleIterator
++;
192
event
= std::get<0>(fData)[
sampleIndex
];
193
matrix
(i, 0) =
event
->GetWeight();
194
}
195
}
196
197
//______________________________________________________________________________
198
template
<>
199
void
TDataLoader<TMVAInput_t, TReference<Double_t>
>::CopyInput(
TMatrixT<Double_t>
&
matrix
,
200
IndexIterator_t
sampleIterator
)
201
{
202
// short-circuit on empty
203
if
(std::get<0>(fData).empty())
204
return
;
205
Event
*
event
=
nullptr
;
206
Int_t
m
=
matrix
.GetNrows();
207
208
// Copy input variables.
209
210
for
(
Int_t
i = 0; i <
m
; i++) {
211
Int_t
sampleIndex
= *
sampleIterator
++;
212
event
= std::get<0>(fData)[
sampleIndex
];
213
for
(
Int_t
j
= 0;
j < static_cast<Int_t>
(event ? event->GetNVariables() : 0);
j
++) {
214
matrix
(i,
j
) =
event
->GetValue(
j
);
215
}
216
}
217
}
218
219
//______________________________________________________________________________
220
template
<>
221
void
TDataLoader<TMVAInput_t, TReference<Double_t>
>::CopyOutput(
TMatrixT<Double_t>
&
matrix
,
222
IndexIterator_t
sampleIterator
)
223
{
224
Event
*
event
=
nullptr
;
225
const
DataSetInfo
&
info
= std::get<1>(fData);
226
Int_t
m
=
matrix
.GetNrows();
227
Int_t
n
=
matrix
.GetNcols();
228
229
for
(
Int_t
i = 0; i <
m
; i++) {
230
Int_t
sampleIndex
= *
sampleIterator
++;
231
event
= std::get<0>(fData)[
sampleIndex
];
232
for
(
Int_t
j
= 0;
j
<
n
;
j
++) {
233
// Classification
234
if
(event->GetNTargets() == 0) {
235
if
(
n
== 1) {
236
// Binary.
237
matrix
(i,
j
) = (
info
.IsSignal(event)) ? 1.0 : 0.0;
238
}
else
{
239
// Multiclass.
240
matrix
(i,
j
) = 0.0;
241
if
(
j
==
static_cast<
Int_t
>
(event->GetClass())) {
242
matrix
(i,
j
) = 1.0;
243
}
244
}
245
}
else
{
246
matrix
(i,
j
) =
static_cast<
Real_t
>
(
event
->GetTarget(
j
));
247
}
248
}
249
}
250
}
251
252
//______________________________________________________________________________
253
template
<>
254
void
TDataLoader<TMVAInput_t, TReference<Double_t>
>::CopyWeights(
TMatrixT<Double_t>
&
matrix
,
255
IndexIterator_t
sampleIterator
)
256
{
257
Event
*
event
=
nullptr
;
258
259
for
(
Int_t
i = 0; i <
matrix
.GetNrows(); i++) {
260
Int_t
sampleIndex
= *
sampleIterator
++;
261
event
= std::get<0>(fData)[
sampleIndex
];
262
matrix
(i, 0) =
event
->GetWeight();
263
}
264
}
265
266
// Explicit instantiations.
267
template
class
TDataLoader<MatrixInput_t, TReference<Real_t>
>;
268
template
class
TDataLoader<TMVAInput_t, TReference<Real_t>
>;
269
template
class
TDataLoader<MatrixInput_t, TReference<Double_t>
>;
270
template
class
TDataLoader<TMVAInput_t, TReference<Double_t>
>;
271
272
}
// namespace DNN
273
}
// namespace TMVA
DataSetInfo.h
Reference.h
Real_t
float Real_t
Definition
RtypesCore.h:68
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
input
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
Definition
TGWin32VirtualXProxy.cxx:142
ROOT::Detail::TRangeCast
Definition
TCollection.h:311
ROOT::Internal::TypedIter
Definition
RRangeCast.hxx:46
TMVA::DataSetInfo
Class that contains all the data information.
Definition
DataSetInfo.h:62
TMVA::Event
Definition
Event.h:51
double
int
n
const Int_t n
Definition
legend1.C:16
TMVA
create variable transformations
Definition
GeneticMinimizer.h:22
m
TMarker m
Definition
textangle.C:8
output
static void output()
tmva
tmva
src
DNN
Architectures
Reference
DataLoader.cxx
ROOT master - Reference Guide Generated on Mon Feb 17 2025 15:03:41 (GVA Time) using Doxygen 1.10.0