Exemplo n.º 1
0
x0 = [1,1.27e-6,0]
# params
paramEval = [('b',0.5), ('k',1.0/3.0)]
# initialize the model
ode = modelDef.SIR().setParameters(paramEval).setInitialValue(x0,t0)

# set the time sequence that we would like to observe
t = numpy.linspace(1, 150, 100)
numStep = len(t) 
# Standard.  Find the solution.
solution = ode.integrate(t)

y = solution[1::,1:2]

theta = [0.4,1.0/2.0]
objSIR = odeLossFunc.squareLoss(theta,ode,x0,t0,t,y,['I','R'])

lb = numpy.array([0.,0.],float)
ub = numpy.array([2.,2.],float)

pyOptimUtil.gradient.simplexGradient

beta,h,adjustedStepSize,info = pyOptimUtil.gradient.simplexGradient.linear(objSIR.cost, theta, h = 0.1, S=None, lb=lb, ub=ub)

info['S'].dot(beta)

numpy.arccos(info['S'].dot(betaNorm))

numpy.arccos(info['S'].dot([0.5,0.5]/numpy.linalg.norm([0.5,0.5])))

numpy.degrees(numpy.arccos(info['S'].dot([0.5,0.5]/numpy.linalg.norm([0.5,0.5]))))
Exemplo n.º 2
0
                     10.0,9.6,5.0,2.0, ### the omega
                     7.0,0.81,0.80, ### alpha, delta, theta
                     0.1,1.0])  ### kappa,intervention time


theta3 = [  2.47063919e-02,   8.34896582e-01,   2.00000000e+00,
         6.52250983e+01,   8.88857685e+01,   7.62593478e+00,
         3.51943235e+01,   2.77555756e-17,   8.14831909e-01,
         3.46944695e-18,   3.73088898e+02,   1.03377245e+01]

theta4 = [  2.31507228e-02,   1.99997489e+00,   1.45839939e+00,
         1.00000000e+02,   1.00000000e+02,   9.87598235e+01,
         1.53450124e+01,   1.00000000e-08,   7.10575971e-01,
         9.99999990e-01,   3.29899411e+02,   1.28215876e+01]

objLegrand = odeLossFunc.squareLoss(theta,ode,x0,t0,t[1::],y[1::,:],['I','R'],[1175e4,1175e4])

objLegrand.cost(theta)
objLegrand.cost(theta1)

objLegrand.sensitivity(theta,intName='ivode')
objLegrand.sensitivity(theta,intName='lsoda')
ode.Jacobian(x0,t0)
scipy.linalg.eig(ode.Jacobian(x0,t0))[0]

S = solution[:,0]
E = solution[:,1]
I = solution[:,2]
H = solution[:,3]
F = solution[:,4]
R = solution[:,5]
Exemplo n.º 3
0
    5.0 / 7.0,
    2.0 / 7.0,  ### the omega
    7.0 / 7.0,
    0.81,
    0.80,  ### alpha, delta, theta
    300,
    12.0
])  ### kappa,intervention time

# starting value
y = numpy.reshape(numpy.append(numpy.array(yCase), numpy.array(yDeath)),
                  (len(yCase), 2), 'F') / 1175e4
x0 = [1, 49.0 / 1175e4, 0.0, 0.0, 0.0, 29.0 / 1175e4]
t0 = 0

objLegrand = odeLossFunc.squareLoss(theta, ode, x0, t0, t[1::], y[1::, :],
                                    ['I', 'R'], [1175e4, 1175e4])

boxBounds = [(0.0, 2.0), (0.0, 2.0), (0.0, 2.0), (0.0, 100.0), (0.0, 100.0),
             (0.0, 100.0), (0.0, 100.0), (0.0, 100.0), (0.0, 1.0), (0.0, 1.0),
             (0.0, 1000.0), (0.0, 218.0)]

cons = ({
    'type': 'ineq',
    'fun': lambda x: numpy.array([x[3] - x[5], x[4] - x[5]])
})

npBox = numpy.array(boxBounds)

