25 template <
typename AFloat>
36 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
m](
UInt_t workerID) {
37 AFloat dy = dataY[workerID] - dataOutput[workerID];
38 temp[workerID] = dataWeights[workerID %
m] * dy * dy;
42 auto reduction = [](
const std::vector<AFloat> &
v )
44 return std::accumulate(
v.begin(),
v.end(),AFloat{});
52 template <
typename AFloat>
65 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights,
m, norm](
UInt_t workerID) {
66 dataDY[workerID] = -2.0 * norm * (dataY[workerID] - dataOutput[workerID]);
67 dataDY[workerID] *= dataWeights[workerID %
m];
75 template <
typename AFloat>
87 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
m](
UInt_t workerID) {
88 AFloat
y = dataY[workerID];
89 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
90 temp[workerID] = - (y *
log(sig) + (1.0 -
y) *
log(1.0 - sig));
91 temp[workerID] *= dataWeights[workerID %
m];
95 auto reduction = [](
const std::vector<AFloat> &
v )
97 return std::accumulate(
v.begin(),
v.end(),AFloat{});
105 template <
typename AFloat>
117 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights,
m, norm](
UInt_t workerID) {
118 AFloat
y = dataY[workerID];
119 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
120 dataDY[workerID] = norm * (sig -
y);
121 dataDY[workerID] *= dataWeights[workerID %
m];
129 template <
typename AFloat>
137 std::vector<AFloat> temp(Y.
GetNrows());
140 AFloat norm = 1.0 / ((AFloat) m);
142 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
n,
m](
UInt_t workerID) {
144 for (
size_t j = 0; j <
n; j++) {
145 sum +=
exp(dataOutput[workerID + j * m]);
147 for (
size_t j = 0; j <
n; j++) {
149 dataY[workerID + j *
m] *
log(
exp(dataOutput[workerID + j * m]) / sum);
151 temp[workerID] *= dataWeights[workerID];
155 auto reduction = [](
const std::vector<AFloat> &
v )
157 return std::accumulate(
v.begin(),
v.end(),AFloat{});
165 template <
typename AFloat>
176 AFloat norm = 1.0 / ((AFloat) m);
178 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights, norm,
n,
m](
UInt_t workerID) {
181 AFloat weight = dataWeights[workerID];
182 for (
size_t j = 0; j <
n; j++) {
183 sum +=
exp(dataOutput[workerID + j * m]);
184 sumY += dataY[workerID + j *
m];
186 for (
size_t j = 0; j <
n; j++) {
187 dataDY[workerID + j *
m] =
188 norm * (
exp(dataOutput[workerID + j * m]) / sum * sumY - dataY[workerID + j *
m]);
189 dataDY[workerID + j *
m] *= weight;
static long int sum(long int i)
static void MeanSquaredErrorGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
static Scalar_t CrossEntropy(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
Sigmoid transformation is implicitly applied, thus output should hold the linear activations of the l...
static Scalar_t MeanSquaredError(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
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 ROOT::TThreadExecutor & GetThreadExecutor()
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
A pseudo container class which is a generator of indices.
static Scalar_t SoftmaxCrossEntropy(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
Softmax transformation is implicitly applied, thus output should hold the linear activations of the l...
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.
static void SoftmaxCrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
static void CrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)