{"id":24117091,"url":"https://github.com/cai991108/optimization-and-modeling-utils","last_synced_at":"2026-05-14T04:36:48.040Z","repository":{"id":270969833,"uuid":"911997262","full_name":"CAI991108/Optimization-and-Modeling-Utils","owner":"CAI991108","description":"This repository contains Python codes for various optimization and modeling tasks, including inheritance partitioning, surface and contour plotting, warehouse location optimization, root-finding using Bisection and Golden Section methods, gradient descent with different step-size strategies, inertial gradient methods, and image inpainting","archived":false,"fork":false,"pushed_at":"2025-01-04T12:23:40.000Z","size":5285,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-04T13:37:46.322Z","etag":null,"topics":["bisection-method","contour-plot","golden-section-search","gradient-method","image-inpainting","inheritance-examples","surface-plot"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CAI991108.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-04T12:21:48.000Z","updated_at":"2025-01-04T12:26:22.000Z","dependencies_parsed_at":"2025-01-04T13:47:52.905Z","dependency_job_id":null,"html_url":"https://github.com/CAI991108/Optimization-and-Modeling-Utils","commit_stats":null,"previous_names":["cai991108/optimization-and-modeling-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAI991108%2FOptimization-and-Modeling-Utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAI991108%2FOptimization-and-Modeling-Utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAI991108%2FOptimization-and-Modeling-Utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CAI991108%2FOptimization-and-Modeling-Utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CAI991108","download_url":"https://codeload.github.com/CAI991108/Optimization-and-Modeling-Utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241164473,"owners_count":19920581,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bisection-method","contour-plot","golden-section-search","gradient-method","image-inpainting","inheritance-examples","surface-plot"],"created_at":"2025-01-11T07:38:18.694Z","updated_at":"2026-05-14T04:36:43.018Z","avatar_url":"https://github.com/CAI991108.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Optimization and Modeling Utils (Python)\n\nThis repository contains Python codes for various optimization and modeling tasks, \nincluding **inheritance partitioning**, **surface and contour plotting**, **warehouse location optimization**, \n**root-finding using Bisection and Golden Section methods**, **gradient descent with different step-size strategies**, \n**inertial gradient methods**, and **image inpainting**. \nEach script or notebook focuses on solving specific problems, such as minimizing functions, \noptimizing warehouse placement, or reconstructing damaged images, using techniques like brute-force search, \ngradient descent, and conjugate gradient methods. \nThe repository also includes visualizations and performance comparisons, with dependencies on \nPython libraries like NumPy, SciPy, Matplotlib, and Jupyter Notebook. \n\n### Repository Structure\n```\n.\n├── Inheritance/\n│   ├── inheritance.py (.ipynb)\n├── Surface and Contour Plot/\n│   ├── plot.py (.ipynb)\n├── Warehouse Location/\n│   ├── warehouse.ipynb\n├── Bisection and Golden Section/\n│   ├── bi_golden_section.py (.ipynb)\n├── (Inertial) Gradient Method/\n│   ├── gradient_method.py \n│   ├── inertial_gradient.py\n├── Smooth Image Inpainting/\n│   ├── img_inpaint.ipynb\n├── reports/\n└── README.md\n```\n\n\n**Inheritance**\n- The `inheritance.py` and the `inheritance.ipynb` aims to divide an inheritance list into three partitions, each intended for a daughter, \nsuch that the difference in the total value of each partition is minimized. \nThe inheritance list contains weighted items, and the target value for each partition is one-third of the total inheritance. \nThe script uses a brute-force approach to generate all possible combinations of partitions, calculates their sums, \nand finds the partition with the smallest maximum difference between the sums. \nIf an optimal partition is found, it prints the three partitions along with their total values and the maximum difference. \nIf no optimal partition is found, it outputs a message indicating so. \nThe brute-force method is feasible due to the relatively small size of the inheritance list.\n\n**Surface and Contour Plot**\n- The `plot.py`  visualizes the function using `numpy` and `matplotlib`.\nIt creates a grid and evaluates the function over this grid, and generates two plots:\na 3D wireframe plot and a contour plot. \nThe contour plot shows 50 levels with labeled contours and the same points marked. \nThe script provides a clear visualization of the function's behavior in both 3D and 2D space.\n- The `plot.ipynb` contains Python code for visualizing and optimizing a function. \nIt generates a 3D surface plot of the function using `numpy` and `matplotlib`.\nThe script then uses `scipy.optimize.minimize` with the BFGS method to find a local minimum near the origin.\nAdditionally, it evaluates the function at four test points far from the origin, \nshowing significant variations in function values. \nThe code provides both visualization and optimization insights for the function.\n\n**Warehouse Location**\n- The `warehouse.ipynb` contains Python code for optimizing the placement of two warehouses \nusing the `dual_annealing` algorithm from `scipy.optimize`. \nIt defines separate objective functions for each warehouse, \ncalculating costs based on distances to fixed points and additional fixed costs. \nThe combined objective function minimizes the total cost for both warehouses. \nThe variables are bounded within specific ranges, and the optimization finds the global minimum. \nThe code efficiently solves the warehouse placement problem to minimize overall costs.\n\n**Bisection and Golden Section**\n- The `bi_golden_section.py` and the `bi_golden_section.ipynb` implements and compares \nthe **Bisection Method** and **Golden Section Method** to find the minimum of the function.\nThe Bisection Method uses the derivative to narrow down the root, \nwhile the Golden Section Method directly minimizes using the golden ratio.\nBoth methods return the optimal value and the number of iterations required. \nThe script also visualizes the function and the iteration paths of both methods using `matplotlib`, \nproviding a clear comparison of their convergence behavior.\n\n**(Inertial) Gradient Method**\n- The `gradient_method.py` implements the **Gradient Descent Method** to minimize the function \nusing three step-size strategies: **backtracking line search**, **diminishing step size**,\nand **exact line search** (via the Golden Section Method). \nIt starts from multiple initial points and iteratively updates the solution until convergence, \ntracking the number of iterations and the convergence path. \nThe script also visualizes the function's contour plot and the convergence paths for each method, \nproviding a clear comparison of their performance in finding the minimum. \nThe results are printed for each initial point and method, showing the convergence points and iteration counts.\n- The `inertial_gradient.py` implements the **Inertial Gradient Method** to minimize the function\nusing different values of the inertial parameter. \nThe method iteratively updates the solution by combining gradient descent with an inertial term, \nensuring convergence by satisfying the Armijo condition. The script starts from multiple initial points, \ntracks the function values, convergence paths, and iteration counts, and prints the results for each.\nIt also visualizes the function's contour plot and the convergence paths, \nproviding insights into how different values affect the optimization process.\n\n**Smooth Image Inpainting**\n- This Python script performs **image inpainting** using a **Conjugate Gradient (CG) Method** \nand a **Standard Solver** (`spsolve`) to reconstruct damaged images based on a given mask. \nIt constructs matrices `A` and `D` to represent the mask and gradient operators, respectively, \nand solves the system `Bx = C` with a regularization parameter `mu`. \nThe script compares the performance of the CG method and `spsolve` in terms of **PSNR (Peak Signal-to-Noise Ratio)** \nand computation time, showing that the CG method is significantly faster while achieving the same PSNR.\nIt also visualizes the original and damaged images, demonstrating the inpainting process. \nThe script is applied to two test images, showcasing its effectiveness in image reconstruction.\n\n\n### Dependencies\n\n- Python 3.x, NumPy, SciPy, Matplotlib, Scikit-learn, Jupyter Notebook\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcai991108%2Foptimization-and-modeling-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcai991108%2Foptimization-and-modeling-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcai991108%2Foptimization-and-modeling-utils/lists"}