|
1 | 1 | { |
2 | | - "cells": [ |
3 | | - { |
4 | | - "cell_type": "code", |
5 | | - "execution_count": 5, |
6 | | - "id": "47f4a073", |
7 | | - "metadata": {}, |
8 | | - "outputs": [], |
9 | | - "source": [ |
10 | | - "%reload_ext autoreload\n", |
11 | | - "%autoreload 2" |
12 | | - ] |
13 | | - }, |
14 | | - { |
15 | | - "cell_type": "code", |
16 | | - "execution_count": 6, |
17 | | - "id": "282a714d", |
18 | | - "metadata": {}, |
19 | | - "outputs": [], |
20 | | - "source": [ |
21 | | - "from cereeberus import Interleave, MapperGraph, ReebGraph\n", |
22 | | - "\n", |
23 | | - "import cereeberus.data.ex_reebgraphs as ex_rg\n", |
24 | | - "import cereeberus.data.ex_mappergraphs as ex_mg" |
25 | | - ] |
26 | | - }, |
27 | | - { |
28 | | - "cell_type": "markdown", |
29 | | - "id": "e191f088", |
30 | | - "metadata": {}, |
31 | | - "source": [ |
32 | | - "# Create torus and line mappers of mismatched heights" |
33 | | - ] |
34 | | - }, |
35 | | - { |
36 | | - "cell_type": "markdown", |
37 | | - "id": "d1a6c618", |
38 | | - "metadata": {}, |
39 | | - "source": [ |
40 | | - "### It works when the differnce is 1" |
41 | | - ] |
42 | | - }, |
43 | | - { |
44 | | - "cell_type": "code", |
45 | | - "execution_count": 7, |
46 | | - "id": "6c6b8ae9", |
47 | | - "metadata": {}, |
48 | | - "outputs": [ |
| 2 | + "cells": [ |
49 | 3 | { |
50 | | - "name": "stdout", |
51 | | - "output_type": "stream", |
52 | | - "text": [ |
53 | | - "Interleaving distance: 3\n", |
54 | | - "Interleaving distance (with dist_fit): 3\n" |
55 | | - ] |
56 | | - } |
57 | | - ], |
58 | | - "source": [ |
59 | | - "line = ex_mg.line(a=0, b= 16)\n", |
60 | | - "torus = ex_mg.torus(a=0, b =2, c = 13, d = 17)\n", |
61 | | - "myInt = Interleave(torus, line)\n", |
62 | | - "result = myInt.fit()\n", |
63 | | - "dist_result = myInt.dist_fit() # dist_fit function optimizes with the distance matrix\n", |
64 | | - "print(f\"Interleaving distance: {result}\")\n", |
65 | | - "print(f\"Interleaving distance (with dist_fit): {dist_result}\")" |
66 | | - ] |
67 | | - }, |
68 | | - { |
69 | | - "cell_type": "markdown", |
70 | | - "id": "30459cf0", |
71 | | - "metadata": {}, |
72 | | - "source": [ |
73 | | - "### But fails when the difference is more than 1" |
74 | | - ] |
75 | | - }, |
76 | | - { |
77 | | - "cell_type": "code", |
78 | | - "execution_count": 9, |
79 | | - "id": "ee3dea41", |
80 | | - "metadata": {}, |
81 | | - "outputs": [ |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "47f4a073", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "%reload_ext autoreload\n", |
| 11 | + "%autoreload 2" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": null, |
| 17 | + "id": "282a714d", |
| 18 | + "metadata": {}, |
| 19 | + "outputs": [], |
| 20 | + "source": [ |
| 21 | + "from cereeberus import Interleave, MapperGraph, ReebGraph\n", |
| 22 | + "\n", |
| 23 | + "import cereeberus.data.ex_reebgraphs as ex_rg\n", |
| 24 | + "import cereeberus.data.ex_mappergraphs as ex_mg" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "id": "e191f088", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "# Create torus and line mappers of mismatched heights" |
| 33 | + ] |
| 34 | + }, |
82 | 35 | { |
83 | | - "ename": "KeyError", |
84 | | - "evalue": "17", |
85 | | - "output_type": "error", |
86 | | - "traceback": [ |
87 | | - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
88 | | - "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", |
89 | | - "Cell \u001b[0;32mIn[9], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m torus \u001b[38;5;241m=\u001b[39m ex_mg\u001b[38;5;241m.\u001b[39mtorus(a\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0\u001b[39m, b \u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m, c \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m13\u001b[39m, d \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m18\u001b[39m)\n\u001b[1;32m 3\u001b[0m myInt \u001b[38;5;241m=\u001b[39m Interleave(torus, line)\n\u001b[0;32m----> 4\u001b[0m result \u001b[38;5;241m=\u001b[39m \u001b[43mmyInt\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfit\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 5\u001b[0m dist_result \u001b[38;5;241m=\u001b[39m myInt\u001b[38;5;241m.\u001b[39mdist_fit() \u001b[38;5;66;03m# dist_fit function optimizes with the distance matrix\u001b[39;00m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterleaving distance: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mresult\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", |
90 | | - "File \u001b[0;32m~/Library/CloudStorage/OneDrive-MichiganStateUniversity/Documents/Research/Projects/Interleaving_to_ML/ceREEBerus/cereeberus/cereeberus/distance/interleave.py:66\u001b[0m, in \u001b[0;36mInterleave.fit\u001b[0;34m(self, pulp_solver, verbose, max_n_for_error)\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m min_n \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m checked_results:\n\u001b[1;32m 65\u001b[0m myAssgn \u001b[38;5;241m=\u001b[39m Assignment(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mF, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mG, n\u001b[38;5;241m=\u001b[39mmin_n)\n\u001b[0;32m---> 66\u001b[0m prob_status \u001b[38;5;241m=\u001b[39m \u001b[43mmyAssgn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptimize\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpulp_solver\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpulp_solver\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 68\u001b[0m checked_results[min_n] \u001b[38;5;241m=\u001b[39m (prob_status, myAssgn)\n\u001b[1;32m 70\u001b[0m prob_status, myAssgn \u001b[38;5;241m=\u001b[39m checked_results[min_n]\n", |
91 | | - "File \u001b[0;32m~/Library/CloudStorage/OneDrive-MichiganStateUniversity/Documents/Research/Projects/Interleaving_to_ML/ceREEBerus/cereeberus/cereeberus/distance/interleave.py:1816\u001b[0m, in \u001b[0;36mAssignment.optimize\u001b[0;34m(self, pulp_solver)\u001b[0m\n\u001b[1;32m 1804\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21moptimize\u001b[39m(\u001b[38;5;28mself\u001b[39m, pulp_solver \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m 1805\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Uses the ILP to find the best interleaving distance bound, returns the loss value found. Further, it stores the optimal phi and psi maps which can be returned using the ``self.phi`` and ``self.psi`` attributes respectively.\u001b[39;00m\n\u001b[1;32m 1806\u001b[0m \u001b[38;5;124;03m This function requires the `pulp` package to be installed.\u001b[39;00m\n\u001b[1;32m 1807\u001b[0m \u001b[38;5;124;03m \u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1813\u001b[0m \u001b[38;5;124;03m \u001b[39;00m\n\u001b[1;32m 1814\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m-> 1816\u001b[0m map_dict, prob_status \u001b[38;5;241m=\u001b[39m \u001b[43msolve_ilp\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpulp_solver\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mpulp_solver\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1818\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m prob_status \u001b[38;5;241m!=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mOptimal\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 1819\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n", |
92 | | - "File \u001b[0;32m~/Library/CloudStorage/OneDrive-MichiganStateUniversity/Documents/Research/Projects/Interleaving_to_ML/ceREEBerus/cereeberus/cereeberus/distance/ilp.py:169\u001b[0m, in \u001b[0;36msolve_ilp\u001b[0;34m(myAssgn, pulp_solver, verbose)\u001b[0m\n\u001b[1;32m 167\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m up_or_down \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mup\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;66;03m#NOTE: the change in block indices\u001b[39;00m\n\u001b[1;32m 168\u001b[0m bou_n \u001b[38;5;241m=\u001b[39m myAssgn\u001b[38;5;241m.\u001b[39mB_up(other_map, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mn\u001b[39m\u001b[38;5;124m'\u001b[39m)[block]\u001b[38;5;241m.\u001b[39mget_array()\n\u001b[0;32m--> 169\u001b[0m bou_0 \u001b[38;5;241m=\u001b[39m \u001b[43mmyAssgn\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mB_up\u001b[49m\u001b[43m(\u001b[49m\u001b[43mstarting_map\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m0\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m[\u001b[49m\u001b[43mblock\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241m.\u001b[39mget_array()\n\u001b[1;32m 170\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m starting_map \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mF\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m 171\u001b[0m map_V \u001b[38;5;241m=\u001b[39m myAssgn\u001b[38;5;241m.\u001b[39mphi(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mV\u001b[39m\u001b[38;5;124m'\u001b[39m)[block\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m1\u001b[39m]\u001b[38;5;241m.\u001b[39mget_array()\n", |
93 | | - "File \u001b[0;32m~/Library/CloudStorage/OneDrive-MichiganStateUniversity/Documents/Research/Projects/Interleaving_to_ML/ceREEBerus/cereeberus/cereeberus/distance/labeled_blocks.py:539\u001b[0m, in \u001b[0;36mLabeledBlockMatrix.__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 529\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__getitem__\u001b[39m(\u001b[38;5;28mself\u001b[39m, key):\n\u001b[1;32m 530\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 531\u001b[0m \u001b[38;5;124;03m Get the i'th block matrix.\u001b[39;00m\n\u001b[1;32m 532\u001b[0m \n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 537\u001b[0m \u001b[38;5;124;03m The item from the block matrix.\u001b[39;00m\n\u001b[1;32m 538\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 539\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mblocks\u001b[49m\u001b[43m[\u001b[49m\u001b[43mkey\u001b[49m\u001b[43m]\u001b[49m\n", |
94 | | - "\u001b[0;31mKeyError\u001b[0m: 17" |
95 | | - ] |
| 36 | + "cell_type": "markdown", |
| 37 | + "id": "d1a6c618", |
| 38 | + "metadata": {}, |
| 39 | + "source": [ |
| 40 | + "### It works when the difference is 1" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": null, |
| 46 | + "id": "6c6b8ae9", |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [], |
| 49 | + "source": [ |
| 50 | + "line = ex_mg.line(a=0, b= 16)\n", |
| 51 | + "torus = ex_mg.torus(a=0, b =2, c = 13, d = 17)\n", |
| 52 | + "myInt = Interleave(torus, line)\n", |
| 53 | + "result = myInt.fit()\n", |
| 54 | + "dist_result = myInt.dist_fit() # dist_fit function optimizes with the distance matrix\n", |
| 55 | + "print(f\"Interleaving distance: {result}\")\n", |
| 56 | + "print(f\"Interleaving distance (with dist_fit): {dist_result}\")" |
| 57 | + ] |
| 58 | + }, |
| 59 | + { |
| 60 | + "cell_type": "markdown", |
| 61 | + "id": "30459cf0", |
| 62 | + "metadata": {}, |
| 63 | + "source": [ |
| 64 | + "### But fails when the difference is more than 1" |
| 65 | + ] |
| 66 | + }, |
| 67 | + { |
| 68 | + "cell_type": "code", |
| 69 | + "execution_count": null, |
| 70 | + "id": "ee3dea41", |
| 71 | + "metadata": {}, |
| 72 | + "outputs": [], |
| 73 | + "source": [ |
| 74 | + "line = ex_mg.line(a =0, b= 16)\n", |
| 75 | + "torus = ex_mg.torus(a=0, b =2, c = 13, d = 18)\n", |
| 76 | + "myInt = Interleave(torus, line)\n", |
| 77 | + "result = myInt.fit()\n", |
| 78 | + "dist_result = myInt.dist_fit() # dist_fit function optimizes with the distance matrix\n", |
| 79 | + "print(f\"Interleaving distance: {result}\")\n", |
| 80 | + "print(f\"Interleaving distance (with dist_fit): {dist_result}\")" |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "id": "b442c31a", |
| 86 | + "metadata": {}, |
| 87 | + "source": [ |
| 88 | + "I checked the code and I think the problem is in the boundary matrix computation. Which affects the edge-vertex parallelogram checks. Tried fixing, but haven't figured it out yet." |
| 89 | + ] |
| 90 | + }, |
| 91 | + { |
| 92 | + "cell_type": "markdown", |
| 93 | + "id": "c17be785", |
| 94 | + "metadata": {}, |
| 95 | + "source": [] |
| 96 | + } |
| 97 | + ], |
| 98 | + "metadata": { |
| 99 | + "kernelspec": { |
| 100 | + "display_name": "interleavingenv", |
| 101 | + "language": "python", |
| 102 | + "name": "python3" |
| 103 | + }, |
| 104 | + "language_info": { |
| 105 | + "codemirror_mode": { |
| 106 | + "name": "ipython", |
| 107 | + "version": 3 |
| 108 | + }, |
| 109 | + "file_extension": ".py", |
| 110 | + "mimetype": "text/x-python", |
| 111 | + "name": "python", |
| 112 | + "nbconvert_exporter": "python", |
| 113 | + "pygments_lexer": "ipython3", |
| 114 | + "version": "3.12.3" |
96 | 115 | } |
97 | | - ], |
98 | | - "source": [ |
99 | | - "line = ex_mg.line(a =0, b= 16)\n", |
100 | | - "torus = ex_mg.torus(a=0, b =2, c = 13, d = 18)\n", |
101 | | - "myInt = Interleave(torus, line)\n", |
102 | | - "result = myInt.fit()\n", |
103 | | - "dist_result = myInt.dist_fit() # dist_fit function optimizes with the distance matrix\n", |
104 | | - "print(f\"Interleaving distance: {result}\")\n", |
105 | | - "print(f\"Interleaving distance (with dist_fit): {dist_result}\")" |
106 | | - ] |
107 | | - }, |
108 | | - { |
109 | | - "cell_type": "markdown", |
110 | | - "id": "b442c31a", |
111 | | - "metadata": {}, |
112 | | - "source": [ |
113 | | - "I checked the code and I think the problem is in the boundary matrix computation. Which affects the edge-vertex parallelogram checks. Tried fixing, but haven't figured it out yet." |
114 | | - ] |
115 | | - }, |
116 | | - { |
117 | | - "cell_type": "markdown", |
118 | | - "id": "c17be785", |
119 | | - "metadata": {}, |
120 | | - "source": [] |
121 | | - } |
122 | | - ], |
123 | | - "metadata": { |
124 | | - "kernelspec": { |
125 | | - "display_name": "interleavingenv", |
126 | | - "language": "python", |
127 | | - "name": "python3" |
128 | 116 | }, |
129 | | - "language_info": { |
130 | | - "codemirror_mode": { |
131 | | - "name": "ipython", |
132 | | - "version": 3 |
133 | | - }, |
134 | | - "file_extension": ".py", |
135 | | - "mimetype": "text/x-python", |
136 | | - "name": "python", |
137 | | - "nbconvert_exporter": "python", |
138 | | - "pygments_lexer": "ipython3", |
139 | | - "version": "3.12.3" |
140 | | - } |
141 | | - }, |
142 | | - "nbformat": 4, |
143 | | - "nbformat_minor": 5 |
| 117 | + "nbformat": 4, |
| 118 | + "nbformat_minor": 5 |
144 | 119 | } |
0 commit comments