Python 更改np.linspace时,数组不能包含INF或NAN

Python 更改np.linspace时,数组不能包含INF或NAN,python,numpy,Python,Numpy,我正在用Python进行敏感性分析,并希望生成散点图来显示系统的结果。我一直在使用np.linspace(0100100)获得结果,但我想增加我成为np.linspace(01000100)的时间,以便在散点图中看到更多结果。由于一些未知的原因,当我增加我的时间间隔时,我的系统不会进行评估(即使时间不会产生影响)。我还得到了一个运行时警告:在双标量中遇到的溢出返回1+((10*(a^n))/((a^n)+1))(这可能是被零除或无穷大),但我不确定它在哪里崩溃以及从哪里崩溃。我曾尝试将灵敏度分析

我正在用Python进行敏感性分析,并希望生成散点图来显示系统的结果。我一直在使用
np.linspace(0100100)
获得结果,但我想增加我成为
np.linspace(01000100)
的时间,以便在散点图中看到更多结果。由于一些未知的原因,当我增加我的时间间隔时,我的系统不会进行评估(即使时间不会产生影响)。我还得到了一个
运行时警告:在双标量中遇到的溢出返回1+((10*(a^n))/((a^n)+1))
(这可能是被零除或无穷大),但我不确定它在哪里崩溃以及从哪里崩溃。我曾尝试将灵敏度分析的参数范围更改为非常小,但遗憾的是,没有任何东西可以消除此错误

这是我的密码:

from scipy import integrate as sp
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import solve_ivp
%matplotlib inline
fig = plt.figure(figsize=(20,10))

def H(A):
    if A<0:
        return 0
    else:
        return 1+((10*(A**n))/((A**n)+1))
    
def Hill(A):
    if A<0:
        return 0
    else:
        return (A**n)/((A**n)+1)

def NDMsignals(time,Z,iota,upsilon,vartheta,varphi1,varphi2):
    dZdt = [(H(Z[0])*iota)-(upsilon*Z[0])+(Z[1]*varphi1), #A1
    (H(Z[1])*vartheta)-(upsilon*Z[1])+(Z[0]*varphi2)] #A2
    return dZdt

def main(iota,upsilon,vartheta,varphi1,varphi2):
    alpha1 = 0.1
    alpha2 = 0.1
    gamma = 0.75
    n=2.2
    d1 = 1.0
    d2 = 1.0
    beta1 = 10*alpha1
    beta2 = 10*alpha2
    mu1 = 6.0
    mu2 = 6.0
    Upsilon1 = 1.0
    Upsilon2 = 1.0
    c1not = 1.0
    c2not = 1.0
    b1 = 1.0
    b2 = 1.0
    k1 = 0.4
    k2 = 0.4
    sigma1 = 1.0
    sigma2 = 1.0
    tau1 = 0.75
    tau2 = 0.75

    time=np.linspace(0,1000,100)

    Zinitial = [0.1, 0.1]

# Dimensional Parameters

    u = (gamma+b1+b2)
    psi = (tau1/tau2)
    c1eq = (sigma1*k1)/(mu1-k1)
    c2eq = (sigma2*k2)/(mu2-k2)
    xeq = (Upsilon1/k1)*((d1*(c1not-c1eq))-(d2*c1eq)+(d2*c2eq))
    yeq = (Upsilon2/k2)*((d1*(c2not-c2eq))-(d2*c2eq)+(d2*c1eq))

    # NDM Parameters
   
    #iota = (xeq)/(tau1)
    #upsilon = (u/alpha1)
    #vartheta = (alpha2*yeq)/(alpha1*tau2)
    #varphi1 = (b1/(psi*alpha1))
    #varphi2 = ((b1*psi)/alpha1)
    
    sol = solve_ivp(lambda t, Z: NDMsignals(time,Z,iota,upsilon,vartheta,varphi1,varphi2), 
                    [time[0],time[-1]], Zinitial, method='BDF', t_eval=time)
    #print([sol.y[0][-1], sol.y[1][-1]])
    return [sol.y[0][-1], sol.y[1][-1], Hill(sol.y[0][-1]), Hill(sol.y[1][-1])]

# Sensitivity Analysis

from SALib.sample import saltelli
from SALib.analyze import sobol

problem = {
    'num_vars': 5,
    'names':['iota', 'upsilon', 'vartheta', 'varphi1', 'varphi2'],
    'bounds': [[0.01, 10],
              [0.01, 35],
              [0.01, 10],
              [0.01, 3],
              [0.01, 3]]
}

param_values = saltelli.sample(problem, 200)

Y1 = np.zeros([param_values.shape[0]])
Y2 = np.zeros([param_values.shape[0]])
Y3 = np.zeros([param_values.shape[0]])
Y4 = np.zeros([param_values.shape[0]])

for i, X in enumerate(param_values):
    xx = main(X[0], X[1], X[2], X[3], X[4])
    Y1[i] = xx[0]
    Y2[i] = xx[1]
    Y3[i] = xx[2]
    Y4[i] = xx[3]

#Si1 = sobol.analyze(problem, Y1, print_to_console=True)
#Si2 = sobol.analyze(problem, Y2, print_to_console=True)
#Si3 = sobol.analyze(problem, Y3, print_to_console=True)
#Si4 = sobol.analyze(problem, Y4, print_to_console=True)

plt.scatter(Y3,Y4)
从scipy导入集成为sp
将numpy作为np导入
将matplotlib.pyplot作为plt导入
来自scipy.integrate import solve\u ivp
%matplotlib内联
图=plt.图(图尺寸=(20,10))
def H(A):
如果Atime=np.linspace(01000100)创建100个值,从值0开始直到值1000。被零除应该可以在具有异常处理的try-catch块中进行跟踪。
time[0] #produces the first value=0
time[-1] #produces the last value=1000

NDMsignals does not use the time list [0,100]

The way your passing variables is hazardous.   Instead, create a class with self variables in the __init__ then use the constructor to initialize the variables.  After which make method calls for your calculation separating primary methods as publicly exposing and private as the internal methods.