mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
Added Softmax to Maths folder (#516)
This commit is contained in:
13
Maths/Softmax.js
Normal file
13
Maths/Softmax.js
Normal 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 }
|
||||
Reference in New Issue
Block a user