Skip to content

Commit

Permalink
Added 'initial-iter-count' & 'max-combined-cases' options
Browse files Browse the repository at this point in the history
  • Loading branch information
dferens committed May 27, 2015
1 parent 595741d commit d2f57dc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 28 deletions.
22 changes: 12 additions & 10 deletions src/clj/asols/solver.clj
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
(defn get-train-validation-entries
[solver]
(let [dataset (data/datasets (:dataset (:mutation-opts solver)))
[train _] (data/split-proportion (:train dataset) 3/4)]
[train _] (data/split-proportion (:train dataset) 2/3)]
[train (:train dataset)]))

(defn get-test-entries
Expand Down Expand Up @@ -108,12 +108,11 @@
mutations))))

(defn- make-combined-cases
[solver net cases]
(let [select-count 10
selected-cases (->> cases
[{m-opts :mutation-opts :as solver} net cases]
(let [selected-cases (->> cases
(sort-cases)
(take-while #(not= ::m/identity (:operation (:mutation %))))
(take select-count))]
(take (:max-combined-count m-opts)))]
(for [select-count (range 2 (inc (count selected-cases)))
:let [merge-cases (take select-count selected-cases)
mutation (m/combined-mutation (map :mutation merge-cases))]]
Expand Down Expand Up @@ -157,15 +156,18 @@
(network/insert-layer 1 hidden-type hidden-count))))

(defn create-initial-case
[{:keys [train-opts] :as solver}]
[{t-opts :train-opts m-opts :mutation-opts :as solver}]
(let [net (create-start-net solver)
;trained-net (trainer/train net (:train (get-train-entries solver)) train-opts)
mutation (first (m/identity-mutations net))]
(solve-mutation solver net mutation)))
[train-e _] (get-train-validation-entries solver)
initial-train-opts (assoc t-opts :iter-count (:initial-iter-count m-opts))
trained-net (trainer/train net train-e initial-train-opts)
mutation (first (m/identity-mutations trained-net))]
(solve-mutation solver trained-net mutation)))

(defn solver-loop
[solver out-chan abort-chan]
(cpool/with-shutdown! [tpool (cpool/threadpool (cpool/ncpus))]
(cpool/with-shutdown!
[tpool (cpool/threadpool (cpool/ncpus))]
(loop [current-case (create-initial-case solver)]
(let [current-net (:net current-case)
solving-chan (go (solve-net solver current-net out-chan tpool))
Expand Down
25 changes: 13 additions & 12 deletions src/cljs/asols/client/settings.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@
[:form.form-horizontal
[:.form-group
[:label.control-label.col-sm-4 "Learning rate"]
[:.col-sm-8
(widgets/input settings [:train-opts :learning-rate] parse-float)]]
[:.col-sm-8 (widgets/input settings [:train-opts :learning-rate] parse-float)]]
[:.form-group
[:label.control-label.col-sm-4 "Momentum"]
[:.col-sm-8
(widgets/input settings [:train-opts :momentum] parse-float)]]
[:.col-sm-8 (widgets/input settings [:train-opts :momentum] parse-float)]]
[:.form-group
[:label.control-label.col-sm-4 "L2 lambda"]
[:.col-sm-8
(widgets/input settings [:train-opts :l2-lambda] parse-float)]]
[:.col-sm-8 (widgets/input settings [:train-opts :l2-lambda] parse-float)]]
[:.form-group
[:label.control-label.col-sm-4 "Iterations"]
[:.col-sm-8
(widgets/input settings [:train-opts :iter-count] parse-int)]]
[:.col-sm-8 (widgets/input settings [:train-opts :iter-count] parse-int)]]
[:.form-group
[:label.control-label.col-sm-4 "Pretrain iter count"]
[:.col-sm-8 (widgets/input settings [:mutation-opts :initial-iter-count] parse-int)]]
[:.form-group
[:label.control-label.col-sm-4 "Input node prob."]
[:.col-sm-8
(widgets/input settings [:train-opts :in-node-prob] parse-float)]]
[:.col-sm-8 (widgets/input settings [:train-opts :in-node-prob] parse-float)]]
[:.form-group
[:label.control-label.col-sm-4 "Hidden node prob."]
[:.col-sm-8
(widgets/input settings [:train-opts :hidden-node-prob] parse-float)]]
[:.col-sm-8 (widgets/input settings [:train-opts :hidden-node-prob] parse-float)]]
[:.form-group
[:.col-sm-8.col-sm-offset-4
(if running?
Expand Down Expand Up @@ -82,6 +79,10 @@
:choices (:out-types settings)
:clean-fn str->keyword})]]

[:.form-group
[:.col-sm-6 [:label.control-label "Max combined count"]]
[:.col-sm-6 (widgets/input settings [:mutation-opts :max-combined-count] parse-int)]]

[:.form-group
[:.col-xs-6
(om/build widgets/checkbox {:cursor settings :path [:mutation-opts :add-nodes?]
Expand Down
19 changes: 13 additions & 6 deletions src/cljx/asols/commands.cljx
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,40 @@
in-node-prob hidden-node-prob]
:or {learning-rate 0.1
momentum 0.9
l2-lambda 0.01
iter-count 100
l2-lambda 0.1
iter-count 20
in-node-prob 1
hidden-node-prob 1}}]
(->TrainOpts learning-rate momentum l2-lambda iter-count
in-node-prob hidden-node-prob))

(defrecord MutationOpts [mode dataset
(defrecord MutationOpts [mode dataset initial-iter-count
hidden-type hidden-count
out-type
max-combined-count
add-nodes? add-edges?
remove-nodes? remove-edges?
add-layers?])

(defn mutation-opts
[& {:keys [mode dataset hidden-type hidden-count out-type
[& {:keys [mode dataset initial-iter-count
hidden-type hidden-count
out-type
max-combined-count
add-nodes? add-edges? add-layers?
remove-edges? remove-nodes?]
:or {hidden-count 1
:or {initial-iter-count 300
hidden-count 1
max-combined-count 10
add-nodes? true
add-edges? true
remove-edges? true
remove-nodes? true
add-layers? false}}]
(->MutationOpts mode dataset
(->MutationOpts mode dataset initial-iter-count
hidden-type hidden-count
out-type
max-combined-count
add-nodes? add-edges?
remove-edges? remove-nodes?
add-layers?))
Expand Down

0 comments on commit d2f57dc

Please sign in to comment.