[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/13: include random.h in swig; add qa_ran
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/13: include random.h in swig; add qa_random testcase |
Date: |
Sun, 6 Sep 2015 01:19:37 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch master
in repository gnuradio.
commit 1206251231696359270a260508551e044f3af33a
Author: Stefan <address@hidden>
Date: Tue Sep 1 12:46:09 2015 +0200
include random.h in swig; add qa_random testcase
---
gnuradio-runtime/python/gnuradio/gr/qa_random.py | 99 ++++++++++++++++++++++++
gnuradio-runtime/swig/runtime_swig.i | 2 +
2 files changed, 101 insertions(+)
diff --git a/gnuradio-runtime/python/gnuradio/gr/qa_random.py
b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
new file mode 100644
index 0000000..39d75f3
--- /dev/null
+++ b/gnuradio-runtime/python/gnuradio/gr/qa_random.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+#
+# Copyright 2006,2007,2010 Free Software Foundation, Inc.
+#
+# This file is part of GNU Radio
+#
+# GNU Radio is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# GNU Radio is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+#
+
+from gnuradio import gr, gr_unittest
+import numpy as np
+from scipy.stats import norm, laplace
+
+class test_random(gr_unittest.TestCase):
+
+ # Disclaimer
+ def test_0(self):
+ print 'NOTE: Following tests are not statistically significant! Check
out fulltest_random.py for full testing.'
+ self.assertEqual(1,1)
+
+ # Check for range [0,1) of uniform distributed random numbers and print
minimal and maximal value
+ def test_1(self):
+ print '# TEST 1'
+ print 'Uniform distributed numbers: Range'
+ num_tests = 10000
+ values = np.zeros(num_tests)
+ rndm = gr.random()
+ 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):', num_tests, min(values),
max(values)
+
+ # Check uniformly distributed random numbers on uniformity (without
assert, only printing)
+ def test_2(self):
+ print '# TEST 2'
+ print 'Uniform random numbers: Distribution'
+ num_tests = 10000
+ num_bins = 11
+ values = np.zeros(num_tests)
+ rndm = gr.random()
+ for k in range(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(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_tests = 10000
+ num_bins = 11
+ hist_range = [-5,5]
+ values = np.zeros(num_tests)
+ rndm = gr.random()
+ for k in range(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]))*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_tests = 100000
+ num_bins = 11
+ hist_range = [-5,5]
+ values = np.zeros(num_tests)
+ rndm = gr.random()
+ for k in range(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]))*num_tests
+
+if __name__ == '__main__':
+ gr_unittest.run(test_random, "test_random.xml")
diff --git a/gnuradio-runtime/swig/runtime_swig.i
b/gnuradio-runtime/swig/runtime_swig.i
index d4b55f1..15cfebd 100644
--- a/gnuradio-runtime/swig/runtime_swig.i
+++ b/gnuradio-runtime/swig/runtime_swig.i
@@ -60,6 +60,7 @@
#include <gnuradio/top_block.h>
#include <gnuradio/logger.h>
#include <gnuradio/math.h>
+#include <gnuradio/random.h>
%}
%constant int sizeof_char = sizeof(char);
@@ -95,3 +96,4 @@
%include "gr_ctrlport.i"
%include "gnuradio/math.h"
+%include "gnuradio/random.h"
- [Commit-gnuradio] [gnuradio] branch master updated (80d5255 -> 45c0fee), git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 06/13: remove fixed fixme, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 01/13: include random.h in swig; add qa_random testcase,
git <=
- [Commit-gnuradio] [gnuradio] 11/13: Merge branch 'maint', git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 04/13: add test-case for reseed feature, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 08/13: add current year to licence header, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 12/13: Merge remote-tracking branch 'stwunsch/newRandom', git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 13/13: Merge remote-tracking branch 'drmpeg/gr-dtv-dvbt-rx', git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 03/13: add boost.random as random number generator, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 02/13: fix wrong laplacian random numbers and add testcase, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 05/13: remove deprecated RANDOM_MAX global and adjust test-cases, git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 10/13: Add DVB-T receiver updated files., git, 2015/09/05
- [Commit-gnuradio] [gnuradio] 07/13: redo qa_random without print statements and scipy; add stand-alone evaluation script in gnuradio-runtime/apps, git, 2015/09/05