Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@tanakahx
Created July 30, 2015 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tanakahx/a46019fdf09faf3387f2 to your computer and use it in GitHub Desktop.
Save tanakahx/a46019fdf09faf3387f2 to your computer and use it in GitHub Desktop.
ニューロンの確率的2値モデルのシミュレーション
;; 試行回数
(defconstant +N+ 1000)
;; 入力値
(defparameter x (list 1 0 1))
;; 結線重み
(defparameter w (list 3 2 -1))
;; 閾値
(defparameter th 1)
;; シグモイド関数
(defun sigmoid (x &optional (a 1))
(/ 1 (+ 1 (exp (- (* a x))))))
;; 重み付け総和
(defun weighted-sum (x w)
(reduce #'+ (mapcar #'* x w)))
;; 確率的2値モデル
(defun prob-unit (x w th)
(if (< (random 1.0)
(sigmoid (- (weighted-sum x w) th)))
1
0))
(defun main ()
(values
;; 理論値
(* +N+ (sigmoid (- (weighted-sum x w) th)))
;; 実測値
(loop repeat +N+
sum (prob-unit x w th))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment