0

I am trying to use pymc3.DiscreteUniform as an index for a numpy 1D array

This worked with pymc (v2) but I am transitioning to pymc3 and code that worked under pymc don't work under pymc3.

import pymc3 as pm
d0 = pm.DiscreteUniform('d0', lower=0, upper=nDens - 1, testval = nDens//2)
pred = np.zeros(len(box.match), np.float64)
for iwvl, amatch in enumerate(box.match):
    pred[iwvl] += amatch['intensitySum'][d0]

I get the following error message: IndexError: only integers, slices (:), ellipsis (...), numpy.newaxis (None) and integer or boolean arrays are valid indices

Ken Dere
  • 1
  • 1
  • 1

1 Answers1

0

I have found something that works but in involves going into theano and theano.tensor. ` import pymc3 as pm with pm.Model() as model: em0 = pm.Normal('em0', mu=emLog, sigma=0.2) d0 = pm.DiscreteUniform('d0', lower = 0, upper = nDens - 1, testval = Dindex) boundNormal = pm.Bound(pm.Normal, lower=0.0) wght = boundNormal('wght', mu=0.2, sigma=0.1)

    pred = np.zeros((nDens, len(box.match)), np.float64)
    for iwvl, amatch in enumerate(box.match):
        pred[0:,iwvl] += amatch['intensitySum']
    xpred = theano.shared(pred, name='p0')
    idx = tensor.as_tensor_variable(d0)
    predicted = xpred[idx]*10.**em0
    nObs = len(box.match)
    intensity = np.zeros(nObs, np.float64)
    for iwvl in range(nObs):
        intensity[iwvl] = box.match[iwvl]['obsIntensity']
    sigma = 0.2
    Y_obs = pm.Normal('Y_obs', mu=predicted, sigma=wght*intensity,    observed=intensity)
    trace = pm.sample(tune=20000, draws=100000, target_accept=0.85)`

and then you can work with the trace it is even possible to make sigma as pm variable

Ken Dere
  • 1
  • 1
  • 1