#! /usr/bin/gawk -f # Last edited on 2020-12-27 06:25:24 by jstolfi BEGIN \ { # Writes to stdout a table with the mapping from pre-synaptic neuron indices # in Nilton Kamiji's 77000-neuron network to the corresponding # indices in a 10% subsampling of the same. # Each line has two entries "{ine_old} {ine_new}" where {ine_old} is # a neuron index (from 0) in the old network and {ine_new} # If {ine_old} is divisible by 10, the neuron will be included in the # sampled network, and {ine_new} will be {ine_old/10}. Otherwise # {ine_new} will be the new index of a retained neuron in the same # neuron group. abort = -1; nng = 8 # Number of neuron groups. nne_old = 77169 # Expected number of neurons in input network. nne_new = 7717 # Expected number of neurons in subsampled network. # Define the number {nne_per_ng_old[ing]} of neurons per group {ing} # in original network: split("20683 5834 21915 5479 4850 1065 14395 2948", nne_per_ng_old) ashift(nng, nne_per_ng_old) ine_start_old = 0; # Old index of first neuron in each group of old network. ine_start_new = 0; # New index of first neuron in each group of new network. for (ing = 0; ing < nng; ing++) { # Compute index range of group in old network: nne_ng_old = nne_per_ng_old[ing] ine_lim_old = ine_start_old + nne_ng_old # Old index of first neuron in next group. # Compute index range of group in new network: nne_ng_new = 0 for (ine_old = ine_start_old; ine_old < ine_lim_old; ine_old++) { if ((ine_old % 10) == 0) { nne_ng_new++; } } ine_lim_new = ine_start_new + nne_ng_new # New index of first neuron in next group. printf "group %d:", ing > "/dev/stderr" printf " old %d (%d..%d)", nne_ng_old, ine_start_old, ine_lim_old-1 > "/dev/stderr" printf " new %d (%d..%d)\n", nne_ng_new, ine_start_new, ine_lim_new-1 > "/dev/stderr" # Map old neurons in group to new ones: for (ine_old = ine_start_old; ine_old < ine_lim_old; ine_old++) { if ((ine_old % 10) == 0) { # Network is retained in sample: ine_new = ine_old/10 } else { # Neuron will be discarded: choose new substitute: ine_new = int(ine_old/10); if (ine_new < ine_start_new) { # Fix {ine_new} to be in the same group: ine_new = ine_new + nne_ng_new } } if ((ine_new < ine_start_new) || (ine_new >= ine_lim_new)) { printf " %d --> %d", ine_old, ine_new > "/dev/stderr" printf "** not in %d..%d\n", ine_start_new, ine_lim_new-1 > "/dev/stderr" } printf "%d %d\n", ine_old, ine_new; } ine_start_old = ine_lim_old ine_start_new = ine_lim_new } if (ine_start_old != nne_old) { prog_error("wrong {ine_start_old}") } if (ine_start_new != nne_new) { prog_error("wrong {ine_start_new}") } } function ashift(n,arr, i) { # Assumes {arr} is an array with elements indexed {1..n}. # Shifts them so that they are indexed {0..n-1}. for (i = 0; i < n; i++) { arr[i] = arr[i+1]; } delete arr[n]; } function data_error(msg,lin) { printf "%s:%d: ** %s\n", FILENAME, FNR, msg > "/dev/stderr"; if (lin != "") { printf " [[%s]]\n", lin > "/dev/stderr"; } abort = 1; exit(1) } function prog_error(msg) { printf "** program error: %s\n", msg > "/dev/stderr"; abort = 1; exit(1) }