# some naming conventions
basnam="reber_617"
sub="080"

# do reber training
awk -vP=1 -vUNARY=2 -vno=4000000 -f reber.awk | java \
-Dfile_map_out=$basnam.$sub.map \
-Dnonode=617 \
-Dnoneighbors=7 \
-Dneighbourhood_shrink_from=15 \
-Dpattern_context_proportion_to=0.8 \
-Drefprop.reflectproperties.reflect=true \
-cp .. -Xoptimize genesom.Main $basnam.train.properties 2> $basnam.$sub.err | gzip -f -9 > $basnam.$sub.out.gz

# convert neuron states to the represented reber letters
zcat $basnam.$sub.out.gz | tr -d '\r' | awk -vtrigger="##" -vpatcol="3,10,19" -vlast=1 -f invreber.awk > $basnam.$sub.log

# calculate receptive fields of neurons
awk '{print $1,$NF}' $basnam.$sub.log | awk -vCOLSEP=" " -vqlen=14 -f cfield.awk | sort -t' ' -k16 -rn | sort -n -s  > $basnam.$sub.ccfield

# look for neuron transition probabilities
awk '{++cnt[$NF]}END{for(i in cnt) print i,cnt[i]/NR}' $basnam.$sub.log > $basnam.$sub.cnt
cat $basnam.$sub.map | sed 'sr] r]/rg' | awk -vFS=/ '/^[^#]/ {print $2,$4,$1}'| awk -vls=1 -vpatcol='1,7' -vlast=1 -f invreber.awk > $basnam.$sub.map.rebio
awk -f gmap2bauto.awk $basnam.$sub.cnt $basnam.$sub.map.rebio > $basnam.$sub.frqs

# calculate triplets
awk -vlevel=2 -f rebmapcontext.awk $basnam.$sub.map.rebio $basnam.$sub.map > $basnam.$sub.rebgrph2

# extract crisp receptive field
awk -f cfield2crisp.awk $basnam.$sub.ccfield > $basnam.$sub.crispcfield

# shorten  crisp receptive field to reber strings only
awk '{printf n=$1" "; for(i=NF;i>1;i--) printf $i; print""}' $basnam.$sub.crispcfield | awk -f isreber.awk > $basnam.$sub.crispcfieldchk

# output physical 2D grid location of neurons
awk -f map2physpos.awk $basnam.$sub.map > $basnam.$sub.physpos
