diff --git a/game_theory/03-lab-non_antoganistic/bimatrix.ipynb b/game_theory/03-lab-non_antoganistic/bimatrix.ipynb index e87f157..8209fd1 100644 --- a/game_theory/03-lab-non_antoganistic/bimatrix.ipynb +++ b/game_theory/03-lab-non_antoganistic/bimatrix.ipynb @@ -23,13 +23,15 @@ }, { "cell_type": "code", + "execution_count": 1, "id": "initial_id", "metadata": { "ExecuteTime": { - "end_time": "2024-04-09T14:50:09.019231Z", - "start_time": "2024-04-09T14:50:08.826810Z" + "end_time": "2024-04-09T16:55:01.568295Z", + "start_time": "2024-04-09T16:55:01.276303Z" } }, + "outputs": [], "source": [ "import logging\n", "\n", @@ -38,9 +40,7 @@ "from game_theory.utils.bimatrix_games.bimatrix import BimatrixGame\n", "\n", "logging.basicConfig(level=logging.INFO, format='%(message)s')" - ], - "outputs": [], - "execution_count": 1 + ] }, { "cell_type": "markdown", @@ -70,52 +70,52 @@ }, { "cell_type": "code", + "execution_count": 2, "id": "60984a19fe976b9c", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:27.387821Z", + "start_time": "2024-04-09T16:55:27.376688Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:17.023790Z", - "start_time": "2024-04-09T14:50:17.013528Z" } }, - "source": [ - "bimatrix_game = BimatrixGame.from_random_values((10, 10), low=-10, high=10)\n", - "bimatrix_game" - ], "outputs": [ { "data": { "text/plain": [ - "\u001B[3m\u001B[1mЖирным курсивом\u001B[0m\u001B[0m выделены ситуации, оптимальные по Парето.\n", - "\u001B[4mПодчеркнутым\u001B[0m - ситуации, равновесные по Нэшу.\n", - "+----------------------------------------------------------------------------------------------------------------+\n", - "| Случайная биматричная игры размера 10x10 |\n", - "+----------+----------+----------+----------+-----------+-----------+----------+----------+-----------+----------+\n", - "| (-4, 4) | (4, -9) | (8, 1) | \u001B[4m\u001B[3m\u001B[1m(10, 10)\u001B[0m\u001B[0m\u001B[0m | (-9, 3) | (9, -6) | (-2, 8) | (-10, 3) | (-10, -4) | (-1, 2) |\n", - "| (6, 8) | (3, 10) | (-3, 9) | (8, 4) | (-6, 10) | (8, 9) | (4, -8) | (-9, 7) | (10, 4) | (-2, 6) |\n", - "| (4, -9) | (7, -2) | (8, 0) | (6, -10) | (-10, -3) | (-9, -10) | (-1, -3) | (0, -6) | (1, 5) | \u001B[4m(10, 9)\u001B[0m |\n", - "| (2, -9) | (4, -3) | (-1, 7) | (-5, 8) | (1, 0) | (1, 7) | (3, 5) | (-2, 5) | (2, 4) | (-5, -2) |\n", - "| \u001B[4m(9, 9)\u001B[0m | (-4, -5) | (5, 2) | (-5, 6) | (-4, -7) | (-8, -9) | (4, -9) | (-10, 7) | (2, 2) | (9, -10) |\n", - "| (-7, 7) | (5, -2) | (-1, -8) | (7, -8) | (5, -8) | (5, 2) | (9, 2) | (9, 9) | (-7, 3) | (-9, -4) |\n", - "| (-8, 4) | (9, -1) | (3, 3) | (-7, -6) | (3, 2) | (7, -10) | (9, 2) | (-8, 6) | (-10, 4) | (-6, 5) |\n", - "| (5, 8) | (4, 8) | (8, 1) | (-5, -5) | (2, 4) | (-9, -2) | (1, -2) | (-4, 0) | (-3, 9) | (8, 0) |\n", - "| (0, 10) | (-5, 9) | (8, -4) | (5, -6) | (0, -5) | (8, 0) | (-8, 1) | (10, 0) | (-1, -6) | (-10, 6) |\n", - "| (-2, -6) | (-1, 6) | (5, -4) | (6, 3) | (-8, -5) | (-2, -6) | (-5, -8) | (7, 1) | (7, -7) | (3, 7) |\n", - "+----------+----------+----------+----------+-----------+-----------+----------+----------+-----------+----------+\n", + "\u001b[3m\u001b[1mЖирным курсивом\u001b[0m\u001b[0m выделены ситуации, оптимальные по Парето.\n", + "\u001b[4mПодчеркнутым\u001b[0m - ситуации, равновесные по Нэшу.\n", + "+--------------------------------------------------------------------------------------------------------------------------------+\n", + "| Случайная биматричная игры размера 10x10 |\n", + "+-----------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n", + "| (68, -8) | (-11, -10) | (-25, -69) | (-1, -46) | (-77, -3) | (42, 50) | (76, 37) | (84, 20) | (-41, 95) | (-5, -53) |\n", + "| (91, 11) | (44, 78) | (27, 25) | (-2, -38) | (-23, -36) | (34, -10) | (-35, -31) | (-94, -72) | (97, -77) | (-49, 77) |\n", + "| (-80, 32) | (67, -54) | (-95, 98) | (-71, 50) | (-13, 98) | \u001b[3m\u001b[1m(68, 99)\u001b[0m\u001b[0m | (37, -59) | (-33, -91) | (27, -57) | (-48, -38) |\n", + "| (22, -3) | (-12, -24) | (-83, -23) | (63, 86) | (89, -82) | (23, 3) | (73, -75) | (-83, -97) | (1, -6) | (42, 84) |\n", + "| (89, 40) | (-12, 92) | (-49, 72) | (21, 96) | (4, 88) | (-35, 71) | (-97, 34) | (75, 25) | (2, 79) | (-87, 39) |\n", + "| \u001b[4m\u001b[3m\u001b[1m(97, 54)\u001b[0m\u001b[0m\u001b[0m | (44, 29) | (-47, 7) | (-19, 34) | (-55, 26) | (6, -40) | (-33, 48) | (56, -65) | (65, -88) | (95, 41) |\n", + "| \u001b[3m\u001b[1m(88, 60)\u001b[0m\u001b[0m | (-62, 57) | (-67, 30) | (73, -59) | (-33, 88) | (92, -37) | (-25, -46) | (10, -49) | (-90, -73) | (-72, 29) |\n", + "| (75, -16) | (-25, 83) | (-69, -4) | (-1, -98) | (3, -100) | (-47, 19) | (5, -61) | (54, -48) | (-41, -2) | (63, 31) |\n", + "| (-96, 10) | (-16, 54) | (43, 78) | (-33, 50) | (11, 22) | (-24, -23) | (-48, 35) | (-5, -96) | (86, -58) | (55, 49) |\n", + "| (30, 18) | (97, -19) | (55, -53) | (-92, -12) | (38, 48) | (96, -13) | (-96, 78) | (25, 55) | (76, -38) | (81, 57) |\n", + "+-----------+------------+------------+------------+------------+------------+------------+------------+------------+------------+\n", "\n", - "Равновесие Нэша: [(9.0, 9.0), (10.0, 9.0), (10.0, 10.0)]\n", - "Оптимальность Парето: [(10.0, 10.0)]" + "Равновесие Нэша: [(97.0, 54.0)]\n", + "Оптимальность Парето: [(68.0, 99.0), (97.0, 54.0), (88.0, 60.0)]" ] }, - "execution_count": 14, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 14 + "source": [ + "bimatrix_game = BimatrixGame.from_random_values()\n", + "bimatrix_game" + ] }, { "cell_type": "markdown", @@ -132,69 +132,69 @@ }, { "cell_type": "code", + "execution_count": 3, "id": "1dd45437c5b26af5", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.590533Z", + "start_time": "2024-04-09T16:55:01.587710Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:20.826543Z", - "start_time": "2024-04-09T14:50:20.822704Z" } }, + "outputs": [], "source": [ "bimatrix = np.array([\n", " [(4, 1), (0, 0)],\n", " [(0, 0), (1, 4)],\n", "])" - ], - "outputs": [], - "execution_count": 15 + ] }, { "cell_type": "code", + "execution_count": 4, "id": "ddcc2e1a97220ec8", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.598367Z", + "start_time": "2024-04-09T16:55:01.593720Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:20.982610Z", - "start_time": "2024-04-09T14:50:20.977681Z" } }, - "source": [ - "bimatrix_game = BimatrixGame(\n", - " bimatrix=bimatrix,\n", - " title='Игра \"Семейный спор\" (\"Battle of Sexes\")',\n", - ")\n", - "bimatrix_game" - ], "outputs": [ { "data": { "text/plain": [ - "\u001B[3m\u001B[1mЖирным курсивом\u001B[0m\u001B[0m выделены ситуации, оптимальные по Парето.\n", - "\u001B[4mПодчеркнутым\u001B[0m - ситуации, равновесные по Нэшу.\n", + "\u001b[3m\u001b[1mЖирным курсивом\u001b[0m\u001b[0m выделены ситуации, оптимальные по Парето.\n", + "\u001b[4mПодчеркнутым\u001b[0m - ситуации, равновесные по Нэшу.\n", "+------------------------------------------+\n", "| Игра \"Семейный спор\" (\"Battle of Sexes\") |\n", "+--------------------+---------------------+\n", - "| \u001B[4m\u001B[3m\u001B[1m(4, 1)\u001B[0m\u001B[0m\u001B[0m | (0, 0) |\n", - "| (0, 0) | \u001B[4m\u001B[3m\u001B[1m(1, 4)\u001B[0m\u001B[0m\u001B[0m |\n", + "| \u001b[4m\u001b[3m\u001b[1m(4, 1)\u001b[0m\u001b[0m\u001b[0m | (0, 0) |\n", + "| (0, 0) | \u001b[4m\u001b[3m\u001b[1m(1, 4)\u001b[0m\u001b[0m\u001b[0m |\n", "+--------------------+---------------------+\n", "\n", "Равновесие Нэша: [(1.0, 4.0), (4.0, 1.0)]\n", "Оптимальность Парето: [(1.0, 4.0), (4.0, 1.0)]" ] }, - "execution_count": 16, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 16 + "source": [ + "bimatrix_game = BimatrixGame(\n", + " bimatrix=bimatrix,\n", + " title='Игра \"Семейный спор\" (\"Battle of Sexes\")',\n", + ")\n", + "bimatrix_game" + ] }, { "cell_type": "markdown", @@ -211,70 +211,70 @@ }, { "cell_type": "code", + "execution_count": 5, "id": "5337157dc1a4e873", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.603578Z", + "start_time": "2024-04-09T16:55:01.599769Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:21.488327Z", - "start_time": "2024-04-09T14:50:21.485583Z" } }, + "outputs": [], "source": [ "shift_1, shift_2 = round(np.random.random(), 3), round(np.random.random(), 3)\n", "bimatrix = np.array([\n", " [(1, 1), (1 - shift_1, 2)],\n", " [(2, 1 - shift_2), (0, 0)],\n", "])" - ], - "outputs": [], - "execution_count": 17 + ] }, { "cell_type": "code", + "execution_count": 6, "id": "562dccd54b14bb45", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.610188Z", + "start_time": "2024-04-09T16:55:01.605558Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:22.046733Z", - "start_time": "2024-04-09T14:50:22.042178Z" } }, - "source": [ - "bimatrix_game = BimatrixGame(\n", - " bimatrix=bimatrix,\n", - " title='Игра \"Перекрёсток\" (\"Crossroad\")',\n", - ")\n", - "bimatrix_game" - ], "outputs": [ { "data": { "text/plain": [ - "\u001B[3m\u001B[1mЖирным курсивом\u001B[0m\u001B[0m выделены ситуации, оптимальные по Парето.\n", - "\u001B[4mПодчеркнутым\u001B[0m - ситуации, равновесные по Нэшу.\n", + "\u001b[3m\u001b[1mЖирным курсивом\u001b[0m\u001b[0m выделены ситуации, оптимальные по Парето.\n", + "\u001b[4mПодчеркнутым\u001b[0m - ситуации, равновесные по Нэшу.\n", "+----------------------------------+\n", "| Игра \"Перекрёсток\" (\"Crossroad\") |\n", - "+---------------+------------------+\n", - "| \u001B[3m\u001B[1m(1.0, 1.0)\u001B[0m\u001B[0m | \u001B[4m\u001B[3m\u001B[1m(0.957, 2.0)\u001B[0m\u001B[0m\u001B[0m |\n", - "| \u001B[4m\u001B[3m\u001B[1m(2.0, 0.38)\u001B[0m\u001B[0m\u001B[0m | (0.0, 0.0) |\n", - "+---------------+------------------+\n", + "+----------------+-----------------+\n", + "| \u001b[3m\u001b[1m(1.0, 1.0)\u001b[0m\u001b[0m | \u001b[4m\u001b[3m\u001b[1m(0.968, 2.0)\u001b[0m\u001b[0m\u001b[0m |\n", + "| \u001b[4m\u001b[3m\u001b[1m(2.0, 0.374)\u001b[0m\u001b[0m\u001b[0m | (0.0, 0.0) |\n", + "+----------------+-----------------+\n", "\n", - "Равновесие Нэша: [(0.957, 2.0), (2.0, 0.38)]\n", - "Оптимальность Парето: [(0.957, 2.0), (2.0, 0.38), (1.0, 1.0)]" + "Равновесие Нэша: [(0.968, 2.0), (2.0, 0.374)]\n", + "Оптимальность Парето: [(0.968, 2.0), (2.0, 0.374), (1.0, 1.0)]" ] }, - "execution_count": 18, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 18 + "source": [ + "bimatrix_game = BimatrixGame(\n", + " bimatrix=bimatrix,\n", + " title='Игра \"Перекрёсток\" (\"Crossroad\")',\n", + ")\n", + "bimatrix_game" + ] }, { "cell_type": "markdown", @@ -291,69 +291,69 @@ }, { "cell_type": "code", + "execution_count": 7, "id": "6eb4549951528038", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.614077Z", + "start_time": "2024-04-09T16:55:01.611361Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:23.128174Z", - "start_time": "2024-04-09T14:50:23.123951Z" } }, + "outputs": [], "source": [ "bimatrix = np.array([\n", " [(-5, -5), (0, -10)],\n", " [(-10, 0), (-1, -1)],\n", "])" - ], - "outputs": [], - "execution_count": 19 + ] }, { "cell_type": "code", + "execution_count": 8, "id": "59b6561f1cc45f9a", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.621760Z", + "start_time": "2024-04-09T16:55:01.615103Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:23.449467Z", - "start_time": "2024-04-09T14:50:23.444922Z" } }, - "source": [ - "bimatrix_game = BimatrixGame(\n", - " bimatrix=bimatrix,\n", - " title=\"\"\"Игра \"Дилемма заключённого\" (\"Prisoner's dilemma\")\"\"\",\n", - ")\n", - "bimatrix_game" - ], "outputs": [ { "data": { "text/plain": [ - "\u001B[3m\u001B[1mЖирным курсивом\u001B[0m\u001B[0m выделены ситуации, оптимальные по Парето.\n", - "\u001B[4mПодчеркнутым\u001B[0m - ситуации, равновесные по Нэшу.\n", + "\u001b[3m\u001b[1mЖирным курсивом\u001b[0m\u001b[0m выделены ситуации, оптимальные по Парето.\n", + "\u001b[4mПодчеркнутым\u001b[0m - ситуации, равновесные по Нэшу.\n", "+----------------------------------------------------+\n", "| Игра \"Дилемма заключённого\" (\"Prisoner's dilemma\") |\n", "+-------------------------+--------------------------+\n", - "| \u001B[4m(-5, -5)\u001B[0m | \u001B[3m\u001B[1m(0, -10)\u001B[0m\u001B[0m |\n", - "| \u001B[3m\u001B[1m(-10, 0)\u001B[0m\u001B[0m | \u001B[3m\u001B[1m(-1, -1)\u001B[0m\u001B[0m |\n", + "| \u001b[4m(-5, -5)\u001b[0m | \u001b[3m\u001b[1m(0, -10)\u001b[0m\u001b[0m |\n", + "| \u001b[3m\u001b[1m(-10, 0)\u001b[0m\u001b[0m | \u001b[3m\u001b[1m(-1, -1)\u001b[0m\u001b[0m |\n", "+-------------------------+--------------------------+\n", "\n", "Равновесие Нэша: [(-5.0, -5.0)]\n", "Оптимальность Парето: [(0.0, -10.0), (-10.0, 0.0), (-1.0, -1.0)]" ] }, - "execution_count": 20, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 20 + "source": [ + "bimatrix_game = BimatrixGame(\n", + " bimatrix=bimatrix,\n", + " title=\"\"\"Игра \"Дилемма заключённого\" (\"Prisoner's dilemma\")\"\"\",\n", + ")\n", + "bimatrix_game" + ] }, { "cell_type": "markdown", @@ -370,82 +370,80 @@ }, { "cell_type": "code", + "execution_count": 9, "id": "e085541bc08521b6", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.625527Z", + "start_time": "2024-04-09T16:55:01.622952Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:24.550039Z", - "start_time": "2024-04-09T14:50:24.542934Z" } }, + "outputs": [], "source": [ "bimatrix = np.array([\n", " [(5, 0), (8, 4)],\n", " [(7, 6), (6, 3)],\n", "])" - ], - "outputs": [], - "execution_count": 21 + ] }, { "cell_type": "code", + "execution_count": 10, "id": "efe4c661e3fbd8d8", "metadata": { + "ExecuteTime": { + "end_time": "2024-04-09T16:55:01.633880Z", + "start_time": "2024-04-09T16:55:01.629755Z" + }, "collapsed": false, "jupyter": { "outputs_hidden": false - }, - "ExecuteTime": { - "end_time": "2024-04-09T14:50:25.298862Z", - "start_time": "2024-04-09T14:50:25.288562Z" } }, - "source": [ - "bimatrix_game = BimatrixGame(\n", - " bimatrix=bimatrix,\n", - " title=\"Биматричная игра по варианту 1\",\n", - ")\n", - "bimatrix_game" - ], "outputs": [ { "data": { "text/plain": [ - "\u001B[3m\u001B[1mЖирным курсивом\u001B[0m\u001B[0m выделены ситуации, оптимальные по Парето.\n", - "\u001B[4mПодчеркнутым\u001B[0m - ситуации, равновесные по Нэшу.\n", + "\u001b[3m\u001b[1mЖирным курсивом\u001b[0m\u001b[0m выделены ситуации, оптимальные по Парето.\n", + "\u001b[4mПодчеркнутым\u001b[0m - ситуации, равновесные по Нэшу.\n", "+--------------------------------+\n", "| Биматричная игра по варианту 1 |\n", "+---------------+----------------+\n", - "| (5, 0) | \u001B[4m\u001B[3m\u001B[1m(8, 4)\u001B[0m\u001B[0m\u001B[0m |\n", - "| \u001B[4m\u001B[3m\u001B[1m(7, 6)\u001B[0m\u001B[0m\u001B[0m | (6, 3) |\n", + "| (5, 0) | \u001b[4m\u001b[3m\u001b[1m(8, 4)\u001b[0m\u001b[0m\u001b[0m |\n", + "| \u001b[4m\u001b[3m\u001b[1m(7, 6)\u001b[0m\u001b[0m\u001b[0m | (6, 3) |\n", "+---------------+----------------+\n", "\n", "Равновесие Нэша: [(8.0, 4.0), (7.0, 6.0)]\n", "Оптимальность Парето: [(8.0, 4.0), (7.0, 6.0)]" ] }, - "execution_count": 22, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 22 + "source": [ + "bimatrix_game = BimatrixGame(\n", + " bimatrix=bimatrix,\n", + " title=\"Биматричная игра по варианту 1\",\n", + ")\n", + "bimatrix_game" + ] }, { "cell_type": "code", + "execution_count": 11, "id": "c7d45f69644d9781", "metadata": { "ExecuteTime": { - "end_time": "2024-04-09T14:50:26.079443Z", - "start_time": "2024-04-09T14:50:26.069921Z" + "end_time": "2024-04-09T16:55:01.639913Z", + "start_time": "2024-04-09T16:55:01.635224Z" } }, - "source": [ - "_, _ = bimatrix_game.get_mixed_balanced_situation()" - ], "outputs": [ { "name": "stderr", @@ -457,7 +455,9 @@ ] } ], - "execution_count": 23 + "source": [ + "_, _ = bimatrix_game.get_mixed_balanced_situation()" + ] } ], "metadata": {