26template <
typename AFloat>
31 const AFloat *dataOutput =
output.GetRawDataPointer();
37 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
m](
UInt_t workerID) {
38 AFloat dy = dataY[workerID] - dataOutput[workerID];
39 temp[workerID] = dataWeights[workerID %
m] * dy * dy;
43 auto reduction = [](
const std::vector<AFloat> &
v )
45 return std::accumulate(
v.begin(),
v.end(),AFloat{});
53template <
typename AFloat>
60 const AFloat *dataOutput =
output.GetRawDataPointer();
66 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights,
m, norm](
UInt_t workerID) {
67 dataDY[workerID] = -2.0 * norm * (dataY[workerID] - dataOutput[workerID]);
68 dataDY[workerID] *= dataWeights[workerID %
m];
76template <
typename AFloat>
81 const AFloat *dataOutput =
output.GetRawDataPointer();
88 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
m](
UInt_t workerID) {
89 AFloat
y = dataY[workerID];
90 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
92 temp[workerID] = -
log(1.0 - sig);
94 temp[workerID] = -
log(sig);
96 temp[workerID] = - (
y *
log(sig) + (1.0 -
y) *
log(1.0 - sig));
98 temp[workerID] *= dataWeights[workerID %
m];
102 auto reduction = [](
const std::vector<AFloat> &
v )
104 return std::accumulate(
v.begin(),
v.end(),AFloat{});
112template <
typename AFloat>
118 const AFloat *dataOutput =
output.GetRawDataPointer();
124 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights,
m, norm](
UInt_t workerID) {
125 AFloat
y = dataY[workerID];
126 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
127 dataDY[workerID] = norm * (sig -
y);
128 dataDY[workerID] *= dataWeights[workerID %
m];
136template <
typename AFloat>
141 const AFloat *dataOutput =
output.GetRawDataPointer();
144 std::vector<AFloat> temp(Y.
GetNrows());
147 AFloat norm = 1.0 / ((AFloat)
m);
149 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
n,
m](
UInt_t workerID) {
151 for (
size_t j = 0; j <
n; j++) {
152 sum +=
exp(dataOutput[workerID + j *
m]);
154 for (
size_t j = 0; j <
n; j++) {
156 dataY[workerID + j *
m] *
log(
exp(dataOutput[workerID + j *
m]) /
sum);
158 temp[workerID] *= dataWeights[workerID];
162 auto reduction = [](
const std::vector<AFloat> &
v )
164 return std::accumulate(
v.begin(),
v.end(),AFloat{});
172template <
typename AFloat>
178 const AFloat *dataOutput =
output.GetRawDataPointer();
183 AFloat norm = 1.0 / ((AFloat)
m);
185 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights, norm,
n,
m](
UInt_t workerID) {
188 AFloat weight = dataWeights[workerID];
189 for (
size_t j = 0; j <
n; j++) {
190 sum +=
exp(dataOutput[workerID + j *
m]);
191 sumY += dataY[workerID + j *
m];
193 for (
size_t j = 0; j <
n; j++) {
194 dataDY[workerID + j *
m] =
195 norm * (
exp(dataOutput[workerID + j *
m]) /
sum * sumY - dataY[workerID + j *
m]);
196 dataDY[workerID + j *
m] *= weight;
A pseudo container class which is a generator of indices.
AFloat * GetRawDataPointer()
Return raw pointer to the elements stored contiguously in column-major order.
static Executor & GetThreadExecutor()
size_t GetNoElements() const
static void SoftmaxCrossEntropyGradients(Matrix_t &dY, const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
static void CrossEntropyGradients(Matrix_t &dY, const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
static void MeanSquaredErrorGradients(Matrix_t &dY, const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
static Scalar_t MeanSquaredError(const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
static Scalar_t CrossEntropy(const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
Sigmoid transformation is implicitly applied, thus output should hold the linear activations of the l...
static Scalar_t SoftmaxCrossEntropy(const Matrix_t &Y, const Matrix_t &output, const Matrix_t &weights)
Softmax transformation is implicitly applied, thus output should hold the linear activations of the l...
auto Reduce(const std::vector< T > &objs, R redfunc) -> decltype(redfunc(objs))
Wrap Reduce function.
auto Map(F func, unsigned nTimes) -> std::vector< typename std::result_of< F()>::type >
Wrap TExecutor::Map functions.
create variable transformations
static long int sum(long int i)
static void output(int code)