# AssertionError with logcdf method for a Beta

**URL:** <https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128>\
**Category:** Questions\
**Tags:** theano\
**Created:** [April 18, 2019, 3:43pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128 "2019-04-18T15:43:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcolo](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@pcolo](https://discourse.pymc.io/u/pcolo)\
**Post date:** [April 18, 2019, 3:43pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/1 "2019-04-18T15:43:51Z")

</div>

Hi,

I’m having a AssertionError issue when using the logcdf method for a Beta, but strangely not for a Normal or a Uniform. From what I understand from other posts on AssertionErrors, this error appears when the incoming object in my deterministic distribution is of the wrong format. But I’m surprised it happens only for Betas. Here is my Code:

```
# Initialize random number generator
np.random.seed(123)

# True parameter values
alpha, sigma = 1, 1
beta = [1, 2.5]

# Size of dataset
size = 100

# Predictor variable
X1 = np.random.randn(size)
X2 = np.random.randn(size) * 0.2

# Simulate outcome variable
data = alpha + beta[0]*X1 + beta[1]*X2 + np.random.randn(size)*sigma
>
basic_model = pm.Model()

with basic_model:

    a = pm.Normal('a', mu=2, sd=2)
    b = pm.Normal('b', mu=2, sd=2)
    s = pm.HalfNormal('sigma', sd=0.01)

    m1 = np.exp(pm.Beta.dist(alpha=a, beta=b).logcdf(0.1))
  
    Y_obs = pm.Normal('Y_obs1', mu=m1, sd=s, observed=data)

map_estimate = pm.find_MAP(model=basic_model)
print map_estimate

with basic_model:
    # Sample from the posterior
      trace = pm.sample(draws=1000, chains=2, tune=500, discard_tuned_samples=True)

      pm.plot_posterior(trace)

```

and here is my error log :

> Traceback (most recent call last):  
> File “/Users/Colo/Google Drive/Projects/greghec/learning pymc2.py”, line 47, in   
> trace = pm.sample(tune=500)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 395, in sample  
> progressbar=progressbar, \*\*args)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 1515, in init\_nuts  
> step = pm.NUTS(potential=potential, model=model, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/hmc/nuts.py”, line 154, in **init**  
> super(NUTS, self). **init** (vars, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/hmc/base\_hmc.py”, line 75, in **init**  
> vars, blocked=blocked, model=model, dtype=dtype, \*\*theano\_kwargs  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/arraystep.py”, line 228, in **init**  
> vars, dtype=dtype, \*\*theano\_kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 710, in logp\_dlogp\_function  
> return ValueGradFunction(self.logpt, grad\_vars, extra\_vars, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 443, in **init**  
> grad = tt.grad(self.\_cost\_joined, self.\_vars\_joined)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 605, in grad  
> grad\_dict, wrt, cost\_name)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1371, in \_populate\_grad\_dict  
> rval = [access\_grad\_cache(elem) for elem in wrt]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1162, in access\_term\_cache  
> new\_output\_grads)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/scan\_module/scan\_op.py”, line 2222, in L\_op  
> assert (x[::-1][:-1].tag.test\_value.shape[0] == n)  
> AssertionError

Any ideas why this happens ? Thanks !

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 18, 2019, 8:16pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/2 "2019-04-18T20:16:36Z")

</div>

I think that the problem is that the beta distribution still doesn’t implement its mode, so there is no tag test value set properly. Try giving setting tag.test\_value of the beta RV to some value.

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 18, 2019, 8:25pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/3 "2019-04-18T20:25:19Z")

</div>

