//Functions to simulate a neuron //Author: Gerd Doeben-Henisch //Version: 7.Jan 2009 //Dependent from: annsvecmtx.sci (Vector and matrix operations) //******************************************************* //Function to compute the netsum of a neuron n.j from the outputs of preceding neurons o // weighted with a vector w of weights function [s] =net(o,w) s=vecprod(o,w) endfunction //************************************************************ // For the different types of activation functions see e.g. Haykin (1999) pp.12ff // or Zell (1994) pp.76ff //**************************************************** //Activation function as Identity (o_j=net_j) // u := net() sum of net-sum function // a := activation value function[a] = actId(u) a=u endfunction //**************************************************** //Activation function as symmetric threshold //(also called 'signum function') // u := net() sum of net-sum function // a := activation value function[a] = actThresSim(u) if (u > 0) then a = 1 elseif (u == 0) a = 0 else a = -1 end endfunction //**************************************************** //Activation function as asymmetric threshold // also called 'heavyside' // u := net() sum of net-sum function // a := activation value function[a] = actThresBin(u) if (u >=0) then a = 1 else a = 0 end endfunction //**************************************************** //Activation function as piecewise linear // u := net() sum of net-sum function // a := activation value function[a] = actPiece(u) if (u >= 0.5) then a = 1 elseif (u <= -0.5) a = 0 else a = u end endfunction //**************************************************** //Activation function as logistic function // u := net() sum of net-sum function // a := activation value function[a] = actLog(u) a=1/(1 + exp(-u)) endfunction //**************************************************** //Activation function as sinus // u := net() sum of net-sum function // a := activation value function[a] = actSin(u) a=sin(u) endfunction //**************************************************** //Activation function as sigmoid // u := net() sum of net-sum function // a := activation value // s := slope of sigmoid function function[a] = actSigm(u,s) a=1/(1 + exp(-s*u)) endfunction //**************************************************** //Activation function as tangens hyperbolics // u := net() sum of net-sum function // a := activation value function[a] = acttanh(u) a=tanh(u) endfunction //**************************************************** //Activation function as probabilistic function // u := net() sum of net-sum function // a := activation value // T := pseudotemperature function[a] = actProb(u,T) a=1/(1 + exp(-u/T)) endfunction //******************************************************* //Function to compute the activation a.j of a neuron n.j from the net.j function //Here we choose a simple binary function with a threshold theta function [a] =actbin(s,theta) if s < theta then a = 0, else a = 1, end endfunction //******************************************************* //Function to compute the reaction of a neuron n.j with input o and w //having a simple binary function as activation function function [o] = neuronbin(in,w,theta) o = actbin(net(in,w),theta), endfunction //******************************************************* //Function to compute the reaction of a neuron n.j with input vector in // and weight matrix W with row indicator i and a threshold vector th // The neuron is assumed to have a simple binary function as activation function function [o] = neuronbin(in,W,th,i) o = actbin(net(in,W(i,:)),th(i)), endfunction