# convert map and given neuron activation frequencies
# into the transition properties of an automaton
#
# ARGV[1] : cnt file (neur.id frq)
# ARGV[2] : rebio file
#

BEGIN { }

/^[^#]/ {

  if(ARGIND == 2) {

    vn = $1
    vc = $2
    n = $3

    ++cfrq[vc]
    ++nfrq[vn]

    icfrq[vc] += ifrq[n]  # XXX ???
    infrq[vn] += ifrq[n]

    ++cnt[vn" "vc]

    icnt[vn" "vc] += ifrq[n]

    ++nr
  }
  else {               # use neuron actitvation freqencies
                       # awk '{++cnt[$NF]}END{for(i in cnt) print i,cnt[i]/NR}'
    ifrq[$1] = $2 + 0
  }
}

END {

  print "#filename(s)"
  print ARGV[1], ARGV[2]
  print ""

  sum = 0
  for(e in nfrq) sum += nfrq[e]
  for(e in nfrq) nfrq[e] /= sum

  sum = 0
  for(e in cfrq) sum += cfrq[e]
  for(e in cfrq) cfrq[e] /= sum

  sum = 0
  for(e in cnt) sum += cnt[e]
  for(e in cnt) cnt[e] /= sum


  print "#x <- y -- transition / rel. occurrance in map / probability"

  for(e in cnt)
    print e, cnt[e], icnt[e]


  print ""
#
#   print "#x <- y -- transition / cond. map transition frq. / [ cond. act. based frq.]"
#   for(e in cnt)
#     if((c = substr(e,3,1)) < 1.5)
#       print e, cnt[e] / cfrq[c], icnt[e] / icfrq[c]

  print ""
  print ""
  print ""
}

