tools/sgf2gtp.py: Extended description, minor commandline option rename.
[pachi.git] / tools / pattern_bayes_gen.sh
blob1d00293c571f1a9358468d90f5b75451f9e11a96
1 #!/bin/sh
2 # pattern_bayes_gen: Generate pattern probability table from a SGF collection
3 # (or stdin GTP stream).
5 (if [ x"$1" = x"-" ]; then cat; else for i in "$@"; do echo $i >&2; tools/sgf2gtp.pl <$i; done; fi) |
6 ./pachi -d 0 -e patternscan competition,spat_split_sizes |
7 perl -nle '
8 BEGIN { use List::MoreUtils qw(uniq); }
10 s/^= // or next;
11 chomp;
12 my ($winner, $witness) = (/^\[(.*)\] \[(.*)\]$/);
14 sub parse { $_ = $_[0]; s/\) \(/),(/g; return split(/,/); }
16 for (uniq(parse($winner))) {
17 $choices{$_}++;
19 for (uniq(parse($witness))) {
20 $counts{$_}++;
23 END {
24 for (keys %counts) {
25 $p{$_} = $choices{$_} / $counts{$_};
27 for (sort { $counts{$a} <=> $counts{$b} } keys %p) {
28 next if ($counts{$_} < 2);
29 printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_);