Skip to content

Instantly share code, notes, and snippets.

View doug-ross's full-sized avatar

Doug Ross doug-ross

  • U.S.
View GitHub Profile
@cyphunk
cyphunk / softmax.js
Last active June 4, 2024 18:19 — forked from vladimir-ivanov/softmax.js
softmax function implementation in js
// Fork & examples for the one-line version by @vladimir-ivanov:
//let softmax = (arr) => (index) => Math.exp(arr[index]) / arr.map(y => Math.exp(y)).reduce((a, b) => a + b);
//
// Also see comments for improvements
function softmax(arr) {
return arr.map(function(value,index) {
return Math.exp(value) / arr.map( function(y /*value*/){ return Math.exp(y) } ).reduce( function(a,b){ return a+b })
})
}