1

Most of my samples are repetitions, is there a way to give a weight to each sample that would represent how frequent it is so that the algorithm would only have to go through the unique set?

Or is there a way to manipulate the log(probability) function that I have defined to achieve this effect?

# simple example for data:
data = [(0,1,10), (0,2,10), (1,0,20), (1,0,20), (1,0,20), (0,0,49), (1,1,12)]

member_a = mc.Uniform('a', lower=-1.0, upper=0.0)
member_d = mc.Uniform('d', lower=-1.0, upper=0.0)

@mc.stochastic(observed=True, dtype=int)
def logLikelihood(value=data, a=member_a, d=member_d):
    ratesMatrix = np.zeros((2,2))
    ratesMatrix[0,0] = a
    ratesMatrix[0,1] = -a
    ratesMatrix[1,0] = -d
    ratesMatrix[1,1] = d

    r = []
    t = []
    for i in range(len(data)):
        r.append(ratesMatrix[int(value[i][0]), int(value[i][1])])
        t.append(value[i][2])
    r = np.array(r, dtype=np.float64)
    t = np.array(t, dtype=np.float64)

model = mc.MCMC([member_a,member_d,logLikelihood])
trace = model.sample(iter=5000)
desertnaut
  • 57,590
  • 26
  • 140
  • 166
user1581390
  • 1,900
  • 5
  • 25
  • 38
  • 1
    Here's [a related question](https://stackoverflow.com/q/47464075/570918), though it only got an answer for how to do this in PyStan. Not sure how this would translate in PyMC3. – merv Sep 19 '18 at 00:40

0 Answers0