Þ ±cell_dependenciesÞ Ù$1517f96d-64a4-445f-bbea-4f3e97ddca78„´precedence_heuristic §cell_idÙ$1517f96d-64a4-445f-bbea-4f3e97ddca78´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$f9f6868b-f906-40cf-9d6f-a72b22fc1826„´precedence_heuristic §cell_idÙ$f9f6868b-f906-40cf-9d6f-a72b22fc1826´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$4bb1040c-fa30-4cde-b308-13df21e8e539„´precedence_heuristic §cell_idÙ$4bb1040c-fa30-4cde-b308-13df21e8e539´downstream_cells_map€²upstream_cells_map‚£sum�¡y‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$4b765b37-9c26-4592-acbf-111d176c5654„´precedence_heuristic §cell_idÙ$4b765b37-9c26-4592-acbf-111d176c5654´downstream_cells_map€²upstream_cells_mapƒ§@md_str�ªkeyconcept�¨getindex�Ù$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405„´precedence_heuristic §cell_idÙ$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405´downstream_cells_map€²upstream_cells_mapƒ§@md_str�ªkeyconcept�¨getindex�Ù$2596781d-3637-41c2-8785-84e23aca7711„´precedence_heuristic §cell_idÙ$2596781d-3637-41c2-8785-84e23aca7711´downstream_cells_map‚©#461#bond�£x_3‘Ù$1bcf1a3b-a68f-413a-926a-32aded5887ae²upstream_cells_map‹Ù#PlutoRunner.PlutoRunner.create_bond�©@bindname�«PlutoRunner�´PlutoRunner.Base.get�·HypertextLiteral.Result�»PlutoRunner.Core.applicable�¡:�·HypertextLiteral.Bypass�¸HypertextLiteral.content�¦Slider�°HypertextLiteral�Ù$54e515dc-c917-4231-9106-e8448400a905„´precedence_heuristic §cell_idÙ$54e515dc-c917-4231-9106-e8448400a905´downstream_cells_map�bar_plot_opts‘Ù$dc62435b-5020-48a9-bc37-d5ee8a663b40²upstream_cells_map‚¡:�§nothing�Ù$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8„´precedence_heuristic §cell_idÙ$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8´downstream_cells_map�®logi_plot_opts‘Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba²upstream_cells_mapƒ¥Plots‘Ù$b4391750-7368-11f0-2e66-6b42d8f70892¡*�§nothing�Ù$1a2a5fe9-b1fc-41b4-a034-0a664632be37„´precedence_heuristic §cell_idÙ$1a2a5fe9-b1fc-41b4-a034-0a664632be37´downstream_cells_map�±logistic_function’Ù$593c3c88-e4ab-463d-b904-4ccd07bf24c2Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba²upstream_cells_map…£exp�¡-�¡/�¡+�¤Real�Ù$13fe6c00-2e27-424f-91e8-6452d76f358e„´precedence_heuristic §cell_idÙ$13fe6c00-2e27-424f-91e8-6452d76f358e´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$5914c0b7-5a46-4166-a4d7-e60013e37029„´precedence_heuristic §cell_idÙ$5914c0b7-5a46-4166-a4d7-e60013e37029´downstream_cells_map€²upstream_cells_map�¥title�Ù$a3fdb14a-29ec-49cd-8cd2-088847ea802b„´precedence_heuristic §cell_idÙ$a3fdb14a-29ec-49cd-8cd2-088847ea802b´downstream_cells_map‚©#465#bond�£x_2‘Ù$1bcf1a3b-a68f-413a-926a-32aded5887ae²upstream_cells_map‹Ù#PlutoRunner.PlutoRunner.create_bond�©@bindname�«PlutoRunner�´PlutoRunner.Base.get�·HypertextLiteral.Result�»PlutoRunner.Core.applicable�¡:�·HypertextLiteral.Bypass�¸HypertextLiteral.content�¦Slider�°HypertextLiteral�Ù$1fccee46-87f1-4733-ad93-8d8f8b64e7cd„´precedence_heuristic §cell_idÙ$1fccee46-87f1-4733-ad93-8d8f8b64e7cd´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$e723edf1-c7f1-4b6f-85ff-aadac9d11f02„´precedence_heuristic §cell_idÙ$e723edf1-c7f1-4b6f-85ff-aadac9d11f02´downstream_cells_map‚£x_1‘Ù$1bcf1a3b-a68f-413a-926a-32aded5887ae©#463#bond�²upstream_cells_map‹Ù#PlutoRunner.PlutoRunner.create_bond�©@bindname�«PlutoRunner�´PlutoRunner.Base.get�·HypertextLiteral.Result�»PlutoRunner.Core.applicable�¡:�·HypertextLiteral.Bypass�¸HypertextLiteral.content�¦Slider�°HypertextLiteral�Ù$b4391750-7368-11f0-2e66-6b42d8f70892„´precedence_heuristic§cell_idÙ$b4391750-7368-11f0-2e66-6b42d8f70892´downstream_cells_map‚¥Plots‘Ù$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8²BmlipTeachingTools�²upstream_cells_map€Ù$829970d4-059a-4335-ad19-c6177861e2d8„´precedence_heuristic §cell_idÙ$829970d4-059a-4335-ad19-c6177861e2d8´downstream_cells_map€²upstream_cells_map�¯TableOfContents�Ù$f9d9a189-7626-43a1-8f47-8835c9e32c5b„´precedence_heuristic §cell_idÙ$f9d9a189-7626-43a1-8f47-8835c9e32c5b´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$e35e9f54-3b5e-464e-8a1d-53a314efdd7e„´precedence_heuristic §cell_idÙ$e35e9f54-3b5e-464e-8a1d-53a314efdd7e´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$87e8178a-3cac-46ad-9a42-69a78e3b6e20„´precedence_heuristic §cell_idÙ$87e8178a-3cac-46ad-9a42-69a78e3b6e20´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef„´precedence_heuristic §cell_idÙ$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef´downstream_cells_map�¡y”Ù$dc62435b-5020-48a9-bc37-d5ee8a663b40Ù$605030dc-5383-4d22-b750-ec14d03abeccÙ$4bb1040c-fa30-4cde-b308-13df21e8e539Ù$b9508dde-429d-414f-b7be-4e94f1ef8c2b²upstream_cells_map‚¡x‘Ù$1bcf1a3b-a68f-413a-926a-32aded5887ae§softmax‘Ù$352cc34b-a1e2-4654-93b4-d40d92909d2aÙ$593c3c88-e4ab-463d-b904-4ccd07bf24c2„´precedence_heuristic §cell_idÙ$593c3c88-e4ab-463d-b904-4ccd07bf24c2´downstream_cells_map�¡b‘Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba²upstream_cells_map‚±logistic_function‘Ù$1a2a5fe9-b1fc-41b4-a034-0a664632be37¡a‘Ù$25a03cb9-3e3b-4988-8a7d-5be17eb143c1Ù$1bcf1a3b-a68f-413a-926a-32aded5887ae„´precedence_heuristic §cell_idÙ$1bcf1a3b-a68f-413a-926a-32aded5887ae´downstream_cells_map�¡x‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef²upstream_cells_mapƒ£x_1‘Ù$e723edf1-c7f1-4b6f-85ff-aadac9d11f02£x_3‘Ù$2596781d-3637-41c2-8785-84e23aca7711£x_2‘Ù$a3fdb14a-29ec-49cd-8cd2-088847ea802bÙ$30ff3c54-9c8b-403f-9301-e196be51d7ee„´precedence_heuristic §cell_idÙ$30ff3c54-9c8b-403f-9301-e196be51d7ee´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$b9508dde-429d-414f-b7be-4e94f1ef8c2b„´precedence_heuristic §cell_idÙ$b9508dde-429d-414f-b7be-4e94f1ef8c2b´downstream_cells_map€²upstream_cells_map‚§extrema�¡y‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7„´precedence_heuristic §cell_idÙ$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$a1c3bb09-f6c5-4a97-995e-7d9d74fe221f„´precedence_heuristic §cell_idÙ$a1c3bb09-f6c5-4a97-995e-7d9d74fe221f´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$dc62435b-5020-48a9-bc37-d5ee8a663b40„´precedence_heuristic §cell_idÙ$dc62435b-5020-48a9-bc37-d5ee8a663b40´downstream_cells_map€²upstream_cells_mapƒ£bar�bar_plot_opts‘Ù$54e515dc-c917-4231-9106-e8448400a905¡y‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$2570f665-21b0-4262-b149-4e9d60e1f36a„´precedence_heuristic §cell_idÙ$2570f665-21b0-4262-b149-4e9d60e1f36a´downstream_cells_map€²upstream_cells_map‚§@md_str�¨getindex�Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba„´precedence_heuristic §cell_idÙ$c9ecaabd-686d-4884-b75e-9e4644d371ba´downstream_cells_map€²upstream_cells_map†®logi_plot_opts‘Ù$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8¤plot�¡b‘Ù$593c3c88-e4ab-463d-b904-4ccd07bf24c2±logistic_function‘Ù$1a2a5fe9-b1fc-41b4-a034-0a664632be37¡a‘Ù$25a03cb9-3e3b-4988-8a7d-5be17eb143c1¨scatter!�Ù$352cc34b-a1e2-4654-93b4-d40d92909d2a„´precedence_heuristic §cell_idÙ$352cc34b-a1e2-4654-93b4-d40d92909d2a´downstream_cells_map�§softmax‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef²upstream_cells_map„£exp�£sum�¡/�¦Vector�Ù$605030dc-5383-4d22-b750-ec14d03abecc„´precedence_heuristic §cell_idÙ$605030dc-5383-4d22-b750-ec14d03abecc´downstream_cells_map€²upstream_cells_mapЧ@md_str�Base.getindex�¦string�¤Base�©@html_str�£sum�®Base.Docs.HTML�¢!=�¢==�¡y‘Ù$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$25a03cb9-3e3b-4988-8a7d-5be17eb143c1„´precedence_heuristic §cell_idÙ$25a03cb9-3e3b-4988-8a7d-5be17eb143c1´downstream_cells_map‚©#459#bond�¡a’Ù$593c3c88-e4ab-463d-b904-4ccd07bf24c2Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba²upstream_cells_map‹Ù#PlutoRunner.PlutoRunner.create_bond�©@bindname�«PlutoRunner�´PlutoRunner.Base.get�·HypertextLiteral.Result�»PlutoRunner.Core.applicable�¡:�·HypertextLiteral.Bypass�¸HypertextLiteral.content�¦Slider�°HypertextLiteral�´cell_execution_orderÜ Ù$b4391750-7368-11f0-2e66-6b42d8f70892Ù$5914c0b7-5a46-4166-a4d7-e60013e37029Ù$829970d4-059a-4335-ad19-c6177861e2d8Ù$f9f6868b-f906-40cf-9d6f-a72b22fc1826Ù$f9d9a189-7626-43a1-8f47-8835c9e32c5bÙ$352cc34b-a1e2-4654-93b4-d40d92909d2aÙ$1517f96d-64a4-445f-bbea-4f3e97ddca78Ù$e723edf1-c7f1-4b6f-85ff-aadac9d11f02Ù$a3fdb14a-29ec-49cd-8cd2-088847ea802bÙ$2596781d-3637-41c2-8785-84e23aca7711Ù$1bcf1a3b-a68f-413a-926a-32aded5887aeÙ$1fccee46-87f1-4733-ad93-8d8f8b64e7cdÙ$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$605030dc-5383-4d22-b750-ec14d03abeccÙ$4bb1040c-fa30-4cde-b308-13df21e8e539Ù$2570f665-21b0-4262-b149-4e9d60e1f36aÙ$b9508dde-429d-414f-b7be-4e94f1ef8c2bÙ$13fe6c00-2e27-424f-91e8-6452d76f358eÙ$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405Ù$e35e9f54-3b5e-464e-8a1d-53a314efdd7eÙ$a1c3bb09-f6c5-4a97-995e-7d9d74fe221fÙ$30ff3c54-9c8b-403f-9301-e196be51d7eeÙ$1a2a5fe9-b1fc-41b4-a034-0a664632be37Ù$87e8178a-3cac-46ad-9a42-69a78e3b6e20Ù$25a03cb9-3e3b-4988-8a7d-5be17eb143c1Ù$593c3c88-e4ab-463d-b904-4ccd07bf24c2Ù$4b765b37-9c26-4592-acbf-111d176c5654Ù$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7Ù$54e515dc-c917-4231-9106-e8448400a905Ù$dc62435b-5020-48a9-bc37-d5ee8a663b40Ù$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8Ù$c9ecaabd-686d-4884-b75e-9e4644d371ba´last_hot_reload_timeË ®process_status¥ready¤pathÙ0/home/runner/work/course/course/minis/Softmax.jlpluto_version¦v1.0.3ªcell_orderÜ Ù$5914c0b7-5a46-4166-a4d7-e60013e37029Ù$829970d4-059a-4335-ad19-c6177861e2d8Ù$f9f6868b-f906-40cf-9d6f-a72b22fc1826Ù$f9d9a189-7626-43a1-8f47-8835c9e32c5bÙ$352cc34b-a1e2-4654-93b4-d40d92909d2aÙ$1517f96d-64a4-445f-bbea-4f3e97ddca78Ù$e723edf1-c7f1-4b6f-85ff-aadac9d11f02Ù$a3fdb14a-29ec-49cd-8cd2-088847ea802bÙ$2596781d-3637-41c2-8785-84e23aca7711Ù$1bcf1a3b-a68f-413a-926a-32aded5887aeÙ$1fccee46-87f1-4733-ad93-8d8f8b64e7cdÙ$761e5cce-bc6e-4b49-b792-c0d79bcaa6efÙ$dc62435b-5020-48a9-bc37-d5ee8a663b40Ù$605030dc-5383-4d22-b750-ec14d03abeccÙ$4bb1040c-fa30-4cde-b308-13df21e8e539Ù$2570f665-21b0-4262-b149-4e9d60e1f36aÙ$b9508dde-429d-414f-b7be-4e94f1ef8c2bÙ$13fe6c00-2e27-424f-91e8-6452d76f358eÙ$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405Ù$e35e9f54-3b5e-464e-8a1d-53a314efdd7eÙ$a1c3bb09-f6c5-4a97-995e-7d9d74fe221fÙ$30ff3c54-9c8b-403f-9301-e196be51d7eeÙ$1a2a5fe9-b1fc-41b4-a034-0a664632be37Ù$87e8178a-3cac-46ad-9a42-69a78e3b6e20Ù$25a03cb9-3e3b-4988-8a7d-5be17eb143c1Ù$593c3c88-e4ab-463d-b904-4ccd07bf24c2Ù$c9ecaabd-686d-4884-b75e-9e4644d371baÙ$4b765b37-9c26-4592-acbf-111d176c5654Ù$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7Ù$b4391750-7368-11f0-2e66-6b42d8f70892Ù$54e515dc-c917-4231-9106-e8448400a905Ù$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8julia_version§v1.12.7±published_objects€¥nbpkgжwaiting_for_permissionÂÙ,waiting_for_permission_but_probably_disabled²installed_versions„Ù!__internal_julia_manifest_version¦1.12.7²BmlipTeachingTools¥1.4.1¥Plots¦1.41.6¸__internal_julia_version¦1.12.7°terminal_outputsƒªnbpkg_syncÚ— [0m[1mResolving...[22m [90m===[39m [36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Project.toml` [32m[1m Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Manifest.toml` [90m[e66e0078] [39m[93m↑ CompilerSupportLibraries_jll v1.3.0+1 ⇒ v1.3.1+2[39m [90m[458c3c95] [39m[93m↑ OpenSSL_jll v3.5.4+0 ⇒ v3.5.6+0[39m [0m[1mInstantiating...[22m [90m===[39m [0m[1mPrecompiling...[22m [90m===[39m Waiting for notebook process to start... Done. Starting precompilation... ¥PlotsÚ— [0m[1mResolving...[22m [90m===[39m [36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Project.toml` [32m[1m Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Manifest.toml` [90m[e66e0078] [39m[93m↑ CompilerSupportLibraries_jll v1.3.0+1 ⇒ v1.3.1+2[39m [90m[458c3c95] [39m[93m↑ OpenSSL_jll v3.5.4+0 ⇒ v3.5.6+0[39m [0m[1mInstantiating...[22m [90m===[39m [0m[1mPrecompiling...[22m [90m===[39m Waiting for notebook process to start... Done. Starting precompilation... ²BmlipTeachingToolsÚ— [0m[1mResolving...[22m [90m===[39m [36m[1m Project[22m[39m No packages added to or removed from `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Project.toml` [32m[1m Updating[22m[39m `~/.julia/scratchspaces/c3e4b0f8-55cb-11ea-2926-15256bba5781/pkg_envs/env_preqpwbhqw/Manifest.toml` [90m[e66e0078] [39m[93m↑ CompilerSupportLibraries_jll v1.3.0+1 ⇒ v1.3.1+2[39m [90m[458c3c95] [39m[93m↑ OpenSSL_jll v3.5.4+0 ⇒ v3.5.6+0[39m [0m[1mInstantiating...[22m [90m===[39m [0m[1mPrecompiling...[22m [90m===[39m Waiting for notebook process to start... Done. Starting precompilation... §enabledìinstantiated÷restart_recommended_msgÀ´restart_required_msgÀ¯install_time_nsÏ %ͪ¦Çbusy_packages�«cell_inputsÞ Ù$1517f96d-64a4-445f-bbea-4f3e97ddca78„§cell_idÙ$1517f96d-64a4-445f-bbea-4f3e97ddca78¤codeÙwmd""" Move the sliders below to create a 3-component vector ``x = (x_1,x_2,x_3)``, where ``x_i \in [-10:.1:10]``. """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$f9f6868b-f906-40cf-9d6f-a72b22fc1826„§cell_idÙ$f9f6868b-f906-40cf-9d6f-a72b22fc1826¤codeÚ-md""" ## The Softmax Function The **softmax** function ([wikipedia](https://en.wikipedia.org/wiki/Softmax_function)), also called the **normalized exponential** function, is a mapping ```math \sigma : \mathbb{R}^M \;\rightarrow\; (0,1)^M, \quad M > 1, ``` defined component-wise as ```math \sigma(x)_i \;=\; \frac{\exp(x_i)}{\sum_{j=1}^M \exp(x_j)} , \quad i = 1, \dots, M. ``` The output of the softmax function defines the parameter vector of a [**Categorical distribution**](https://en.wikipedia.org/wiki/Categorical_distribution), regardless of the values of ``x_i``, since all components ``\sigma(x)_i`` are strictly positive and sum to one (see also the [Multinomial Distributions lecture](https://bmlip.github.io/course/lectures/The%20Multinomial%20Distribution.html#The-Categorical-Distribution)). """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$4bb1040c-fa30-4cde-b308-13df21e8e539„§cell_idÙ$4bb1040c-fa30-4cde-b308-13df21e8e539¤code¦sum(y)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$4b765b37-9c26-4592-acbf-111d176c5654„§cell_idÙ$4b765b37-9c26-4592-acbf-111d176c5654¤codeÙïkeyconcept("", md""" The output of the **logistic** function ``\sigma'(a)`` defines the parameter vector of a **Bernoulli distribution**, regardless of the values of ``a``, since ``\sigma'(a)`` is strictly positive and less than one. """) ¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405„§cell_idÙ$a76f25fc-f1c1-4f83-97d8-bebe0a8d1405¤codeÙðkeyconcept("", md""" The output of the **softmax** function defines the parameter vector of a **Categorical distribution**, regardless of the values of ``x_i``, since all components ``\sigma(x)_i`` are strictly positive and sum to one. """)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$2596781d-3637-41c2-8785-84e23aca7711„§cell_idÙ$2596781d-3637-41c2-8785-84e23aca7711¤codeÙ;@bindname x_3 Slider(-10:.1:10; default=0, show_value=true)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$54e515dc-c917-4231-9106-e8448400a905„§cell_idÙ$54e515dc-c917-4231-9106-e8448400a905¤codeÙ†const bar_plot_opts = ( label=nothing, ylabel="softmax(x)", size=(400,150), ylim=(0,1), xticks=(1:3,["yâ‚�","yâ‚‚","y₃"]), )¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8„§cell_idÙ$56a3d5ce-5944-4914-97ce-9a2f74bbe8e8¤codeÙºconst logi_plot_opts = ( legend=nothing, color=:black, lw=3, size=(600,200), xlabel="a", ylabel="b", left_margin=10Plots.PlotMeasures.px, bottom_margin=10Plots.PlotMeasures.px, )¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$1a2a5fe9-b1fc-41b4-a034-0a664632be37„§cell_idÙ$1a2a5fe9-b1fc-41b4-a034-0a664632be37¤codeÙAfunction logistic_function(a::Real)::Real 1 / (1 + exp(-a)) end;¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$13fe6c00-2e27-424f-91e8-6452d76f358e„§cell_idÙ$13fe6c00-2e27-424f-91e8-6452d76f358e¤codeÚymd""" Moreover, the softmax function preserves the relative order between entries: if ``x_k > x_j``, then ``\sigma(x)_k > \sigma(x)_j``. In particular, ```math \arg\max(x) = \arg\max(\sigma(x)) , ``` which motivates the name `softmax`: it produces a “softâ€� probability distribution that emphasizes the maximum entry while still assigning nonzero weight to all others. """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$5914c0b7-5a46-4166-a4d7-e60013e37029„§cell_idÙ$5914c0b7-5a46-4166-a4d7-e60013e37029¤codeÙ#title("Mini: The Softmax Function")¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$a3fdb14a-29ec-49cd-8cd2-088847ea802b„§cell_idÙ$a3fdb14a-29ec-49cd-8cd2-088847ea802b¤codeÙ;@bindname x_2 Slider(-10:.1:10; default=0, show_value=true)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$1fccee46-87f1-4733-ad93-8d8f8b64e7cd„§cell_idÙ$1fccee46-87f1-4733-ad93-8d8f8b64e7cd¤codeÙ'md""" and display ``y = \sigma(x)`` """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$e723edf1-c7f1-4b6f-85ff-aadac9d11f02„§cell_idÙ$e723edf1-c7f1-4b6f-85ff-aadac9d11f02¤codeÙ;@bindname x_1 Slider(-10:.1:10; default=0, show_value=true)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$b4391750-7368-11f0-2e66-6b42d8f70892„§cell_idÙ$b4391750-7368-11f0-2e66-6b42d8f70892¤code¿using Plots, BmlipTeachingTools¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$829970d4-059a-4335-ad19-c6177861e2d8„§cell_idÙ$829970d4-059a-4335-ad19-c6177861e2d8¤code±TableOfContents()¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$f9d9a189-7626-43a1-8f47-8835c9e32c5b„§cell_idÙ$f9d9a189-7626-43a1-8f47-8835c9e32c5b¤code»md""" ## Implementation """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$e35e9f54-3b5e-464e-8a1d-53a314efdd7e„§cell_idÙ$e35e9f54-3b5e-464e-8a1d-53a314efdd7e¤codeÚØmd""" ## The logistic function The **logistic** (or sigmoid) function ([wikipedia](https://en.wikipedia.org/wiki/Logistic_function)) can be seen as a special case of the softmax function for ``M=2``. Let's work this out. The softmax for ``M=2`` takes a vector ``x = (x_1, x_2) \in \mathbb{R}^2`` and maps it to probabilities: ```math \sigma(x)_1 = \frac{e^{x_1}}{e^{x_1} + e^{x_2}}, \quad \sigma(x)_2 = \frac{e^{x_2}}{e^{x_1} + e^{x_2}}\, . ``` If we now look only at ``\sigma(x)_1``, we can rewrite it as ```math \sigma(x)_1 = \frac{1}{1 + e^{-(x_1 - x_2)}} , ``` which is the logistic (sigmoid) function ```math \sigma'(a) \triangleq \frac{1}{1 + e^{-a}} ``` applied to the difference ``x_1 - x_2 \in \mathbb{R}``. """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$87e8178a-3cac-46ad-9a42-69a78e3b6e20„§cell_idÙ$87e8178a-3cac-46ad-9a42-69a78e3b6e20¤codeÙ7md""" Choose any value in the range ``[-10:.1:10]`` """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef„§cell_idÙ$761e5cce-bc6e-4b49-b792-c0d79bcaa6ef¤code®y = softmax(x)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$593c3c88-e4ab-463d-b904-4ccd07bf24c2„§cell_idÙ$593c3c88-e4ab-463d-b904-4ccd07bf24c2¤code¸b = logistic_function(a)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$1bcf1a3b-a68f-413a-926a-32aded5887ae„§cell_idÙ$1bcf1a3b-a68f-413a-926a-32aded5887ae¤code³x = [x_1, x_2, x_3]¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$30ff3c54-9c8b-403f-9301-e196be51d7ee„§cell_idÙ$30ff3c54-9c8b-403f-9301-e196be51d7ee¤code¼md""" ### Implementation """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$b9508dde-429d-414f-b7be-4e94f1ef8c2b„§cell_idÙ$b9508dde-429d-414f-b7be-4e94f1ef8c2b¤codeªextrema(y)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7„§cell_idÙ$ed56bd39-5e77-47fd-b1a7-6e0844b79ea7¤code°md""" # Code """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$a1c3bb09-f6c5-4a97-995e-7d9d74fe221f„§cell_idÙ$a1c3bb09-f6c5-4a97-995e-7d9d74fe221f¤codeÚmd""" As we also see in [Eq. B-4.89 in the Discriminative Classification lecture](https://bmlip.github.io/course/lectures/Discriminative%20Classification.html#Data-generating-distribution), the **logistic function produces the parameters for a Bernoulli distribution**. """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$dc62435b-5020-48a9-bc37-d5ee8a663b40„§cell_idÙ$dc62435b-5020-48a9-bc37-d5ee8a663b40¤code¸bar(y; bar_plot_opts...)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$2570f665-21b0-4262-b149-4e9d60e1f36a„§cell_idÙ$2570f665-21b0-4262-b149-4e9d60e1f36a¤codeÙZmd""" And each **entry lies between 0 and 1**. Here are the lowest and highest values: """¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$c9ecaabd-686d-4884-b75e-9e4644d371ba„§cell_idÙ$c9ecaabd-686d-4884-b75e-9e4644d371ba¤codeÙYlet plot(logistic_function; xlim=(-8,8), logi_plot_opts...) scatter!([a],[b]; ms=7) end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$352cc34b-a1e2-4654-93b4-d40d92909d2a„§cell_idÙ$352cc34b-a1e2-4654-93b4-d40d92909d2a¤codeÙ@function softmax(x::Vector)::Vector exp.(x) / sum(exp.(x)) end;¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÂÙ$605030dc-5383-4d22-b750-ec14d03abecc„§cell_idÙ$605030dc-5383-4d22-b750-ec14d03abecc¤codeÚlet extra = if string(sum(y)) != "1.0" html"(Except for some floating-point imprecision 😅)" else "" end md""" ### Check the Result Check that the output of the softmax function sums to ``1``. $(extra) """ end¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedÃÙ$25a03cb9-3e3b-4988-8a7d-5be17eb143c1„§cell_idÙ$25a03cb9-3e3b-4988-8a7d-5be17eb143c1¤codeÙ9@bindname a Slider(-10:.1:10; default=0, show_value=true)¨metadataƒ©show_logsèdisabled®skip_as_script«code_foldedënotebook_idÙ$660d2aee-b809-11f1-9cba-3fe38659311a¥bonds€¬cell_resultsÞ Ù$1517f96d-64a4-445f-bbea-4f3e97ddca78Цqueued¤logs�§running¦output†¤bodyÙÒ
Move the sliders below to create a 3-component vector $x = (x_1,x_2,x_3)$, where $x_i \in [-10:.1:10]$.
The softmax function (wikipedia), also called the normalized exponential function, is a mapping
$$\sigma : \mathbb{R}^M \;\rightarrow\; (0,1)^M, \quad M > 1,$$
defined component-wise as
$$\sigma(x)_i \;=\; \frac{\exp(x_i)}{\sum_{j=1}^M \exp(x_j)} , \quad i = 1, \dots, M.$$
The output of the softmax function defines the parameter vector of a Categorical distribution, regardless of the values of $x_i$, since all components $\sigma(x)_i$ are strictly positive and sum to one (see also the Multinomial Distributions lecture).
🎯 Key concept
The output of the logistic function $\sigma'(a)$ defines the parameter vector of a Bernoulli distribution, regardless of the values of $a$, since $\sigma'(a)$ is strictly positive and less than one.
🎯 Key concept
The output of the softmax function defines the parameter vector of a Categorical distribution, regardless of the values of $x_i$, since all components $\sigma(x)_i$ are strictly positive and sum to one.
Moreover, the softmax function preserves the relative order between entries: if $x_k > x_j$, then $\sigma(x)_k > \sigma(x)_j$. In particular,
$$\arg\max(x) = \arg\max(\sigma(x)) ,$$
which motivates the name softmax: it produces a “soft� probability distribution that emphasizes the maximum entry while still assigning nonzero weight to all others.
and display $y = \sigma(x)$
The logistic (or sigmoid) function (wikipedia) can be seen as a special case of the softmax function for $M=2$.
Let's work this out. The softmax for $M=2$ takes a vector $x = (x_1, x_2) \in \mathbb{R}^2$ and maps it to probabilities:
$$\sigma(x)_1 = \frac{e^{x_1}}{e^{x_1} + e^{x_2}}, \quad \sigma(x)_2 = \frac{e^{x_2}}{e^{x_1} + e^{x_2}}\, .$$
If we now look only at $\sigma(x)_1$, we can rewrite it as
$$\sigma(x)_1 = \frac{1}{1 + e^{-(x_1 - x_2)}} ,$$
which is the logistic (sigmoid) function
$$\sigma'(a) \triangleq \frac{1}{1 + e^{-a}}$$
applied to the difference $x_1 - x_2 \in \mathbb{R}$.
Choose any value in the range $[-10:.1:10]$
As we also see in Eq. B-4.89 in the Discriminative Classification lecture, the logistic function produces the parameters for a Bernoulli distribution.
And each entry lies between 0 and 1. Here are the lowest and highest values:
Check that the output of the softmax function sums to $1$.