You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Whether to add costs or gradients to destination Matrix should be decided by user. Current implement is:
voidCpuMatrix::smoothL1(Matrix& output, Matrix& label) {
CHECK(output.useGpu_ == false && label.useGpu_ == false)
<< "Matrix type are not equal";
size_t numSamples = getHeight();
size_t dim = output.getWidth();
CHECK_EQ(label.getHeight(), numSamples);
CHECK_EQ(output.getHeight(), numSamples);
CHECK_EQ(label.getWidth(), dim);
CHECK_EQ(getWidth(), (size_t)1);
real* cost = getData();
real* out = output.getData();
real* lbl = label.getData();
for (size_t i = 0; i < numSamples; ++i, out += dim, lbl += dim) {
for (size_t j = 0; j < dim; ++j) {
real absVal = std::fabs(out[j] - lbl[j]);
if (absVal < 1.0)
cost[i] += 0.5 * absVal * absVal;
else
cost[i] += absVal - 0.5;
}
}
}
voidCpuMatrix::smoothL1Bp(Matrix& output, Matrix& label) {
CHECK(output.useGpu_ == false && label.useGpu_ == false)
<< "Matrix type are not equal";
size_t numSamples = getHeight();
size_t dim = output.getWidth();
CHECK_EQ(label.getHeight(), numSamples);
CHECK_EQ(output.getHeight(), numSamples);
CHECK_EQ(label.getWidth(), dim);
CHECK_EQ(getWidth(), dim);
real* out = output.getData();
real* lbl = label.getData();
real* grad = getData();
for (size_t i = 0; i < numSamples; ++i, out += dim, grad += dim, lbl += dim) {
for (size_t j = 0; j < dim; ++j) {
real val = out[j] - lbl[j];
if (std::fabs(val) < 1) {
grad[j] += val;
} else {
grad[j] += (real(0) < val) - (val < real(0));
}
}
}
}
As we can see, current implement adds cost and gradient to caller object leaving no other choice. A solution is adding a scale factor to caller object.
The text was updated successfully, but these errors were encountered:
Whether to add costs or gradients to destination Matrix should be decided by user. Current implement is:
As we can see, current implement adds cost and gradient to caller object leaving no other choice. A solution is adding a scale factor to caller object.
The text was updated successfully, but these errors were encountered: