# this implements the kohonen algorithm
# using the findext code in xpp
number ntot=100
# here is the Gaussian like nbhd function
h(u)=exp(-sig*(1-cos(2*pi*u*k/ntot)))
par sig=10
# k=1 gives 1 peak, k=2, 2, etc
# eps is the growth rate
par k=1,eps=.1
par br=4
# generate a random stimulus
za=2*ran(1)-1
zb=br*ran(1)
dp(x)=min(abs(x),min(abs(x+br),abs(x-br)))
# compute distance between stimulus and weight
d[0..99]=sqrt((wa[j]-za)^2+((wb[j]-zb))^2)
# find minimum  mx(2) is value mx(3) is index
special mx=findext(-1,100,1,d0)
# here is the algorithm
wa[0..99]'=wa[j]+eps*(za-wa[j])*h(mx(3)-[j])
wb[0..99]'=wb[j]+eps*(zb-wb[j])*h(mx(3)-[j])
# keep track of the index
ip'=mx(3)
# and keep track of the stim
aux zza=za
aux zzb=zb
# randomly initialize
global 0 t-t0 {wa[0..99]=2*ran(1)-1;wb[j]=br*ran(1)}
par t0=0
# 
@ meth=discrete, total=20000,nout=8,trans=10000
@ colormap=6
d

[wa,wb]' = eps [wa-za,wb-zb] h(xhat - x)



