That is how I have a successful model specified, with a unique state-cluster index and
y ~ x * c[state_cluster_indices]
In this instance, all state-cluster coefs use their own constants for the parameters of their sample distributions, or they all use a single mu and sigma for a global distribution as the parameters for their sample distributions. I would like to compare to a model with cluster-level distributions that feed the state-cluster distributions, i.e.
with numpyro.plate("clusters", n_clusters):
cluster_mus = numpyro.sample('cluster_mus ', dist.Normal(loc=np.array([0] * n_clusters),scale=np.ones(n_clusters)))
cluster_sigmas = numpyro.sample('cluster_sigmas', dist.HalfNormal(np.ones(n_clusters)))
with numpyro.plate("states", n_states):
state_cluster_coefs = numpyro.sample('state_cluster_coefs', dist.Normal(cluster_mus, cluster_sigmas))
...
y_hat =np.array(X).T * state_cluster_coefs [np.array(stateClusterList)].T
with numpyro.plate("data", len(X)):
numpyro.sample("estimates", dist.Normal(y_hat , 1.), obs=np.array(y))
Where stateClusterList is an array of tuples the length of X with (state, cluster). If I don’t do the transposes, I am getting an error that the broadcast shapes are incorrect, but that seems odd to me given that
y_hat =state_cluster_coefs [np.array(state_cluster_indices)] * np.array(X)
has worked for me where state_cluster_indicesis an array of single values in this case (custom index of state/cluster combination). The broadcast error says the Incompatible shapes for broadcasting: ((len(X), 2, n_clusters), (1, 1, len(X))). The transposes feel out of place, but can you explain why I would need the transposes? Trying
y_hat =np.array(X) * state_cluster_coefs [np.array(stateClusterList)]
or
y_hat =state_cluster_coefs [np.array(stateClusterList)]*np.array(X)
did not solve the issue, while I would have thought at least one of them would broadcast appropriately.