<commit_before>(ns clojush.pushgp.visualize
  (:use [clojush.globals])
  (:require [quil.core :as q]))

;; The initial value of viz-data-atom is set in clojush.pushgp.report/initial-report,
;; and updates are made in other functions in that namespace.

(defn visualize []
  (let [scale-x 10
        scale-y 2]
    (q/background 255)
    (q/fill 0)
    (q/text "Evolution!" 100 100)
    (let [gen (:generation @viz-data-atom)]
      (q/line (* (inc gen) scale-x) 0 (* (inc gen) scale-x) 1000))
    (doseq [[gen err] 
            (map vector 
                 (iterate inc 0) 
                 (map (partial * scale-y) 
                      (map (partial apply +)
                           (:history-of-errors-of-best @viz-data-atom))))]
      (q/fill 0)
      (q/rect (* gen scale-x) (- 1000 (* err scale-y) scale-y) scale-x scale-y))))

(defn start-visualization []
  (reset! viz-data-atom {:generation 0
                         :history-of-errors-of-best []})
  (q/sketch
    :size [1000 1000]
    :draw visualize))

(start-visualization)

<commit_msg>Improve default :visualize behavior<commit_after>(ns clojush.pushgp.visualize
  (:use [clojush.globals])
  (:require [quil.core :as q]))

(def viz-width 1000) 
(def viz-height 1000)
(def viz-border 50)

;; The initial value of viz-data-atom is set set below, in start-visualization.

;; Updates should be made in clojush.pushgp.report/report-and-check-for-success.

(defn visualize []
  (let [data @viz-data-atom
        gen (:generation data)]
    (when (> gen 0)
      (let [bests (:history-of-errors-of-best data)
            num-errors (count (first bests))
            scale-x (/ (- viz-width (* 2 viz-border))
                       (max 1 gen))
            scale-y (/ (- viz-height (* 2 viz-border))
                       (max 1 (apply max (flatten bests))))]
        (q/color-mode :rgb 255)
        (q/background 255)
        ;(q/fill 0)
        ;(q/text (str "Generation: " gen) 10 20)
        (q/color-mode :hsb)
        (doseq [[g errs] (map vector (iterate inc 0) bests)]
          (doseq [[i e] (map vector (iterate inc 0) errs)]
            (q/no-stroke)
            (q/fill (* i (/ 255 num-errors)) 255 255 64)
            (q/ellipse (+ viz-border (* g scale-x))
                       (- viz-height viz-border (* e scale-y)) 
                       20
                       20)))))))

(defn start-visualization []
  ;; Initialize viz-data-atom here, with whatever keys you want to track.
  (reset! viz-data-atom {:generation 0
                         :history-of-errors-of-best []})
  (q/sketch
    :size [viz-width viz-height]
    :draw visualize))

(start-visualization)


{'fraction_non_alphanumeric': 0.14798036995092487, 'fraction_numerical': 0.029067572668931674, 'mean_word_length': 1.9411764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6793511', 'n_tokens_mistral': 997, 'n_tokens_neox': 854, 'n_words': 244}