{"id":18855289,"url":"https://github.com/kongeor/chickn","last_synced_at":"2025-09-03T16:31:30.290Z","repository":{"id":43626764,"uuid":"64995538","full_name":"kongeor/chickn","owner":"kongeor","description":"Evolutionary algorithms library for Clojure(script)","archived":false,"fork":false,"pushed_at":"2024-02-04T13:34:01.000Z","size":120,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-08T06:19:51.553Z","etag":null,"topics":["clojure","clojurescript","evolutionary-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kongeor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-05T06:45:43.000Z","updated_at":"2024-11-22T16:41:44.000Z","dependencies_parsed_at":"2023-01-22T20:25:11.508Z","dependency_job_id":null,"html_url":"https://github.com/kongeor/chickn","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongeor%2Fchickn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongeor%2Fchickn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongeor%2Fchickn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kongeor%2Fchickn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kongeor","download_url":"https://codeload.github.com/kongeor/chickn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231902080,"owners_count":18443328,"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":["clojure","clojurescript","evolutionary-algorithms"],"created_at":"2024-11-08T03:53:26.223Z","updated_at":"2024-12-30T18:43:17.100Z","avatar_url":"https://github.com/kongeor.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# chickn\n\n![clojure.yml](https://github.com/kongeor/chickn/actions/workflows/clojure.yml/badge.svg)\n[![Clojars Project](https://img.shields.io/clojars/v/com.github.kongeor/chickn.svg)](https://clojars.org/com.github.kongeor/chickn)\n\nEvolutionary algorithms library for Clojure(script)\n\n\n## Install\n\nAdd the following dependency to your `project.clj`:\n\n```\n[com.github.kongeor/chickn \"0.1.105\"]\n```\n\nor: \n\n```\ncom.github.kongeor/chickn {:mvn/version \"0.1.105\"}\n```\n\nif you are using `deps.edn`\n\n## Usage\n\nIn the following example we will try to solve one of the most trivial problems to understand the concepts of\nthe library:\n\nFirst we need to create a function that will randomize ones and zeros. This will be used for the initial population\nbut also for our mutation function:\n\n```clojure\n(def one-or-zero (fn [\u0026 _] (if (\u003e (rand) 0.5) 1 0)))\n```\n\nLet's define a population size:\n\n```clojure\n(def population-size 20)\n```\n\nThe `chromo-gen` function is used to create the initial population:\n\n```clojure\n(def chromo-gen #(repeatedly population-size one-or-zero))\n```\n\nFitness is the function that assigns a score to each possible solution. In this case it's just the sum of\nall numbers. Fitness for solution `[0 0 1 1 0]` would be 2, for `[0 0 1 1 1]` 3 etc.\n\n```clojure\n(defn fitness [xs]\n  (apply + xs))\n```\n\nIn some cases we may be able to define a function that determines if the problem is solved, which will allow us\nto avoid wasting iteration cycles when we have found the solution we are looking for. This is an optional key.\n\n```clojure\n(defn solved? [_ {:keys [best-chromosome]}]\n  (every? #(= 1 %) best-chromosome))\n```\n\nWe need to customize the build-in `rand-mutation` operator and specify the mutation function, which is the\nsame we used for initializing the population. This is suboptimal, we could have just flipped the bit here,\nbut for this example it should be all right.\n\n```clojure\n(def mutation-op\n  #:chickn.mutation\n          {:type          :chickn.mutation/rand-mutation\n           :rate          0.3\n           :random-func   rand\n           :mutation-func one-or-zero})\n```\n\n`Chickn` comes with a default config, but some customization is needed (`chromo-gen` and `fitness` have to be provided).\nHere we are also specifying the `:solved?` which was explained above. We are muting the `:reporter` to avoid getting\nprints, setting up our mutation operator, and setting that solutions with higher scores are preferred.\n\n```clojure\n(def config (merge\n              default-cfg\n              #:chickn.core\n                      {:chromo-gen chromo-gen\n                       :fitness    fitness\n                       :solved?    solved?\n                       :reporter   util/noop\n                       :mutation   mutation-op\n                       :comparator higher-is-better}))\n```\n\nIt's time to fire the process!\n\n```clojure\n(dissoc\n    (init-and-evolve config 100) :population)\n=\u003e {:solved? true, :iteration 9, :best-chromosome [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1], :time 1}\n```\n\nWe are `dissoc`ing the `:population` as it will include the entire population and the output can\nbe quite verbose. \n\nYou can find the code for this example here [src/chickn/examples/hello_world.cljc](src/chickn/examples/hello_world.cljc).\n\n\n## Examples\n\n[Examples namespace](/src/chickn/examples) has a few code examples.\n\n[Using chickn from cljs](https://kongeor.github.io/chicknism/) for solving the\nTraveling Salesman Problem.\n\n[Evolduo](https://github.com/kongeor/evolduo-app) is using Chickn for evolving musical phrases.\n\n\n## Project Status\n\nChickn should be considered alpha quality software.\n\n\n## License\n\nCopyright © 2018-2024 Kostas Georgiadis\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkongeor%2Fchickn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkongeor%2Fchickn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkongeor%2Fchickn/lists"}