lb = npBox[:, 0]
ub = npBox[:, 1]
Exemplo n.º 4
0
    1.0
])  ### kappa,intervention time

theta3 = [
    2.47063919e-02, 8.34896582e-01, 2.00000000e+00, 6.52250983e+01,
    8.88857685e+01, 7.62593478e+00, 3.51943235e+01, 2.77555756e-17,
    8.14831909e-01, 3.46944695e-18, 3.73088898e+02, 1.03377245e+01
]

theta4 = [
    2.31507228e-02, 1.99997489e+00, 1.45839939e+00, 1.00000000e+02,
    1.00000000e+02, 9.87598235e+01, 1.53450124e+01, 1.00000000e-08,
    7.10575971e-01, 9.99999990e-01, 3.29899411e+02, 1.28215876e+01
]

objLegrand = odeLossFunc.squareLoss(theta, ode, x0, t0, t[1::], y[1::, :],
                                    ['I', 'R'], [1175e4, 1175e4])
objLegrand.cost()

ode.setParameters(theta).setInitialValue(x0, t0)

objLegrand.cost()
s, o = objLegrand.sensitivity(full_output=True)

j, o = objLegrand.jac(full_output=True)
j1, o1 = objLegrand.jacIV(full_output=True)
s1, o1 = objLegrand.sensitivityIV(full_output=True)

objLegrand.adjointInterpolate()
objLegrand.adjointInterpolate1()
objLegrand.adjointInterpolate2()
Exemplo n.º 5
0
                     10.0,9.6,5.0,2.0, ### the omega
                     7.0,0.81,0.80, ### alpha, delta, theta
                     0.1,1.0])  ### kappa,intervention time


theta3 = [  2.47063919e-02,   8.34896582e-01,   2.00000000e+00,
         6.52250983e+01,   8.88857685e+01,   7.62593478e+00,
         3.51943235e+01,   2.77555756e-17,   8.14831909e-01,
         3.46944695e-18,   3.73088898e+02,   1.03377245e+01]

theta4 = [  2.31507228e-02,   1.99997489e+00,   1.45839939e+00,
         1.00000000e+02,   1.00000000e+02,   9.87598235e+01,
         1.53450124e+01,   1.00000000e-08,   7.10575971e-01,
         9.99999990e-01,   3.29899411e+02,   1.28215876e+01]

objLegrand = odeLossFunc.squareLoss(theta,ode,x0,t0,t[1::],y[1::,:],['I','R'],[1175e4,1175e4])
objLegrand.cost()

ode.setParameters(theta).setInitialValue(x0,t0)

objLegrand.cost()
s,o = objLegrand.sensitivity(full_output=True)

j,o = objLegrand.jac(full_output=True)
j1,o1 = objLegrand.jacIV(full_output=True)
s1,o1 = objLegrand.sensitivityIV(full_output=True)

objLegrand.adjointInterpolate()
objLegrand.adjointInterpolate1()
objLegrand.adjointInterpolate2()
Exemplo n.º 6
0
t = numpy.linspace(0, 150, 100)
numStep = len(t)
# Standard.  Find the solution.
ode = modelDef.SIR()
ode.setParameters([0.5,1.0/3.0])
ode.setInitialValue(x0,t0)
solution = ode.integrate(t[1::],full_output=False)

theta = [0.2,0.2]

# y = copy.copy(solution[:,1:2])
# y[1::] = y[1::] + numpy.random.normal(loc=0.0,scale=0.1,size=numStep-1)

# odeSIR = odeLossFunc.squareLoss([0.5,1.0/3.0] ,ode,x0,t0,t[1:len(t)],y[1:len(t)],'R')

objSIR = odeLossFunc.squareLoss(theta,ode,x0,t0,t[1::],solution[1::,1:3],['I','R'])

box = [(0.,2.),(0.,2.)]
npBox = numpy.array(box)
lb = npBox[:,0]
ub = npBox[:,1]

solvers = [
    'ralg',
    'lincher',
    'gsubg',
    'scipy_slsqp',
    'scipy_cobyla',
    'interalg',
    'auglag',
    'ptn',