I am trying to define the following distribution:
P(t) = exp(R*t)
Where R is 2x2 rates matrix that I want to solve for with the data (the sum of each of its rows must be 0). This is the log likelihood function, and some data:
import numpy as np
# The data is in the format: (row index, column index, t)
data = {(0,1,10), (1,0,20), (0,0,49), (1,1,12)}
def logp(values, ratesMatrix):
r = []
t = []
for i in range(len(data)):
r.append(ratesMatrix[values[i][0], values[i][1]])
t.append(values[i][2])
r = np.array(r, dtype=np.float64)
t = np.array(t, dtype=np.float64)
# log( prod( exp(r*t) ) )
# == sum( log( exp(r*t) ) )
# == sum( r*t )
return np.sum(r*t)
How do I define the ratesMatrix variable as a stochastic 2x2 matrix where, each entry in the diagonal is between -1 and 0 (equally likely), and outside the diagonal between 0 and 1 (equally likely), such that the sum of each row is 0?