What are the returned values of find_MAP in pymc3 ?
It seems that pymc3.Normal and pymc3.Uniform variables are not considered the same: for pymc3.Normal variables, f
By default, pymc3 transforms some variables with bounded support to the set of real numbers. The enables a variety of operations which would otherwise choke when given bounded distributions (e.g. some methods of optimizations and sampling). When this automatic transformation is applied, the random variable that you added to the model becomes a child of the transformed variable. This transformed variable is added to the model with [var]_[transform]_
as the name.
The default transformation for a uniform random variable is called the "interval transformation" and the new name of this variable is [name]_interval_
. The MAP estimate is the found by optimizing all of the parameters to maximize the posterior probability. We only need to optimize the transformed variable, since this fully determines the value of the variable you originally added to the model. pm.find_MAP()
returns only the variables being optimized, not the original variables. Notice that a2
is also not returned, since it is fully determined by a0
and a1
.
The code that pymc3 uses for the interval transformation [^1] is
def forward(self, x):
a, b = self.a, self.b
r = T.log((x - a) / (b - x))
return r
Where a
is the lower bound, b
is the upper bound, and x
is the variable being transformed. Using this map, values which are very close to the lower bound have transformed values approaching negative infinity, and values very close to the upper bound approach positive infinity.
Knowing the bounds, we can convert back from the real line to the bounded interval. The code that pymc3 uses for this is
def backward(self, x):
a, b = self.a, self.b
r = (b - a) * T.exp(x) / (1 + T.exp(x)) + a
return r
If you apply this backwards transformation yourself, you can recover a0
itself:
(5 - 0) * exp(-1.0812715249577414) / (1 + exp(-1.0812715249577414)) + 0 = 1.26632733897
Other transformations automatically applied include the log transform (for variables bounded on one side), and the stick-breaking transform (for variables which sum to 1).
[^1] As of commit 87cdd712c86321121c2ed3150764f3d847f5083c.