Problem encountered while running the student-T process in example

I received an error when running the following code.
the error is “input operand has more dimensions than allowed by the axis remapping”

# set the seed
np.random.seed(1)

n = 100  # The number of data points
X = np.linspace(0, 10, n)[:, None]  # The inputs to the GP, they must be arranged as a column vector

# Define the true covariance function and its parameters
ℓ_true = 1.0
η_true = 3.0
cov_func = η_true**2 * pm.gp.cov.Matern52(1, ℓ_true)

# A mean function that is zero everywhere
mean_func = pm.gp.mean.Zero()

# The latent function values are one sample from a multivariate normal
# Note that we have to call `eval()` because PyMC3 built on top of Theano
tp_samples = pm.MvStudentT.dist(mu=mean_func(X), cov=cov_func(X), nu=3).random(size=8)

## Plot samples from TP prior
fig = plt.figure(figsize=(12, 5))
ax = fig.gca()
ax.plot(X.flatten(), tp_samples.T, lw=3, alpha=0.6)
ax.set_xlabel("X")
ax.set_ylabel("y")
ax.set_title("Samples from TP with DoF=3")


gp_samples = pm.MvNormal.dist(mu=mean_func(X).eval(), cov=cov_func(X).eval()).random(size=8)
fig = plt.figure(figsize=(12, 5))
ax = fig.gca()
ax.plot(X.flatten(), gp_samples.T, lw=3, alpha=0.6)
ax.set_xlabel("X")
ax.set_ylabel("y")
ax.set_title("Samples from GP");

The problem occurs when run this line of code

gp_samples = pm.MvNormal.dist(mu=mean_func(X).eval(), cov=cov_func(X).eval()).random(size=8)

I suggest you try in the new version of pymc (>4), where the dist.random(size=8) call is replaced by pm.draw(dist, 8)

If you see the same error or need to stick with pymc3, please share the whole error message.

Thanks,the whole error message is here.

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_33164/2673626657.py in <module>
     15 # The latent function values are one sample from a multivariate normal
     16 # Note that we have to call `eval()` because PyMC3 built on top of Theano
---> 17 tp_samples = pm.MvStudentT.dist(mu=mean_func(X), cov=cov_func(X), nu=3).random(size=8)
     18 
     19 ## Plot samples from TP prior

D:\program\anaconda\envs\pymc_env\lib\site-packages\pymc3\distributions\multivariate.py in random(self, point, size)
    395                 dist = MvNormal.dist(mu=np.zeros_like(mu), chol=chol, shape=self.shape)
    396 
--> 397             samples = dist.random(point, size)
    398 
    399         chi2_samples = np.random.chisquare(nu, size)

D:\program\anaconda\envs\pymc_env\lib\site-packages\pymc3\distributions\multivariate.py in random(self, point, size)
    274 
    275         mu = broadcast_dist_samples_to(to_shape=output_shape, samples=[mu], size=size)[0]
--> 276         param = np.broadcast_to(param, shape=output_shape + dist_shape[-1:])
    277 
    278         assert mu.shape == output_shape

<__array_function__ internals> in broadcast_to(*args, **kwargs)

D:\program\anaconda\envs\pymc_env\lib\site-packages\numpy\lib\stride_tricks.py in broadcast_to(array, shape, subok)
    409            [1, 2, 3]])
    410     """
--> 411     return _broadcast_to(array, shape, subok=subok, readonly=True)
    412 
    413 

D:\program\anaconda\envs\pymc_env\lib\site-packages\numpy\lib\stride_tricks.py in _broadcast_to(array, shape, subok, readonly)
    346                          'negative')
    347     extras = []
--> 348     it = np.nditer(
    349         (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
    350         op_flags=['readonly'], itershape=shape, order='C')

ValueError: input operand has more dimensions than allowed by the axis remapping

Either your random size is invalid, or there is a bug. This would very likely work out of the box in pymc>4.0, so I keep my suggestion of trying to update it.

OK,i’ll try it .Thank you very much.