code: def test_truncated_inference():
      # exercise 3.3, p 47, from David MacKay Information Theory book
      lam_true = 3
      lower = 0
      upper = 5
  
      rng = np.random.default_rng(260)
      x = rng.exponential(lam_true, size=5000)
      obs = x[
          np.where(~((x < lower) | (x > upper)))
      ]  # remove values outside range
  
      with Model() as m:
          lam = Exponential(
              "lam", lam=1 / 5
          )  # prior exponential with mean of 5
          Truncated(
              "x",
              dist=Exponential.dist(lam=1 / lam),
              lower=lower,
              upper=upper,
              observed=obs,
          )
  
          map = find_MAP(progressbar=False)
  
      assert np.isclose(map["lam"], lam_true, atol=0.1)
  
imports: import numpy
  import pytensor
  import pytensor.tensor
  import pytest
  import scipy
  from pytensor.tensor.random.basic import GeometricRV, NormalRV
  from pymc import Censored, Model, draw, find_MAP
  from pymc.distributions.continuous import Exponential, Gamma, TruncatedNormal, TruncatedNormalRV
  from pymc.distributions.shape_utils import change_dist_size
  from pymc.distributions.transforms import _default_transform
  from pymc.distributions.truncated import Truncated, TruncatedRV, _truncated
  from pymc.exceptions import TruncationError
  from pymc.logprob.abstract import _icdf
  from pymc.logprob.basic import logcdf, logp
  from pymc.logprob.transforms import IntervalTransform
  from pymc.logprob.utils import ParameterValueError
  from pymc.testing import assert_moment_is_expected
label_desc: Use image node_id 16 for calling a global function with example usage: test_truncated_inference() without return types