1.2.3-SNAPSHOT Arrow_down_16x16

som-batch-train

incanter.som

  • (som-batch-train data & options)
Performs BL-SOM (batch-learning self organizing map) learning on
the given data, returning a hashmap containing resulting BL-SOM
values.


Arguments:
data -- data matrix

Options:
:cycles -- number of cycles of learning
:alpha -- initial value of alpha learning parameter
:beta -- initial value of beta learning parameter


Returns: A hashmap containing the following fields:

:fit -- array of fitness values for each cycle of SOM learning
:weights -- hashmap of weight vectors, keyed by lattice indices
:sets -- hashmap mapping data elements to lattice nodes
(key lattice index) (value list of row indices from data)
:dims -- dimensions of SOM lattice
:data-means -- column means of input data matrix


Examples:

(use '(incanter core som stats charts datasets))
(def data (to-matrix (sel (get-dataset :iris)
:cols ["Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"])))

(def som (som-batch-train data :cycles 10 :alpha 0.5 :beta 3))

;; plot the fitness for each cycle of training
(view (xy-plot (range (count (:fit som))) (:fit som)))
;; view indices of data items in each cell
(:sets som)
;; view the species in each cell
(doseq [rws (vals (:sets som))]
(println (sel (get-dataset :iris) :cols "Species" :rows rws) \newline))

;; plot the means of the data vectors in each cell/cluster
(def cell-means (map #(map mean (trans (sel data :rows ((:sets som) %)))) (keys (:sets som))))
(def x (range (ncol data)))
(doto (xy-plot x (first cell-means))
view
(add-lines x (nth cell-means 1))
(add-lines x (nth cell-means 2)))


References:

http://en.wikipedia.org/wiki/Self-organizing_map

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source incanter/som.clj:136 top

(defn som-batch-train
" Performs BL-SOM (batch-learning self organizing map) learning on
  the given data, returning a hashmap containing resulting BL-SOM
  values.


  Arguments:
    data -- data matrix

  Options:
    :cycles -- number of cycles of learning
    :alpha -- initial value of alpha learning parameter
    :beta -- initial value of beta learning parameter


  Returns: A hashmap containing the following fields:

    :fit -- array of fitness values for each cycle of SOM learning
    :weights -- hashmap of weight vectors, keyed by lattice indices
    :sets -- hashmap mapping data elements to lattice nodes
             (key lattice index) (value list of row indices from data)
    :dims -- dimensions of SOM lattice
    :data-means -- column means of input data matrix


  Examples:

    (use '(incanter core som stats charts datasets))
    (def data (to-matrix (sel (get-dataset :iris)
                           :cols [\"Sepal.Length\" \"Sepal.Width\" \"Petal.Length\" \"Petal.Width\"])))

    (def som (som-batch-train data :cycles 10 :alpha 0.5 :beta 3))

    ;; plot the fitness for each cycle of training
    (view (xy-plot (range (count (:fit som))) (:fit som)))
    ;; view indices of data items in each cell
    (:sets som)
    ;; view the species in each cell
    (doseq [rws (vals (:sets som))]
      (println (sel (get-dataset :iris) :cols \"Species\" :rows rws) \\newline))

    ;; plot the means of the data vectors in each cell/cluster
    (def cell-means (map #(map mean (trans (sel data :rows ((:sets som) %)))) (keys (:sets som))))
    (def x (range (ncol data)))
    (doto (xy-plot x (first cell-means))
          view
          (add-lines x (nth cell-means 1))
          (add-lines x (nth cell-means 2)))


  References:

    http://en.wikipedia.org/wiki/Self-organizing_map

"
  ([data & options]
   (let [opts (when options (apply assoc {} options))
         alpha-init (or (:alpha opts) 0.5)
         beta-init (or (:beta opts) 3)
         total-cycles (or (:cycles opts) 10)]
    (loop [r 1 som (som-initialize-linear data) fit []]
      (if (= r total-cycles)
        (assoc som :fit fit)
        (let [new-som (som-update-weights r total-cycles (som-update-cells data som)
                                          alpha-init beta-init)]
          (recur (inc r) new-som (conj fit (som-fitness data new-som)))))))))
Vars in incanter.som/som-batch-train: = assoc conj defn inc let loop
Used in 0 other vars

Comments top

No comments for som-batch-train. Log in to add a comment.