-
Notifications
You must be signed in to change notification settings - Fork 27
A sample workflow with the REPL
Let's use the REPL to run the directional-steps-1d
demo (blog post, comportexviz).
As described in README.md, start a REPL:
lein repl
Now, in the REPL, let's load the demo code, referring its public vars into the current namespace:
(use 'org.nfrac.comportex.demos.directional-steps-1d)
We're now equipped to create a model:
(def model (n-region-model 2))
You can explore the model. You probably shouldn't print the whole thing at once. Instead, explore it with keys
.
(keys model)
;= (:ff-deps-map :fb-deps-map :strata :inputs-map :regions-map :uuid->id)
(keys (:regions-map model))
;= (:r0 :r1)
(keys (:r0 (:regions-map model)))
;= (:column-field :layer-3 :uuid :step-counter)
(keys (:column-field (:r0 (:regions-map model))))
;= (:spec :ff-sg :topology :input-topology :overlaps :sig-overlaps :prox-exc :inh-radius :boosts :active-duty-cycles :overlap-duty-cycles)
(keys (:layer-3 (:r0 (:regions-map model))))
;= (:spec :topology :distal-sg :active-cols :burst-cols :active-cells :learn-cells :signal-cells :tp-cells :prior-active-cells :prior-learn-cells :pred-cells :prior-pred-cells :distal-exc :tp-exc)
There are also generic functions in the protocols namespace to work with some of these values.
Use column-state-freqs
for a summary.
(use 'org.nfrac.comportex.core)
(column-state-freqs (:r0 (:regions-map model)))
;= {:size 1000, :timestep 0, :active-predicted 0, :active 0, :predicted 0}
Before we move on and run the model, let's examine the input.
initial-input
;= [:up 0]
(input-transform initial-input-val)
;= [:up 1]
(input-transform (input-transform initial-input-val))
;= [:up 0]
Note that input-transform
is nondeterministic. Let's look at sequences of transforms. To get pprint
to work, you may need to (use 'clojure.pprint)
.
(def the-inputs (iterate input-transform initial-input-val))
(pprint (take 10 the-inputs))
; ([:up 0]
; [:down 1]
; [:down 0]
; [:up 0]
; [:down 1]
; [:up 0]
; [:up 1]
; [:up 2]
; [:down 3]
; [:up 2]
; [:down 3])
;= nil
Now let's see these inputs' encodings.
(use 'org.nfrac.comportex.protocols)
(def the-encodings (map #(apply sorted-set (encode encoder 0 %)) the-inputs))
(pprint (take 10 (interleave the-inputs the-encodings)))
; ([:down 3]
; #{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
; 26 27 28 29 150 151 152 153 154 155 156 157 158 159 160 161 162 163
; 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179},
; [:up 2]
; #{30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
; 53 54 55 56 57 58 59 120 121 122 123 124 125 126 127 128 129 130 131
; 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
; 149},
; [:up 1]
; #{30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
; 53 54 55 56 57 58 59 90 91 92 93 94 95 96 97 98 99 100 101 102 103
; 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119},
; [:down 0]
; #{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
; 26 27 28 29 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
; 79 80 81 82 83 84 85 86 87 88 89},
; [:down 1]
; #{0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
; 26 27 28 29 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
; 106 107 108 109 110 111 112 113 114 115 116 117 118 119},
; [:up 0]
; #{30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
; 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
; 76 77 78 79 80 81 82 83 84 85 86 87 88 89})
;= nil
Let's run the model.
(use 'org.nfrac.comportex.protocols) ; if you haven't done this already
(def model-t1 (htm-step model initial-input-val))
You can probe into model-t1
, similar to above.
Let's create a lazy sequence to represent the simulation.
(def simulation
(reductions (fn [model input]
(htm-step model input))
model the-inputs))
(def model-t2000 (nth simulation 2000))
Wait a minute for it to compute. And then explore.
(column-state-freqs (:r0 (:regions-map model-t2000)))
;= {:size 500, :timestep 2000, :active-predicted 25, :active 0, :predicted 16}
;; These keywords and formats may change! In fact, some already have.
;; The point is, feel free to explore.
(pprint (:prior-pred-cells (:layer-3 (:r0 (:regions-map model-t2000)))))
; #{[347 1] [188 3] [133 3] [40 3] [107 3] [311 0] [299 3] [48 1] [284 2]
; [117 2] [284 3] [237 0] [94 2] [271 1] [227 0] [163 1] [123 2]
; [332 0] [332 3] [227 2] [203 0] [94 1] [81 1] [127 3] [357 3] [150 1]
; [131 1] [299 0] [10 1] [27 2] [136 1] [50 0] [103 0] [67 0] [271 3]
; [255 1] [66 1] [311 1] [87 3] [0 2] [26 3] [147 0] [107 0] [2 1]
; [136 0] [131 3] [237 1] [34 2] [66 3] [36 2] [67 1] [221 2] [133 1]
; [10 3] [221 3] [373 2] [247 3]}
;= nil
(pprint (:active-cells (:layer-3 (:r0 (:regions-map model-t2000)))))
; #{[347 1] [188 3] [40 3] [284 3] [271 1] [332 3] [227 2] [203 0] [94 1]
; [131 1] [299 0] [136 1] [50 0] [103 0] [255 1] [311 1] [87 3] [0 2]
; [26 3] [34 2] [67 1] [221 2] [10 3] [373 2] [247 3]}
;= nil
(pprint (:burst-cols (:layer-3 (:r0 (:regions-map model-t2000)))))
; #{}
;= nil
Every active cell was predicted in the previous timestep (among others), so no columns were bursted.
Hopefully this page has helped you:
- Get an idea of where to start with Comportex
- See how useful it is to have visualizations like comportexviz, and not just a REPL :)