# Implementation of the paper 'A Comprehensive Study for Center Loss'

I have studied the research paper A Comprehensive Study for Center Loss. The implementation in Caffe also exists in this github repo. In the paper, the author talks about a generalized implementation of centerloss by penalizing loss with $$\rho$$. This is thoroughly discussed in the paper. but in the implementation there is also another code for when cosine distance is considered:

    else if (this->layer_param_.center_loss_param().type()==CenterLossParameter_DistanceType_COSINE) {
const Dtype eps_ = this->layer_param_.center_loss_param().eps();
const Dtype margin_ = this->layer_param_.center_loss_param().margin();
Dtype* propagate_data = propagate_.mutable_cpu_data();
for (int m = 0; m < M_; m++) {
const int label_value = static_cast<int>(label[m]);
// margin, xx, xc, cc
Dtype g = margin_;
Dtype r = caffe_cpu_dot(K_, bottom_data + m * K_, bottom_data + m * K_);
Dtype s = caffe_cpu_dot(K_, bottom_data + m * K_, center + label_value * K_);
Dtype t = caffe_cpu_dot(K_, center + label_value * K_, center + label_value * K_);
if (!(s / sqrt(r) / sqrt(t) < g)) {
propagate_data[m] = (Dtype)0.;
} else {
// a, b, c
Dtype c = s * s - g * g * r * t;
Dtype b = (Dtype)2. * (((Dtype)1. - g * g) * s * t - c);
Dtype a = ((Dtype)1. - g * g) * t * (t - (Dtype)2. * s) + c;
// x1, x2, propagate
Dtype x1 = (-b + sqrt(b * b - (Dtype)4. * a * c + eps_)) / ((Dtype)2. * a);
Dtype x2 = (-b - sqrt(b * b - (Dtype)4. * a * c + eps_)) / ((Dtype)2. * a);
if (x1*x2 < (Dtype)0. || x1+x2 > (Dtype)1.) {
propagate_data[m] = (x1 > (Dtype)0. && x1 < (Dtype)1.000001) ? x1 : x2;
} else {
propagate_data[m] = x1 > x2 ? x1 : x2;
}
}


So far my understanding is that if $$cos(\theta) > m$$ in which $$m$$ is a margin, then there is no loss penalty so $$0$$ is propagated. Otherwise, a quadratic function is solved and the roots of this quadratic function are compared and a decision for penalizing loss is made. My question is where is this quadratic function coming from and what is the intuition behind it.