56 lines
874 B
Bash
Executable File
56 lines
874 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# calculate fprob from indices and fprob matrix
|
|
# output: average feature's feature probability and average non-feature's feature probability
|
|
|
|
bidx=$1
|
|
fprob=$2
|
|
n=$3
|
|
|
|
script=$(cat - <<EOS
|
|
BEGIN {
|
|
type = 0; # 0: bidx, 1: fprob
|
|
|
|
nprob = 0;
|
|
nprob_max = 0;
|
|
pprob = 0;
|
|
pprob_max = 0;
|
|
}
|
|
|
|
{
|
|
if (type == 0) {
|
|
split("", feats);
|
|
|
|
for (i = 1; i <= NF; ++i) {
|
|
feats[i] = \$i;
|
|
}
|
|
|
|
type = 1;
|
|
} else if (type == 1) {
|
|
sum = 0;
|
|
for (i = 1; i <= NF; ++i) {
|
|
sum += \$i;
|
|
}
|
|
|
|
lprob = 0;
|
|
for (i = 1; i <= length(feats); ++i) {
|
|
lprob += \$(feats[i]+1);
|
|
}
|
|
|
|
nprob += sum-lprob;
|
|
pprob += lprob;
|
|
|
|
nprob_max += NF-length(feats)
|
|
pprob_max += length(feats)
|
|
|
|
type = 0;
|
|
}
|
|
}
|
|
|
|
END {
|
|
print pprob/pprob_max, nprob/nprob_max;
|
|
}
|
|
EOS
|
|
)
|
|
paste -d "\n" $bidx $fprob | head -n$((n*2)) | awk "$script"
|