示例#1
0
文件: EMdemo.py 项目: pyfun/msf
dbm = DiscreteBrownianMotion.MultiPath.ofSize(5, 1000, .001)

"""
Solve the SDE. We define the f and g functions first, then pass them to
the solver. We also use the known solution for the SDE for comparison 
purposes.
"""

def f(x):
    return 2 * x
def g(x):
    return x

# numeric solutions
t, Xt = DiscreteBrownianMotion.sdeEM(f, g, 1, dbm)  
# exact solutions
Yt = N.exp(1.5*t + dbm.Wt)       

"""
Now use a different time interval for integration than for the discretized
Brownian motion. Just expand the time interval for the Brownian motion, and
repeat the integration.
"""

expandFactor = 10
dbm2 = dbm.expandInterval(expandFactor)
t2, Xt2  = DiscreteBrownianMotion.sdeEM(f, g, 1, dbm2)  

"""
Take a look at the results. We'll first examine the RMS error of the numeric