25template <
typename AFloat>
30 const AFloat *dataOutput =
output.GetRawDataPointer();
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{});
52template <
typename AFloat>
59 const AFloat *dataOutput =
output.GetRawDataPointer();
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];
75template <
typename AFloat>
80 const AFloat *dataOutput =
output.GetRawDataPointer();
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]));
91 temp[workerID] = -
log(1.0 - sig);
93 temp[workerID] = -
log(sig);
95 temp[workerID] = - (
y *
log(sig) + (1.0 -
y) *
log(1.0 - sig));
97 temp[workerID] *= dataWeights[workerID %
m];
101 auto reduction = [](
const std::vector<AFloat> &
v )
103 return std::accumulate(
v.begin(),
v.end(),AFloat{});
111template <
typename AFloat>
117 const AFloat *dataOutput =
output.GetRawDataPointer();
123 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights,
m, norm](
UInt_t workerID) {
124 AFloat
y = dataY[workerID];
125 AFloat sig = 1.0 / (1.0 +
exp(- dataOutput[workerID]));
126 dataDY[workerID] = norm * (sig -
y);
127 dataDY[workerID] *= dataWeights[workerID %
m];
135template <
typename AFloat>
140 const AFloat *dataOutput =
output.GetRawDataPointer();
143 std::vector<AFloat> temp(Y.
GetNrows());
146 AFloat norm = 1.0 / ((AFloat)
m);
148 auto f = [&dataY, &dataOutput, &dataWeights, &temp,
n,
m](
UInt_t workerID) {
150 for (
size_t j = 0; j <
n; j++) {
151 sum +=
exp(dataOutput[workerID + j *
m]);
153 for (
size_t j = 0; j <
n; j++) {
155 dataY[workerID + j *
m] *
log(
exp(dataOutput[workerID + j *
m]) /
sum);
157 temp[workerID] *= dataWeights[workerID];
161 auto reduction = [](
const std::vector<AFloat> &
v )
163 return std::accumulate(
v.begin(),
v.end(),AFloat{});
171template <
typename AFloat>
177 const AFloat *dataOutput =
output.GetRawDataPointer();
182 AFloat norm = 1.0 / ((AFloat)
m);
184 auto f = [&dataDY, &dataY, &dataOutput, &dataWeights, norm,
n,
m](
UInt_t workerID) {
187 AFloat weight = dataWeights[workerID];
188 for (
size_t j = 0; j <
n; j++) {
189 sum +=
exp(dataOutput[workerID + j *
m]);
190 sumY += dataY[workerID + j *
m];
192 for (
size_t j = 0; j <
n; j++) {
193 dataDY[workerID + j *
m] =
194 norm * (
exp(dataOutput[workerID + j *
m]) /
sum * sumY - dataY[workerID + j *
m]);
195 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 CrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
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...
static Scalar_t MeanSquaredError(const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
static void SoftmaxCrossEntropyGradients(TCpuMatrix< Scalar_t > &dY, const TCpuMatrix< Scalar_t > &Y, const TCpuMatrix< Scalar_t > &output, const TCpuMatrix< Scalar_t > &weights)
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...
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)