Skip to content

Instantly share code, notes, and snippets.

"""
blog - randomcomputation.blogspot.com
(c) - jccc
"""
"""
We provide a tutorial on register machine induction and investigat
e the nature of various heuristic assumptions on learning performa
nce.
(defn rand-seqn [prog size seed]
(loop [ i 0
seqn [seed]]
(if (>= i size)
seqn
(recur (inc i)
(conj seqn (first
(execute prog [(last seqn) 1.0 1.0 1.0])))))))
(defn execute [prog regs]
(first (reduce interpret [regs true] prog)))
(defn rand-inst []
(let [ops '("add" "sub" "mul" "div" "cpy" " > ")
regs '(0 1 2 3)]
(list (rand-nth ops) (rand-nth regs)
(rand-nth regs)
(rand-nth regs))))
(defn gen-rand [size]
(for [n (range 0 size)]
(rand-inst)))
(def ctl #{" > "})
(defn interpret [[regs branch] [op arg1 arg2 arg3]]
;(println op arg1 arg2 arg3 regs branch)
(if branch
(if (contains? ctl op)
(case op
" > " (if (> (regs arg1)(regs arg2))
[regs (not branch)]
[regs branch]))
(ns bench.ptest
(:import (java.util.concurrent Executors)))
(defn run [num-threads]
"Create a vector of atoms of size size. Create a thread-pool
of size num-threads. Each thread will iterate (1) selecting
ten random atoms from the vector and then (2) reset!ing the
lowest valued atom with the value of the highest. Each thread
has its own java.util.Random."
(let [size 1000000
(ns clj-bunnies.simpleabm)
(def SIZE 5)
(def HISTORY 3)
(def EAT-RATE 1)
(def METABOLIC-RATE 0.3)
(def MOVE-RANGE 1)
(defn grass
[s]
;; problem representation
;; {:L 5
;; :S { 0 #{1 2}
;; 1 #{1 5 3}
;; 2 #{2 3} }}
(defn combos
[n s]
(letfn
[(expand
(defn queue
[& c]
(into
(clojure.lang.PersistentQueue/EMPTY)
c))
(defn k-combos
[k r]
(if (zero? k) nil
(letfn