如何解决获取 ValueError:使用 binom.rvs() 时参数中的域错误
我是新来的,我的第一个问题。使用此代码片段更新 SEIR 模型时
def reset_initialize_simulation(self):
if self.quarantine_mode == 'isolation':
self.S = np.round(self.population * self.kappa).astype(int)
self.R = np.round(self.population * (1-self.kappa)).astype(int)
else:
self.S = self.population.copy()
self.R = np.zeros(self.population.shape,dtype=int)
self.E = np.zeros(self.population.shape,dtype=int)
self.I = np.zeros(self.population.shape,dtype=int)
self.D = np.zeros(self.population.shape,dtype=int)
self.observables = {}
self.observables['t'] = []
if 'epi_subpopulations' in self.save_observables:
self.observables['S'] = []
self.observables['E'] = []
self.observables['I'] = []
self.observables['R'] = []
self.observables['D'] = []
if 'epi_total' in self.save_observables:
self.observables['S_total'] = []
self.observables['E_total'] = []
self.observables['I_total'] = []
self.observables['R_total'] = []
self.observables['D_total'] = []
if 'arrival_times' in self.save_observables:
M = self.population.shape[0] # number of subpopulations
self.observables['T_arrival'] = np.ones(M) * self.T_max
self._seed_infection()
我收到此错误
/usr/local/lib/python3.7/dist-packages/scipy/stats/_distn_infrastructure.py in rvs(self,*args,**kwds)
964 cond = logical_and(self._argcheck(*args),(scale >= 0))
965 if not np.all(cond):
--> 966 raise ValueError("参数中的域错误。") 967 第 968 章
我真的不明白为什么要这样称呼。 scipy中该函数的代码部分如下:
def rvs(self,**kwds):
"""
Random variates of given type.
Parameters
----------
arg1,arg2,arg3,... : array_like
The shape parameter(s) for the distribution (see docstring of the
instance object for more information).
loc : array_like,optional
Location parameter (default=0).
scale : array_like,optional
Scale parameter (default=1).
size : int or tuple of ints,optional
Defining number of random variates (default is 1).
random_state : None or int or ``np.random.RandomState`` instance,optional
If int or RandomState,use it for drawing the random variates.
If None,rely on ``self.random_state``.
Default is None.
Returns
-------
rvs : ndarray or scalar
Random variates of given `size`.
"""
discrete = kwds.pop('discrete',None)
rndm = kwds.pop('random_state',None)
args,loc,scale,size = self._parse_args_rvs(*args,**kwds)
cond = logical_and(self._argcheck(*args),(scale >= 0))
# if not np.all(cond):
# raise ValueError("Domain error in arguments.")
if np.all(scale == 0):
return loc*ones(size,'d')
# extra gymnastics needed for a custom random_state
if rndm is not None:
random_state_saved = self._random_state
self._random_state = check_random_state(rndm)
# `size` should just be an argument to _rvs(),but for,um,# historical reasons,it is made an attribute that is read
# by _rvs().
self._size = size
vals = self._rvs(*args)
vals = vals * scale + loc
# do not forget to restore the _random_state
if rndm is not None:
self._random_state = random_state_saved
# Cast to int if discrete
if discrete:
if size == ():
vals = int(vals)
else:
vals = vals.astype(int)
return vals
值定义如下:
T_max=100,dt=0.1,dt_save=1,mu= 1/8,delta=1/4,alpha = 0.024,rho = 1/11,R0=3.0,E0=10,
如果有人可以提供帮助,那将非常有帮助...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。