inst4.0		! 20-Sep-89  (spr.ins)  SPR Network Builder version 2
!****************************************************************
!*								*
!*	Spatio-Temporal Pattern Recognition Network Generator	*
!*								*
!****************************************************************
! Input:	# of input PE's
! Hidden 1:	if non-zero, add a normalizing layer (polar norm)
! Hidden 2:	# of temporal steps to generate network for (# of SPR layers)
! Output:	# of classes of output
!
! register usage:
!	n0 =  previous layer number
!	n1 =  input layer (or normalizing layer)
!	n2 =  "output" layer (where outputs go)		
!	n3 =  result of global inhibition layer
!	n4 =  current category number (PE in output)
!	n5 =  counter of number of layers to add

!	*** check that input / hidden / output PE count is non-zero

?&In	1
>bge	CheckOut
@Err	"SPR MUST have at least one input PE"
:CheckOut
?&Out	1
>bge	OutOK
@Err	"SPR MUST have at least one output PE"
:OutOK
?&Hd2	2
>bge	HidOK
@Err	"SPR MUST have at lease two temporal time steps (Hidden 2)"
:HidOK

!	*** Load the Control Strategy and LRS if needed

@LdCS	"spr"			!control strategy
@LdLR	"spr"			!L/R schedule

=netn	"InstaNet (tm) SPR (Avalanche) Network version 2.00 20-Sep-89"
=DLnF	0			!learn  re-display off
=DRcF	0			!recall re-display off

!	*** Build the Input Layer ***

@LLdf				!load default layer to mi_layer structure
=LDln	"In"			!layer name
=Lpes	&In			!copy # of input PEs from menu
=x	100			!place to put layer on screen
=y	 80
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the input layer
=n1	LayN			!input layer
=n0	LayN			!prior layer

!	*** Add a layer to compute the Polar Norm (if Hidden 1 != 0) ***

?&Hd1	0			!normalizing layer?
>ble	NoNorm			!no
@LLdf				!load default layer to mi_layer structure
=LDln	"Norm"			!layer name
=Lpes	&In			!set number of PEs
+Lpes	1			!# of inputs + 1
=Lsum	"NormPolar"		!special normalization
+y	50
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the layer
=n1	LayN			!use norm layer as "input" for now

=SPEl	LayN			!current layer
@SlPE
=NPEl	n0			!input layer
@NrPE
=cnwt	1.0			!unit weights
=cnty	WFix			!fixed weights
=cnsc	WRel			!relative positions
@LCCr				!connect corresponding PEs
=n0	LayN			!previous layer
:NoNorm

!	*** Build as many SPR layers as required and connect them up ***

=n5	&Out			!number of SPR layers to build

:MkSPR				!*** Main loop to build SPR layers ***
@LLdf				!start with default layer again
=LDln	"SPR"			!layer name
+LDln	LayN			!con-catenante layer number
=Lpes	&Hd2			!number of time steps in each sequence
=Lsum	"SPR"			!summation function
=Ltrn	"SPR"			!transfer function
=Lcmp	"SPR"			!SPR competition during learning
=Llrn	"SPR"			!learning rule
=Llow	0.0			!limit low output to zero
=Lhgh	1.0			!limit high output to one
+y	50			!up higher on display
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd
-n5	1			!decrement number of layers left to add
?n5	0
>bgt	MkSPR			!keep adding layers
=n0	LayN			!prior layer

!	*** Build the output layer & connect it to prior layer ***

@LLdf				!load default layer to mi_layer structure
=LDln	"N Act"			!layer name
=Lpes	&Out			!copy # of input PEs from menu
=Llow	0.0			!minimum value of zero output
+y	50
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the output layer
=n2	LayN			!category layer to connect to
=n0	LayN

@LLdf				!special sum layer
=LDln	"NT"			!activity level in network
=Lpes	1			!one PE
+y	40
-x	50
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add it

=SPEn	0			!select PE number in layer
=SPEl	LayN			!current layer
@SlPE				!selecte it
@LdSP
=PENm	"Act"
@SvSP
=NPEn	0			!neare PE number in layer
=NPEl	n0			!prior layer
@NrPE				!point to it

