|
53 | 53 | obj_att_nums)))) |
54 | 54 |
|
55 | 55 |
|
| 56 | +;; (defmethod make-context-from-attribute-numbers-per-object :att-coll-obj-coll |
| 57 | +;; [att obj obj_att_nums] |
| 58 | +;; (let [matrix (flatten (map #(shuffle (into (vec (take % (repeat 1))) |
| 59 | +;; (vec (take (- (count att) %) (repeat 0))))) obj_att_nums))] |
| 60 | +;; (contexts/make-context-from-matrix |
| 61 | +;; (into [] obj) |
| 62 | +;; (into [] att) |
| 63 | +;; matrix))) |
| 64 | + |
56 | 65 | (defmethod make-context-from-attribute-numbers-per-object :att-coll-obj-coll |
57 | 66 | [att obj obj_att_nums] |
58 | | - (let [matrix (flatten (map #(shuffle (into (vec (take % (repeat 1))) |
59 | | - (vec (take (- (count att) %) (repeat 0))))) obj_att_nums))] |
| 67 | + (let [att-count (count att) |
| 68 | + matrix (mapcat #(shuffle (concat (repeat % 1) |
| 69 | + (repeat (- att-count %) 0))) |
| 70 | + obj_att_nums)] |
60 | 71 | (contexts/make-context-from-matrix |
61 | 72 | (into [] obj) |
62 | 73 | (into [] att) |
63 | | - matrix))) |
| 74 | + (flatten matrix)))) |
64 | 75 |
|
65 | 76 |
|
66 | 77 | (defmethod make-context-from-attribute-numbers-per-object :att-coll-obj-num |
|
276 | 287 | (let [attr (contexts/attributes ctx) |
277 | 288 | objects (contexts/objects ctx) |
278 | 289 | num_objects (count objects) |
279 | | - freq (frequencies (map #(count (contexts/object-derivation ctx [%])) objects)) |
280 | | - probabilities (into {} (for [[k v] freq] [k (/ v (reduce + (vals freq)))])) |
281 | | - cat_distr (createCategoricalDistribution probabilities)] |
282 | | - (makeContext attr objects (for [i (range num_objects)] (.sample cat_distr))))) |
| 290 | + freq (frequencies (pmap #(count (contexts/object-derivation ctx [%])) objects)) |
| 291 | + valsum (reduce + (vals freq)) |
| 292 | + probabilities (into {} (for [[k v] freq] [k (/ v valsum)])) |
| 293 | + cat_distr (createCategoricalDistribution probabilities) |
| 294 | + samples (for [i (range num_objects)] (.sample cat_distr))] |
| 295 | + (makeContext attr objects samples ))) |
283 | 296 |
|
284 | 297 |
|
285 | 298 | (defn imitate-context-with-cointoss |
|
0 commit comments