<commit_before>(ns clojush.pushgp.pushgp
  (:require [clojure.java.io :as io]
            [clj-random.core :as random]
            [clojure.repl :as repl])
  (:use [clojush globals util pushstate random individual evaluate simplification translate]
        [clojush.instructions boolean code common numbers random-instructions string char vectors tag zip return input-output]
        [clojush.pushgp breed parent-selection report]
        [clojush.experimental.decimation]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pushgp

(def push-argmap
  (atom (sorted-map
          ;;----------------------------------------
          ;; Clojush system arguments
          ;;----------------------------------------
          :use-single-thread false ;; When true, Clojush will only use a single thread
          :random-seed (random/generate-mersennetwister-seed) ;; The seed for the random number generator
          :save-initial-population false ;; When true, saves the initial population
          ;;
          ;;----------------------------------------
          ;; Standard GP arguments
          ;;----------------------------------------
          :error-function (fn [p] '(0)) ;; Function that takes a program and returns a list of errors
          :error-threshold 0 ;; Pushgp will stop and return the best program if its total error is <= the error-threshold
          :atom-generators (concat @registered-instructions ;; The instructions that pushgp will use in random code
                                   (list 
                                     (fn [] (lrand-int 100))
                                     (fn [] (lrand))))
          :population-size 1000 ;; Number of individuals in the population
          :max-generations 1001 ;; The maximum number of generations to run GP
          :max-points 50 ;; Maximum size of push programs, as counted by points in the program
          :max-points-in-initial-program 50 ;; Maximum size of initial programs in generation 0
          :evalpush-limit 150 ;; The number of Push instructions that can be evaluated before stopping evaluation
          :evalpush-time-limit 0 ;; The time in nanoseconds that a program can evaluate before stopping, 0 means no time limit
          :reuse-errors true ;; When true, children produced through direct reproduction will not be re-evaluated but will have the error vector of their parent
          ;;
          ;;----------------------------------------
          ;; Genetic operator probabilities
          ;;----------------------------------------
          ;; The map supplied to :genetic-operator-probabilities should contain genetic operators
          ;; that sum to 1.0. All available genetic operators are defined in clojush.pushgp.breed.
          ;; Along with single operators, pipelines (vectors) containing multiple operators are
          ;; also allowed, where each operator is applied to the child of the previous operator, along
          ;; with newly selecting individuals where necessary. If an operator is preceeded by
          ;; :make-next-operator-revertable, it will only keep the child if it is at least as good as
          ;; its (first) parent on every test case.
          :genetic-operator-probabilities {:reproduction 0.0
                                           :alternation 0.7
                                           :uniform-mutation 0.1
                                           [:alternation :uniform-mutation] 0.2 ;Somewhat equivalent to normal Push's ULTRA operator
                                           :uniform-close-mutation 0.0
                                           :uniform-silence-mutation 0.0
                                           [:make-next-operator-revertable :uniform-silence-mutation] 0.0 ;Equivalent to a hill-climbing version of uniform-silence-mutation
                                           }
          ;;
          ;;----------------------------------------
          ;; Arguments related to genetic operators
          ;;----------------------------------------
          :alternation-rate 0.01 ;; When using alternation, how often alternates between the parents
          :alignment-deviation 10 ;; When using alternation, the standard deviation of how far alternation may jump between indices when switching between parents
          :uniform-mutation-rate 0.01 ;; The probability of each token being mutated during uniform mutation
          :uniform-mutation-constant-tweak-rate 0.5 ;; The probability of using a constant mutation instead of simply replacing the token with a random instruction during uniform mutation
          :uniform-mutation-float-gaussian-standard-deviation 1.0 ;; The standard deviation used when tweaking float constants with Gaussian noise
          :uniform-mutation-int-gaussian-standard-deviation 1 ;; The standard deviation used when tweaking integer constants with Gaussian noise
          :uniform-mutation-string-char-change-rate 0.1 ;; The probability of each character being changed when doing string constant tweaking
          :uniform-mutation-tag-gaussian-standard-deviation 100 ;; The standard deviation used when tweaking tag locations with Gaussian noise
          :uniform-close-mutation-rate 0.1 ;; The probability of each :close being incremented or decremented during uniform close mutation
          :close-increment-rate 0.2 ;; The probability of making an increment change to :close during uniform close mutation, as opposed to a decrement change
          :uniform-silence-mutation-rate 0.1 ;; The probability of each :silent being switched during uniform silent mutation
          :replace-child-that-exceeds-size-limit-with :parent ;; When a child is produced that exceeds the size limit of max-points, this is used to determine what program to return. Options include :parent, :empty, :random
          :parent-reversion-probability 1.0 ;; The probability of a child being reverted to its parent by a genetic operator that has been made revertable, if the child is not as good as the parent on at least one test case
          ;;
          ;;----------------------------------------
          ;; Epignenetics
          ;;----------------------------------------
          :epigenetic-markers [:close] ;; A vector of the epigenetic markers that should be used in the individuals. Implemented options include: :close, :silent
          :close-probabilities [0.772 0.206 0.021 0.001] ;; A vector of the probabilities for the number of parens ending at that position. See random-closes in clojush.random          
          :silent-instruction-probability 0.2 ;; If :silent is used as an epigenetic-marker, this is the probability of random instructions having :silent be true
          ;;
          ;;----------------------------------------
          ;; Arguments related to parent selection
          ;;----------------------------------------
          :parent-selection :lexicase ;; The parent selection method. Options include :tournament, :lexicase, :elitegroup-lexicase
          :tournament-size 7 ;; If using tournament selection, the size of the tournaments
          :total-error-method :sum ;; The method used to compute total error. Options include :sum (standard), :hah (historically-assessed hardness), :rmse (root mean squared error), and :ifs (implicit fitness sharing)
          :normalization :none ;; The method used to normalize the errors to the range [0,1], with 0 being best. Options include :none (no normalization), :divide-by-max-error (divides by value of argument :max-error), :e-over-e-plus-1 (e/(e+1) = 1 - 1/(e+1))
          :max-error 1000 ;; If :normalization is set to :max-error, will use this number for normalization
          :trivial-geography-radius 0 ;; If non-zero, this is used as the radius from which to select individuals for tournament or lexicase selection
          :decimation-ratio 1 ;; If >= 1, does nothing. Otherwise, is the percent of the population size that is retained before breeding. If 0 < decimation-ratio < 1, decimation tournaments will be used to reduce the population to size (* population-size decimation-ratio) before breeding.
          :decimation-tournament-size 2 ;; Size of the decimation tournaments
          ;;
          ;;----------------------------------------<commit_msg>Changed default for :replace-child-that-exceeds-size-limit-with to :random<commit_after>(ns clojush.pushgp.pushgp
  (:require [clojure.java.io :as io]
            [clj-random.core :as random]
            [clojure.repl :as repl])
  (:use [clojush globals util pushstate random individual evaluate simplification translate]
        [clojush.instructions boolean code common numbers random-instructions string char vectors tag zip return input-output]
        [clojush.pushgp breed parent-selection report]
        [clojush.experimental.decimation]))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; pushgp

(def push-argmap
  (atom (sorted-map
          ;;----------------------------------------
          ;; Clojush system arguments
          ;;----------------------------------------
          :use-single-thread false ;; When true, Clojush will only use a single thread
          :random-seed (random/generate-mersennetwister-seed) ;; The seed for the random number generator
          :save-initial-population false ;; When true, saves the initial population
          ;;
          ;;----------------------------------------
          ;; Standard GP arguments
          ;;----------------------------------------
          :error-function (fn [p] '(0)) ;; Function that takes a program and returns a list of errors
          :error-threshold 0 ;; Pushgp will stop and return the best program if its total error is <= the error-threshold
          :atom-generators (concat @registered-instructions ;; The instructions that pushgp will use in random code
                                   (list 
                                     (fn [] (lrand-int 100))
                                     (fn [] (lrand))))
          :population-size 1000 ;; Number of individuals in the population
          :max-generations 1001 ;; The maximum number of generations to run GP
          :max-points 50 ;; Maximum size of push programs, as counted by points in the program
          :max-points-in-initial-program 50 ;; Maximum size of initial programs in generation 0
          :evalpush-limit 150 ;; The number of Push instructions that can be evaluated before stopping evaluation
          :evalpush-time-limit 0 ;; The time in nanoseconds that a program can evaluate before stopping, 0 means no time limit
          :reuse-errors true ;; When true, children produced through direct reproduction will not be re-evaluated but will have the error vector of their parent
          ;;
          ;;----------------------------------------
          ;; Genetic operator probabilities
          ;;----------------------------------------
          ;; The map supplied to :genetic-operator-probabilities should contain genetic operators
          ;; that sum to 1.0. All available genetic operators are defined in clojush.pushgp.breed.
          ;; Along with single operators, pipelines (vectors) containing multiple operators are
          ;; also allowed, where each operator is applied to the child of the previous operator, along
          ;; with newly selecting individuals where necessary. If an operator is preceeded by
          ;; :make-next-operator-revertable, it will only keep the child if it is at least as good as
          ;; its (first) parent on every test case.
          :genetic-operator-probabilities {:reproduction 0.0
                                           :alternation 0.7
                                           :uniform-mutation 0.1
                                           [:alternation :uniform-mutation] 0.2 ;Somewhat equivalent to normal Push's ULTRA operator
                                           :uniform-close-mutation 0.0
                                           :uniform-silence-mutation 0.0
                                           [:make-next-operator-revertable :uniform-silence-mutation] 0.0 ;Equivalent to a hill-climbing version of uniform-silence-mutation
                                           }
          ;;
          ;;----------------------------------------
          ;; Arguments related to genetic operators
          ;;----------------------------------------
          :alternation-rate 0.01 ;; When using alternation, how often alternates between the parents
          :alignment-deviation 10 ;; When using alternation, the standard deviation of how far alternation may jump between indices when switching between parents
          :uniform-mutation-rate 0.01 ;; The probability of each token being mutated during uniform mutation
          :uniform-mutation-constant-tweak-rate 0.5 ;; The probability of using a constant mutation instead of simply replacing the token with a random instruction during uniform mutation
          :uniform-mutation-float-gaussian-standard-deviation 1.0 ;; The standard deviation used when tweaking float constants with Gaussian noise
          :uniform-mutation-int-gaussian-standard-deviation 1 ;; The standard deviation used when tweaking integer constants with Gaussian noise
          :uniform-mutation-string-char-change-rate 0.1 ;; The probability of each character being changed when doing string constant tweaking
          :uniform-mutation-tag-gaussian-standard-deviation 100 ;; The standard deviation used when tweaking tag locations with Gaussian noise
          :uniform-close-mutation-rate 0.1 ;; The probability of each :close being incremented or decremented during uniform close mutation
          :close-increment-rate 0.2 ;; The probability of making an increment change to :close during uniform close mutation, as opposed to a decrement change
          :uniform-silence-mutation-rate 0.1 ;; The probability of each :silent being switched during uniform silent mutation
          :replace-child-that-exceeds-size-limit-with :random ;; When a child is produced that exceeds the size limit of max-points, this is used to determine what program to return. Options include :parent, :empty, :random
          :parent-reversion-probability 1.0 ;; The probability of a child being reverted to its parent by a genetic operator that has been made revertable, if the child is not as good as the parent on at least one test case
          ;;
          ;;----------------------------------------
          ;; Epignenetics
          ;;----------------------------------------
          :epigenetic-markers [:close] ;; A vector of the epigenetic markers that should be used in the individuals. Implemented options include: :close, :silent
          :close-probabilities [0.772 0.206 0.021 0.001] ;; A vector of the probabilities for the number of parens ending at that position. See random-closes in clojush.random          
          :silent-instruction-probability 0.2 ;; If :silent is used as an epigenetic-marker, this is the probability of random instructions having :silent be true
          ;;
          ;;----------------------------------------
          ;; Arguments related to parent selection
          ;;----------------------------------------
          :parent-selection :lexicase ;; The parent selection method. Options include :tournament, :lexicase, :elitegroup-lexicase
          :tournament-size 7 ;; If using tournament selection, the size of the tournaments
          :total-error-method :sum ;; The method used to compute total error. Options include :sum (standard), :hah (historically-assessed hardness), :rmse (root mean squared error), and :ifs (implicit fitness sharing)
          :normalization :none ;; The method used to normalize the errors to the range [0,1], with 0 being best. Options include :none (no normalization), :divide-by-max-error (divides by value of argument :max-error), :e-over-e-plus-1 (e/(e+1) = 1 - 1/(e+1))
          :max-error 1000 ;; If :normalization is set to :max-error, will use this number for normalization
          :trivial-geography-radius 0 ;; If non-zero, this is used as the radius from which to select individuals for tournament or lexicase selection
          :decimation-ratio 1 ;; If >= 1, does nothing. Otherwise, is the percent of the population size that is retained before breeding. If 0 < decimation-ratio < 1, decimation tournaments will be used to reduce the population to size (* population-size decimation-ratio) before breeding.
          :decimation-tournament-size 2 ;; Size of the decimation tournaments
          ;;
          ;;----------------------------------------
{'fraction_non_alphanumeric': 0.13650774660525214, 'fraction_numerical': 0.012203146497577316, 'mean_word_length': 2.019869942196532, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4797623', 'n_tokens_mistral': 4064, 'n_tokens_neox': 3613, 'n_words': 1615}