# getfinalneurons.awk
#
# use output...out[.bz2] to extract the prototypes really valid after training
# However, possibly not all neurons are active and
# the final context_eta remains unavailable.

P || /testing/ {

  if(P) {

    if(col == 0) col = (dim = (NF-1) / 3) + 1

    if(!((n = $col) in neurons)) {
      ++neurons[n]
      for(i = col + 1; i <= NF; i++) pt[n,i-col] = $i
    }
  }

  P = 1
}

END {

  P = "sort -n"

  for(n in neurons) {
    line = n
    for(i = 1; i <= 2 * dim; i++) line = line " " pt[n,i]
    print line | P
    ++printed
  }
  close(P)

  P = "cat >& 2"
  print "neurons: " printed | P
  close(P)
}
