Skip to content
Snippets Groups Projects

WIP: Resolve "Toy dataset"

Closed Frank Sauerburger requested to merge 7-toy-dataset into master
2 files
+ 115
1
Compare changes
  • Side-by-side
  • Inline
Files
2
import unittest
import numpy as np
from nnfwtbn.toydata import rand
from nnfwtbn.toydata import rand, ipdf_gluon, ipdf_quark
class ToyDataTestBase(unittest.TestCase):
@@ -51,3 +51,81 @@ class ToyDataTestBase(unittest.TestCase):
self.assertAlmostEqual(a, 0.90141859)
self.assertAlmostEqual(b, 0.85225178)
self.assertAlmostEqual(c, 0.93632300)
def test_pdf_gluon_pos(self):
"""
Check that the pdf is always positive.
"""
N = 100
for i in range(N):
self.assertTrue(ipdf_gluon(i / N, 1 / N) >= 0)
def test_pdf_gluon_normalized(self):
"""
Check that the pdf is normalized.
"""
self.assertAlmostEqual(ipdf_gluon(0, 1), 1)
def test_pdf_gluon_max(self):
"""
Check that the pdf has it's maximum at x=0.
"""
N = 100
bins = np.empty(N)
for i in range(N):
bins[i] = ipdf_gluon(i / N, 1 / N)
self.assertEqual(np.argmax(bins), 0)
def test_pdf_gluon_at_1(self):
"""
Check that the pdf vanishes at x=1.
"""
d = 1e-4
self.assertAlmostEqual(ipdf_gluon(1 - d, d), 0)
def test_pdf_quark_pos(self):
"""
Check that the pdf is always positive.
"""
N = 100
for i in range(N):
self.assertTrue(ipdf_quark(i / N, 1 / N) >= 0)
def test_pdf_quark_normalized(self):
"""
Check that the pdf is normalized.
"""
self.assertAlmostEqual(ipdf_quark(0, 1), 1)
def test_pdf_quark_max(self):
"""
Check that the pdf has it's maximum at x=0.
"""
N = 100
bins = np.empty(N)
for i in range(N):
bins[i] = ipdf_quark(i / N, 1 / N)
self.assertEqual(np.argmax(bins), 0)
def test_pdf_quark_at_1(self):
"""
Check that the pdf vanishes at x=1.
"""
d = 1e-9
self.assertAlmostEqual(ipdf_quark(1 - d, d), 0)
def test_pdf_quark_peak(self):
"""
Check that there is a peak at x=0.5.
"""
d = 1e-4
self.assertGreater(
ipdf_quark(0.5, d),
ipdf_quark(0.3, d)
)
Loading