<commit_before>;; vector_average.clj
;; <NAME>, <EMAIL>
;;
;; Problem Source: iJava (http://ijava.cs.umass.edu/)
;;
;; Given a vector of floats with length in [1,50], with each float in [-1000,1000],
;; return the average of those floats. Results are rounded to 4 decimal places.
;;
;; input stack has 1 input vector of floats

(ns clojush.problems.software.vector-average
  (:use clojush.pushgp.pushgp
        [clojush pushstate interpreter random util globals]
        clojush.instructions.tag
        [clojure.math numeric-tower combinatorics]
        ))

; Atom generators
(def vector-average-atom-generators
  (concat (list
            ;;; end constants
            ;;; end ERCs
            (tag-instruction-erc [:vector_float :float :integer :exec] 1000)
            (tagged-instruction-erc 1000)
            ;;; end tag ERCs
            'in1
            ;;; end input instructions
            )
          (registered-for-stacks [:vector_float :float :integer :exec])))


;; Define test cases
(defn vector-average-input
  "Makes a Vector Average input vector of length len."
  [len]
  (vec (repeatedly len
                   #(- (* (lrand) 2000.0) 1000.0))))

;; A list of data domains for the problem. Each domain is a vector containing
;; a "set" of inputs and two integers representing how many cases from the set
;; should be used as training and testing cases respectively. Each "set" of
;; inputs is either a list or a function that, when called, will create a
;; random element of the set.
(def vector-average-data-domains
  [[(list [0.0] [100.0] [-100.0]) 3 0] ;; Length 1 vectors
   [(list [2.0 129.0]
          [0.12345 -4.678]
          [999.99 74.113]) 3 0] ;; Length 2 vectors
   [(fn [] (vector-average-input 50)) 4 50] ;; Length 50 vectors
   [(fn [] (vector-average-input (inc (lrand-int 50)))) 90 950] ;; Random length, random floats
   ])

;;Can make Vector Average test data like this:
;(test-and-train-data-from-domains vector-average-data-domains)

; Helper function for error function
(defn vector-average-test-cases
  "Takes a sequence of inputs and gives IO test cases of the form
   [input output]."
  [inputs]
  (map #(vector %
                (/ (apply + %)
                   (count %)))
       inputs))

; Define error function. For now, each run uses different random inputs
(defn vector-average-error-function
  "Returns the error function for the vector-average problem. Takes as
   input Vector Average data domains."
  [data-domains]
  (let [[train-cases test-cases] (map vector-average-test-cases
                                      (test-and-train-data-from-domains data-domains))]<commit_msg>Added shorter test cases to Vector Average problem<commit_after>;; vector_average.clj
;; <NAME>, <EMAIL>
;;
;; Problem Source: iJava (http://ijava.cs.umass.edu/)
;;
;; Given a vector of floats with length in [1,50], with each float in [-1000,1000],
;; return the average of those floats. Results are rounded to 4 decimal places.
;;
;; input stack has 1 input vector of floats

(ns clojush.problems.software.vector-average
  (:use clojush.pushgp.pushgp
        [clojush pushstate interpreter random util globals]
        clojush.instructions.tag
        [clojure.math numeric-tower combinatorics]
        ))

; Atom generators
(def vector-average-atom-generators
  (concat (list
            ;;; end constants
            ;;; end ERCs
            (tag-instruction-erc [:vector_float :float :integer :exec] 1000)
            (tagged-instruction-erc 1000)
            ;;; end tag ERCs
            'in1
            ;;; end input instructions
            )
          (registered-for-stacks [:vector_float :float :integer :exec])))


;; Define test cases
(defn vector-average-input
  "Makes a Vector Average input vector of length len."
  [len]
  (vec (repeatedly len
                   #(- (* (lrand) 2000.0) 1000.0))))

;; A list of data domains for the problem. Each domain is a vector containing
;; a "set" of inputs and two integers representing how many cases from the set
;; should be used as training and testing cases respectively. Each "set" of
;; inputs is either a list or a function that, when called, will create a
;; random element of the set.
(def vector-average-data-domains
  [[(list [0.0] [100.0] [-100.0] [1000.0] [-1000.0]) 5 0] ;; Length-1 vectors
   [(fn [] (vector-average-input 1)) 45 500] ;; Random Length-1 vectors
   [(list [2.0 129.0]
          [0.12345 -4.678]
          [999.99 74.113]
          [987.654321 995.0003]
          [-788.788 -812.19]) 5 0] ;; Length-2 vectors
   [(fn [] (vector-average-input 2)) 45 500] ;; Random Length-2 vectors
   [(fn [] (vector-average-input (+ 3 (lrand-int 3)))) 50 500] ;; Random Length-3, -4, and -5 vectors
   [(fn [] (vector-average-input 50)) 5 50] ;; Random Length-50 vectors
   [(fn [] (vector-average-input (inc (lrand-int 50)))) 95 1000] ;; Random length, random floats
   ])

;;Can make Vector Average test data like this:
;(test-and-train-data-from-domains vector-average-data-domains)

; Helper function for error function
(defn vector-average-test-cases
  "Takes a sequence of inputs and gives IO test cases of the form
   [input output]."
  [inputs]
  (map #(vector %
                (/ (apply + %)
                   (count %)))
       inputs))

; Define error function. For now, each run uses different random inputs
(defn vector-average-error-function
  "Returns the error function for the vector-average problem. Takes as
   input Vector Average data domains."
  [data-domains]
  (let [[train-cases test-cases] (map vector-average-test-cases
                                      (test-and-train-data-from-domains data-domains))]
{'fraction_non_alphanumeric': 0.1217006200177148, 'fraction_numerical': 0.04216120460584588, 'mean_word_length': 2.6877857609405615, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5318360', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1643, 'n_words': 605}