=cnwt	1.0			!connection weight
=cnty	WFix			!fixed weights
=cnsc	WAbs			!absolute geometry
@LCFl				!connect fully

=cnwt	0.0			!target activity level = # of steps in seq
-cnwt	&Hd2
=NPEl	-1			!bias layer
@NrPE				!now we are near that PE
@PCon				!connect it up
=n0	LayN			!prior layer

!	*** build the multiply layer next ***

@LLdf				!load default layer to mi_layer structure
=LDln	"I"			!layer name
=Lpes	1			!only one PE in this layer
=Llow	0			!minimum output of zero
=Lhgh	2			!maximum output of one
=Lsum	"CumSum"		!cumulative sum
+y	40
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the inhibition layer
=n3	LayN			!keep track of it for posterity

=NPEl	n0			!point to prior layer
@NrPE
=SPEl	LayN			!current layer
@SlPE
@LdSP
=PENm	"Inh"
@SvSP
=cnwt	.05			!Inhibition must change slowly
@PCon				!connect it to inhibitory term

=n0	LayN			!prior layer hook up

!	*** Create the network output layer ***

@LLdf				!special sum layer
=LDln	"Out"			!output of the network network
=Lpes	&Out			!total number of output PEs
+y	40
+x	50
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add it
=n7	LayN			!save for stdprobe

=SPEl	LayN			!select output layer
@SlPE
=NPEl	n2			!"prior" output layer
@NrPE
=cnwt	1.0
/cnwt	&Hd2			!divide by # of inputs
=cnsc	WRel
@LCCr				!connect corresponding

!	*** go back and properly connect up the various SPR chains ***
!	    First, connect them to the output layer

=SPEl	n2			!output layer
=NPEl	n1			!"input" layer
=cnwt	1.0			!connect to it with fixed weights
=cnsc	WRel
=cnty	WFix
=n4	0			!start with category zero
:CnOuts
=SPEn	n4			!output PE to connect to
@SlPE				!select the appropriate output PE
+NPEl	1
=NPEn	0			!start with PE 1 from current layer
:Cn1O
@NrPE				!selecte it
@PCon				!connect it
+NPEn	1			!next PE in layer
?NPEn	&Hd2			!are we done?
>blt	Cn1O			!no, keep going

+n4	1			!next output category
?n4	&Out
>blt	CnOuts

!	*** Go back through the SPR layer & connect up its inputs ***

=SPEl	n1			!point to input layer
+SPEl	1			!next layer
:CnSPR				!connect up SPR layer
=NPEn	0			!near PE 0
=NPEl	SPEl			!connect up chain first
=SPEn	1
@NrPE
@SlPE
=cnty	WSet			!modified weight
=cnsc	WRel			!  connected relatively
=cnwt	1.0			!  1.0
@PCon				!connect it
=NPEn	1			!both near & selected
@NrPE
@LCLk				!connect like

=cnsc	WAbs			!absolute connection to inhibition
=cnty	WFix			!fixed weights too
=cnwt	-1.0			!negative weight to inhibition
=NPEn	0
=NPEl	n3			!point to global inhibition
@NrPE
@LCFl				!connect fully to it

=cnty	WVar			!variable weights for input
=cnwt	0.0			!zero for now (randomized later)
=NPEl	n1			!point to input layer
@NrPE
@LCFl				!connect fully to it too

+SPEl	1			!next layer
?SPEl	n2			!are we done?
>blt	CnSPR			!no, keep connecting


!	*** Select Control Strategy & L/R Schedule ***

@LLsl				!load super layer
=Lctl	"spr"			!SPR control strategy
=Llrs	"spr"			!SPR L/R Schedule
=Llnn	"spr"			!name of learn input
=Lrcn	"spr"			!name of recall output
=Lscl	-1			!input  low-value
=Loff	 1			!input  high-value
=Llow	 0			!output low-value
=Lhgh	 1			!output high-value
@SVsl				!save it back
!
=n5	0.0
=n6	1.0
=n4	&Out
#Incl	"stdprobe.iif"		!Standard probe include file
!
=jogl	-.1			!lower limit for jog
=jogh	+.1			!upper limit for jog
=seed	257			!starting seed number
@seed				!set the seed
@Nrnd				!randomize the network

@EOF

