From 8fae435046c3fcd6c635eb556b3b9db8be6221c9 Mon Sep 17 00:00:00 2001 From: Shuzo Katayama <62683709+DuckNoodleSoup@users.noreply.github.com> Date: Mon, 19 Jul 2021 16:36:31 -0400 Subject: [PATCH] Delete coin_sums.cljc --- src/propeller/problems/PSB2/coin_sums.cljc | 96 ---------------------- 1 file changed, 96 deletions(-) delete mode 100644 src/propeller/problems/PSB2/coin_sums.cljc diff --git a/src/propeller/problems/PSB2/coin_sums.cljc b/src/propeller/problems/PSB2/coin_sums.cljc deleted file mode 100644 index 3c5a73c..0000000 --- a/src/propeller/problems/PSB2/coin_sums.cljc +++ /dev/null @@ -1,96 +0,0 @@ -(ns propeller.problems.PSB2.coin-sums - (:require [psb2.core :as psb2] - [propeller.genome :as genome] - [propeller.push.interpreter :as interpreter] - [propeller.utils :as utils] - [propeller.push.utils.helpers :refer [get-stack-instructions]] - [propeller.push.state :as state] - [propeller.tools.math :as math] - [propeller.gp :as gp] - [propeller.push.utils.macros :refer [def-instruction - generate-instructions]])) - -; =========== PROBLEM DESCRIPTION ============================ -; COIN SUMS from PSB2 -; Given a number of cents, find the fewest -; number of US coins (pennies, nickles, dimes, quarters) needed -; to make that amount, and return the number of each type -; of coin as a separate output -; -; Source: https://arxiv.org/pdf/2106.06086.pdf -; =============================================================== - -(def train-and-test-data (psb2/fetch-examples "data" "coin-sums" 200 2000)) - -; Random integer between -100 and 100 (from smallest) -(defn random-int [] (- (rand-int 201) 100)) - -(def-instruction - :output_pennies - ^{:stacks [:integer]} - (fn [state] - (if (empty? (:integer state)) - state - (let [top-int (state/peek-stack :integer state)] - )))) - ;(stack-assoc top-int :output 0 state)))) - ;(assoc map key val) - -(def instructions - (utils/not-lazy - (concat - ;;; stack-specific instructions - (get-stack-instructions #{:exec :integer :boolean :print}) - ;;; input instructions - (list :in1) - ;;; close - (list 'close) - ;;; ERCs (constants) - (list 0 1 5 10 25)))) - -(defn error-function - [argmap data individual] - (let [program (genome/plushy->push (:plushy individual) argmap) - inputs (map (fn [i] (get i :input1)) data) - correct-outputs (map (fn [i] (get i :output1)) data) - outputs (map (fn [input] - (state/peek-stack - (interpreter/interpret-program - program - (assoc state/empty-state :input {:in1 input}) - (:step-limit argmap)) - :integer)) - inputs) - errors (map (fn [correct-output output] - (if (= output :no-stack-item) - 1000000 - (min 1000.0 (math/abs (- correct-output output))))) - correct-outputs - outputs)] - (assoc individual - :behaviors outputs - :errors errors - :total-error #?(:clj (apply +' errors) - :cljs (apply + errors))))) - -(defn -main - "Runs propel-gp, giving it a map of arguments." - [& args] - (gp/gp - (merge - {:instructions instructions - :error-function error-function - :training-data (:train train-and-test-data) - :testing-data (:test train-and-test-data) - :max-generations 300 - :population-size 1000 - :max-initial-plushy-size 250 - :step-limit 2000 - :parent-selection :lexicase - :tournament-size 5 - :umad-rate 0.1 - :variation {:umad 1.0 :crossover 0.0} - :elitism false} - (apply hash-map (map #(if (string? %) (read-string %) %) args))))) - -