mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00
14 lines
395 B
JavaScript
14 lines
395 B
JavaScript
// Wikipedia: https://en.wikipedia.org/wiki/Softmax_function
|
|
|
|
const Softmax = (inputs) => {
|
|
const eulerExpOfAllInputs = inputs.map(input => Math.exp(input))
|
|
const sumOfEulerExpOfAllInputs = eulerExpOfAllInputs.reduce((a, b) => a + b)
|
|
|
|
return inputs.map((input) => {
|
|
const eulerExpInputs = Math.exp(input)
|
|
return eulerExpInputs / sumOfEulerExpOfAllInputs
|
|
})
|
|
}
|
|
|
|
export { Softmax }
|