Skip to content

Commit 2bbab2e

Browse files
authored
Merge pull request #69 from patham9/2.0.0_postdev3
v2.0.1 refinement commit.
2 parents 2ee80c4 + ddc84ea commit 2bbab2e

File tree

10 files changed

+150
-56
lines changed

10 files changed

+150
-56
lines changed

docs/examples.pong.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2873,32 +2873,34 @@
28732873
[gui.gui-utils :refer [invert-comp]]
28742874
[narjure.global-atoms :refer :all]
28752875
[narjure.core :as nar]
2876+
[narjure.defaults :refer [max-term-complexity]]
28762877
[narjure.sensorimotor :refer :all])
28772878
(:gen-class))</pre></td></tr><tr><td class="docs">
28782879
</td><td class="codes"><pre class="brush: clojure">(def py (atom 280))
28792880
(def direction (atom 0))
2880-
(def barheight 50)
2881+
(def barheight 125)
28812882
(def fieldmax 760)
28822883
(def fieldmin 20)</pre></td></tr><tr><td class="docs">
28832884
</td><td class="codes"><pre class="brush: clojure">(defn with-print [x]
28842885
#_(println (str x))
28852886
x)</pre></td></tr><tr><td class="docs"><p>Registers the operations</p>
28862887
</td><td class="codes"><pre class="brush: clojure">(defn setup-pong
28872888
[]
2889+
(reset! max-term-complexity 21)
28882890
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;)
28892891
(q/frame-rate 100)
28902892
(nars-register-operation 'op_up (fn [args operationgoal]
28912893
(do
28922894
(when (= (:source operationgoal) :derived)
28932895
#_(println &quot;system decided up&quot;))
28942896
(reset! direction -1)
2895-
true #_(with-print (not= @py fieldmin)))))
2897+
(with-print (not= @py fieldmin)))))
28962898
(nars-register-operation 'op_down (fn [args operationgoal]
28972899
(do
28982900
(when (= (:source operationgoal) :derived)
28992901
#_(println &quot;system decided down&quot;))
29002902
(reset! direction 1)
2901-
true #_(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
2903+
(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
29022904
(merge hnav/states {:ball-px 380
29032905
:ball-py 400
29042906
:direction-x 1
@@ -2921,7 +2923,7 @@
29212923
&quot; below truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set below]] :belief :event)))
29222924
&quot; equal truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set equal]] :belief :event)))))
29232925
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;))
2924-
(when (= (mod (:iteration state) 250) 1)
2926+
(when (= (mod (:iteration state) 125) 1)
29252927
(println &quot;rand action&quot;)
29262928
(nars-input-narsese (str (rand-nth [&quot;&lt;(*,{SELF}) --&gt; op_up&gt;! :|:&quot;
29272929
&quot;&lt;(*,{SELF}) --&gt; op_down&gt;! :|:&quot;
@@ -2984,8 +2986,8 @@
29842986
(let [kset-x (+ 0.6 (/ (Math/random) 2.0))
29852987
kset-y (+ 0.6 (/ (Math/random) 2.0))
29862988
state2 (assoc state
2987-
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 3))
2988-
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 3)))
2989+
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 1))
2990+
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 1)))
29892991
state3 (if (&gt;= (:ball-px state2) ;collided on right wall
29902992
fieldmax)
29912993
(assoc state2 :direction-x (- kset-x))

docs/nal.deriver.html

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,7 +2872,7 @@
28722872
[nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants
28732873
path-with-max-level]]
28742874
[nal.deriver.rules :refer [rule]]
2875-
[nal.deriver.normalization :refer [commutative-ops]]
2875+
[nal.deriver.normalization :refer [commutative-ops sort-commutative]]
28762876
[clojure.set :as set]
28772877
[nal.term_utils :refer :all]
28782878
[clojure.core.memoize :refer [lru]]
@@ -2884,17 +2884,39 @@
28842884
(case (count matchers)
28852885
0 (constantly [])
28862886
1 (first matchers)
2887-
(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>
2887+
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs">
28882888
</td><td class="codes"><pre class="brush: clojure">#_(def mget-matcher (memoize get-matcher))
28892889
(def mget-matcher (lru get-matcher :lru/threshold 50))
28902890
#_(def mget-matcher get-matcher)
28912891
#_(def mpath (memoize path-with-max-level))
28922892
(def mpath (lru path-with-max-level :lru/threshold 50))
28932893
#_(def mpath path-with-max-level)
2894-
(defn generate-conclusions-no-commutativity
2894+
(defn parallel-conj [term]
2895+
(and (coll? term)
2896+
(= (first term) '&amp;|)))</pre></td></tr><tr><td class="docs">
2897+
</td><td class="codes"><pre class="brush: clojure">(defn sequ-conj [term]
2898+
(and (coll? term)
2899+
(= (first term) 'seq-conj)))</pre></td></tr><tr><td class="docs">
2900+
</td><td class="codes"><pre class="brush: clojure">(defn parallel-conj-reduce [term layer]
2901+
term
2902+
(if (parallel-conj term)
2903+
(let [reduced (apply concat
2904+
(for [x term]
2905+
(if (parallel-conj x)
2906+
(parallel-conj-reduce x (inc layer))
2907+
(if (= x '&amp;|)
2908+
[]
2909+
[x]))))]
2910+
(if (= layer 0)
2911+
(vec (conj reduced '&amp;|))
2912+
(vec reduced)))
2913+
term))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
2914+
</td><td class="codes"><pre class="brush: clojure">(defn generate-conclusions-no-commutativity
28952915
[rules {p1 :statement :as t1} {p2 :statement :as t2}]
2896-
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))]
2897-
(matcher t1 t2)))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
2916+
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))
2917+
result (set (matcher t1 t2))]
2918+
(for [z result]
2919+
(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>
28982920
</td><td class="codes"><pre class="brush: clojure">(def use-counter (ref 0))</pre></td></tr><tr><td class="docs">
28992921
</td><td class="codes"><pre class="brush: clojure">(defn use-counter-reset []
29002922
(do
@@ -2959,6 +2981,10 @@
29592981
#_(some #(= % (first term)) '[--&gt; &lt;-&gt; ==&gt; pred-impl retro-impl
29602982
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;
29612983
-- || conj seq-conj &amp;|])
2984+
;temporal copula only allowed once
2985+
(&lt;= (count (filter '#{==&gt; pred-impl retro-impl
2986+
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;} (flatten term)))
2987+
1)
29622988
;inheritance and Similarity can't have independent vars
29632989
(not (and (coll? term)
29642990
(some #(= % (first term)) '[--&gt; &lt;-&gt;])

docs/nal.deriver.normalization.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,10 +2919,12 @@
29192919
</td><td class="codes"><pre class="brush: clojure">(defn sort-commutative
29202920
[conclusions]
29212921
(if (coll? conclusions)
2922-
(let [f (first conclusions)]
2923-
(if (commutative-ops f)
2924-
(vec (conj (sort-by hash (drop 1 conclusions)) f))
2925-
conclusions))
2922+
(if (= (first conclusions) '--)
2923+
['-- (sort-commutative (second conclusions))]
2924+
(let [f (first conclusions)]
2925+
(if (commutative-ops f)
2926+
(vec (conj (sort-by hash (drop 1 conclusions)) f))
2927+
conclusions)))
29262928
conclusions))</pre></td></tr><tr><td class="docs"><p>the union set operation for extensional and intensional sets</p>
29272929

29282930
<p>https://gist.github.com/TonyLo1/a3f8e05458c5e90c2e72</p>

docs/narjure.defaults.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,10 +2912,10 @@
29122912
</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">
29132913
</td><td class="codes"><pre class="brush: clojure">(def system-tick-interval-slow 136)
29142914
(def inference-tick-interval-slow 100)
2915-
(def system-tick-interval-medium 50)
2916-
(def inference-tick-interval-medium 25)
2917-
(def system-tick-interval-fast 20)
2918-
(def inference-tick-interval-fast 10)
2915+
(def system-tick-interval-medium 60)
2916+
(def inference-tick-interval-medium 30)
2917+
(def system-tick-interval-fast 30)
2918+
(def inference-tick-interval-fast 15)
29192919
(def system-tick-interval (atom system-tick-interval-medium)) ;make big enough</pre></td></tr><tr><td class="docs"><p>make big enough</p>
29202920
</td><td class="codes"><pre class="brush: clojure">(def inference-tick-interval (atom inference-tick-interval-medium))
29212921
(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>

docs/uberdoc.html

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,10 +3402,12 @@
34023402
</td><td class="codes"><pre class="brush: clojure">(defn sort-commutative
34033403
[conclusions]
34043404
(if (coll? conclusions)
3405-
(let [f (first conclusions)]
3406-
(if (commutative-ops f)
3407-
(vec (conj (sort-by hash (drop 1 conclusions)) f))
3408-
conclusions))
3405+
(if (= (first conclusions) '--)
3406+
['-- (sort-commutative (second conclusions))]
3407+
(let [f (first conclusions)]
3408+
(if (commutative-ops f)
3409+
(vec (conj (sort-by hash (drop 1 conclusions)) f))
3410+
conclusions)))
34093411
conclusions))</pre></td></tr><tr><td class="docs"><p>the union set operation for extensional and intensional sets</p>
34103412

34113413
<p>https://gist.github.com/TonyLo1/a3f8e05458c5e90c2e72</p>
@@ -4201,7 +4203,7 @@ <h2></h2>
42014203
[nal.deriver.key-path :refer [mall-paths all-paths mpath-invariants
42024204
path-with-max-level]]
42034205
[nal.deriver.rules :refer [rule]]
4204-
[nal.deriver.normalization :refer [commutative-ops]]
4206+
[nal.deriver.normalization :refer [commutative-ops sort-commutative]]
42054207
[clojure.set :as set]
42064208
[nal.term_utils :refer :all]
42074209
[clojure.core.memoize :refer [lru]]
@@ -4213,17 +4215,39 @@ <h2></h2>
42134215
(case (count matchers)
42144216
0 (constantly [])
42154217
1 (first matchers)
4216-
(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>
4218+
(fn [t1 t2] (mapcat #(% t1 t2) matchers)))))</pre></td></tr><tr><td class="docs">
42174219
</td><td class="codes"><pre class="brush: clojure">#_(def mget-matcher (memoize get-matcher))
42184220
(def mget-matcher (lru get-matcher :lru/threshold 50))
42194221
#_(def mget-matcher get-matcher)
42204222
#_(def mpath (memoize path-with-max-level))
42214223
(def mpath (lru path-with-max-level :lru/threshold 50))
42224224
#_(def mpath path-with-max-level)
4223-
(defn generate-conclusions-no-commutativity
4225+
(defn parallel-conj [term]
4226+
(and (coll? term)
4227+
(= (first term) '&amp;|)))</pre></td></tr><tr><td class="docs">
4228+
</td><td class="codes"><pre class="brush: clojure">(defn sequ-conj [term]
4229+
(and (coll? term)
4230+
(= (first term) 'seq-conj)))</pre></td></tr><tr><td class="docs">
4231+
</td><td class="codes"><pre class="brush: clojure">(defn parallel-conj-reduce [term layer]
4232+
term
4233+
(if (parallel-conj term)
4234+
(let [reduced (apply concat
4235+
(for [x term]
4236+
(if (parallel-conj x)
4237+
(parallel-conj-reduce x (inc layer))
4238+
(if (= x '&amp;|)
4239+
[]
4240+
[x]))))]
4241+
(if (= layer 0)
4242+
(vec (conj reduced '&amp;|))
4243+
(vec reduced)))
4244+
term))</pre></td></tr><tr><td class="docs"><p>generate conclusions not taking commutative subterms of premises into account</p>
4245+
</td><td class="codes"><pre class="brush: clojure">(defn generate-conclusions-no-commutativity
42244246
[rules {p1 :statement :as t1} {p2 :statement :as t2}]
4225-
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))]
4226-
(matcher t1 t2)))</pre></td></tr><tr><td class="docs"><p>USE COUNTER (global seed, for making testcased deterministic</p>
4247+
(let [matcher (mget-matcher rules (mpath p1) (mpath p2))
4248+
result (set (matcher t1 t2))]
4249+
(for [z result]
4250+
(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>
42274251
</td><td class="codes"><pre class="brush: clojure">(def use-counter (ref 0))</pre></td></tr><tr><td class="docs">
42284252
</td><td class="codes"><pre class="brush: clojure">(defn use-counter-reset []
42294253
(do
@@ -4288,6 +4312,10 @@ <h2></h2>
42884312
#_(some #(= % (first term)) '[--&gt; &lt;-&gt; ==&gt; pred-impl retro-impl
42894313
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;
42904314
-- || conj seq-conj &amp;|])
4315+
;temporal copula only allowed once
4316+
(&lt;= (count (filter '#{==&gt; pred-impl retro-impl
4317+
=|&gt; &lt;=&gt; &lt;/&gt; &lt;|&gt;} (flatten term)))
4318+
1)
42914319
;inheritance and Similarity can't have independent vars
42924320
(not (and (coll? term)
42934321
(some #(= % (first term)) '[--&gt; &lt;-&gt;])
@@ -5836,10 +5864,10 @@ <h2></h2>
58365864
</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">
58375865
</td><td class="codes"><pre class="brush: clojure">(def system-tick-interval-slow 136)
58385866
(def inference-tick-interval-slow 100)
5839-
(def system-tick-interval-medium 50)
5840-
(def inference-tick-interval-medium 25)
5841-
(def system-tick-interval-fast 20)
5842-
(def inference-tick-interval-fast 10)
5867+
(def system-tick-interval-medium 60)
5868+
(def inference-tick-interval-medium 30)
5869+
(def system-tick-interval-fast 30)
5870+
(def inference-tick-interval-fast 15)
58435871
(def system-tick-interval (atom system-tick-interval-medium)) ;make big enough</pre></td></tr><tr><td class="docs"><p>make big enough</p>
58445872
</td><td class="codes"><pre class="brush: clojure">(def inference-tick-interval (atom inference-tick-interval-medium))
58455873
(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>
@@ -8788,32 +8816,34 @@ <h2></h2>
87888816
[gui.gui-utils :refer [invert-comp]]
87898817
[narjure.global-atoms :refer :all]
87908818
[narjure.core :as nar]
8819+
[narjure.defaults :refer [max-term-complexity]]
87918820
[narjure.sensorimotor :refer :all])
87928821
(:gen-class))</pre></td></tr><tr><td class="docs">
87938822
</td><td class="codes"><pre class="brush: clojure">(def py (atom 280))
87948823
(def direction (atom 0))
8795-
(def barheight 50)
8824+
(def barheight 125)
87968825
(def fieldmax 760)
87978826
(def fieldmin 20)</pre></td></tr><tr><td class="docs">
87988827
</td><td class="codes"><pre class="brush: clojure">(defn with-print [x]
87998828
#_(println (str x))
88008829
x)</pre></td></tr><tr><td class="docs"><p>Registers the operations</p>
88018830
</td><td class="codes"><pre class="brush: clojure">(defn setup-pong
88028831
[]
8832+
(reset! max-term-complexity 21)
88038833
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;)
88048834
(q/frame-rate 100)
88058835
(nars-register-operation 'op_up (fn [args operationgoal]
88068836
(do
88078837
(when (= (:source operationgoal) :derived)
88088838
#_(println &quot;system decided up&quot;))
88098839
(reset! direction -1)
8810-
true #_(with-print (not= @py fieldmin)))))
8840+
(with-print (not= @py fieldmin)))))
88118841
(nars-register-operation 'op_down (fn [args operationgoal]
88128842
(do
88138843
(when (= (:source operationgoal) :derived)
88148844
#_(println &quot;system decided down&quot;))
88158845
(reset! direction 1)
8816-
true #_(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
8846+
(with-print (not= @py (- fieldmax barheight (- fieldmin)))))))
88178847
(merge hnav/states {:ball-px 380
88188848
:ball-py 400
88198849
:direction-x 1
@@ -8836,7 +8866,7 @@ <h2></h2>
88368866
&quot; below truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set below]] :belief :event)))
88378867
&quot; equal truth &quot; (vec (:truth (lense-max-statement-confidence-projected-to-now '[--&gt; ballpos [int-set equal]] :belief :event)))))
88388868
(nars-input-narsese &quot;&lt;ballpos --&gt; [equal]&gt;! :|:&quot;))
8839-
(when (= (mod (:iteration state) 250) 1)
8869+
(when (= (mod (:iteration state) 125) 1)
88408870
(println &quot;rand action&quot;)
88418871
(nars-input-narsese (str (rand-nth [&quot;&lt;(*,{SELF}) --&gt; op_up&gt;! :|:&quot;
88428872
&quot;&lt;(*,{SELF}) --&gt; op_down&gt;! :|:&quot;
@@ -8899,8 +8929,8 @@ <h2></h2>
88998929
(let [kset-x (+ 0.6 (/ (Math/random) 2.0))
89008930
kset-y (+ 0.6 (/ (Math/random) 2.0))
89018931
state2 (assoc state
8902-
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 3))
8903-
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 3)))
8932+
:ball-px #_(:ball-px state) (+ (:ball-px state) (* (:direction-x state) 1 1))
8933+
:ball-py #_(:ball-py state) (+ (:ball-py state) (* (:direction-y state) 1 1)))
89048934
state3 (if (&gt;= (:ball-px state2) ;collided on right wall
89058935
fieldmax)
89068936
(assoc state2 :direction-x (- kset-x))

src/examples/perception1.nal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ p_2_3. :|: %0.8%
1717
// |█ █|
1818
//observed in experience?
1919

20-
(&|,p_1_2,(&|,p_2_1,p_2_3))?
20+
(&|,p_1_2,p_2_1,p_2_3)?

0 commit comments

Comments
 (0)