data loading done

This commit is contained in:
Rowan Torbitzky-Lane 2025-03-15 01:49:00 -05:00
parent def7c1e965
commit 9a465ab566
3 changed files with 775 additions and 777 deletions
src/propeller

File diff suppressed because it is too large Load Diff

@ -1,24 +1,22 @@
(ns propeller.problems.stocks.stock-regression
(:require
[clojure.core :refer [read-string]]
[propeller.tools.math :as math]
[propeller.genome :as genome]
[propeller.gp :as gp]
[propeller.push.interpreter :as interpreter]
[propeller.push.state :as state]
[propeller.tools.math :as math]))
(defn- target-function
"Target function: f(x) = x^3 + 2*x^2 + x + 3"
[x]
(+ (* x x x) (* 2 x x) x 3))
[propeller.tools.loading :as loading]))
(def train-and-test-data
"Training data: Inputs and outputs with -10 <= x < 11
Test data: Inputs and outputs of -20 <= x < -10 and 11 <= x < 21"
(let [train-inputs (range -10 11)
test-inputs (concat (range -20 -10) (range 11 21))]
{:train (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) train-inputs)
:test (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) test-inputs)}))
(let [data (loading/basic-load-data-csv "src/propeller/problems/stocks/data/GLD.csv")
train-len (math/round (* (count data) 0.8))
test-len (- (count data) train-len)
]
{:train (map (fn [x] {:input1 (first (map read-string x)) :output1 (fnext (map read-string x))}) (doall (take train-len data)))
:test (map (fn [x] {:input1 (first (map read-string x)) :output1 (fnext (map read-string x))}) (doall (take-last test-len data)))}))
(def instructions
"stack-specific instructions, input instructions, close, and constants"
@ -38,6 +36,7 @@
:hold
))
(comment
(defn error-function
"Finds the behaviors and errors of an individual. The error is the absolute
deviation between the target output value and the program's selected behavior,
@ -66,10 +65,11 @@
:errors errors
:total-error #?(:clj (apply +' errors)
:cljs (apply + errors))))))
)
(def integer-argmap
{:instructions instructions
:error-function error-function
;:error-function error-function
:training-data (:train train-and-test-data)
:testing-data (:test train-and-test-data)
:max-generations 300

@ -5,7 +5,7 @@
[clojure.java.io :as io]
[clojure.data.csv :as csv]))
(defn load-data-csv
(defn basic-load-data-csv
[path]
(with-open [reader (io/reader path)]
(->> (csv/read-csv reader)