data loading done
This commit is contained in:
parent
def7c1e965
commit
9a465ab566
File diff suppressed because it is too large
Load Diff
@ -1,24 +1,22 @@
|
|||||||
(ns propeller.problems.stocks.stock-regression
|
(ns propeller.problems.stocks.stock-regression
|
||||||
(:require
|
(:require
|
||||||
[clojure.core :refer [read-string]]
|
[clojure.core :refer [read-string]]
|
||||||
|
[propeller.tools.math :as math]
|
||||||
[propeller.genome :as genome]
|
[propeller.genome :as genome]
|
||||||
[propeller.gp :as gp]
|
[propeller.gp :as gp]
|
||||||
[propeller.push.interpreter :as interpreter]
|
[propeller.push.interpreter :as interpreter]
|
||||||
[propeller.push.state :as state]
|
[propeller.push.state :as state]
|
||||||
[propeller.tools.math :as math]))
|
[propeller.tools.loading :as loading]))
|
||||||
|
|
||||||
(defn- target-function
|
|
||||||
"Target function: f(x) = x^3 + 2*x^2 + x + 3"
|
|
||||||
[x]
|
|
||||||
(+ (* x x x) (* 2 x x) x 3))
|
|
||||||
|
|
||||||
(def train-and-test-data
|
(def train-and-test-data
|
||||||
"Training data: Inputs and outputs with -10 <= x < 11
|
"Training data: Inputs and outputs with -10 <= x < 11
|
||||||
Test data: Inputs and outputs of -20 <= x < -10 and 11 <= x < 21"
|
Test data: Inputs and outputs of -20 <= x < -10 and 11 <= x < 21"
|
||||||
(let [train-inputs (range -10 11)
|
(let [data (loading/basic-load-data-csv "src/propeller/problems/stocks/data/GLD.csv")
|
||||||
test-inputs (concat (range -20 -10) (range 11 21))]
|
train-len (math/round (* (count data) 0.8))
|
||||||
{:train (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) train-inputs)
|
test-len (- (count data) train-len)
|
||||||
:test (map (fn [x] {:input1 (vector x) :output1 (vector (target-function x))}) test-inputs)}))
|
]
|
||||||
|
{: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
|
(def instructions
|
||||||
"stack-specific instructions, input instructions, close, and constants"
|
"stack-specific instructions, input instructions, close, and constants"
|
||||||
@ -38,6 +36,7 @@
|
|||||||
:hold
|
:hold
|
||||||
))
|
))
|
||||||
|
|
||||||
|
(comment
|
||||||
(defn error-function
|
(defn error-function
|
||||||
"Finds the behaviors and errors of an individual. The error is the absolute
|
"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,
|
deviation between the target output value and the program's selected behavior,
|
||||||
@ -66,10 +65,11 @@
|
|||||||
:errors errors
|
:errors errors
|
||||||
:total-error #?(:clj (apply +' errors)
|
:total-error #?(:clj (apply +' errors)
|
||||||
:cljs (apply + errors))))))
|
:cljs (apply + errors))))))
|
||||||
|
)
|
||||||
|
|
||||||
(def integer-argmap
|
(def integer-argmap
|
||||||
{:instructions instructions
|
{:instructions instructions
|
||||||
:error-function error-function
|
;:error-function error-function
|
||||||
:training-data (:train train-and-test-data)
|
:training-data (:train train-and-test-data)
|
||||||
:testing-data (:test train-and-test-data)
|
:testing-data (:test train-and-test-data)
|
||||||
:max-generations 300
|
:max-generations 300
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.data.csv :as csv]))
|
[clojure.data.csv :as csv]))
|
||||||
|
|
||||||
(defn load-data-csv
|
(defn basic-load-data-csv
|
||||||
[path]
|
[path]
|
||||||
(with-open [reader (io/reader path)]
|
(with-open [reader (io/reader path)]
|
||||||
(->> (csv/read-csv reader)
|
(->> (csv/read-csv reader)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user