This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created for MyWeather | |
// by Stewart Lynch on 2024-02-24 | |
// | |
// Follow me on Mastodon: @[email protected] | |
// Follow me on Threads: @StewartLynch (https://www.threads.net) | |
// Follow me on X: https://x.com/StewartLynch | |
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch | |
// Subscribe on YouTube: https://youTube.com/@StewartLynch | |
// Buy me a ko-fi: https://ko-fi.com/StewartLynch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 }) | |
}) | |
} |