pattern_bayes_gen.sh: Prune patterns with just a single occurence
[pachi.git] / tools / pattern_bayes_gen.sh
blobd37f7443252266646a2819efb0fc8d267d17c92c
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,spat_split_sizes |
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 next if ($counts{$_} < 2);
28 printf("%.3f %d %d %s\n", $p{$_}, $choices{$_}, $counts{$_}, $_);