SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
Static Public Member Functions | List of all members
MNIST::CatHinge Class Reference

Categorical hinge loss. Use if weights are restricted to be >0. More...

#include <mnist_mlp.hpp>

Static Public Member Functions

static Real calc_loss (const uint16_t label, const std::vector< Real > &output)
 
static std::vector< Real > calc_error (const uint16_t label, const std::vector< Real > &output)
 

Detailed Description

Categorical hinge loss. Use if weights are restricted to be >0.

Definition at line 71 of file mnist_mlp.hpp.

Member Function Documentation

static std::vector<Real> MNIST::CatHinge::calc_error ( const uint16_t  label,
const std::vector< Real > &  output 
)
inlinestatic

Definition at line 87 of file mnist_mlp.hpp.

89  {
90  // Real pos = output[label];
91  std::vector<Real> vec = output;
92  vec[label] = -0.0;
93  auto neg_elem = std::max_element(vec.begin(), vec.end());
94  auto index = std::distance(vec.begin(), neg_elem);
95  auto res = std::vector<Real>(output.size(), 0.0);
96 
97  // Require that label neuron and the next most active neuron have at
98  // least a difference of 1
99  if ((*neg_elem) - output[label] + 1 >= 0.0) {
100  res[label] = -1.0;
101  if (label != index) {
102  res[index] = +1;
103  }
104  }
105  return res;
106  }
static Real MNIST::CatHinge::calc_loss ( const uint16_t  label,
const std::vector< Real > &  output 
)
inlinestatic

Definition at line 73 of file mnist_mlp.hpp.

75  {
76  Real res = 0.0;
77  for (size_t neuron = 0; neuron < output.size(); neuron++) {
78  if (label == neuron) {
79  res += std::max(0.0, 1.0 - Real(output[neuron]));
80  }
81  else {
82  res += std::max(0.0, 1.0 + Real(output[neuron]));
83  }
84  }
85  return res;
86  }

The documentation for this class was generated from the following file: