Skip to content

Instantly share code, notes, and snippets.

@raymondjplante
Created October 4, 2016 18:21
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raymondjplante/d826df05349c1d4350e0aa2d7ca01da4 to your computer and use it in GitHub Desktop.
Save raymondjplante/d826df05349c1d4350e0aa2d7ca01da4 to your computer and use it in GitHub Desktop.
Softmax calculation for PHP (useful for logistic classifications)
function softmax(array $v){
//Just in case values are passed in as string, apply floatval
$v = array_map('exp',array_map('floatval',$v));
$sum = array_sum($v);
foreach($v as $index => $value) {
$v[$index] = $value/$sum;
}
return $v;
}
@jonasborn
Copy link

Is there a license under which this was published?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment