Skip to content

Commit

Permalink
Merge pull request #69 from patham9/2.0.0_postdev3
Browse files Browse the repository at this point in the history
v2.0.1 refinement commit.
  • Loading branch information
TonyLo1 authored Oct 18, 2016
2 parents 2ee80c4 + ddc84ea commit 2bbab2e
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 56 deletions.
14 changes: 8 additions & 6 deletions docs/examples.pong.html
Original file line number Diff line number Diff line change
Expand Up @@ -2873,32 +2873,34 @@
[gui.gui-utils :refer [invert-comp]]
[narjure.global-atoms :refer :all]
[narjure.core :as nar]
[narjure.defaults :refer [max-term-complexity]]
[narjure.sensorimotor :refer :all])
(:gen-class))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(def py (atom 280))
(def direction (atom 0))
(def barheight 50)
(def barheight 125)
(def fieldmax 760)
(def fieldmin 20)</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn with-print [x]
#_(println (str x))
x)</pre></td></tr><tr><td class="docs"><p>Registers the operations</p>
</td><td class="codes"><pre class="brush: clojure">(defn setup-pong
[]
(reset! max-term-complexity 21)
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;)
(q/frame-rate 100)
(nars-register-operation 'op_up (fn [args operationgoal]
(do
(when (= (:source operationgoal) :derived)
#_(println &quot;system decided up&quot;))
(reset! direction -1)
true #_(with-print (not= @py fieldmin)))))
(with-print (not= @py fieldmin)))))
(nars-register-operation 'op_down (fn [args operationgoal]
(do
(when (= (:source operationgoal) :derived)
#_(println &quot;system decided down&quot;))
(reset! direction 1)
true #_(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
(merge hnav/states {:ball-px 380
:ball-py 400
:direction-x 1
Expand All @@ -2921,7 +2923,7 @@
&quot; below truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set below]] :belief :event)))
&quot; equal truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set equal]] :belief :event)))))
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;))
(when (= (mod (:iteration state) 250) 1)
(when (= (mod (:iteration state) 125) 1)
(println &quot;rand action&quot;)
(nars-input-narsese (str (rand-nth [&quot;&lt;(*,{SELF}) --&gt; op_up&gt;! :|:&quot;
&quot;&lt;(*,{SELF}) --&gt; op_down&gt;! :|:&quot;
Expand Down Expand Up @@ -2984,8 +2986,8 @@
(let [kset-x (+ 0.6 (/ (Math/random) 2.0))
kset-y (+ 0.6 (/ (Math/random) 2.0))
state2 (assoc state
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 3))
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 3)))
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 1))
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 1)))
state3 (if (&gt;= (:ball-px state2) ;collided on right wall
fieldmax)
(assoc state2 :direction-x (- kset-x))
Expand Down
36 changes: 31 additions & 5 deletions docs/nal.deriver.html
Original file line number Diff line number Diff line change
Expand Up @@ -2872,7 +2872,7 @@
[nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants
path-with-max-level]]
[nal.deriver.rules :refer [rule]]
[nal.deriver.normalization :refer [commutative-ops]]
[nal.deriver.normalization :refer [commutative-ops sort-commutative]]
[clojure.set :as set]
[nal.term_utils :refer :all]
[clojure.core.memoize :refer [lru]]
Expand All @@ -2884,17 +2884,39 @@
(case (count matchers)
0 (constantly [])
1 (first matchers)
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">#_(def mget-matcher (memoize get-matcher))
(def mget-matcher (lru get-matcher :lru/threshold 50))
#_(def mget-matcher get-matcher)
#_(def mpath (memoize path-with-max-level))
(def mpath (lru path-with-max-level :lru/threshold 50))
#_(def mpath path-with-max-level)
(defn generate-conclusions-no-commutativity
(defn parallel-conj [term]
(and (coll? term)
(= (first term) '&amp;|)))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn sequ-conj [term]
(and (coll? term)
(= (first term) 'seq-conj)))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn parallel-conj-reduce [term layer]
term
(if (parallel-conj term)
(let [reduced (apply concat
(for [x term]
(if (parallel-conj x)
(parallel-conj-reduce x (inc layer))
(if (= x '&amp;|)
[]
[x]))))]
(if (= layer 0)
(vec (conj reduced '&amp;|))
(vec reduced)))
term))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
</td><td class="codes"><pre class="brush: clojure">(defn generate-conclusions-no-commutativity
[rules {p1 :statement :as t1} {p2 :statement :as t2}]
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))]
(matcher t1 t2)))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))
result (set (matcher t1 t2))]
(for [z result]
(assoc z :statement (sort-commutative (parallel-conj-reduce (:statement z) 0))))))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
</td><td class="codes"><pre class="brush: clojure">(def use-counter (ref 0))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn use-counter-reset []
(do
Expand Down Expand Up @@ -2959,6 +2981,10 @@
#_(some #(= % (first term)) '[--&gt; &lt;-&gt; ==&gt; pred-impl retro-impl
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;
-- || conj seq-conj &amp;|])
;temporal copula only allowed once
(&lt;= (count (filter '#{==&gt; pred-impl retro-impl
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;} (flatten term)))
1)
;inheritance and Similarity can't have independent vars
(not (and (coll? term)
(some #(= % (first term)) '[--&gt; &lt;-&gt;])
Expand Down
10 changes: 6 additions & 4 deletions docs/nal.deriver.normalization.html
Original file line number Diff line number Diff line change
Expand Up @@ -2919,10 +2919,12 @@
</td><td class="codes"><pre class="brush: clojure">(defn sort-commutative
[conclusions]
(if (coll? conclusions)
(let [f (first conclusions)]
(if (commutative-ops f)
(vec (conj (sort-by hash (drop 1 conclusions)) f))
conclusions))
(if (= (first conclusions) '--)
['-- (sort-commutative (second conclusions))]
(let [f (first conclusions)]
(if (commutative-ops f)
(vec (conj (sort-by hash (drop 1 conclusions)) f))
conclusions)))
conclusions))</pre></td></tr><tr><td class="docs"><p>the union set operation for extensional and intensional sets</p>

<p>https://gist.github.com/TonyLo1/a3f8e05458c5e90c2e72</p>
Expand Down
8 changes: 4 additions & 4 deletions docs/narjure.defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -2912,10 +2912,10 @@
</td><td class="codes"><pre class="brush: clojure">(def inverse-decay-rate 10) ; forgetting adjustment rate for concepts e^-lt where l = (1.0 - durabiity) / decay-rate</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(def system-tick-interval-slow 136)
(def inference-tick-interval-slow 100)
(def system-tick-interval-medium 50)
(def inference-tick-interval-medium 25)
(def system-tick-interval-fast 20)
(def inference-tick-interval-fast 10)
(def system-tick-interval-medium 60)
(def inference-tick-interval-medium 30)
(def system-tick-interval-fast 30)
(def inference-tick-interval-fast 15)
(def system-tick-interval (atom system-tick-interval-medium)) ;make big enough</pre></td></tr><tr><td class="docs"><p>make big enough</p>
</td><td class="codes"><pre class="brush: clojure">(def inference-tick-interval (atom inference-tick-interval-medium))
(def anticipation-scale-dependent-tolerance 4.0) ;has to be 4 since interval rounding has to agree with time measurement in 2-power</pre></td></tr><tr><td class="docs"><p>has to be 4 since interval rounding has to agree with time measurement in 2-power</p>
Expand Down
68 changes: 49 additions & 19 deletions docs/uberdoc.html
Original file line number Diff line number Diff line change
Expand Up @@ -3402,10 +3402,12 @@
</td><td class="codes"><pre class="brush: clojure">(defn sort-commutative
[conclusions]
(if (coll? conclusions)
(let [f (first conclusions)]
(if (commutative-ops f)
(vec (conj (sort-by hash (drop 1 conclusions)) f))
conclusions))
(if (= (first conclusions) '--)
['-- (sort-commutative (second conclusions))]
(let [f (first conclusions)]
(if (commutative-ops f)
(vec (conj (sort-by hash (drop 1 conclusions)) f))
conclusions)))
conclusions))</pre></td></tr><tr><td class="docs"><p>the union set operation for extensional and intensional sets</p>

<p>https://gist.github.com/TonyLo1/a3f8e05458c5e90c2e72</p>
Expand Down Expand Up @@ -4201,7 +4203,7 @@ <h2></h2>
[nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants
path-with-max-level]]
[nal.deriver.rules :refer [rule]]
[nal.deriver.normalization :refer [commutative-ops]]
[nal.deriver.normalization :refer [commutative-ops sort-commutative]]
[clojure.set :as set]
[nal.term_utils :refer :all]
[clojure.core.memoize :refer [lru]]
Expand All @@ -4213,17 +4215,39 @@ <h2></h2>
(case (count matchers)
0 (constantly [])
1 (first matchers)
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">#_(def mget-matcher (memoize get-matcher))
(def mget-matcher (lru get-matcher :lru/threshold 50))
#_(def mget-matcher get-matcher)
#_(def mpath (memoize path-with-max-level))
(def mpath (lru path-with-max-level :lru/threshold 50))
#_(def mpath path-with-max-level)
(defn generate-conclusions-no-commutativity
(defn parallel-conj [term]
(and (coll? term)
(= (first term) '&amp;|)))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn sequ-conj [term]
(and (coll? term)
(= (first term) 'seq-conj)))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn parallel-conj-reduce [term layer]
term
(if (parallel-conj term)
(let [reduced (apply concat
(for [x term]
(if (parallel-conj x)
(parallel-conj-reduce x (inc layer))
(if (= x '&amp;|)
[]
[x]))))]
(if (= layer 0)
(vec (conj reduced '&amp;|))
(vec reduced)))
term))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
</td><td class="codes"><pre class="brush: clojure">(defn generate-conclusions-no-commutativity
[rules {p1 :statement :as t1} {p2 :statement :as t2}]
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))]
(matcher t1 t2)))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))
result (set (matcher t1 t2))]
(for [z result]
(assoc z :statement (sort-commutative (parallel-conj-reduce (:statement z) 0))))))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
</td><td class="codes"><pre class="brush: clojure">(def use-counter (ref 0))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn use-counter-reset []
(do
Expand Down Expand Up @@ -4288,6 +4312,10 @@ <h2></h2>
#_(some #(= % (first term)) '[--&gt; &lt;-&gt; ==&gt; pred-impl retro-impl
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;
-- || conj seq-conj &amp;|])
;temporal copula only allowed once
(&lt;= (count (filter '#{==&gt; pred-impl retro-impl
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;} (flatten term)))
1)
;inheritance and Similarity can't have independent vars
(not (and (coll? term)
(some #(= % (first term)) '[--&gt; &lt;-&gt;])
Expand Down Expand Up @@ -5836,10 +5864,10 @@ <h2></h2>
</td><td class="codes"><pre class="brush: clojure">(def inverse-decay-rate 10) ; forgetting adjustment rate for concepts e^-lt where l = (1.0 - durabiity) / decay-rate</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(def system-tick-interval-slow 136)
(def inference-tick-interval-slow 100)
(def system-tick-interval-medium 50)
(def inference-tick-interval-medium 25)
(def system-tick-interval-fast 20)
(def inference-tick-interval-fast 10)
(def system-tick-interval-medium 60)
(def inference-tick-interval-medium 30)
(def system-tick-interval-fast 30)
(def inference-tick-interval-fast 15)
(def system-tick-interval (atom system-tick-interval-medium)) ;make big enough</pre></td></tr><tr><td class="docs"><p>make big enough</p>
</td><td class="codes"><pre class="brush: clojure">(def inference-tick-interval (atom inference-tick-interval-medium))
(def anticipation-scale-dependent-tolerance 4.0) ;has to be 4 since interval rounding has to agree with time measurement in 2-power</pre></td></tr><tr><td class="docs"><p>has to be 4 since interval rounding has to agree with time measurement in 2-power</p>
Expand Down Expand Up @@ -8788,32 +8816,34 @@ <h2></h2>
[gui.gui-utils :refer [invert-comp]]
[narjure.global-atoms :refer :all]
[narjure.core :as nar]
[narjure.defaults :refer [max-term-complexity]]
[narjure.sensorimotor :refer :all])
(:gen-class))</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(def py (atom 280))
(def direction (atom 0))
(def barheight 50)
(def barheight 125)
(def fieldmax 760)
(def fieldmin 20)</pre></td></tr><tr><td class="docs">
</td><td class="codes"><pre class="brush: clojure">(defn with-print [x]
#_(println (str x))
x)</pre></td></tr><tr><td class="docs"><p>Registers the operations</p>
</td><td class="codes"><pre class="brush: clojure">(defn setup-pong
[]
(reset! max-term-complexity 21)
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;)
(q/frame-rate 100)
(nars-register-operation 'op_up (fn [args operationgoal]
(do
(when (= (:source operationgoal) :derived)
#_(println &quot;system decided up&quot;))
(reset! direction -1)
true #_(with-print (not= @py fieldmin)))))
(with-print (not= @py fieldmin)))))
(nars-register-operation 'op_down (fn [args operationgoal]
(do
(when (= (:source operationgoal) :derived)
#_(println &quot;system decided down&quot;))
(reset! direction 1)
true #_(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
(merge hnav/states {:ball-px 380
:ball-py 400
:direction-x 1
Expand All @@ -8836,7 +8866,7 @@ <h2></h2>
&quot; below truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set below]] :belief :event)))
&quot; equal truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set equal]] :belief :event)))))
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;))
(when (= (mod (:iteration state) 250) 1)
(when (= (mod (:iteration state) 125) 1)
(println &quot;rand action&quot;)
(nars-input-narsese (str (rand-nth [&quot;&lt;(*,{SELF}) --&gt; op_up&gt;! :|:&quot;
&quot;&lt;(*,{SELF}) --&gt; op_down&gt;! :|:&quot;
Expand Down Expand Up @@ -8899,8 +8929,8 @@ <h2></h2>
(let [kset-x (+ 0.6 (/ (Math/random) 2.0))
kset-y (+ 0.6 (/ (Math/random) 2.0))
state2 (assoc state
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 3))
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 3)))
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 1))
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 1)))
state3 (if (&gt;= (:ball-px state2) ;collided on right wall
fieldmax)
(assoc state2 :direction-x (- kset-x))
Expand Down
2 changes: 1 addition & 1 deletion src/examples/perception1.nal
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ p_2_3. :|: %0.8%
// |█ █|
//observed in experience?

(&|,p_1_2,(&|,p_2_1,p_2_3))?
(&|,p_1_2,p_2_1,p_2_3)?
Loading

0 comments on commit 2bbab2e

Please sign in to comment.