[Scipy-svn] r3480 - in trunk/scipy/sandbox/montecarlo: . examples

scipy-svn at scipy.org scipy-svn at scipy.org
Thu Nov 1 07:57:04 EDT 2007


Author: edschofield
Date: 2007-11-01 06:56:59 -0500 (Thu, 01 Nov 2007)
New Revision: 3480

Added:
   trunk/scipy/sandbox/montecarlo/examples/
   trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed.py
   trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_2.py
   trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_3.py
   trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_4.py
Log:
Add examples (simple benchmarks) of using the montecarlo module


Added: trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed.py
===================================================================
--- trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed.py	2007-11-01 11:35:51 UTC (rev 3479)
+++ trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed.py	2007-11-01 11:56:59 UTC (rev 3480)
@@ -0,0 +1,20 @@
+"""Generates 10**8 random variates (strings) drawn from a discrete distribution
+on the sample space {'a', 'b', 'c'}.
+
+Run this script with timeit to get an idea of how the speed compares with
+sampling strings and/or integers over a much larger sample space.
+
+The point of the montecarlo module's compact 5-table sampler is for the time
+for simulating variates to be independent (or nearly so) of the size of the
+sample space.
+"""
+
+from scipy import *
+from scipy.sandbox import montecarlo
+
+d = {'a':0.2,'b':0.3,'c':0.5}
+
+s = montecarlo.dictsampler(d)
+for i in range(10):
+    temp = s.sample(10**7)
+

Added: trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_2.py
===================================================================
--- trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_2.py	2007-11-01 11:35:51 UTC (rev 3479)
+++ trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_2.py	2007-11-01 11:56:59 UTC (rev 3480)
@@ -0,0 +1,11 @@
+from scipy import *
+from scipy.sandbox import montecarlo
+
+k = [str(x) for x in range(10**6)]
+v = rand(10**6)
+d = dict(zip(k, v))
+
+s = montecarlo.dictsampler(d)
+for i in range(10):
+    temp = s.sample(10**7)
+

Added: trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_3.py
===================================================================
--- trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_3.py	2007-11-01 11:35:51 UTC (rev 3479)
+++ trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_3.py	2007-11-01 11:56:59 UTC (rev 3480)
@@ -0,0 +1,9 @@
+from scipy import *
+from scipy.sandbox import montecarlo
+
+v = rand(10**6)
+
+s = montecarlo.intsampler(v)
+for i in range(10):
+    temp = s.sample(10**7)
+

Added: trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_4.py
===================================================================
--- trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_4.py	2007-11-01 11:35:51 UTC (rev 3479)
+++ trunk/scipy/sandbox/montecarlo/examples/test_montecarlo_speed_4.py	2007-11-01 11:56:59 UTC (rev 3480)
@@ -0,0 +1,9 @@
+from scipy import *
+from scipy.sandbox import montecarlo
+
+v = rand(10)
+
+s = montecarlo.intsampler(v)
+for i in range(10):
+    temp = s.sample(10**7)
+




More information about the Scipy-svn mailing list