コード例 #1
0
ファイル: npbackend_test.py プロジェクト: liadomide/tvb-root
 def _test_integrator(self, Integrator, delays=False):
     dt = 0.01
     if issubclass(Integrator, IntegratorStochastic):
         integrator = Integrator(dt=dt, noise=Additive(nsig=np.r_[dt]))
         integrator.noise.dt = integrator.dt
     else:
         integrator = Integrator(dt=dt)
     if isinstance(integrator, (Identity, IdentityStochastic)):
         self._test_mvar(integrator, delays=delays)
     else:
         self._test_mpr(integrator, delays=delays)
コード例 #2
0
ファイル: npbackend_test.py プロジェクト: liadomide/tvb-root
 def _test_integrator(self, Integrator):
     if issubclass(Integrator, IntegratorStochastic):
         integrator = Integrator(dt=0.1, noise=Additive(nsig=np.r_[0.01]))
         integrator.noise.dt = integrator.dt
     else:
         integrator = Integrator(dt=0.1)
     nn = 76
     state = np.random.randn(2, 1, nn)
     weights = np.random.randn(nn, nn)
     cx = weights.dot(state[:, 0].T).T
     assert cx.shape == (2, nn)
     expected = integrator.scheme(state[:, 0], self._test_dfun, cx, 0, 0)
     actual = state.copy()
     np.random.seed(42)
     self._eval_cg(integrator, actual, weights)
     np.testing.assert_allclose(actual[:, 0], expected)
コード例 #3
0
ファイル: utils.py プロジェクト: bvalean/tvb-root
def generate_region_demo_data(file_path=os.path.join(os.getcwd(), "demo_data_region_16s_2048Hz.npy")):
    """
    Generate 16 seconds of 2048Hz data at the region level, stochastic integration.

    ``Run time``: approximately 4 minutes (workstation circa 2010)

    ``Memory requirement``: < 1GB
    ``Storage requirement``: ~ 19MB

    .. moduleauthor:: Stuart A. Knock <*****@*****.**>

    """

    ##----------------------------------------------------------------------------##
    ##-                      Perform the simulation                              -##
    ##----------------------------------------------------------------------------##

    LOG.info("Configuring...")

    # Initialise a Model, Coupling, and Connectivity.
    pars = {'a': np.array([1.05]),
            'b': np.array([-1]),
            'c': np.array([0.0]),
            'd': np.array([0.1]),
            'e': np.array([0.0]),
            'f': np.array([1 / 3.]),
            'g': np.array([1.0]),
            'alpha': np.array([1.0]),
            'beta': np.array([0.2]),
            'tau': np.array([1.25]),
            'gamma': np.array([-1.0])}

    oscillator = Generic2dOscillator(**pars)

    white_matter = Connectivity.from_file()
    white_matter.speed = np.array([4.0])
    white_matter_coupling = Linear(a=np.array([0.033]))

    # Initialise an Integrator
    hiss = Additive(nsig=np.array([2 ** -10, ]))
    heunint = HeunStochastic(dt=0.06103515625, noise=hiss)

    # Initialise a Monitor with period in physical time
    what_to_watch = TemporalAverage(period=0.48828125)  # 2048Hz => period=1000.0/2048.0

    # Initialise a Simulator -- Model, Connectivity, Integrator, and Monitors.
    sim = Simulator(model=oscillator, connectivity=white_matter,
                    coupling=white_matter_coupling,
                    integrator=heunint, monitors=[what_to_watch])

    sim.configure()

    # Perform the simulation
    tavg_data = []
    tavg_time = []
    LOG.info("Starting simulation...")
    for tavg in sim(simulation_length=16000):
        if tavg is not None:
            tavg_time.append(tavg[0][0])  # TODO:The first [0] is a hack for single monitor
            tavg_data.append(tavg[0][1])  # TODO:The first [0] is a hack for single monitor

    LOG.info("Finished simulation.")

    ##----------------------------------------------------------------------------##
    ##-                     Save the data to a file                              -##
    ##----------------------------------------------------------------------------##

    # Make the list a numpy.array.
    LOG.info("Converting result to array...")
    TAVG = np.array(tavg_data)

    # Save it
    LOG.info("Saving array to %s..." % file_path)
    np.save(file_path, TAVG)

    LOG.info("Done.")