Skip to content

Commit

Permalink
update function name
Browse files Browse the repository at this point in the history
  • Loading branch information
heyjianjing authored Dec 19, 2024
1 parent d32f9c6 commit 9978441
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions cvx_09_barrier_interior_point_method.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 143,7 @@
"height": 457
},
"id": "MdfDfS81Y64l",
"outputId": "27e37b3b-fc4f-40e2-c26c-4da6873be64f"
"outputId": "99b9a5a0-4d55-4b5f-b3da-0d285dd90345"
},
"execution_count": null,
"outputs": [
Expand Down Expand Up @@ -434,7 434,7 @@
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "c4e2fe3d-026a-46f1-cd12-29de5a50e798"
"outputId": "75cbbfa0-924c-4f5f-acce-6f8ef80cdf7d"
},
"execution_count": null,
"outputs": [
Expand Down Expand Up @@ -470,15 470,15 @@
"base_uri": "https://localhost:8080/"
},
"id": "yYg5e3_PRc_D",
"outputId": "f958a129-dd8f-444b-bc3e-1877444b4772"
"outputId": "14aa7878-a381-40fc-d573-63f412d81c7c"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Time taken: 11.912322998046875\n",
"Time taken: 13.673829317092896\n",
"Optimal objective value (CVXPY): -356.2157974048377\n",
"Feasibility (CVXPY): False\n"
]
Expand Down Expand Up @@ -544,7 544,7 @@
{
"cell_type": "code",
"source": [
"def int_pt_lp_ieq(A, b, c, x0, mu, tol, np_solver=False):\n",
"def ipm_lp_ieq(A, b, c, x0, mu, tol, np_solver=False):\n",
" total_iter = 500\n",
" alpha = 0.01\n",
" beta = 0.5\n",
Expand Down Expand Up @@ -632,7 632,7 @@
"data = []\n",
"for mu in muvals:\n",
" start_time = time.time()\n",
" x, iters, gaps = int_pt_lp_ieq(A, b, c, x0, mu, 1e-5, np_solver=True)\n",
" x, iters, gaps = ipm_lp_ieq(A, b, c, x0, mu, 1e-5, np_solver=True)\n",
" print(\"Time taken:\", time.time() - start_time)\n",
" print(f\"Converged c^Tx (with mu={mu})\", c @ x)\n",
" print(\"Primal feasibility inequality\", np.all(A @ x < b))\n",
Expand Down Expand Up @@ -660,27 660,27 @@
"height": 738
},
"id": "Fci2FFojKW0H",
"outputId": "f6bce0da-d3a8-490a-f87a-8b5b77d78132"
"outputId": "c35434ca-3584-497b-8c5e-b507ea72c87e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Time taken: 0.825857400894165\n",
"Time taken: 3.582063674926758\n",
"Converged c^Tx (with mu=2) -356.2155502252572\n",
"Primal feasibility inequality True\n",
"\n",
"Time taken: 0.4883434772491455\n",
"Time taken: 1.431135654449463\n",
"Converged c^Tx (with mu=10) -356.215551205489\n",
"Primal feasibility inequality True\n",
"\n",
"Time taken: 0.4445624351501465\n",
"Time taken: 0.6336369514465332\n",
"Converged c^Tx (with mu=50) -356.215552565489\n",
"Primal feasibility inequality True\n",
"\n",
"Time taken: 0.396073579788208\n",
"Time taken: 0.6889493465423584\n",
"Converged c^Tx (with mu=120) -356.2155522409828\n",
"Primal feasibility inequality True\n",
"\n"
Expand Down Expand Up @@ -767,7 767,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "THcXBx6dnKgN",
"outputId": "9a186f38-8d23-4c6c-f399-cdb495a0023c"
"outputId": "2cbb57eb-ecdf-4012-f727-f1e06a66ca83"
},
"execution_count": null,
"outputs": [
Expand Down Expand Up @@ -807,15 807,15 @@
"base_uri": "https://localhost:8080/"
},
"id": "HN9RysxP-hLQ",
"outputId": "32ac1103-1e3c-44f8-929a-f71a25261041"
"outputId": "c9a728b4-85d4-4676-ebff-392348c2bae1"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Time taken: 0.037413835525512695\n",
"Time taken: 0.05348777770996094\n",
"Optimal objective value (CVXPY): -14.901129108789444\n",
"Feasibility (CVXPY): True\n",
"Non-negativity (CVXPY): False\n"
Expand All @@ -835,7 835,7 @@
{
"cell_type": "code",
"source": [
"def int_pt_lp_eq_ieq(A, b, c, x_0, mu, n_iter=100, np_solver=False):\n",
"def ipm_lp_eq_ieq(A, b, c, x_0, mu, n_iter=100, np_solver=False):\n",
" alpha = 0.01\n",
" beta = 0.5\n",
" tol = 1e-3 # Tolerance for duality gap\n",
Expand Down Expand Up @@ -920,7 920,7 @@
"data = []\n",
"for mu in muvals:\n",
" start_time = time.time()\n",
" x, iters, gaps, x_list = int_pt_lp_eq_ieq(A, b, c, x0, mu, np_solver=False)\n",
" x, iters, gaps, x_list = ipm_lp_eq_ieq(A, b, c, x0, mu, np_solver=False)\n",
" print(\"Time taken:\", time.time() - start_time)\n",
" print(f\"Converged c^Tx (with mu={mu})\", c @ x)\n",
" print(\"Primal feasibility inequality\", np.all(x >= 0))\n",
Expand Down Expand Up @@ -949,30 949,30 @@
"height": 806
},
"id": "lV2DHF5K-I_D",
"outputId": "dc59f271-3cbf-41a1-d699-060f47191f74"
"outputId": "aa3157bb-6703-41ef-b41a-85661e11975e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Time taken: 0.3608250617980957\n",
"Time taken: 0.6347932815551758\n",
"Converged c^Tx (with mu=2) -14.899600106192244\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 1.4198472499847412\n",
"Time taken: 2.723405122756958\n",
"Converged c^Tx (with mu=10) -14.900625682618752\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 1.9167921543121338\n",
"Time taken: 3.033484935760498\n",
"Converged c^Tx (with mu=50) -14.900725576855768\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 3.299870491027832\n",
"Time taken: 3.4300501346588135\n",
"Converged c^Tx (with mu=120) -14.90109655543085\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
Expand Down Expand Up @@ -1109,7 1109,7 @@
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "93cf9f2a-88ac-46c8-eef3-1e39bae950cc"
"outputId": "985df9a1-10fa-40b0-c1bb-61b042fc5353"
},
"execution_count": null,
"outputs": [
Expand All @@ -1133,7 1133,7 @@
{
"cell_type": "code",
"source": [
"_, _, _, z_list = int_pt_lp_eq_ieq(A1, b1, c1, z0, mu=50, n_iter=50, np_solver=False)"
"_, _, _, z_list = ipm_lp_eq_ieq(A1, b1, c1, z0, mu=50, n_iter=50, np_solver=False)"
],
"metadata": {
"id": "2hGba11Fz7Xm"
Expand All @@ -1159,7 1159,7 @@
"base_uri": "https://localhost:8080/"
},
"id": "65sajDM_qIn2",
"outputId": "755f2222-d03d-4f74-d419-16b3585139fa"
"outputId": "62604052-1098-423a-ceed-9d77bec8afcb"
},
"execution_count": null,
"outputs": [
Expand Down Expand Up @@ -1190,7 1190,7 @@
"data = []\n",
"for mu in muvals:\n",
" start_time = time.time()\n",
" x, iters, gaps, x_list = int_pt_lp_eq_ieq(A, b, c, x0, mu, np_solver=False)\n",
" x, iters, gaps, x_list = ipm_lp_eq_ieq(A, b, c, x0, mu, np_solver=False)\n",
" print(\"Time taken:\", time.time() - start_time)\n",
" print(f\"Converged c^Tx (with mu={mu})\", c @ x)\n",
" print(\"Primal feasibility inequality\", np.all(x >= 0))\n",
Expand Down Expand Up @@ -1219,7 1219,7 @@
"height": 842
},
"id": "YqymhC7EqLMV",
"outputId": "1c89aa07-a77c-49da-b7ba-f7c6927fde87"
"outputId": "65fbfeeb-46b4-4a5a-e050-7ee21861011d"
},
"execution_count": null,
"outputs": [
Expand All @@ -1229,22 1229,22 @@
"text": [
"Initial objective value 41.35722626454216\n",
"\n",
"Time taken: 0.3372030258178711\n",
"Time taken: 0.5014801025390625\n",
"Converged c^Tx (with mu=2) -14.89960005095006\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 1.2263190746307373\n",
"Time taken: 1.2994284629821777\n",
"Converged c^Tx (with mu=10) -14.9006257608807\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 0.35614752769470215\n",
"Time taken: 0.3332540988922119\n",
"Converged c^Tx (with mu=50) -14.900725562605299\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Time taken: 2.1362998485565186\n",
"Time taken: 2.116426467895508\n",
"Converged c^Tx (with mu=120) -14.90109695114552\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
Expand Down Expand Up @@ -1332,7 1332,7 @@
{
"cell_type": "code",
"source": [
"def int_pt_lp_eq_ieq_infeasible_start(A, b, c, mu, n_iter=500, np_solver=False):\n",
"def ipm_lp_eq_ieq_infeasible_start(A, b, c, mu, n_iter=500, np_solver=False):\n",
" alpha = 0.01\n",
" beta = 0.3\n",
" tol_norm = 1e-6\n",
Expand Down Expand Up @@ -1429,7 1429,7 @@
"data = []\n",
"for mu in muvals:\n",
" start_time = time.time()\n",
" x, iters, gaps = int_pt_lp_eq_ieq_infeasible_start(A, b, c, mu=mu, np_solver=False)\n",
" x, iters, gaps = ipm_lp_eq_ieq_infeasible_start(A, b, c, mu=mu, np_solver=False)\n",
" print(\"Time taken:\", time.time() - start_time)\n",
" print(f\"Converged c^Tx (with mu={mu})\", c @ x)\n",
" print(\"Primal feasibility inequality\", np.all(x >= 0))\n",
Expand Down Expand Up @@ -1458,7 1458,7 @@
"height": 955
},
"id": "3QVpTY3TgnNE",
"outputId": "89047170-ce2e-47a9-98e0-6a7a7fe399fc"
"outputId": "39c43c07-a7a0-4e27-c260-b032790057fd"
},
"execution_count": null,
"outputs": [
Expand All @@ -1468,28 1468,28 @@
"text": [
"Feasible initial x? False\n",
"Initial objective value 29.846488899047426\n",
"Time taken: 0.4532499313354492\n",
"Time taken: 0.7532291412353516\n",
"Converged c^Tx (with mu=2) -14.90111962565468\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Feasible initial x? False\n",
"Initial objective value 29.846488899047426\n",
"Time taken: 0.22894001007080078\n",
"Time taken: 0.34696054458618164\n",
"Converged c^Tx (with mu=10) -14.901120586118418\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Feasible initial x? False\n",
"Initial objective value 29.846488899047426\n",
"Time taken: 0.1451714038848877\n",
"Time taken: 0.2696413993835449\n",
"Converged c^Tx (with mu=50) -14.90111758612111\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
"\n",
"Feasible initial x? False\n",
"Initial objective value 29.846488899047426\n",
"Time taken: 2.1653923988342285\n",
"Time taken: 2.8580918312072754\n",
"Converged c^Tx (with mu=120) -14.901125344990183\n",
"Primal feasibility inequality True\n",
"Primal feasibility equality True\n",
Expand Down

0 comments on commit 9978441

Please sign in to comment.