inst4.0		! 8/15/90 

!****************************************************************
!*								*
!*	Self Organizing Map to Layer to Backprop *
!*								*
!****************************************************************
!
!	Set counter "Aux 1" in the super layer to the number of
!	interations between updating weights with the accumulated
!	deltas.

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

?&In	2
>bge	InOK
@Err	"Network MUST have at least two input PE's"
:InOK

?&Hd1	1
>bge	Hid1OK
@Err	"Kohonen Layer MUST have at least 1 row of PE's"
:Hid1OK
=n2	&Hd1			!n2 holds the number of rows in SOM

?&Hd2	1
>bge	Hid2OK
@Err	"Kohonen Layer MUST have at least 1 column of PE's"
:Hid2OK

?&Hd3	1
>bge	Hid3OK
@Err 	"Back-prop Hidden Layer MUST have at least 1 PE"
:Hid3OK

?&Out	1
>bge	OutOK
@Err	"Output Layer MUST have at least 1 output PE"
:OutOK

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

@LdCS	"som_bp"		!som control strategy
@LdLR	"som"			!som L/R schedule
@LdLR	"som_2hid"		!L/R schedule
@LdLR	"sombpout"		!L/R schedule for hidden layer

=netn "Self Organizing Map to Back-Prop v1.00 11-Sep-90"
=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
=Ltrn	"Linear"		!buffer
=x	100			!place to put layer on screen
=y	 80
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the input layer

!	*** Build the Kohonen Layer ***

@LLdf				!start with default layer again
=LDln	"2-D Kohonen"		!layer name
=Lpes	&Hd1			!number of PEs
*Lpes	&Hd2
=LDnr   &Hd1			!number of rows
=LInL 	-0.10			!Init low value
=LInH	0.10			!Init high value
=Lsum	"SOM"			!SOM summation function
=Llrn	"SOM"			!SOM learning rule
=Lcmp	"SOM"			!no output function required
=Llrs	"som"			!som L/R schedule
+y	60			!up higher on display
?&Hd2	15			!if 15 or more cols, shrink display
>blt	small
?&Hd2   21		
>blt	medium			
=LDsp	2			!21 or more cols
>br	small
:medium
=LDsp	4			!between 15 and 20 cols
:small
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!less than 15 cols

!	*** Connect Kohonen to Input Layer ***

=SPEl	LayN			!2-D Kohonen layer
@SlPE				!select it as destination 
=NPEl	0			!previous layer
@NrPE
=cnwt	0.0			!connection weight
=cnty	WVar			!variable
=cnsc	WAbs			!absolute
@LCFl				!fully connect to input layer
=n0	LayN			!save 2-D Kohonen layer for later


!	*** Build the back-prop hidden Layer ***

@LLdf				!start with default layer again
=LDln	"Back-prop Hidden"	!layer name
=Lpes	&Hd3			!Proper number of PEs
=Ltrn	"TanH"  		!transfer function
=Llrn	"Delta-Rule"		!Delta-Rule learning rule
=Llrs	"som_2hid"		!L/R schedule
=Lscl	2.0			!transform input to hidden layer
=Loff	-1.0			!from 0 to 1, to -1.0 to 1.0
*n2	55			!55 pixels for each SOM row
+y	n2			!move cursor up higher on display
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd

!	*** Connect Hidden Layer to Bias & Classification Layers ***

=SPEl	LayN			!current layer
@SlPE				!select it as destination 
=NPEl	-1			!near to bias term (source)
@NrPE
=cnwt	0.0			!connection weight
=cnty	WVar			!variable
=cnsc	WAbs			!absolute
@LCFl				!fully connect to bias element
=NPEl	n0			!classification layer
@NrPE
@LCFl				!fully connect to classification layer
=n0	LayN			!save current layer for later

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

@LLdf				!load default layer to mi_layer structure
=LDln	"Out"			!layer name
=Lpes	&Out			!copy # of input PEs from menu
=Ltrn	"TanH"  		!transfer function
=Llrn	"Delta-Rule"		!Delta-Rule learning rule
=Llrs	"sombpout"		!L/R schedule
+y	60
+x	15
#Incl	"stdnwgtf.iif"		!standard # weight fields
@LAdd				!add the output layer
=n7	LayN			!save for stdprobe
=n1	LayN			!save output layer for later

=SPEl	LayN			!current layer
@SlPE				!select it as destination
=NPEl	-1			!near to bias term (source)
@NrPE
@LCFl				!fully connect to bias element
=NPEl	n0			!previous layer
@NrPE
@LCFl				!fully connect to previous layer

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

@LLsl				!load super layer
=Lctl	"som_bp"		!som to class to bp control strategy
=Llrs	"som "			!self organ. map L/R Schedule
=Llnn	"train"  		!name of learn input
=Lrcn	"test"  		!name of recall output
#Incl	"stdioset.iif"		!standard I/O settings
=Lax1	15			!epoch size
=Lscl	 -1.0			!input  low-value
=Loff	 1.0			!input  high-value
=Llow	 0.0			!output low-value
=Lhgh	 1.0			!output high-value
=Lepc	0			!learn count=0
@SVsl				!save it back
@Nini				!initialize the network
!
=n5	0.0
=n6	1.0
=n4	&Out
#Incl	"stdprobe.iif"		!Standard probe include file
!
@EOF
