对于这个报错,总共有两种解决办法。
一、简单粗暴,更换包版本
主要原因在于gym在0.11后的版本删除prng的内容,因此需要更换到之前的版本。
pip install gym==0.10.5
二、修改代码,比想象的简单
在网上搜了下prng,发现prng是(pseudorandom number generator)伪随机数生成器的缩写。它通过特定算法生成一系列的数字,使得这一系列的数字看起来是随机的,但是实际是确定的,所以叫伪随机数。
源码如下,即生成长度为self.num_discrete_space的一维随机数数组,用于随机抽样。
def sample(self):
random_array = prng.np_random.rand(self.num_discrete_space)
因此可用np.random.RandomState()代替,同样是伪随机数生成器。
另外相同的功能,np.random.rand,np.random.random,np.random.random_sample都可以完成的,用它们代替都没问题。
import numpy as np
random_array = np.random.RandomState().rand(self.num_discrete_space)
random_array = np.random.rand(self.num_discrete_space)
random_array = np.random.random(self.num_discrete_space)
random_array = np.random.random_sample(self.num_discrete_space)