{"id":1534,"date":"2026-10-27T09:00:00","date_gmt":"2026-10-27T00:00:00","guid":{"rendered":"https:\/\/quantumsea.net\/?p=1534"},"modified":"2026-10-24T09:17:44","modified_gmt":"2026-10-24T00:17:44","slug":"qs-logsumexp-numerical-stability-20261024","status":"publish","type":"post","link":"https:\/\/quantumsea.net\/?p=1534","title":{"rendered":"log-sum-exp\u3001\u7b54\u3048\u306f\u6709\u9650\u306a\u306e\u306b\u9014\u4e2d\u306e\u8a08\u7b97\u304c\u3042\u3075\u308c\u308b\u7406\u7531"},"content":{"rendered":"<p>\u8a08\u7b97\u306e\u7b54\u3048\u306f1,001\u7a0b\u5ea6\u306a\u306e\u306b\u3001\u9014\u4e2d\u3067\u300c\u5927\u304d\u3059\u304e\u3066\u6271\u3048\u306a\u3044\u300d\u3068\u6b62\u307e\u3063\u3066\u3057\u307e\u3046\u3002\u6307\u6570\u95a2\u6570\u3068\u5bfe\u6570\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u8a08\u7b97\u3067\u306f\u3001\u305d\u3093\u306a\u3053\u3068\u304c\u8d77\u3053\u308a\u307e\u3059\u3002\u4ee3\u8868\u4f8b\u304c<strong>log-sum-exp\uff08\u30ed\u30b0\u30fb\u30b5\u30e0\u30fb\u30a8\u30af\u30b9\u30d7\uff09<\/strong>\u3067\u3059\u3002<\/p>\n<p>\u5165\u529b\u3092\u305d\u308c\u305e\u308c\u6307\u6570\u95a2\u6570\u306b\u901a\u3057\u3001\u8db3\u3057\u5408\u308f\u305b\u3001\u6700\u5f8c\u306b\u5bfe\u6570\u3092\u53d6\u308b\u95a2\u6570\u3067\u3001\u6a5f\u68b0\u5b66\u7fd2\u306e\u6b63\u898f\u5316\u306a\u3069\u306b\u4f7f\u308f\u308c\u307e\u3059\u3002\u6700\u7d42\u7d50\u679c\u3060\u3051\u3092\u898b\u3066\u8a08\u7b97\u7cbe\u5ea6\u3092\u9078\u3076\u3068\u3001\u9014\u4e2d\u306e\u5024\u304c\u8868\u73fe\u7bc4\u56f2\u3092\u8d85\u3048\u308b\u554f\u984c\u3092\u898b\u843d\u3068\u3057\u307e\u3059\u3002\u6700\u5927\u5024\u3092\u3044\u3063\u305f\u3093\u53d6\u308a\u9664\u304f\u5de5\u592b\u304c\u3001\u306a\u305c\u7b54\u3048\u3092\u5909\u3048\u305a\u306b\u3053\u306e\u554f\u984c\u3092\u907f\u3051\u3089\u308c\u308b\u306e\u304b\u3092\u78ba\u304b\u3081\u307e\u3059\u3002<\/p>\n<section class=\"influvetor-quick-summary\">\n<p><strong>\u7c21\u5358\u306b\u307e\u3068\u3081\u308b\u3068\uff1f<\/strong><\/p>\n<ul>\n<li>log-sum-exp\u306e\u7d50\u679c\u304c\u6709\u9650\u3067\u3082\u3001\u5148\u306b\u8a08\u7b97\u3059\u308b\u6307\u6570\u95a2\u6570\u304c\u6841\u3042\u3075\u308c\u3057\u305f\u308a\u3001\u6975\u7aef\u306b\u5c0f\u3055\u304f\u306a\u3063\u30660\u3078\u4e38\u3081\u3089\u308c\u305f\u308a\u3057\u307e\u3059\u3002<\/li>\n<li>\u5404\u5165\u529b\u304b\u3089\u6700\u5927\u5024\u3092\u5f15\u304f\u3068\u3001\u6307\u6570\u95a2\u6570\u3078\u6e21\u3059\u5024\u306f0\u4ee5\u4e0b\u306b\u306a\u308a\u307e\u3059\u3002\u6700\u5f8c\u306b\u305d\u306e\u6700\u5927\u5024\u3092\u8db3\u3057\u623b\u305b\u3070\u3001\u6570\u5b66\u7684\u306b\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<\/li>\n<li>\u6841\u3042\u3075\u308c\u5bfe\u7b56\u3068\u4e38\u3081\u8aa4\u5dee\u306e\u5bfe\u7b56\u306f\u5225\u3067\u3059\u3002\u5c0f\u3055\u306a\u88dc\u6b63\u306b\u306flog1p\u3092\u4f7f\u3046\u5de5\u592b\u304c\u3042\u308a\u3001\u7121\u9650\u5927\u30fbNaN\u30fb\u8ca0\u306e\u91cd\u307f\u306a\u3069\u306f\u8ffd\u52a0\u306e\u6271\u3044\u304c\u5fc5\u8981\u3067\u3059\u3002<\/li>\n<\/ul>\n<\/section>\n<h2>\u5bfe\u6570\u3092\u53d6\u308b\u524d\u306e\u5024\u304c\u3001\u5148\u306b\u9650\u754c\u3078\u9054\u3059\u308b<\/h2>\n<p>\u6709\u9650\u306e\u5b9f\u6570 <em>x<sub>1<\/sub>, \u2026, x<sub>n<\/sub><\/em> \u306b\u5bfe\u3057\u3066\u3001log-sum-exp\u3092\u6b21\u306e\u3088\u3046\u306b\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u672c\u7a3f\u306e <em>log<\/em> \u306f\u81ea\u7136\u5bfe\u6570\u3067\u3059\u3002<\/p>\n<p><strong>LSE(x)\uff1dlog(exp(x<sub>1<\/sub>)\uff0b\u2026\uff0bexp(x<sub>n<\/sub>))<\/strong><\/p>\n<p>\u305f\u3068\u3048\u3070\u5165\u529b\u304c <em>[1000, 1001]<\/em> \u306a\u3089\u3001\u7b54\u3048\u306f\u7d04<strong>1001.313262<\/strong>\u3067\u3059\u3002\u3068\u3053\u308d\u304c\u3001\u901a\u5e38\u306e\u500d\u7cbe\u5ea6\u6d6e\u52d5\u5c0f\u6570\u70b9\u6570\u3067 <em>exp(1000)<\/em> \u3092\u5148\u306b\u4f5c\u308d\u3046\u3068\u3059\u308b\u3068\u3001\u305d\u306e\u6642\u70b9\u3067\u8868\u73fe\u7bc4\u56f2\u3092\u8d85\u3048\u307e\u3059\u3002\u3053\u308c\u304c<strong>\u30aa\u30fc\u30d0\u30fc\u30d5\u30ed\u30fc<\/strong>\u3001\u3064\u307e\u308a\u6841\u3042\u3075\u308c\u3067\u3059\u3002<\/p>\n<p>\u5bfe\u6570\u306b\u306f\u5927\u304d\u306a\u5024\u3092\u5c0f\u3055\u306a\u6841\u6570\u306b\u5727\u7e2e\u3059\u308b\u50cd\u304d\u304c\u3042\u308a\u307e\u3059\u304c\u3001\u5f8c\u304b\u3089\u53d6\u308b\u5bfe\u6570\u306f\u3001\u3059\u3067\u306b\u8868\u73fe\u3067\u304d\u306a\u304f\u306a\u3063\u305f\u4e2d\u9593\u7d50\u679c\u3092\u6551\u3048\u307e\u305b\u3093\u3002\u6570\u5f0f\u3068\u3057\u3066\u7b49\u3057\u3044\u66f8\u304d\u65b9\u3067\u3082\u3001\u6709\u9650\u306e\u6841\u3057\u304b\u6301\u305f\u306a\u3044\u8a08\u7b97\u6a5f\u3067\u306f\u8a08\u7b97\u9806\u5e8f\u304c\u7d50\u679c\u3092\u5de6\u53f3\u3057\u307e\u3059\u3002[1]<\/p>\n<h2>\u6700\u5927\u5024\u3092\u5916\u306b\u51fa\u3057\u3001\u5dee\u3060\u3051\u3092\u6307\u6570\u95a2\u6570\u3078\u6e21\u3059<\/h2>\n<p>\u5165\u529b\u306e\u6700\u5927\u5024\u3092 <em>m\uff1dmax(x)<\/em> \u3068\u3057\u307e\u3059\u3002\u5404\u6307\u6570\u95a2\u6570\u304b\u3089\u5171\u901a\u306e <em>exp(m)<\/em> \u3092\u304f\u304f\u308a\u51fa\u3059\u3068\u3001\u5bfe\u6570\u306e\u6027\u8cea\u306b\u3088\u3063\u3066\u6b21\u306e\u5f0f\u3078\u66f8\u304d\u63db\u3048\u3089\u308c\u307e\u3059\u3002[1]<\/p>\n<p><strong>LSE(x)\uff1dm\uff0blog(\u03a3 exp(x<sub>i<\/sub>\u2212m))<\/strong><\/p>\n<p>\u3053\u3053\u3067\u306e\u30dd\u30a4\u30f3\u30c8\u306f\u3001<strong>exp(m)\u3092\u5b9f\u969b\u306b\u306f\u8a08\u7b97\u3057\u306a\u3044<\/strong>\u3053\u3068\u3067\u3059\u3002\u5171\u901a\u56e0\u5b50\u3092\u6570\u5f0f\u306e\u4e0a\u3067\u5bfe\u6570\u306e\u5916\u3078\u51fa\u3057\u3001\u6700\u5f8c\u306b <em>m<\/em> \u3092\u8db3\u3059\u5f62\u306b\u3057\u307e\u3059\u3002<\/p>\n<p><em>m<\/em> \u306f\u6700\u5927\u5024\u306a\u306e\u3067\u3001\u3059\u3079\u3066\u306e <em>x<sub>i<\/sub>\u2212m<\/em> \u306f0\u4ee5\u4e0b\u3067\u3059\u3002\u6307\u6570\u95a2\u6570\u306e\u5024\u306f1\u4ee5\u4e0b\u3068\u306a\u308a\u3001\u5c11\u306a\u304f\u3068\u3082\u6700\u5927\u5024\u306b\u5bfe\u5fdc\u3059\u308b\u4e00\u3064\u306f <em>exp(0)\uff1d1<\/em> \u306b\u306a\u308a\u307e\u3059\u3002\u6307\u6570\u306e\u8a08\u7b97\u304c\u5de8\u5927\u5316\u305b\u305a\u3001\u548c\u304c\u5168\u90e80\u306b\u306a\u308b\u3053\u3068\u3082\u907f\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n<p>\u5148\u307b\u3069\u306e <em>[1000, 1001]<\/em> \u306a\u3089\u30011001\u3092\u5f15\u3044\u3066 <em>[\u22121, 0]<\/em> \u306b\u3057\u307e\u3059\u3002\u6307\u6570\u306e\u5024\u306f\u7d04 <em>[0.367879, 1]<\/em>\u3001\u305d\u306e\u548c\u306e\u5bfe\u6570\u306f\u7d040.313262\u3067\u3059\u3002\u6700\u5f8c\u306b1001\u3092\u8db3\u3059\u3068\u3001\u7d041001.313262\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<figure><img decoding=\"async\" src=\"https:\/\/quantumsea.net\/wp-content\/uploads\/2026\/10\/qs-logsumexp-numerical-stability-20261024-figure-4816cd43d231.png\" alt=\"\u5165\u529b1000\u30681001\u304b\u3089\u6700\u5927\u50241001\u3092\u5f15\u304f\u3068-1\u30680\u3002\u6307\u6570\u306f\u7d040.367879\u30681\u306b\u53ce\u307e\u308a\u3001\u5bfe\u6570\u306e\u5f8c\u30671001\u3092\u8db3\u3059\u30681001.313262\u3068\u306a\u308b\u3002\" style=\"max-width:100%;height:auto\" \/><figcaption>\u6700\u5927\u5024\u3092\u5dee\u3057\u5f15\u304f\u8a08\u7b97\u7d4c\u8def\u3002\u5171\u901a\u306e\u5927\u304d\u3055\u306f\u6700\u5f8c\u306b\u8db3\u3057\u623b\u3057\u3001\u6307\u6570\u95a2\u6570\u306b\u306f\u5165\u529b\u540c\u58eb\u306e\u5dee\u3060\u3051\u3092\u6e21\u3059\u3002\u6570\u5024\u306f\u672c\u7a3f\u306e\u8a08\u7b97\u4f8b\u3002<\/figcaption><\/figure>\n<h2>\u5927\u304d\u306a\u8ca0\u306e\u5024\u3067\u3082\u3001\u540c\u3058\u5de5\u592b\u304c\u5f79\u7acb\u3064<\/h2>\n<p>\u9006\u306b\u5165\u529b\u304c <em>[\u22121000, \u2212999]<\/em> \u306e\u5834\u5408\u3001\u6307\u6570\u306e\u5024\u306f\u6975\u7aef\u306b\u5c0f\u3055\u304f\u306a\u308a\u307e\u3059\u3002\u4eca\u56de\u306e\u500d\u7cbe\u5ea6\u8a08\u7b97\u3067\u306f\u4e21\u65b9\u304c0\u306b\u4e38\u3081\u3089\u308c\u3001\u76f4\u63a5\u5f0f\u306f <em>log(0)<\/em> \u3092\u8a08\u7b97\u3057\u3088\u3046\u3068\u3057\u3066\u5931\u6557\u3057\u307e\u3057\u305f\u3002\u3053\u308c\u306f\u5c0f\u3055\u3059\u304e\u308b\u5024\u3092\u6271\u3048\u306a\u304f\u306a\u308b<strong>\u30a2\u30f3\u30c0\u30fc\u30d5\u30ed\u30fc<\/strong>\u306e\u5f71\u97ff\u3067\u3059\u3002<\/p>\n<p>\u6700\u5927\u5024\u306e\u2212999\u3092\u5f15\u3051\u3070\u3001\u3084\u306f\u308a <em>[\u22121, 0]<\/em> \u306b\u306a\u308a\u307e\u3059\u3002\u3057\u305f\u304c\u3063\u3066\u7d50\u679c\u306f <em>\u2212999\uff0b0.313262<\/em>\u3001\u7d04<strong>\u2212998.686738<\/strong>\u3067\u3059\u3002<\/p>\n<div style=\"overflow-x:auto\">\n<table style=\"border-collapse:collapse;min-width:580px;width:100%\">\n<thead>\n<tr>\n<th style=\"padding:10px;border:1px solid #ccd\">\u5165\u529b<\/th>\n<th style=\"padding:10px;border:1px solid #ccd\">\u6307\u6570\u3092\u5148\u306b\u4f5c\u308b\u76f4\u63a5\u5f0f<\/th>\n<th style=\"padding:10px;border:1px solid #ccd\">\u6700\u5927\u5024\u30b7\u30d5\u30c8\u5f8c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:10px;border:1px solid #ccd\">[1000, 1001]<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">exp\u3067\u6841\u3042\u3075\u308c<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">1001.313262<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:10px;border:1px solid #ccd\">[0, 1]<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">1.313262<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">1.313262<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:10px;border:1px solid #ccd\">[\u22121000, \u2212999]<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">\u6307\u6570\u304c\u4e21\u65b90\u3001log\u3067\u5931\u6557<\/td>\n<td style=\"padding:10px;border:1px solid #ccd\">\u2212998.686738<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>\u8868\u306fPython\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u306e <code>math<\/code> \u3068\u500d\u7cbe\u5ea6\u306e <code>float<\/code> \u3067\u78ba\u8a8d\u3057\u305f\u3082\u306e\u3067\u3059\u3002\u76f4\u63a5\u5f0f\u3067\u306f\u4e0a\u6bb5\u304c <code>OverflowError<\/code>\u3001\u4e0b\u6bb5\u304c <code>ValueError<\/code> \u306b\u306a\u308a\u307e\u3057\u305f\u3002\u5225\u306e\u6570\u5024\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u306f\u4f8b\u5916\u3067\u306f\u306a\u304f\u7121\u9650\u5927\u3084\u8b66\u544a\u3067\u77e5\u3089\u305b\u308b\u5834\u5408\u3082\u3042\u308b\u305f\u3081\u3001\u5931\u6557\u306e\u8868\u793a\u3068\u6570\u5b66\u7684\u306a\u539f\u56e0\u3092\u5206\u3051\u3066\u898b\u307e\u3059\u3002\u30b7\u30d5\u30c8\u5f8c\u306e\u5024\u306f\u300180\u6841\u7cbe\u5ea6\u306e\u5341\u9032\u8a08\u7b97\u306b\u3088\u308b\u76f4\u63a5\u5f0f\u3068\u3082\u7167\u5408\u3057\u307e\u3057\u305f\u3002<\/p>\n<h2>\u6700\u5927\u5024\u3092\u5f15\u3051\u3070\u3001\u4e38\u3081\u8aa4\u5dee\u307e\u3067\u306a\u304f\u306a\u308b\u308f\u3051\u3067\u306f\u306a\u3044<\/h2>\n<p>\u6700\u5927\u5024\u30b7\u30d5\u30c8\u306f\u4e2d\u9593\u5024\u306e\u5927\u304d\u3055\u3092\u6291\u3048\u307e\u3059\u304c\u3001\u6709\u9650\u7cbe\u5ea6\u3067\u3042\u308b\u3053\u3068\u81ea\u4f53\u306f\u5909\u3048\u307e\u305b\u3093\u3002\u305f\u3068\u3048\u3070 <em>[0, \u221240]<\/em> \u3067\u306f\u3001\u6307\u6570\u306e\u548c\u306f <em>1\uff0bexp(\u221240)<\/em> \u3067\u3059\u3002\u5c0f\u3055\u3044\u9805\u306f\u7d04 <em>4.25\u00d710<sup>\u221218<\/sup><\/em> \u3067\u3001\u500d\u7cbe\u5ea6\u3067\u5148\u306b1\u3078\u8db3\u3059\u3068\u3001\u305d\u306e\u5dee\u304c\u4e38\u3081\u3089\u308c\u30661\u306b\u306a\u308a\u307e\u3057\u305f\u3002\u305d\u306e\u5f8c\u306b\u5bfe\u6570\u3092\u53d6\u308b\u30680\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u5834\u5408\u306f\u3001<strong>log1p(s)<\/strong>\u3001\u3064\u307e\u308a\u300c1\uff0bs\u306e\u5bfe\u6570\u300d\u3092\u5c0f\u3055\u306a <em>s<\/em> \u306b\u3082\u914d\u616e\u3057\u3066\u8a08\u7b97\u3059\u308b\u95a2\u6570\u304c\u5f79\u7acb\u3061\u307e\u3059\u3002\u6700\u5927\u306e\u9805\u4e00\u3064\u3092\u548c\u304b\u3089\u53d6\u308a\u51fa\u3059\u3068\u3001\u6b21\u306e\u5f62\u306b\u3067\u304d\u307e\u3059\u3002[1]<\/p>\n<p><strong>LSE(x)\uff1dm\uff0blog1p(\u03a3<sub>i\u2260k<\/sub> exp(x<sub>i<\/sub>\u2212m))<\/strong><br \/><em>k<\/em> \u306f\u6700\u5927\u5024\u3092\u53d6\u308b\u4f4d\u7f6e\u306e\u4e00\u3064\u3067\u3059\u3002<\/p>\n<p>\u6700\u5927\u5024\u304c\u8907\u6570\u3042\u3063\u3066\u3082\u3001\u53d6\u308a\u51fa\u3059\u306e\u306f\u4e00\u3064\u3060\u3051\u3067\u3059\u3002\u305f\u3068\u3048\u3070 <em>[0, 0]<\/em> \u306a\u3089\u3001\u6b8b\u308b\u9805\u30821\u306a\u306e\u3067\u7b54\u3048\u306f <em>log(2)<\/em> \u3067\u3059\u3002\u6700\u5927\u306e\u9805\u3092\u3059\u3079\u3066\u6368\u3066\u308b\u3068\u3001\u7570\u306a\u308b\u8a08\u7b97\u306b\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<p><em>[0, \u221240]<\/em> \u3067\u306f <em>log1p(exp(\u221240))<\/em> \u306b\u3088\u308a\u3001\u7d04 <em>4.25\u00d710<sup>\u221218<\/sup><\/em> \u306e\u88dc\u6b63\u3092\u6b8b\u305b\u307e\u3057\u305f\u3002\u305f\u3060\u3057\u3001\u6700\u5f8c\u306b\u5927\u304d\u306a <em>m<\/em> \u3078\u8db3\u3059\u6bb5\u968e\u3067\u5fae\u5c0f\u306a\u5dee\u304c\u4e38\u3081\u3089\u308c\u308b\u5834\u5408\u306a\u3069\u3001\u6b8b\u308b\u7cbe\u5ea6\u306e\u9650\u754c\u306f\u3042\u308a\u307e\u3059\u3002<\/p>\n<h2>softmax\u3067\u306f\u3001\u5171\u901a\u306e\u5927\u304d\u3055\u304c\u5206\u6bcd\u3068\u5206\u5b50\u3067\u6d88\u3048\u308b<\/h2>\n<p><strong>softmax<\/strong>\u306f\u3001\u5404\u5165\u529b\u306e\u6307\u6570\u3092\u6307\u6570\u306e\u7dcf\u548c\u3067\u5272\u308a\u3001\u5408\u8a081\u306e\u5024\u3078\u5909\u63db\u3059\u308b\u95a2\u6570\u3067\u3059\u3002\u3053\u3061\u3089\u3082\u5206\u5b50\u3068\u5206\u6bcd\u304b\u3089\u540c\u3058 <em>exp(m)<\/em> \u3092\u9664\u3051\u307e\u3059\u3002<\/p>\n<p><strong>softmax(x)<sub>i<\/sub>\uff1dexp(x<sub>i<\/sub>\u2212m) \/ \u03a3 exp(x<sub>j<\/sub>\u2212m)<\/strong><\/p>\n<p><em>[1000, 1001]<\/em> \u306a\u3089\u3001\u7d50\u679c\u306f\u7d04 <em>[0.268941, 0.731059]<\/em>\u3002\u5165\u529b\u306e\u4e21\u65b9\u3078\u540c\u3058\u6570\u3092\u8db3\u3057\u3066\u3082\u3001\u5dee\u306f\u5909\u308f\u3089\u306a\u3044\u306e\u3067softmax\u306e\u5024\u306f\u5909\u308f\u308a\u307e\u305b\u3093\u3002\u4e00\u65b9\u3001log-sum-exp\u306e\u7d50\u679c\u306f\u3001\u305d\u306e\u5171\u901a\u306e\u6570\u3060\u3051\u79fb\u52d5\u3057\u307e\u3059\u3002\u3053\u306e\u9055\u3044\u306f\u3001\u6b63\u898f\u5316\u3055\u308c\u305f\u6bd4\u7387\u304c\u5fc5\u8981\u306a\u306e\u304b\u3001\u6b63\u898f\u5316\u306b\u4f7f\u3046\u91cf\u306e\u5bfe\u6570\u304c\u5fc5\u8981\u306a\u306e\u304b\u3092\u6574\u7406\u3059\u308b\u3068\u304d\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/p>\n<h2>\u5b9f\u88c5\u3067\u306f\u3001\u5165\u529b\u306e\u7bc4\u56f2\u3068\u96c6\u8a08\u3059\u308b\u8ef8\u3082\u6c7a\u3081\u308b<\/h2>\n<p>\u4ed5\u7d44\u307f\u3092\u78ba\u304b\u3081\u308b\u305f\u3081\u3001\u4eca\u56de\u306e\u8a08\u7b97\u3067\u306f\u6b21\u306e\u95a2\u6570\u3092\u4f7f\u3044\u307e\u3057\u305f\u3002\u7a7a\u3067\u306a\u3044\u3001\u6709\u9650\u5b9f\u6570\u306e\u4e00\u6b21\u5143\u5217\u306b\u5bfe\u8c61\u3092\u7d5e\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre style=\"overflow-x:auto;white-space:pre;padding:16px;background:#f1f4f5\"><code>import math\n\ndef lse_finite(x):\n    x = list(x)\n    if not x or not all(math.isfinite(v) for v in x):\n        raise ValueError(\"nonempty finite input required\")\n    k = max(range(len(x)), key=x.__getitem__)\n    m = x[k]\n    s = math.fsum(math.exp(v - m)\n                  for i, v in enumerate(x) if i != k)\n    return m + math.log1p(s)<\/code><\/pre>\n<p>\u5b9f\u969b\u306e\u914d\u5217\u51e6\u7406\u3067\u306f\u3001\u5c02\u7528\u95a2\u6570\u306e\u5bfe\u8c61\u7bc4\u56f2\u3082\u78ba\u8a8d\u3057\u307e\u3059\u3002SciPy\u306e <code>scipy.special.logsumexp<\/code> \u306f\u5b89\u5b9a\u3057\u305f\u8a08\u7b97\u3092\u63d0\u4f9b\u3057\u3001<code>axis<\/code> \u3067\u96c6\u8a08\u3059\u308b\u8ef8\u3001<code>keepdims<\/code> \u3067\u6b21\u5143\u3092\u6b8b\u3059\u304b\u3092\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002[2] \u8907\u6570\u306e\u30b5\u30f3\u30d7\u30eb\u3092\u4e26\u3079\u305f\u914d\u5217\u306a\u3089\u3001\u5404\u30b5\u30f3\u30d7\u30eb\u5185\u3067\u5408\u8a08\u3057\u305f\u3044\u306e\u304b\u3001\u914d\u5217\u5168\u4f53\u3092\u5408\u8a08\u3057\u305f\u3044\u306e\u304b\u3092\u5148\u306b\u6c7a\u3081\u307e\u3059\u3002<\/p>\n<p>\u8ca0\u306e\u91cd\u307f\u3092\u4ed8\u3051\u305f\u6307\u6570\u306e\u548c\u306f\u3001\u9805\u304c\u6253\u3061\u6d88\u3057\u5408\u3044\u3001\u548c\u304c\u8ca0\u306b\u306a\u308b\u53ef\u80fd\u6027\u3082\u3042\u308a\u307e\u3059\u3002\u307e\u305f\u3001\u5165\u529b\u306bNaN\u3084\u7121\u9650\u5927\u304c\u3042\u308b\u3068\u3001\u5358\u7d14\u306a\u300c\u6700\u5927\u5024\u3092\u5f15\u304f\u300d\u3060\u3051\u3067\u306f\u6271\u3048\u307e\u305b\u3093\u3002\u672c\u7a3f\u306e\u6709\u9650\u30fb\u91cd\u307f\u306a\u3057\u306e\u4f8b\u3068\u5206\u3051\u3066\u3001\u5c02\u7528\u95a2\u6570\u306e\u4ed5\u69d8\u3092\u78ba\u8a8d\u3059\u308b\u7bc4\u56f2\u3067\u3059\u3002<\/p>\n<p>\u9014\u4e2d\u306e\u5024\u304c\u8868\u73fe\u7bc4\u56f2\u306b\u53ce\u307e\u308b\u304b\u3001\u53ce\u307e\u3063\u3066\u3044\u3066\u3082\u5c0f\u3055\u306a\u5dee\u304c\u4e38\u3081\u3089\u308c\u306a\u3044\u304b\u3002\u3053\u306e\u4e8c\u3064\u3092\u5206\u3051\u3066\u70b9\u691c\u3059\u308b\u3068\u3001\u7b54\u3048\u3060\u3051\u3092\u898b\u3066\u3044\u305f\u3068\u304d\u306b\u306f\u6c17\u3065\u304d\u306b\u304f\u3044\u6570\u5024\u8a08\u7b97\u306e\u5931\u6557\u3092\u898b\u3064\u3051\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u51fa\u5178<\/h2>\n<ol>\n<li>Pierre Blanchard, Desmond J. Higham, Nicholas J. Higham, <a href=\"https:\/\/eprints.maths.manchester.ac.uk\/2744\/1\/paper.pdf\">Accurately Computing the Log-Sum-Exp and Softmax Functions<\/a>\uff08\u672c\u6587\u8a18\u8f09\u306e\u7248\uff1a2020\u5e741\u670831\u65e5\u3002\u5f0f1.3\u30fb1.4\u30014\u7bc0\u30fbAlgorithm 4.1\uff09\u3002<\/li>\n<li>SciPy v1.18.0 Manual, <a href=\"https:\/\/docs.scipy.org\/doc\/scipy\/reference\/generated\/scipy.special.logsumexp.html\">scipy.special.logsumexp<\/a>\uff08\u30d1\u30e9\u30e1\u30fc\u30bf\u30fc\u3068\u8a08\u7b97\u5bfe\u8c61\u306e\u8aac\u660e\uff09\u3002<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u8a08\u7b97\u306e\u7b54\u3048\u306f1,001\u7a0b\u5ea6\u306a\u306e\u306b\u3001\u9014\u4e2d\u3067\u300c\u5927\u304d\u3059\u304e\u3066\u6271\u3048\u306a\u3044\u300d\u3068\u6b62\u307e\u3063\u3066\u3057\u307e\u3046\u3002\u6307\u6570\u95a2\u6570\u3068\u5bfe\u6570\u3092\u7d44\u307f\u5408\u308f\u305b\u308b\u8a08\u7b97\u3067\u306f\u3001\u305d\u3093\u306a\u3053\u3068\u304c\u8d77\u3053\u308a\u307e\u3059\u3002\u4ee3\u8868\u4f8b\u304clog-sum-exp\uff08\u30ed\u30b0\u30fb\u30b5\u30e0\u30fb\u30a8\u30af\u30b9\u30d7\uff09\u3067\u3059\u3002 \u5165\u529b\u3092\u305d\u308c\u305e\u308c\u6307 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":1532,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":false,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[31],"tags":[308],"class_list":["post-1534","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ai-software","tag-log-sum-exp"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/quantumsea.net\/wp-content\/uploads\/2026\/10\/qs-logsumexp-numerical-stability-20261024-featured-939f05a7d700.png","_links":{"self":[{"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/posts\/1534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/quantumsea.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1534"}],"version-history":[{"count":1,"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/posts\/1534\/revisions"}],"predecessor-version":[{"id":1535,"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/posts\/1534\/revisions\/1535"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/quantumsea.net\/index.php?rest_route=\/wp\/v2\/media\/1532"}],"wp:attachment":[{"href":"https:\/\/quantumsea.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quantumsea.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quantumsea.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}