# Mirrored and bounded HalfNormal Distribution

Dear all,

Is there any way to generate a HalfNormal distribution within the bounds in pymc3? My bounds are [0 10] and distribution should be increasing toward 10 like an mirror image of typical HalfNormal distribution.

Just translate and reflect

``````BoundedHalfNormal = pm.Bound(pm.Normal, 0., 10.)
xlat = BoundedHalfNormal('x_lat', 0., 1.)
x = pm.Deterministic('x', 10. - xlat)
``````
3 Likes

``````import pymc3 as pm
model=pm.Model()

with model:
BoundedHalfNormal = pm.Bound(pm.Normal, 0., 10.)
xlat = BoundedHalfNormal('x_lat', 0., 1.)
x = pm.Deterministic('x', 10. - xlat)

with model:
trace=pm.sample(500)
``````

But getting the error:

``````  File "<ipython-input-6-3144eb9ad758>", line 6, in <module>
xlat = BoundedHalfNormal('x_lat', 0., 1.)

File "C:\Users\CT\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\distributions\bound.py", line 219, in __call__
self.lower, self.upper, *args, **kwargs)

File "C:\Users\CT\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\distributions\distribution.py", line 41, in __new__
dist = cls.dist(*args, **kwargs)

File "C:\Users\CT\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\distributions\distribution.py", line 52, in dist
dist.__init__(*args, **kwargs)

File "C:\Users\CT\AppData\Local\Continuum\anaconda3\lib\site-packages\pymc3\distributions\bound.py", line 155, in __init__
transform=transform, default=default, *args, **kwargs)

TypeError: __init__() got multiple values for argument 'distribution'``````

See https://docs.pymc.io/api/bounds.html ; but you have to use keyword arguments

``````with pm.Model() as model:
BHN = pm.Bound(pm.Normal, lower=0., upper=10.)
u = BHN('u', mu=0., sd=2.)
x = pm.Deterministic('x', 10. - u)
trace = pm.sample_prior_predictive(25000)
``````
1 Like