{"id":20328755,"url":"https://github.com/inborastudio/machine-learning","last_synced_at":"2026-03-19T15:18:03.606Z","repository":{"id":298268570,"uuid":"509549899","full_name":"InboraStudio/machine-learning","owner":"InboraStudio","description":null,"archived":false,"fork":false,"pushed_at":"2022-07-01T18:19:26.000Z","size":11,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-10T08:40:36.650Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/InboraStudio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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,"zenodo":null}},"created_at":"2022-07-01T18:14:19.000Z","updated_at":"2024-05-26T02:43:41.000Z","dependencies_parsed_at":"2025-06-10T08:51:53.359Z","dependency_job_id":null,"html_url":"https://github.com/InboraStudio/machine-learning","commit_stats":null,"previous_names":["inborastudio/machine-learning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/InboraStudio/machine-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InboraStudio%2Fmachine-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InboraStudio%2Fmachine-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InboraStudio%2Fmachine-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InboraStudio%2Fmachine-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/InboraStudio","download_url":"https://codeload.github.com/InboraStudio/machine-learning/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/InboraStudio%2Fmachine-learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28920738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-30T20:25:28.696Z","status":"ssl_error","status_checked_at":"2026-01-30T20:25:13.426Z","response_time":66,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-14T20:07:50.059Z","updated_at":"2026-01-30T22:10:44.391Z","avatar_url":"https://github.com/InboraStudio.png","language":null,"readme":"\u003ctable border=\"0\" width=\"10%\"\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/1.jpg?raw=true\" height=\"80\" width=\"82\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/2.jpg?raw=true\" height=\"80\" width=\"82\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/3.jpg?raw=true\" height=\"80\" width=\"82\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n  \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/4.jpg?raw=true\" height=\"80\" width=\"82\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://img.shields.io/github/stars/guofei9987/scikit-opt.svg?style=social\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/6.jpg?raw=true\" height=\"82\" width=\"82\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n   \u003ctr\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/7.jpg?raw=true\" height=\"82\" width=\"82\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/8.jpg?raw=true\" height=\"82\" width=\"82\"\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg src=\"https://github.com/guofei9987/pictures_for_blog/blob/master/tmp/9.jpg?raw=true\" height=\"82\" width=\"82\"\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\n\n# [scikit-opt](https://github.com/guofei9987/scikit-opt)\n\n[![PyPI](https://img.shields.io/pypi/v/scikit-opt)](https://pypi.org/project/scikit-opt/)\n[![Build Status](https://travis-ci.com/guofei9987/scikit-opt.svg?branch=master)](https://travis-ci.com/guofei9987/scikit-opt)\n[![codecov](https://codecov.io/gh/guofei9987/scikit-opt/branch/master/graph/badge.svg)](https://codecov.io/gh/guofei9987/scikit-opt)\n[![License](https://img.shields.io/pypi/l/scikit-opt.svg)](https://github.com/guofei9987/scikit-opt/blob/master/LICENSE)\n![Python](https://img.shields.io/badge/python-\u003e=3.5-green.svg)\n![Platform](https://img.shields.io/badge/platform-windows%20|%20linux%20|%20macos-green.svg)\n[![PyPI_downloads](https://img.shields.io/pypi/dm/scikit-opt)](https://pypi.org/project/scikit-opt/)\n[![Join the chat at https://gitter.im/guofei9987/scikit-opt](https://badges.gitter.im/guofei9987/scikit-opt.svg)](https://gitter.im/guofei9987/scikit-opt?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\n\nSwarm Intelligence in Python  \n(Genetic Algorithm, Particle Swarm Optimization, Simulated Annealing, Ant Colony Algorithm, Immune Algorithm,Artificial Fish Swarm Algorithm in Python)  \n\n\n- **Instagram：** [https://instagram.com/inbora.studio](https://instagram.com/inbora.studio)  \n- **Website:** [inborastudio.wixsite.com/inborastudio](inborastudio.wixsite.com/inborastudio)\n\n# install\n```bash\npip install scikit-opt\n```\n\nFor the current developer version:\n```bach\ngit clone git@github.com:guofei9987/scikit-opt.git\ncd scikit-opt\npip install .\n```\n\n# Features\n## Feature1: UDF\n\n**UDF** (user defined function) is available now!\n\nFor example, you just worked out a new type of `selection` function.  \nNow, your `selection` function is like this:  \n-\u003e Demo code: [examples/demo_ga_udf.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L1)\n```python\n# step1: define your own operator:\ndef selection_tournament(algorithm, tourn_size):\n    FitV = algorithm.FitV\n    sel_index = []\n    for i in range(algorithm.size_pop):\n        aspirants_index = np.random.choice(range(algorithm.size_pop), size=tourn_size)\n        sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n    algorithm.Chrom = algorithm.Chrom[sel_index, :]  # next generation\n    return algorithm.Chrom\n\n\n```\n\nImport and build ga  \n-\u003e Demo code: [examples/demo_ga_udf.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L12)\n```python\nimport numpy as np\nfrom sko.GA import GA, GA_TSP\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nga = GA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -5], ub=[2, 10, 2],\n        precision=[1e-7, 1e-7, 1])\n\n```\nRegist your udf to GA  \n-\u003e Demo code: [examples/demo_ga_udf.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L20)\n```python\nga.register(operator_name='selection', operator=selection_tournament, tourn_size=3)\n```\n\nscikit-opt also provide some operators  \n-\u003e Demo code: [examples/demo_ga_udf.py#s4](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L22)\n```python\nfrom sko.operators import ranking, selection, crossover, mutation\n\nga.register(operator_name='ranking', operator=ranking.ranking). \\\n    register(operator_name='crossover', operator=crossover.crossover_2point). \\\n    register(operator_name='mutation', operator=mutation.mutation)\n```\nNow do GA as usual  \n-\u003e Demo code: [examples/demo_ga_udf.py#s5](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L28)\n```python\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n\n\u003e Until Now, the **udf** surport `crossover`, `mutation`, `selection`, `ranking` of GA\n\u003e scikit-opt provide a dozen of operators, see [here](https://github.com/guofei9987/scikit-opt/tree/master/sko/operators)\n\nFor advanced users:\n\n-\u003e Demo code: [examples/demo_ga_udf.py#s6](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_udf.py#L31)\n```python\nclass MyGA(GA):\n    def selection(self, tourn_size=3):\n        FitV = self.FitV\n        sel_index = []\n        for i in range(self.size_pop):\n            aspirants_index = np.random.choice(range(self.size_pop), size=tourn_size)\n            sel_index.append(max(aspirants_index, key=lambda i: FitV[i]))\n        self.Chrom = self.Chrom[sel_index, :]  # next generation\n        return self.Chrom\n\n    ranking = ranking.ranking\n\n\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + (x[2] - 0.5) ** 2\nmy_ga = MyGA(func=demo_func, n_dim=3, size_pop=100, max_iter=500, lb=[-1, -10, -5], ub=[2, 10, 2],\n        precision=[1e-7, 1e-7, 1])\nbest_x, best_y = my_ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n```\n## feature2: GPU computation\n We are developing GPU computation, which will be stable on version 1.0.0  \nAn example is already available: [https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_gpu.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_gpu.py)\n\n##  feature3: continue to run\n(New in version 0.3.6)  \nRun an algorithm for 10 iterations, and then run another 20 iterations base on the 10 iterations before:\n```python\nfrom sko.GA import GA\n\nfunc = lambda x: x[0] ** 2\nga = GA(func=func, n_dim=1)\nga.run(10)\nga.run(20)\n```\n\n# Quick start\n\n## 1. Differential Evolution\n**Step1**：define your problem  \n-\u003e Demo code: [examples/demo_de.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_de.py#L1)\n```python\n'''\nmin f(x1, x2, x3) = x1^2 + x2^2 + x3^2\ns.t.\n    x1*x2 \u003e= 1\n    x1*x2 \u003c= 5\n    x2 + x3 = 1\n    0 \u003c= x1, x2, x3 \u003c= 5\n'''\n\n\ndef obj_func(p):\n    x1, x2, x3 = p\n    return x1 ** 2 + x2 ** 2 + x3 ** 2\n\n\nconstraint_eq = [\n    lambda x: 1 - x[1] - x[2]\n]\n\nconstraint_ueq = [\n    lambda x: 1 - x[0] * x[1],\n    lambda x: x[0] * x[1] - 5\n]\n\n```\n\n**Step2**: do Differential Evolution  \n-\u003e Demo code: [examples/demo_de.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_de.py#L25)\n```python\nfrom sko.DE import DE\n\nde = DE(func=obj_func, n_dim=3, size_pop=50, max_iter=800, lb=[0, 0, 0], ub=[5, 5, 5],\n        constraint_eq=constraint_eq, constraint_ueq=constraint_ueq)\n\nbest_x, best_y = de.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n\n```\n\n## 2. Genetic Algorithm\n\n**Step1**：define your problem  \n-\u003e Demo code: [examples/demo_ga.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga.py#L1)\n```python\nimport numpy as np\n\n\ndef schaffer(p):\n    '''\n    This function has plenty of local minimum, with strong shocks\n    global minimum at (0,0) with value 0\n    '''\n    x1, x2 = p\n    x = np.square(x1) + np.square(x2)\n    return 0.5 + (np.sin(x) - 0.5) / np.square(1 + 0.001 * x)\n\n\n```\n\n**Step2**: do Genetic Algorithm  \n-\u003e Demo code: [examples/demo_ga.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga.py#L14)\n```python\nfrom sko.GA import GA\n\nga = GA(func=schaffer, n_dim=2, size_pop=50, max_iter=800, lb=[-1, -1], ub=[1, 1], precision=1e-7)\nbest_x, best_y = ga.run()\nprint('best_x:', best_x, '\\n', 'best_y:', best_y)\n\n```\n\n**Step3**: plot the result  \n-\u003e Demo code: [examples/demo_ga.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga.py#L21)\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\n\nY_history = pd.DataFrame(ga.all_history_Y)\nfig, ax = plt.subplots(2, 1)\nax[0].plot(Y_history.index, Y_history.values, '.', color='red')\nY_history.min(axis=1).cummin().plot(kind='line')\nplt.show()\n```\n\n![Figure_1-1](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/ga_1.png?raw=true)\n\n### 2.2 Genetic Algorithm for TSP(Travelling Salesman Problem)\nJust import the `GA_TSP`, it overloads the `crossover`, `mutation` to solve the TSP\n\n**Step1**: define your problem. Prepare your points coordinate and the distance matrix.  \nHere I generate the data randomly as a demo:  \n-\u003e Demo code: [examples/demo_ga_tsp.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_tsp.py#L1)\n```python\nimport numpy as np\nfrom scipy import spatial\nimport matplotlib.pyplot as plt\n\nnum_points = 50\n\npoints_coordinate = np.random.rand(num_points, 2)  # generate coordinate of points\ndistance_matrix = spatial.distance.cdist(points_coordinate, points_coordinate, metric='euclidean')\n\n\ndef cal_total_distance(routine):\n    '''The objective function. input routine, return total distance.\n    cal_total_distance(np.arange(num_points))\n    '''\n    num_points, = routine.shape\n    return sum([distance_matrix[routine[i % num_points], routine[(i + 1) % num_points]] for i in range(num_points)])\n\n\n```\n\n**Step2**: do GA  \n-\u003e Demo code: [examples/demo_ga_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_tsp.py#L19)\n```python\n\nfrom sko.GA import GA_TSP\n\nga_tsp = GA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=50, max_iter=500, prob_mut=1)\nbest_points, best_distance = ga_tsp.run()\n\n```\n\n**Step3**: Plot the result:  \n-\u003e Demo code: [examples/demo_ga_tsp.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ga_tsp.py#L26)\n```python\nfig, ax = plt.subplots(1, 2)\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1], 'o-r')\nax[1].plot(ga_tsp.generation_best_Y)\nplt.show()\n```\n\n![GA_TPS](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/ga_tsp.png?raw=true)\n\n\n## 3. PSO(Particle swarm optimization)\n\n### 3.1 PSO with constraint\n**Step1**: define your problem:  \n-\u003e Demo code: [examples/demo_pso.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L1)\n```python\ndef demo_func(x):\n    x1, x2, x3 = x\n    return x1 ** 2 + (x2 - 0.05) ** 2 + x3 ** 2\n\n\n```\n\n**Step2**: do PSO  \n-\u003e Demo code: [examples/demo_pso.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L6)\n```python\nfrom sko.PSO import PSO\n\npso = PSO(func=demo_func, dim=3, pop=40, max_iter=150, lb=[0, -1, 0.5], ub=[1, 1, 1], w=0.8, c1=0.5, c2=0.5)\npso.run()\nprint('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)\n\n```\n\n**Step3**: Plot the result  \n-\u003e Demo code: [examples/demo_pso.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L13)\n```python\nimport matplotlib.pyplot as plt\n\nplt.plot(pso.gbest_y_hist)\nplt.show()\n\n```\n\n\n![PSO_TPS](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/pso.png?raw=true)\n\n\n![pso_ani](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/pso.gif?raw=true)  \n↑**see [examples/demo_pso_ani.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso_ani.py)**\n\n### 3.2 PSO without constraint\n-\u003e Demo code: [examples/demo_pso.py#s4](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_pso.py#L19)\n```python\npso = PSO(func=demo_func, dim=3)\nfitness = pso.run()\nprint('best_x is ', pso.gbest_x, 'best_y is', pso.gbest_y)\n```\n\n## 4. SA(Simulated Annealing)\n### 4.1 SA for multiple function\n**Step1**: define your problem  \n-\u003e Demo code: [examples/demo_sa.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa.py#L1)\n```python\ndemo_func = lambda x: x[0] ** 2 + (x[1] - 0.05) ** 2 + x[2] ** 2\n\n```\n**Step2**: do SA  \n-\u003e Demo code: [examples/demo_sa.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa.py#L3)\n```python\nfrom sko.SA import SA\n\nsa = SA(func=demo_func, x0=[1, 1, 1], T_max=1, T_min=1e-9, L=300, max_stay_counter=150)\nbest_x, best_y = sa.run()\nprint('best_x:', best_x, 'best_y', best_y)\n\n```\n\n**Step3**: Plot the result  \n-\u003e Demo code: [examples/demo_sa.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa.py#L10)\n```python\nimport matplotlib.pyplot as plt\nimport pandas as pd\n\nplt.plot(pd.DataFrame(sa.best_y_history).cummin(axis=0))\nplt.show()\n\n```\n![sa](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/sa.png?raw=true)\n\n\nMoreover, scikit-opt provide 3 types of Simulated Annealing: Fast, Boltzmann, Cauchy. See [more sa](https://scikit-opt.github.io/scikit-opt/#/en/more_sa)\n### 4.2 SA for TSP\n**Step1**: oh, yes, define your problems. To boring to copy this step.  \n\n**Step2**: DO SA for TSP  \n-\u003e Demo code: [examples/demo_sa_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa_tsp.py#L21)\n```python\nfrom sko.SA import SA_TSP\n\nsa_tsp = SA_TSP(func=cal_total_distance, x0=range(num_points), T_max=100, T_min=1, L=10 * num_points)\n\nbest_points, best_distance = sa_tsp.run()\nprint(best_points, best_distance, cal_total_distance(best_points))\n```\n\n**Step3**: plot the result  \n-\u003e Demo code: [examples/demo_sa_tsp.py#s3](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa_tsp.py#L28)\n```python\nfrom matplotlib.ticker import FormatStrFormatter\n\nfig, ax = plt.subplots(1, 2)\n\nbest_points_ = np.concatenate([best_points, [best_points[0]]])\nbest_points_coordinate = points_coordinate[best_points_, :]\nax[0].plot(sa_tsp.best_y_history)\nax[0].set_xlabel(\"Iteration\")\nax[0].set_ylabel(\"Distance\")\nax[1].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1],\n           marker='o', markerfacecolor='b', color='c', linestyle='-')\nax[1].xaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))\nax[1].set_xlabel(\"Longitude\")\nax[1].set_ylabel(\"Latitude\")\nplt.show()\n\n```\n![sa](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/sa_tsp.png?raw=true)\n\n\nMore: Plot the animation:  \n\n![sa](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/sa_tsp1.gif?raw=true)  \n↑**see [examples/demo_sa_tsp.py](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_sa_tsp.py)**\n\n\n\n\n## 5. ACA (Ant Colony Algorithm) for tsp \n-\u003e Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L17)\n```python\nfrom sko.ACA import ACA_TSP\n\naca = ACA_TSP(func=cal_total_distance, n_dim=num_points,\n              size_pop=50, max_iter=200,\n              distance_matrix=distance_matrix)\n\nbest_x, best_y = aca.run()\n\n```\n\n![ACA](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/aca_tsp.png?raw=true)\n\n\n## 6. immune algorithm (IA)\n-\u003e Demo code: [examples/demo_ia.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_ia.py#L6)\n```python\n\nfrom sko.IA import IA_TSP\n\nia_tsp = IA_TSP(func=cal_total_distance, n_dim=num_points, size_pop=500, max_iter=800, prob_mut=0.2,\n                T=0.7, alpha=0.95)\nbest_points, best_distance = ia_tsp.run()\nprint('best routine:', best_points, 'best_distance:', best_distance)\n\n```\n\n![IA](https://github.com/guofei9987/pictures_for_blog/blob/master/heuristic_algorithm/ia2.png?raw=true)\n\n## 7. Artificial Fish Swarm Algorithm (AFSA)\n-\u003e Demo code: [examples/demo_afsa.py#s1](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_afsa.py#L1)\n```python\ndef func(x):\n    x1, x2 = x\n    return 1 / x1 ** 2 + x1 ** 2 + 1 / x2 ** 2 + x2 ** 2\n\n\nfrom sko.AFSA import AFSA\n\nafsa = AFSA(func, n_dim=2, size_pop=50, max_iter=300,\n            max_try_num=100, step=0.5, visual=0.3,\n            q=0.98, delta=0.5)\nbest_x, best_y = afsa.run()\nprint(best_x, best_y)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finborastudio%2Fmachine-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finborastudio%2Fmachine-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finborastudio%2Fmachine-learning/lists"}