Probability pattern ditionary: Expect patterns ordered from least used to most used
[pachi.git] / tools / pattern_bayes_gen.sh
blobdfff880d48a62349d34ed6e4142c1295818346a7
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{$a} <=> $counts{$b} } keys %p) {
25 printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_);