获取 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 (将#修改为@)