Answers for "softmax c++"

C++
0

softmax c++

// this function calculates the the softmax function.
// @param size is the size of the input vector.
// @param z is the input vector.
// @return buff is the output vector.
double* softmax(const int size, double* z)
{
  double* buff = new double[size];
  double sum = 0;
  for (int i = 0; i < size; i++)
    sum += Exp(z[i]);

  for (int i = 0; i < size; i++)
    buff[i] = Exp(z[i]) / sum;
  
  return buff;
}
Posted by: Guest on March-01-2021

Browse Popular Code Answers by Language