Hi,
Newbie here. I’m trying to make a custom spherical distribution which takes in pairs of longitudes and latitudes in my model. But I’m stuck at this testval argument here while initializing a model.
My functions look like this:
def fisher_distribution_PdA(k, theta):
PdA = k*np.exp(k*np.cos(theta/180*np.pi))/(2*np.pi*(np.exp(k)-np.exp(-k)))
return PdA
def vmf_random(lon_lat, k):
lon_lat_int = ipmag.fishrot(k = k, n = 1, dec = lon_lat[0], inc = lon_lat[1], di_block = True)
lon_lat = np.array([lon_lat_int[0][0], lon_lat_int[0][1]])
return lon_lat
def vmf_logp(lon_lat, k, x):
if x[1] < -90. or x[1] > 90.:
raise ZeroProbability
return -np.inf
if k < eps:
return np.log(1. / 4. / np.pi)
angle = pmag.angle(x, lon_lat)
logp = np.log(fisher_distribution_PdA(k, angle))
return logp
class VMF(Continuous):
def __init__(self, lon_lat, k, mv = True, *args, **kwargs):
super(VMF, self).__init__(*args, **kwargs)
self._lon_lat = lon_lat
self._k = k
self.mode = 0
def random(self):
lon_lat = self._lon_lat
k = self._k
return vmf_random(lon_lat, k)
def logp(self, value):
print(value)
lon_lat = self._lon_lat
k = self._k
logp = vmf_logp(lon_lat, k, value)
return logp
with pm.Model() as model:
vmf = VMF('vmf', lon_lat = np.array([0, 90]), k = 10, shape = 2, testval = np.array([1,1]), observed = False)
the print out of value is always TensorConstant{0.0} instead of the test array.
Similar code worked in pymc2:
VMF('start', lon_lat=(lon, lat), k=k, value=(0.,0.), observed=False)
I am new to this and would love to have some guidance, thanks!
I found my issue similar to this: How to customize von-mises-fisher distribution in PyMC3?.
However, in my case I want my value to be something like a location coordinates, [longitude, latitude] instead of a value. How should I do that?