Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sequence generation option by giving a generator method #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/nature/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
(fn? fitness-function))]}
(let [solutions (max 1 (:solutions options))
carry-over (max 1 (:carry-over options))
monitors (:monitors options)]
(loop [population (io/build-population population-size allele-set genome-length fitness-function)
monitors (:monitors options)
sequence-generator-function (:generator options)]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add this to the docstring for this function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit addresses this, you can find my detailed response below.

(loop [population (if (some? sequence-generator-function)
(io/build-population population-size sequence-generator-function fitness-function)
(io/build-population population-size allele-set genome-length fitness-function))
current-generation 0]
(when monitors (monitors/apply-monitors monitors population current-generation))
(if (>= current-generation generations)
Expand Down
10 changes: 7 additions & 3 deletions src/nature/initialization_operators.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
:fitness-score (fitness-function genetic-sequence))))

(defn build-population
"Build `population-size` individuals by invoking `build-individual` on random, conforming genetic sequences."
[population-size alleles sequence-length fitness-function]
(repeatedly population-size #(build-individual (generate-sequence alleles sequence-length) fitness-function)))
"Build `population-size` individuals by invoking `build-individual` on random, conforming genetic sequences.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I'd really appreciate a test with a trivial sequence-generator-function if you wouldn't mind

If given a sequence generator function, uses this function to generate valid sequences instead."
([population-size sequence-generator-function fitness-function]
(repeatedly population-size #(build-individual (sequence-generator-function) fitness-function)))

([population-size alleles sequence-length fitness-function]
(repeatedly population-size #(build-individual (generate-sequence alleles sequence-length) fitness-function))))