MCPcopy Create free account
hub / github.com/davisking/dlib / soft_max

Function soft_max

dlib/matrix/matrix_math_functions.h:463–477  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

461 typename EXP
462 >
463 const matrix_op<op_softmax<EXP> > soft_max (
464 const matrix_exp<EXP>& m
465 )
466 {
467 // you can only compute softmax on matrices that contain floats, doubles or long doubles.
468 COMPILE_TIME_ASSERT((
469 is_same_type<typename EXP::type,float>::value == true ||
470 is_same_type<typename EXP::type,double>::value == true ||
471 is_same_type<typename EXP::type,long double>::value == true
472 ));
473 typedef op_softmax<EXP> op;
474 typename EXP::type max_val = max(m);
475 typename EXP::type temp = static_cast<typename EXP::type>(1) / sum(exp(m - max_val));
476 return matrix_op<op>(op(m.ref(), temp, max_val));
477 }
478
479}
480

Callers 1

matrix_test2Function · 0.85

Calls 3

expFunction · 0.85
maxFunction · 0.70
sumFunction · 0.70

Tested by 1

matrix_test2Function · 0.68