Created
July 30, 2015 17:25
-
-
Save tanakahx/a46019fdf09faf3387f2 to your computer and use it in GitHub Desktop.
ニューロンの確率的2値モデルのシミュレーション
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 試行回数 | |
(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