docstr: Xavier Glorot truncated normal.
docstr_tok: ["Xavier","Glorot","truncated","normal","."]
code: def test_xavier_truncated_normal(self):
      """Xavier Glorot truncated normal."""
      for s in (
          (4, 3, 2, 10000),
          (12, 2, 10000),
          (24, 10000),
          (32, 10000),
      ):
          for gain in (1, 2):
              for a, b in ((-100, 100), (-2, 2), (-0.1, 0.1)):
                  objax.random.DEFAULT_GENERATOR.seed(
                      123
                  )  # TODO: remove once JAX#4548 is released.
                  init = np.asarray(
                      objax.nn.init.xavier_truncated_normal(
                          s, lower=a, upper=b, gain=gain
                      )
                  )
                  std = np.sqrt(2 / (np.prod(s[:-1]) + s[-1]))
                  truncated_std = scipy.stats.truncnorm.std(
                      a=a, b=b, loc=0.0, scale=1
                  )
                  self.assertGreaterEqual(
                      init.min() + 1e-6,
                      a * std * gain / truncated_std,
                      msg=(s, gain, (a, b)),
                  )
                  self.assertLessEqual(
                      init.max() - 1e-6,
                      b * std * gain / truncated_std,
                      msg=(s, gain, (a, b)),
                  )
                  self.assertAlmostEqual(
                      init.mean(), 0, delta=1e-2, msg=(s, gain, (a, b))
                  )
                  self.assertAlmostEqual(
                      init.std(),
                      std * gain,
                      delta=1e-2,
                      msg=(s, gain, (a, b)),
                  )
  
file_path: objax/tests/nn_init.py
imports: import unittest
  import numpy
  import scipy.stats
  import objax
label_desc: Use image node_id 5 for calling the TestNNInit obj's underlying member method code with example usage: obj.test_xavier_truncated_normal() without return types