annotate scripts/stat_graph.py @ 450:c1df23c98eb6

New script to create histograms for datasets (for the report)
author Arnaud Bergeron <abergeron@gmail.com>
date Mon, 10 May 2010 11:41:02 -0400
parents
children 227ebc0be7ae
rev   line source
450
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
1 import matplotlib
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
2 matplotlib.use('Agg')
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
3
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
4 from pylab import *
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
5 from scipy import stats
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
6 import numpy
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
7 from ift6266 import datasets
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
8
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
9 nistp_valid = stats.itemfreq(datasets.PNIST07().valid(10000000).next()[1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
10 nist_valid = stats.itemfreq(datasets.nist_all().valid(10000000).next()[1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
11 nist_test = stats.itemfreq(datasets.nist_all().test(10000000).next()[1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
12 print 'nistp_valid', sum(nistp_valid[:,1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
13 print 'nist_valid', sum(nist_valid[:,1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
14 print 'nist_test', sum(nist_test[:,1])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
15
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
16 xloc = numpy.arange(62)+0.5
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
17
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
18 labels = map(str, range(10)) + map(chr, range(65,91)) + map(chr, range(97,123))
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
19
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
20 def makegraph(data, fname, labels=labels, xloc=xloc, width=0.5):
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
21 figure(figsize=(8,6))
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
22 # clf()
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
23 bar(xloc, data, width=width)
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
24 xticks([])
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
25 for x, l in zip(xloc, labels):
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
26 text(x+width/2, -250, l, horizontalalignment='center', verticalalignment='baseline')
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
27 # xticks(xloc+width/2, labels, verticalalignment='bottom')
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
28 xlim(0, xloc[-1]+width*2)
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
29 ylim(0, 7000)
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
30
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
31 savefig(fname)
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
32
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
33
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
34 makegraph(nistp_valid[:,1], 'nistpvalidstats.png')
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
35 makegraph(nist_valid[:,1], 'nistvalidstats.png')
c1df23c98eb6 New script to create histograms for datasets (for the report)
Arnaud Bergeron <abergeron@gmail.com>
parents:
diff changeset
36 makegraph(nist_test[:,1], 'nistteststats.png')