I am trying to use trace of one model as starting point for advi. I am using below model
with pm.Model(coords=coords) as neural_network_minibatch:
weights_in_macro1 = horseshoe("w_in_macro1", (num_macro,hidden_layer_macro1),sparsity, rng)
weights_in_macro2 = pm.Norma("test",0,1)
if retrain == True:
post_dict_mean = {}
post_dict_std = {}
for i in list(idata.posterior.data_vars.variables):
mean_var = np.squeeze(np.array(idata.posterior.data_vars[i].mean(axis=1)))
std_var = np.squeeze(np.array(idata.posterior.data_vars[i].std(axis=1))).flatten()
if len( mean_var.shape)==0:
mean_var = np.expand_dims(mean_var,axis=0)
std_var = np.expand_dims(std_var,axis=0)
else:
mean_var = mean_var
std_var = std_var
post_dict_mean[i] = mean_var
post_dict_std[i] = std_var
inference = pm.ADVI(random_seed=seed, start = post_dict_mean, start_sigma = post_dict_std)
where horshoe is defined as below
def horseshoe(name, shape, sparsity, rng):
D = shape[0]*shape[1]
D0 = sparsity*D
sig = pm.HalfNormal("sig"+name, 2.5, rng = rng)
tau = pm.HalfStudentT("tau"+name, 2, D0 / (D - D0) * sig / pm.math.sqrt(40000), rng = rng)
lamb = pm.HalfStudentT("lamb"+name, 5, shape=shape, rng = rng)
c2 = pm.InverseGamma("c2"+name, 1, 1, rng = rng)
lamb_ = lamb * pm.math.sqrt(c2 / (c2 + tau**2 * lamb**2))
z = pm. Normal('z'+name, mu=0, sigma=1, shape= shape, rng=rng)
beta = pm.Deterministic(name, z * tau * lamb_)
return beta
The idea of above code is use to train the model on some data and get trace and then use trace as starting point to retrain the model on new data. I am trying to use the above code with trace already given but I get the following error-
Cannot convert Type TensorType(float64, (1,)) (of Variable Elemwise{exp,no_inplace}.0) into Type TensorType(float64, ()). You can try to manually convert Elemwise{exp,no_inplace}.0 into a TensorType(float64, ()).
When I don’t use trace of horshoe variables then the code runs fine but when I try to use trace of horshoe then I get the above error for all the variables in horseshoe. Any suggestions @ricardoV94?