25 template<
typename AFloat>
34 auto f = [&dataY, &dataOutput, &temp](
UInt_t workerID)
36 AFloat dy = dataY[workerID] - dataOutput[workerID];
37 temp[workerID] = dy * dy;
42 auto reduction = [](
const std::vector<AFloat> &
v )
46 return std::accumulate(
v.begin(),
v.end(),AFloat{});
54 template<
typename AFloat>
66 auto f = [&dataDY, &dataY, &dataOutput,
norm](
UInt_t workerID)
68 dataDY[workerID] = - 2.0 * norm * (dataY[workerID] - dataOutput[workerID]);
76 template<
typename AFloat>
85 auto f = [&dataY, &dataOutput, &temp](
UInt_t workerID)
87 AFloat
y = dataY[workerID];
88 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
89 temp[workerID] = - (y *
log(sig) + (1.0 -
y) *
log(1.0 - sig));
97 auto reduction = [](
const std::vector<AFloat> &
v )
99 return std::accumulate(
v.begin(),
v.end(),AFloat{});
108 template<
typename AFloat>
119 auto f = [&dataDY, &dataY, &dataOutput,
norm](
UInt_t workerID)
121 AFloat
y = dataY[workerID];
122 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
123 dataDY[workerID] = norm * (sig -
y);
131 template<
typename AFloat>
138 std::vector<AFloat> temp(Y.
GetNrows());
141 AFloat
norm = 1.0 / ((AFloat) m);
143 auto f = [&dataY, &dataOutput, &temp,
n,
m](
UInt_t workerID)
146 for (
size_t j = 0; j <
n; j++) {
147 sum +=
exp(dataOutput[workerID + j * m]);
149 for (
size_t j = 0; j <
n; j++) {
151 dataY[workerID + j *
m] *
log(
exp(dataOutput[workerID + j * m]) / sum);
160 auto reduction = [](
const std::vector<AFloat> &
v )
162 return std::accumulate(
v.begin(),
v.end(),AFloat{});
170 template<
typename AFloat>
181 AFloat
norm = 1.0 / ((AFloat) m);
183 auto f = [&dataDY, &dataY, &dataOutput,
norm,
n,
m](
UInt_t workerID)
187 for (
size_t j = 0; j <
n; j++) {
188 sum +=
exp(dataOutput[workerID + j * m]);
189 sumY += dataY[workerID + j *
m];
191 for (
size_t j = 0; j <
n; j++) {
192 dataDY[workerID + j *
m] =
193 norm * (
exp(dataOutput[workerID + j * m]) / sum * sumY - dataY[workerID + j *
m]);
static long int sum(long int i)
static Scalar_t MeanSquaredError(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
static void CrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
size_t GetNElements() const
auto Reduce(const std::vector< T > &objs, BINARYOP redfunc) -> decltype(redfunc(objs.front(), objs.front()))
"Reduce" an std::vector into a single object in parallel by passing a binary operator as the second a...
static Scalar_t SoftmaxCrossEntropy(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
Softmax transformation is implicitly applied, thus output should hold the linear activations of the l...
static void MeanSquaredErrorGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
static void SoftmaxCrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
A pseudo container class which is a generator of indices.
ROOT::TThreadExecutor & GetThreadExecutor() const
Abstract ClassifierFactory template that handles arbitrary types.
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Execute func (with no arguments) nTimes in parallel.
double norm(double *x, double *p)
static Scalar_t CrossEntropy(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output)
Sigmoid transformation is implicitly applied, thus output should hold the linear activations of the l...