mattja / nsim Goto Github PK
View Code? Open in Web Editor NEWLarge scale simulation of ODEs or SDEs, analyze time series.
License: GNU General Public License v3.0
Large scale simulation of ODEs or SDEs, analyze time series.
License: GNU General Public License v3.0
When you plot a simulation with timeseries.plot(),
the time axis is not scaled correctly.
if you run a simulation like this:
sim = nsim.RepeatedSim(Model, T=100, repeat=2)
sim.timeseries.plot()
The time scale of the plot should go from 0 to 100, right?.
nsim works fine with ipyparallel 4 and earlier, but gives spurious messages with ipyparallel 5.0.x and breaks with ipyparallel >=5.1.x, working some of the time, and completely freezing with no error message at other times. See mattja/distob#3.
Have not yet investigated this to find whether this is a bug in ipyparallel or distob, or whether it results from a change to the AsyncResult interface in ipyparallel.
Until this issue is sorted out, temporarily require ipyparallel 4.x
Hi, I am trying to use nsim to simulate the following model:
"""
SIR Epidemic Model
S --> I --> R
X(t) = [S(t), I(t)]
Equations:
dS = -r0*S*I dt -sqrt(r0*S*I) dW1
dI = r0*S*I dt + sqrt(r0*S*I) dW1 -sqrt(I) dW2
"""
import nsim
import numpy as np
class SIR(nsim.ItoModel):
r0 = 1.5
y0 = np.array([0.9, 0.1]).T
def f(self, y, t):
A = np.array([[-self.r0*y[0]*y[1]],
[self.r0*y[0]*y[1] - y[1]]])
return A
def G(self, y, t):
B = np.array([[-np.sqrt(self.r0*y[0]*y[1]), 0],
[np.sqrt(self.r0*y[0]*y[1]), - y[1]]])
return B
To simulate it I tried the following:
s = nsim.Simulation(SIR, T=520.0)
It seems to work but when I try to plot the results, I get this error:
Traceback (most recent call last):
File "SDE_SIR.py", line 38, in <module>
print(s.output, dir(s))
File "/usr/local/lib/python3.5/dist-packages/nsim/nsim.py", line 1330, in output
self.compute()
File "/usr/local/lib/python3.5/dist-packages/nsim/nsim.py", line 1313, in compute
ar = self.system.integrate(tspan)
File "/usr/local/lib/python3.5/dist-packages/nsim/nsim.py", line 870, in integrate
ar = self.integrator[0](self.f, self.G, self.y0, tspan)
File "/usr/local/lib/python3.5/dist-packages/sdeint/integrate.py", line 125, in itoint
return chosenAlgorithm(f, G, y0, tspan)
File "/usr/local/lib/python3.5/dist-packages/sdeint/integrate.py", line 305, in itoSRI2
return _Roessler2010_SRK2(f, G, y0, tspan, Imethod, dW, I)
File "/usr/local/lib/python3.5/dist-packages/sdeint/integrate.py", line 439, in _Roessler2010_SRK2
H20b = np.reshape(H20, (d, 1))
File "/usr/local/lib/python3.5/dist-packages/numpy/core/fromnumeric.py", line 225, in reshape
return reshape(newshape, order=order)
ValueError: total size of new array must be unchanged
Is this a bug, or maybe a mistake in my model?
I don't know if you already support python 3, but I noticed the follwing exception when trying to run one of the examples under Python3:
import nsim
File "/usr/local/lib/python3.5/dist-packages/nsim/__init__.py", line 5, in <module>
from . import analyses1
File "/usr/local/lib/python3.5/dist-packages/nsim/analyses1/__init__.py", line 12, in <module>
from .pyeeg import (hurst, embed_seq, in_range, bin_power, pfd, hfd, hjorth,
File "/usr/local/lib/python3.5/dist-packages/nsim/analyses1/pyeeg.py", line 161
print "Cannot build such a matrix, because D * Tau > N"
^
SyntaxError: Missing parentheses in call to 'print'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.