docstr: Test for objax.random.truncated_normal.
docstr_tok: ["Test","for","objax.random.truncated_normal","."]
code: def test_truncated_normal(self):
      """Test for objax.random.truncated_normal."""
      objax.random.DEFAULT_GENERATOR.seed(123)
      self.helper_test_truncated_normal(
          shape=(5, 7), stddev=1.0, bound=2.0
      )
      self.helper_test_truncated_normal(
          shape=(4,), stddev=2.0, bound=4.0
      )
      self.helper_test_truncated_normal(shape=(), stddev=1.0, bound=4.0)
      value = np.array(objax.random.truncated_normal((1000, 100)))
      truncated_std = scipy.stats.truncnorm.std(
          a=-2, b=2, loc=0.0, scale=1
      )
      self.assertAlmostEqual(value.mean(), 0, delta=0.01)
      self.assertAlmostEqual(value.std(), truncated_std, delta=0.01)
      self.assertAlmostEqual(value.min(), -1.9, delta=0.1)
      self.assertAlmostEqual(value.max(), 1.9, delta=0.1)
      value = np.array(
          objax.random.truncated_normal(
              (1000, 100), stddev=2, lower=-3, upper=3
          )
      )
      truncated_std = scipy.stats.truncnorm.std(
          a=-3, b=3, loc=0.0, scale=2
      )
      self.assertAlmostEqual(value.mean(), 0, delta=0.02)
      self.assertAlmostEqual(value.std(), truncated_std, delta=0.01)
      self.assertAlmostEqual(value.min(), -5.9, delta=0.1)
      self.assertAlmostEqual(value.max(), 5.9, delta=0.1)
      value = np.array(
          objax.random.truncated_normal((1000, 100), stddev=1.5)
      )
      truncated_std = scipy.stats.truncnorm.std(
          a=-2, b=2, loc=0.0, scale=1.5
      )
      self.assertAlmostEqual(value.mean(), 0, delta=0.015)
      self.assertAlmostEqual(value.std(), truncated_std, delta=0.01)
      self.assertAlmostEqual(value.min(), -2.9, delta=0.1)
      self.assertAlmostEqual(value.max(), 2.9, delta=0.1)
  
file_path: objax/tests/testrandom.py
imports: import unittest
  import numpy
  import scipy.stats
  import objax
label_desc: Use image node_id 6 for calling the TestRandom obj's underlying member method code with example usage: obj.test_truncated_normal() without return types