pattern_bayes_gen.sh: Sort patterns by occurence count by default
[pachi/t.git] / tools / pattern_bayes_gen.sh
blob9872b3b617a046468dfe454455a216e2a1d045c7
1 #!/bin/sh
2 # pattern_bayes_gen: Generate pattern probability table from a SGF collection
4 (for i in "$@"; do echo $i >&2; tools/sgf2gtp.pl <$i; done) |
5 ./pachi -d 0 -e patternscan competition |
6 perl -nle '
7 BEGIN { use List::MoreUtils qw(uniq); }
9 s/^= // or next;
10 chomp;
11 s/\) \(/),(/g;
12 @a = split(/,/);
14 $win = shift @a;
15 $choices{$win}++;
16 for (uniq @a) {
17 $counts{$_}++;
20 END {
21 for (keys %counts) {
22 $p{$_} = $choices{$_} / $counts{$_};
24 for (sort { $counts{$b} <=> $counts{$a} } keys %p) {
25 printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_);