Hi everyone, I’m new to the world of automatic differenciation, and I’m trying to get the gradient of this loss function with respect to weights. the problem is that I am working with the data type map which has made it difficult for me to transfer the function to stan notation. If someone could help me, I would be very glad.Since I’ve tried to do it but I’m not going in a good way.

```
vector<map<int,double>> data;
map<int,double> weights;
vector<int> index(data.size());
iota(index.begin(),index.end(),0);
double lossFunction(map<int,double>& features,map<int,double>& weights){
Matrix<stan::math::var, Dynamic, 1> loss(1);
double logit = 0.0;
static double overflow = 20.0;
vector<int> aux(features.size()); // vector index de largo de data
iota(aux.begin(),aux.end(),0);
int label = features[aux[0]];
for(auto it = features.begin(); it != features.end(); it++){
if(it->first != 0){
logit += it->second * weights[it->first];
}
}
if (logit > overflow) logit = overflow;
if (logit < -overflow) logit = -overflow;
double predicted = 1.0/(1.0 + exp(-logit));
loss = label*log(predicted)+(1-label)*log(1-predicted);
loss = loss *-1;
loss.grad()
double grad_val = loss.val();
return grad_val
}
double result = lossFunction(data[index[i]],weights);
```