Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TensorDataLoader.cxx
Go to the documentation of this file.
1// @(#)root/tmva/tmva/dnn:$Id$
2// Author: Vladimir Ilievski
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : TTensorDataLoader *
8 * *
9 * *
10 * Description: *
11 * Specialization of the Tensor Data Loader Class *
12 * *
13 * Authors (alphabetical): *
14 * Vladimir Ilievski <ilievski.vladimir@live.com> - CERN, Switzerland *
15 * *
16 * Copyright (c) 2005-2015: *
17 * CERN, Switzerland *
18 * U. of Victoria, Canada *
19 * MPI-K Heidelberg, Germany *
20 * U. of Bonn, Germany *
21 * *
22 * Redistribution and use in source and binary forms, with or without *
23 * modification, are permitted according to the terms listed in LICENSE *
24 * (see tmva/doc/LICENSE) *
25 **********************************************************************************/
26
27///////////////////////////////////////////////////////////////////
28// Specializations of Copy functions for the TensorDataLoader //
29// specialized for the reference architecture. //
30///////////////////////////////////////////////////////////////////
31
33#include "TMVA/DataSetInfo.h"
34
35namespace TMVA {
36namespace DNN {
37
38//______________________________________________________________________________
39template <>
42{
43 const std::vector<TMatrixT<Double_t>> &linputTensor = std::get<0>(fData);
44
45 if (fBatchDepth == 1) {
46 for (size_t i = 0; i < fBatchHeight; i++) {
48 for (size_t j = 0; j < fBatchWidth; j++) {
49 tensor[0](i, j) = static_cast<Real_t>(linputTensor[0](sampleIndex, j));
50 }
52 }
53 } else {
54 for (size_t i = 0; i < fBatchDepth; i++) {
56 for (size_t j = 0; j < fBatchHeight; j++) {
57 for (size_t k = 0; k < fBatchWidth; k++) {
58 tensor[i](j, k) = static_cast<Real_t>(linputTensor[sampleIndex](j, k));
59 }
60 }
62 }
63 }
64}
65
66//______________________________________________________________________________
67template <>
70{
71 const TMatrixT<Double_t> &loutputMatrix = std::get<1>(fData);
72 size_t n = loutputMatrix.GetNcols();
73
74 for (size_t i = 0; i < fInputShape[0]; i++) {
76 for (size_t j = 0; j < n; j++) {
77 matrix(i, j) = static_cast<Real_t>(loutputMatrix(sampleIndex, j));
78 }
79
81 }
82}
83
84//______________________________________________________________________________
85template <>
88{
89 const TMatrixT<Double_t> &lweightMatrix = std::get<2>(fData);
90
91 for (size_t i = 0; i < fInputShape[0]; i++) {
93 matrix(i, 0) = static_cast<Real_t>(lweightMatrix(sampleIndex, 0));
95 }
96}
97
98//______________________________________________________________________________
99template <>
102{
103 const std::vector<TMatrixT<Double_t>> &linputTensor = std::get<0>(fData);
104
105 if (fBatchDepth == 1) {
106 for (size_t i = 0; i < fBatchHeight; i++) {
107 size_t sampleIndex = *sampleIterator;
108 for (size_t j = 0; j < fBatchWidth; j++) {
109 tensor[0](i, j) = linputTensor[0](sampleIndex, j);
110 }
112 }
113 } else {
114 for (size_t i = 0; i < fBatchDepth; i++) {
115 size_t sampleIndex = *sampleIterator;
116 for (size_t j = 0; j < fBatchHeight; j++) {
117 for (size_t k = 0; k < fBatchWidth; k++) {
118 tensor[i](j, k) = linputTensor[sampleIndex](j, k);
119 }
120 }
122 }
123 }
124}
125
126//______________________________________________________________________________
127template <>
130{
131 const TMatrixT<Double_t> &loutputMatrix = std::get<1>(fData);
132 size_t n = loutputMatrix.GetNcols();
133
134 for (size_t i = 0; i < fInputShape[0]; i++) {
135 size_t sampleIndex = *sampleIterator;
136 for (size_t j = 0; j < n; j++) {
138 }
139
141 }
142}
143
144//______________________________________________________________________________
145template <>
148{
149 const TMatrixT<Double_t> &lweightMatrix = std::get<2>(fData);
150
151 for (size_t i = 0; i < fInputShape[0]; i++) {
152 size_t sampleIndex = *sampleIterator;
153 matrix(i, 0) = lweightMatrix(sampleIndex, 0);
155 }
156}
157
158//______________________________________________________________________________
159template <>
162{
163 // one event, one example in the batch
164 Event *event = std::get<0>(fData)[0];
165
166 if (fBatchDepth == 1) {
167 for (size_t i = 0; i < fBatchHeight; i++) {
168 size_t sampleIndex = *sampleIterator;
169 for (size_t j = 0; j < fBatchWidth; j++) {
170 event = std::get<0>(fData)[sampleIndex];
171 tensor[0](i, j) = static_cast<Real_t>(event->GetValue(j));
172 }
174 }
175 } else {
176 for (size_t i = 0; i < fBatchDepth; i++) {
177 size_t sampleIndex = *sampleIterator;
178 for (size_t j = 0; j < fBatchHeight; j++) {
179 for (size_t k = 0; k < fBatchWidth; k++) {
180 event = std::get<0>(fData)[sampleIndex];
181 tensor[i](j, k) = static_cast<Real_t>(event->GetValue(j * fBatchWidth + k));
182 }
183 }
185 }
186 }
187}
188
189//______________________________________________________________________________
190template <>
193{
194 const DataSetInfo &info = std::get<1>(fData);
195 Int_t n = matrix.GetNcols();
196
197 for (size_t i = 0; i < fInputShape[0]; i++) {
198 size_t sampleIndex = *sampleIterator++;
199 Event *event = std::get<0>(fData)[sampleIndex];
200
201 for (Int_t j = 0; j < n; j++) {
202 if (event->GetNTargets() == 0) {
203 if (n == 1) {
204 matrix(i, j) = (info.IsSignal(event)) ? 1.0 : 0.0;
205 } else {
206 matrix(i, j) = 0.0;
207 if (j == (Int_t)event->GetClass()) {
208 matrix(i, j) = 1.0;
209 }
210 }
211 } else {
212 matrix(i, j) = static_cast<Real_t>(event->GetTarget(j));
213 }
214 }
215 }
216}
217
218//______________________________________________________________________________
219template <>
222{
223 for (size_t i = 0; i < fInputShape[0]; i++) {
224 size_t sampleIndex = *sampleIterator++;
225 Event *event = std::get<0>(fData)[sampleIndex];
226 matrix(i, 0) = static_cast<Real_t>(event->GetWeight());
227 }
228}
229
230//______________________________________________________________________________
231template <>
234{
235 // one event, one example in the batch
236 Event *event = std::get<0>(fData)[0];
237
238 if (fBatchDepth == 1) {
239 for (size_t i = 0; i < fBatchHeight; i++) {
240 size_t sampleIndex = *sampleIterator;
241 for (size_t j = 0; j < fBatchWidth; j++) {
242 event = std::get<0>(fData)[sampleIndex];
243 tensor[0](i, j) = event->GetValue(j);
244 }
246 }
247 } else {
248 for (size_t i = 0; i < fBatchDepth; i++) {
249 size_t sampleIndex = *sampleIterator;
250 for (size_t j = 0; j < fBatchHeight; j++) {
251 for (size_t k = 0; k < fBatchWidth; k++) {
252 event = std::get<0>(fData)[sampleIndex];
253 tensor[i](j, k) = event->GetValue(j * fBatchWidth + k);
254 }
255 }
257 }
258 }
259}
260
261//______________________________________________________________________________
262template <>
265{
266 const DataSetInfo &info = std::get<1>(fData);
267 Int_t n = matrix.GetNcols();
268
269 for (size_t i = 0; i < fInputShape[0]; i++) {
270 size_t sampleIndex = *sampleIterator++;
271 Event *event = std::get<0>(fData)[sampleIndex];
272
273 for (Int_t j = 0; j < n; j++) {
274 if (event->GetNTargets() == 0) {
275 if (n == 1) {
276 matrix(i, j) = (info.IsSignal(event)) ? 1.0 : 0.0;
277 } else {
278 matrix(i, j) = 0.0;
279 if (j == (Int_t)event->GetClass()) {
280 matrix(i, j) = 1.0;
281 }
282 }
283 } else {
284 matrix(i, j) = event->GetTarget(j);
285 }
286 }
287 }
288}
289
290//______________________________________________________________________________
291template <>
294{
295 for (size_t i = 0; i < fInputShape[0]; i++) {
296 size_t sampleIndex = *sampleIterator++;
297 Event *event = std::get<0>(fData)[sampleIndex];
298 matrix(i, 0) = event->GetWeight();
299 }
300}
301
302} // namespace DNN
303} // namespace TMVA
float Real_t
Definition RtypesCore.h:68
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Class that contains all the data information.
Definition DataSetInfo.h:62
Double_t GetWeight() const
return the event weight - depending on whether the flag IgnoreNegWeightsInTraining is or not.
Definition Event.cxx:389
const Int_t n
Definition legend1.C:16
create variable transformations