Added Softmax to Maths folder (#516)

This commit is contained in:
Fergus McDonald
2020-10-30 23:50:29 -07:00
committed by GitHub
parent 2190b92e1b
commit 9c9640c1c3
3 changed files with 27 additions and 0 deletions

13
Maths/Softmax.js Normal file
View File

@@ -0,0 +1,13 @@
// 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 }