summaryrefslogtreecommitdiff
path: root/gnuradio-runtime/python
diff options
context:
space:
mode:
authorStefan <stefan.wunsch@student.kit.edu>2015-09-04 11:22:13 +0200
committerStefan <stefan.wunsch@student.kit.edu>2015-09-04 11:22:13 +0200
commit44fb1cb0482fa778c8e652164551711818db5476 (patch)
tree7de348490303418f1212caebca3d68ef602f1a89 /gnuradio-runtime/python
parent190ebe6caa1b92172fba691285b1bdb684e6ae83 (diff)
redo qa_random without print statements and scipy; add stand-alone evaluation script in gnuradio-runtime/apps
Diffstat (limited to 'gnuradio-runtime/python')
-rw-r--r--gnuradio-runtime/python/gnuradio/gr/qa_random.py109
1 files changed, 9 insertions, 100 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
index c0d9a7f34c..83fee56181 100644
--- a/gnuradio-runtime/python/gnuradio/gr/qa_random.py
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2006,2007,2010 Free Software Foundation, Inc.
+# Copyright 2006,2007,2010,2015 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -22,133 +22,42 @@
from gnuradio import gr, gr_unittest
import numpy as np
-from scipy.stats import norm, laplace, rayleigh
-#from time import sleep
class test_random(gr_unittest.TestCase):
- num_tests = 10000
+ # NOTE: For tests on the output distribution of the random numbers, see gnuradio-runtime/apps/evaluation_random_numbers.py.
- # Disclaimer
- def test_0(self):
- print 'NOTE: Following tests are not statistically significant!'
- print 'Realisations per test:',self.num_tests
- self.assertEqual(1,1)
-
- # Check for range [0,1) of uniform distributed random numbers and print minimal and maximal value
+ # Check for range [0,1) of uniform distributed random numbers
def test_1(self):
- print '# TEST 1'
- print 'Uniform distributed numbers: Range'
- values = np.zeros(self.num_tests)
+ num_tests = 10000
+ values = np.zeros(num_tests)
rndm = gr.random()
- for k in range(self.num_tests):
+ for k in range(num_tests):
values[k] = rndm.ran1()
for value in values:
self.assertLess(value, 1)
self.assertGreaterEqual(value, 0)
- print 'Uniform random numbers (num/min/max):', self.num_tests, min(values), max(values)
- # Check uniformly distributed random numbers on uniformity (without assert, only printing)
+ # Check reseed method (init with time and seed as fix number)
def test_2(self):
- print '# TEST 2'
- print 'Uniform random numbers: Distribution'
- num_bins = 11
- values = np.zeros(self.num_tests)
- rndm = gr.random()
- for k in range(self.num_tests):
- values[k] = rndm.ran1()
- bins = np.linspace(0,1,num_bins) # These are the bin edges!
- hist = np.histogram(values,bins)
- print 'Lower edge bin / upper edge bin / count / expected'
- for k in range(len(hist[0])):
- print hist[1][k], hist[1][k+1], hist[0][k], float(self.num_tests)/(num_bins-1)
-
- # Check distribution of normally (gaussian, mean=0, variance=1) distributed random numbers (no assert)
- def test_3(self):
- print '# TEST 3'
- print 'Normal random numbers: Distribution'
- num_bins = 11
- hist_range = [-5,5]
- values = np.zeros(self.num_tests)
- rndm = gr.random()
- for k in range(self.num_tests):
- values[k] = rndm.gasdev()
- bins = np.linspace(hist_range[0],hist_range[1],num_bins)
- hist = np.histogram(values,bins)
- print 'Lower edge bin / upper edge bin / count / expected'
- for k in range(len(hist[0])):
- print hist[1][k], hist[1][k+1], hist[0][k], float(norm.cdf(hist[1][k+1])-norm.cdf(hist[1][k]))*self.num_tests
-
- # Check distribution of laplacian (mean=0, variance=1) distributed random numbers (no assert)
- def test_4(self):
- print '# TEST 4'
- print 'Laplacian random numbers: Distribution'
- num_bins = 11
- hist_range = [-5,5]
- values = np.zeros(self.num_tests)
- rndm = gr.random()
- for k in range(self.num_tests):
- values[k] = rndm.laplacian()
- bins = np.linspace(hist_range[0],hist_range[1],num_bins)
- hist = np.histogram(values,bins)
- print 'Lower edge bin / upper edge bin / count / expected'
- for k in range(len(hist[0])):
- print hist[1][k], hist[1][k+1], hist[0][k], float(laplace.cdf(hist[1][k+1])-laplace.cdf(hist[1][k]))*self.num_tests
-
- # Check distribution of laplacian (mean=0, variance=1) distributed random numbers (no assert)
- def test_5(self):
- print '# TEST 5'
- print 'Rayleigh random numbers: Distribution'
- num_bins = 11
- hist_range = [0,10]
- values = np.zeros(self.num_tests)
- rndm = gr.random()
- for k in range(self.num_tests):
- values[k] = rndm.rayleigh()
- bins = np.linspace(hist_range[0],hist_range[1],num_bins)
- hist = np.histogram(values,bins)
- print 'Lower edge bin / upper edge bin / count / expected'
- for k in range(len(hist[0])):
- print hist[1][k], hist[1][k+1], hist[0][k], float(rayleigh.cdf(hist[1][k+1])-rayleigh.cdf(hist[1][k]))*self.num_tests
-
- # Check seeds (init with time and seed as fix number)
- def test_6(self):
- print '# TEST 6'
num = 5
- print 'Some random numbers in [0,1), should change every run:'
- rndm0 = gr.random(0); # init with time
- # NOTE: the sleep increases the executiont time massively, remove assert for convenience
- #sleep(1)
- #rndm1 = gr.random(0); # init with fix seed
- for k in range(num):
- x = rndm0.ran1();
- print x,
- # y = rndm1.ran1();
- # print x, '!=', y
- # self.assertNotEqual(x,y)
- print ' '
-
- print 'Some random numbers in [0,1) (seed two instances), should be the same every run:'
rndm0 = gr.random(42); # init with time
rndm1 = gr.random(42); # init with fix seed
for k in range(num):
x = rndm0.ran1();
y = rndm1.ran1();
- print x, '=', y
self.assertEqual(x,y)
- print 'Some random numbers in [0,1) (reseed one instance), should be the same every run:'
x = np.zeros(num)
y = np.zeros(num)
- rndm0 = gr.random(42); # init with time
+ rndm0 = gr.random(42); # init with fix seed 1
for k in range(num):
x[k] = rndm0.ran1();
- rndm1.reseed(43); # init with fix seed
+ rndm1.reseed(43); # init with fix seed 2
for k in range(num):
y[k] = rndm0.ran1();
for k in range(num):
- print x[k], '!=', y[k]
self.assertNotEqual(x[k],y[k])
if __name__ == '__main__':