Sorry, I’m struggling trying to understand scan. I’m getting this error: ValueError: When compiling the inner function of scan the following error has been encountered: The initial state (outputs_info in scan nomenclature) of variable IncSubtensor{Set;:int64:}.0 (argument number 0) has dtype int64, while the result of the inner function (fn) has dtype float64. This can happen if the inner function of scan results in an upcast or downcast.
I’m not 100% sure how to do my initial values. I’m just trying to set the initial value to 0 and then run that for loop. Lmk if you’d prefer this as a separate question since it’s a different thing.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import pymc as pm
import aesara
import aesara.tensor as at
tweet_model = pm.Model()
with tweet_model:
alpha = pm.Uniform("alpha", lower=-30, upper=700)
beta = pm.LogNormal("beta", mu=0, sigma=2)
delta = pm.Beta("delta", alpha=5, beta=1)
k = at.iscalar("k")
v = at.iscalar("v")
outputs_info = at.as_tensor_variable(np.asarray(0, first_index['index']))
result, updates = aesara.scan(fn=lambda prior_result: delta*prior_result * data.gamma(),
outputs_info=outputs_info,
n_steps=k)
virality = aesara.function(inputs=[v,k], outputs=result, updates=updates)
shares = alpha*(pm.math.exp(beta*virality) - 1/(virality+1))
Y_obs = pm.Normal("Y_obs", mu=shares, sigma=1, observed=Y)
trace_g = pm.sample(2000, tune=1000, cores=2)