> [@pcolo](#):
>
> `m1 = np.exp(pm.Beta.dist(alpha=a, beta=b).logcdf(0.1))`

Another thing you could try is to replace `np` with `theano.tensor`. I’m not sure how well `np.exp` mixes with theano tensors.

---

<div class="post-metadata">

**Author:** ![pcolo](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@pcolo](https://discourse.pymc.io/u/pcolo)\
**Post date:** [April 30, 2019, 8:03am UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/4 "2019-04-30T08:03:42Z")

</div>

I works well with floats or arrays, but if I try

```
with basic_model:

    # Priors for unknown model parameters
    a = pm.HalfNormal('alpha', sd=10)
    b = 1.0
    sigma = pm.HalfNormal('sigma', sd=1)
    a.tag.test_value = pm.HalfNormal('alphat', sd=10)

    m1 = pm.Beta.dist(alpha=a, beta=b).logcdf(0.1)

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal('Y_obs', mu=m1, sd=sigma, observed=Y)

with basic_model:
    # Sample from the posterior
      trace = pm.sample(tune=500)
      pm.plot_posterior(trace)

```

I get :

> Traceback (most recent call last):  
> File “/Users/Colo/Google Drive/Projects/greghec/learning pymc2.py”, line 48, in   
> m1 = pm.Beta.dist(alpha=a, beta=b).logp(0.1)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/distributions/distribution.py”, line 52, in dist  
> dist. **init** (\*args, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/distributions/continuous.py”, line 1122, in **init**  
> self.mean = self.alpha / (self.alpha + self.beta)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/tensor/var.py”, line 128, in **add**  
> return theano.tensor.basic.add(self, other)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gof/op.py”, line 625, in **call**  
> storage\_map[ins] = [self.\_get\_test\_value(ins)]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gof/op.py”, line 562, in \_get\_test\_value  
> ret = v.type.filter(v.tag.test\_value)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/tensor/type.py”, line 87, in filter  
> 'Expected an array-like object, but found a Variable: ’  
> TypeError: For compute\_test\_value, one input test value does not have the requested type.
> 
> The error when converting the test value to that variable type:  
> Expected an array-like object, but found a Variable: maybe you are trying to call a function on a (possibly shared) variable instead of a numeric array?

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 30, 2019, 8:35am UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/5 "2019-04-30T08:35:53Z")

</div>

This is a different error. You’re setting `a`'s test value to an RV. That is not supported because test values must always be numbers or arrays.

---

<div class="post-metadata">

**Author:** ![pcolo](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@pcolo](https://discourse.pymc.io/u/pcolo)\
**Post date:** [April 30, 2019, 9:22am UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/6 "2019-04-30T09:22:07Z")

</div>

I see, thanks. So with this code :

```
basic_model = pm.Model()

with basic_model:

    # Priors for unknown model parameters
    a = pm.HalfNormal('alpha', sd=10)
    b = 1.0
    sigma = pm.HalfNormal('sigma', sd=1)
    a.tag.test_value = 1

    m1 = pm.Beta.dist(alpha=a, beta=b).logcdf(0.1)

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal('Y_obs', mu=m1, sd=sigma, observed=Y)

with basic_model:
      trace = pm.sample(tune=500)
      pm.plot_posterior(trace)

```

I get :

> Running on PyMC3 v3.6  
> Auto-assigning NUTS sampler…  
> Initializing NUTS using jitter+adapt\_diag…  
> Traceback (most recent call last):  
> File “/Users/Colo/Google Drive/Projects/greghec/learning pymc2.py”, line 62, in   
> trace = pm.sample(tune=500)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 395, in sample  
> progressbar=progressbar, \*\*args)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/sampling.py”, line 1515, in init\_nuts  
> step = pm.NUTS(potential=potential, model=model, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/hmc/nuts.py”, line 154, in **init**  
> super(NUTS, self). **init** (vars, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/hmc/base\_hmc.py”, line 75, in **init**  
> vars, blocked=blocked, model=model, dtype=dtype, \*\*theano\_kwargs  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/step\_methods/arraystep.py”, line 228, in **init**  
> vars, dtype=dtype, \*\*theano\_kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 710, in logp\_dlogp\_function  
> return ValueGradFunction(self.logpt, grad\_vars, extra\_vars, \*\*kwargs)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/pymc3/model.py”, line 443, in **init**  
> grad = tt.grad(self.\_cost\_joined, self.\_vars\_joined)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 605, in grad  
> grad\_dict, wrt, cost\_name)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1371, in \_populate\_grad\_dict  
> rval = [access\_grad\_cache(elem) for elem in wrt]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1021, in access\_term\_cache  
> output\_grads = [access\_grad\_cache(var) for var in node.outputs]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1326, in access\_grad\_cache  
> term = access\_term\_cache(node)[idx]  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/gradient.py”, line 1162, in access\_term\_cache  
> new\_output\_grads)  
> File “/Users/Colo/anaconda/lib/python2.7/site-packages/theano/scan\_module/scan\_op.py”, line 2222, in L\_op  
> assert (x[::-1][:-1].tag.test\_value.shape[0] == n)  
> AssertionError

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [April 30, 2019, 1:43pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/7 "2019-04-30T13:43:21Z")

</div>

I found some time to take a look at your code. It seems that the `logcdf` of the `Beta` distribution uses some `scan` operations to perform the computations. These seem to fail when either `alpha` or `beta` are RVs… I did not manage to find a workaround to the problem, sorry. Maybe @junpenglao can help with this.

---

<div class="post-metadata">

**Author:** ![junpenglao](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/junpenglao/32/8_2.png) [@junpenglao](https://discourse.pymc.io/u/junpenglao)\
**Post date:** [April 30, 2019, 6:15pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/8 "2019-04-30T18:15:59Z")

</div>

hmmm, seems the gradient is broken in the scan, but I dont see an easy fix as well - doesn’t seems trivial to fix unfortunately…

---

<div class="post-metadata">

**Author:** ![pcolo](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@pcolo](https://discourse.pymc.io/u/pcolo)\
**Post date:** [May 1, 2019, 6:14pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/9 "2019-05-01T18:14:13Z")

</div>

Thanks for having tried. Any idea if I can do without using

> pm.Beta.dist(alpha=a, beta=b).logcdf(0.1)

Could I implement a beta cdf by hand and plug it into a PyMC model ?

---

<div class="post-metadata">

**Author:** ![lucianopaz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/lucianopaz/32/2186_2.png) [@lucianopaz](https://discourse.pymc.io/u/lucianopaz)\
**Post date:** [May 1, 2019, 7:46pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/10 "2019-05-01T19:46:37Z")

</div>

Yes, if you’re up for the challenge. You could implement the Op and its gradient in theano and then use that.

---

<div class="post-metadata">

**Author:** ![chartl](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/chartl/32/1515_2.png) [@chartl](https://discourse.pymc.io/u/chartl)\
**Post date:** [May 1, 2019, 8:37pm UTC](https://discourse.pymc.io/t/assertionerror-with-logcdf-method-for-a-beta/3128/11 "2019-05-01T20:37:14Z")

</div>

To follow up: have a look at `pymc3.distributions.dist_math.incomplete_beta` which calls power-series and continued-fraction expansions for the incomplete beta function (beta CDF). As these are power expansions, they use `scan`; and one or both of these has a broken gradient.

You might unwrap the scan to some term of the approximation that is good enough; and this should deal with the problem.

Alternatively you can implement the gradients directly rather than using automatic differentiation - as power series are easily differentiated. Continued fractions are nastier, but sum-product formulas exist for their derivatives.
