Patternscan: Change output format, clearly identify winner and witnesses
[pachi/nmclean.git] / tools / pattern_bayes_gen.sh
blob8caea3c592c2bc80799b23053bea9ecbd32a103f
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 my ($winner, $witness) = (/^\[(.*)\] \[(.*)\]$/);
13 sub parse { $_ = $_[0]; s/\) \(/),(/g; return split(/,/); }
15 for (uniq(parse($winner))) {
16 $choices{$_}++;
18 for (uniq(parse($witness))) {
19 $counts{$_}++;
22 END {
23 for (keys %counts) {
24 $p{$_} = $choices{$_} / $counts{$_};
26 for (sort { $counts{$a} <=> $counts{$b} } keys %p) {
27 printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_);