Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.