{"id":3567,"date":"2023-06-29T17:29:09","date_gmt":"2023-06-29T08:29:09","guid":{"rendered":"https:\/\/blog.since2020.jp\/?p=3567"},"modified":"2023-06-29T17:29:09","modified_gmt":"2023-06-29T08:29:09","slug":"python%e3%81%aenashpy%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%9b%9a%e4%ba%ba%e3%81%ae%e3%82%b8%e3%83%ac%e3%83%b3%e3%83%9e%e3%81%ab%e3%81%8a%e3%81%91","status":"publish","type":"post","link":"https:\/\/since2020.jp\/media\/python%e3%81%aenashpy%e3%83%a9%e3%82%a4%e3%83%96%e3%83%a9%e3%83%aa%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e5%9b%9a%e4%ba%ba%e3%81%ae%e3%82%b8%e3%83%ac%e3%83%b3%e3%83%9e%e3%81%ab%e3%81%8a%e3%81%91\/","title":{"rendered":"Python\u306eNashpy\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u306b\u304a\u3051\u308b\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u6c42\u3081\u3066\u307f\u305f\u3002"},"content":{"rendered":"\n<p>Python\u3092\u4f7f\u7528\u3057\u3066\u3001\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u3068\u3057\u3066\u77e5\u3089\u308c\u308b\u30b2\u30fc\u30e0\u7406\u8ad6\u306e\u30b7\u30ca\u30ea\u30aa\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3059\u308b\u3002<\/p>\n\n\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u672c\u8a18\u4e8b\u3067\u306f\u3001<span data-token-index=\"1\" class=\"notion-enable-hover\">nashpy<\/span>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u3068\u3057\u3066\u77e5\u3089\u308c\u308b\u30b2\u30fc\u30e0\u7406\u8ad6\u306e\u30b7\u30ca\u30ea\u30aa\u306b\u3064\u3044\u3066\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u6c42\u3081\u308b\u65b9\u6cd5\u3092\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/span><\/strong>\n\n<h2>\u624b\u98061: \u30b2\u30fc\u30e0\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7<\/h2>\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u307e\u305a\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u884c\u52d5\u306b\u5bfe\u3059\u308b\u5831\u916c\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067\u30b2\u30fc\u30e0\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u3067\u306f\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306f\u300c\u9ed9\u79d8\u300d\u307e\u305f\u306f\u300c\u81ea\u767d\u300d\u306e2\u3064\u306e\u9078\u629e\u80a2\u3092\u6301\u3061\u307e\u3059\u3002\u5831\u916c\u306f\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u9078\u629e\u306b\u57fa\u3065\u304f\u53ce\u76ca\u3068\u3057\u3066\u3001\u61f2\u5f79\u5e74\u6570\u3092\u8868\u3057\u307e\u3059\u3002<\/span><\/strong>\r\n\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u307e\u305a\u3001\u5fc5\u8981\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u30a4\u30f3\u30dd\u30fc\u30c8\u3057\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>!pip install nashpy\r\n\r\nimport nashpy as nash\r\nimport pandas as pd\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u6b21\u306b\u3001\u5831\u916c\u884c\u5217\u3092\u30ea\u30b9\u30c8\u306e\u30ea\u30b9\u30c8\u3068\u3057\u3066\u5b9a\u7fa9\u3057\u307e\u3059\u3002\u3053\u3053\u3067\u3001\u5404\u5185\u90e8\u30ea\u30b9\u30c8\u306f\u3001\u30d7\u30ec\u30a4\u30e4\u30fcA\u3068\u30d7\u30ec\u30a4\u30e4\u30fcB\u306e\u5831\u916c\u3092\u8868\u3057\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>payoff_matrix = [\r\n[\"2 or 2\", \"10 or 0\"],\r\n[\"10 or 0\", \"5 or 5\"]\r\n]<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u4eca\u56de\u306f\u9078\u629e\u80a2\u3092\u5206\u304b\u308a\u3084\u3059\u304f\u3059\u308b\u306e\u305f\u3081\u306b\u3001\u5831\u916c\u884c\u5217\u3092Pandas\u306eDataFrame\u3092\u4f7f\u3063\u3066\u8996\u899a\u5316\u3057\u3066\u307f\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>index = ['A\u306e\u9ed9\u79d8', 'A\u306e\u81ea\u767d']\r\ncolumns = ['B\u306e\u9ed9\u79d8', 'B\u306e\u81ea\u767d']\r\ndf = pd.DataFrame(payoff_matrix, index=index, columns=columns)\r\nprint(df)<\/code><\/pre>\r\n<\/div>\r\n<span style=\"font-family: arial, helvetica, sans-serif\"><strong>\u30fb\u51fa\u529b\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/strong><\/span>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>\u3000\u3000 \u3000  B\u306e\u9ed9\u79d8   B\u306e\u81ea\u767d\r\nA\u306e\u9ed9\u79d8  2 or 2  10 or 0\r\nA\u306e\u81ea\u767d 10 or 0   5 or 5<\/code><\/pre>\r\n<\/div>\n\n<h2>\u624b\u98062: \u30ca\u30c3\u30b7\u30e5\u5747\u8861\u306e\u6c42\u3081\u65b9<\/h2>\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u30b2\u30fc\u30e0\u306e\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u304c\u5b8c\u4e86\u3057\u305f\u3089\u3001<span data-token-index=\"1\" class=\"notion-enable-hover\">nashpy<\/span>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305a\u3001\u30d7\u30ec\u30a4\u30e4\u30fcA\u3068\u30d7\u30ec\u30a4\u30e4\u30fcB\u306e\u5831\u916c\u884c\u5217\u3092\u4f7f\u3063\u3066<span data-token-index=\"3\" class=\"notion-enable-hover\">Game<\/span>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>payoffs_a = np.array([[2, 0], [10, 5]]) # \u30d7\u30ec\u30a4\u30e4\u30fcA\u306e\u9078\u629e\u80a2\r\npayoffs_b = np.array([[2, 10], [0, 5]]) # \u30d7\u30ec\u30a4\u30e4\u30fcB\u306e\u9078\u629e\u80a2\r\nprisoners_dilemma = nash.Game(payoffs_a, payoffs_b)\r\nprisoners_dilemma<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\"><code>\u30fbGame<\/code>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001<code>support_enumeration()<\/code>\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u7528\u3057\u3066\u3059\u3079\u3066\u306e\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>equilibria = prisoners_dilemma.support_enumeration()<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u4e0a\u8a18\u3067\u6c42\u3081\u3089\u308c\u305f\u5747\u8861\u3092\u53cd\u5fa9\u51e6\u7406\u3057\u3001\u7d50\u679c\u3092\u51fa\u529b\u3057\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>for eq in equilibria:\r\n    print(equilibrium)<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u51fa\u529b\u7d50\u679c\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/span><\/strong>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>(array([1., 0.]), array([1., 0.]))<\/code><\/pre>\r\n<\/div>\r\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u30fb\u4e0a\u8a18\u306e\u7d50\u679c\u306f\u3001\u30d7\u30ec\u30a4\u30e4\u30fcA\u3068\u30d7\u30ec\u30a4\u30e4\u30fcB\u304c\u3068\u3082\u306b\u300c\u81ea\u767d\u300d\u3092\u9078\u629e\u3057\u305f\u5834\u5408\u304c\u552f\u4e00\u306e\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3067\u3042\u308b\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/strong>\n\n<h2>\u6700\u5f8c\u306b<\/h2>\n<strong><span style=\"font-family: arial, helvetica, sans-serif\">\u4eca\u56de\u306f\u3001<span data-token-index=\"1\" class=\"notion-enable-hover\">nashpy<\/span>\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u30b2\u30fc\u30e0\u306e\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u6c42\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002\u4e0a\u8a18\u306e\u624b\u9806\u306b\u5f93\u3063\u3066\u30b2\u30fc\u30e0\u3092\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\u3059\u308b\u3053\u3068\u3067\u3001\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092\u8a08\u7b97\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u306e\u7406\u89e3\u306f\u3001\u69d8\u3005\u306a\u30b7\u30ca\u30ea\u30aa\u3067\u306e\u6226\u7565\u7684\u610f\u601d\u6c7a\u5b9a\u3092\u5206\u6790\u3057\u3001\u30b2\u30fc\u30e0\u7406\u8ad6\u3068\u305d\u306e\u5b9f\u4e16\u754c\u3078\u306e\u5fdc\u7528\u306b\u3064\u3044\u3066\u30a4\u30f3\u30b5\u30a4\u30c8\u3092\u5f97\u308b\u306e\u306b\u5f79\u7acb\u3061\u307e\u3059\u3002<\/span><\/strong>","protected":false},"excerpt":{"rendered":"<p>Python\u3092\u4f7f\u7528\u3057\u3066\u3001\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u3068\u3057\u3066\u77e5\u3089\u308c\u308b\u30b2\u30fc\u30e0\u7406\u8ad6\u306e\u30b7\u30ca\u30ea\u30aa\u3092\u7c21\u5358\u306b\u5b9f\u88c5\u3059\u308b\u3002 \u306f\u3058\u3081\u306b \u30fb\u672c\u8a18\u4e8b\u3067\u306f\u3001nashpy\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3057\u3066\u3001\u56da\u4eba\u306e\u30b8\u30ec\u30f3\u30de\u3068\u3057\u3066\u77e5\u3089\u308c\u308b\u30b2\u30fc\u30e0\u7406\u8ad6\u306e\u30b7\u30ca\u30ea\u30aa\u306b\u3064\u3044\u3066\u30ca\u30c3\u30b7\u30e5\u5747\u8861\u3092 [&hellip;]<\/p>\n","protected":false},"author":87,"featured_media":3123,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","swell_btn_cv_data":"","footnotes":"","_wp_rev_ctl_limit":""},"categories":[1247],"tags":[465,466,331],"class_list":["post-3567","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business-transformation","tag-gametheory","tag-nashpy","tag-python"],"_links":{"self":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/3567","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/comments?post=3567"}],"version-history":[{"count":0,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/posts\/3567\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media\/3123"}],"wp:attachment":[{"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/media?parent=3567"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/categories?post=3567"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/since2020.jp\/media\/wp-json\/wp\/v2\/tags?post=3567"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}