defmultiをつかう
http://killingout-n-bita.hateblo.jp/entry/2015/03/21/122739
(defmulti pre-process class) (defmethod pre-process java.lang.Long [a] (cons (double a) nil)) (defmethod pre-process java.lang.Double [a] (cons a nil)) (defmethod pre-process clojure.lang.PersistentVector [a] (lazy-seq a)) (defmethod pre-process clatrix.core.Matrix [a] (lazy-seq a)) (defmethod pre-process :default [a] a) (defmulti post-process (fn [a y] [(class a) (class y)])) (defmethod post-process [java.lang.Long clatrix.core.Matrix] [a y] (apply double y)) (defmethod post-process [java.lang.Double clatrix.core.Matrix] [a y] (apply double y)) (defmethod post-process [clojure.lang.PersistentVector clatrix.core.Matrix] [a y] (vec y)) (defmethod post-process [clatrix.core.Matrix clatrix.core.Matrix] [a y] y) (defmethod post-process :default [a y] y) (defn softmax [a'] (let [a (pre-process a') c' (apply max a) c (repeat (length a) c') exp_a (exp (minus a c)) sum_exp_a (sum exp_a) y' (div exp_a sum_exp_a) y (post-process a' y')] y))