Created
October 4, 2016 18:21
-
-
Save raymondjplante/d826df05349c1d4350e0aa2d7ca01da4 to your computer and use it in GitHub Desktop.
Softmax calculation for PHP (useful for logistic classifications)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a license under which this was published?