forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSoftmax.js
More file actions
Latest commit
13 lines (10 loc) · 397 Bytes
/
Copy pathSoftmax.js
File metadata and controls
13 lines (10 loc) · 397 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
// Wikipedia: https://en.wikipedia.org/wiki/Softmax_function
constSoftmax=(inputs)=>{
consteulerExpOfAllInputs=inputs.map((input)=>Math.exp(input))
constsumOfEulerExpOfAllInputs=eulerExpOfAllInputs.reduce((a,b)=>a+b)
returninputs.map((input)=>{
consteulerExpInputs=Math.exp(input)
returneulerExpInputs/sumOfEulerExpOfAllInputs
})
}
export{Softmax}