In [1]:
%pylab nbagg
from tvb.simulator.lab import *
from tvb.simulator.plot.phase_plane_interactive import PhasePlaneInteractive
Populating the interactive namespace from numpy and matplotlib
   INFO  log level set to INFO

Exploring A Model

This tutorial discusses using the phase_plane_interactive plotting tool to explore the dynamics of a Model object and, at the same time, set its parameters.

This works best for the simpler, 2d, Models, as their trajectories and nullclines lie within a single plane and are thus easily visualised. And so, for the demo here we'll stick with a Model of that type. However, although it requires a little more effort, it can still be used to get a basic handle on the dynamics of higher dimensional models.

It is also important to note that this is only for the local dynamic model, that is, it only represents the dynamic behaviour of a disconnected node.

Create An Interactive Phase-Plane

PhasePlaneInteractive produces an interactive window containing plots of a Model's phase-plane, sample trajectories, and sliders and buttons for adjusting various parameters.

The important thing to note here is that as we drag around the sliders for the Model's parameters we are actually modifying the parameters of the Model we passed in, so when we close the figure at the end whatever values the Model's parameters are set to will be the values in the Model. Also, changing the range of the phase-plane plot (that is, the extent of the x and y axis) changes the "state_variable_range" attribute of a Model. This attribute is used when constructing random initial conditions for a simulation, so setting the axis to be relatively tightly bound around a fixed point for example will produce initial conditions that better approximate the range of the Model's state variables for the given parameters.

We'll begin by creating a Model object and taking a quick look at its parameters:

In [2]:
oscillator = models.Generic2dOscillator()


We'll now create and launch the interactive plot.

NOTE: Changing the Model's parameters or the axis settings causes a redraw of the entire phase-plane, clearing trajectories and their corresponding time-series.

In [3]:
ppi_fig = PhasePlaneInteractive(model=oscillator)
C:\Users\mw\Downloads\TVB_Distribution\tvb_data\Lib\site-packages\matplotlib\ MatplotlibDeprecationWarning: The set_color_cycle attribute was deprecated in version 1.5. Use set_prop_cycle instead.
  warnings.warn(message, mplDeprecation, stacklevel=1)

In the main central panel of the window you can see the phase-plane for the model, including arrows representing the vector field and coloured lines representing any nullclines present in this plane. Clicking on the phase-plane will launch a sample trajectory originating from where you clicked. Below the phase-plane is a panel which will show time-series for all state variables for any sample trajectories you initiate. All around the edges are sliders for adjusting Model parameters and adjusting what is displayed. The red vertical lines in sliders indicate the initial values.

After we've adjusted parameters to our satisfaction we can close the window and take another quick look at the parameters of our Model

In [4]:
tau[ 1.]
c[ 0.]
e[ 3.]
d[ 0.02]
g[ 0.]
f[ 1.]
I[ 0.]
state_variable_range{'W': array([-6., 6.]), 'V': array([-2., 4.])}
beta[ 1.]
alpha[ 1.]
gamma[ 1.]

As you can see in the line above, the Model's parameters, for example "a", "tau", and the state_variable_ranges are modified from their initial values.

Specifying Stochastic Integration

It is possible to explicitly specify the integration scheme used to plot sample trajectories. This can be useful when deciding what amplitude to give your noise when specifying a stochastic integration scheme.

We'll take a look at this using HeunStochastic, we'll also pass in the same Model object we modified above. In this way PhasePlaneInteractive initialises with the parameters we'd set for the Model, so that here we can focus on the effect of the noise amplitude relative to the intrinsic dynamics.

Unlike changes to Model parameters and the axes, changing to the noise amplitude doesn't cause a redraw of the existing trajectories, so, after creating a trajectory you can alter the noise strength and click on the same starting location to see the effect of a different noise amplitude on the same trajectory.

Starting by setting the noise to 0.0, to get a deterministic trajectory, and then adding a small amount of noise can help give a useful intuition for the effects of noise on a simulation.

Also, as the random sequence used each time you launch a trajectory is distinct, clicking on the same point multiple times will give you an idea of the range of trajectory a given type of noise can produce.

Alternatively, clicking reset random stream enables you to see the effect of the same random sequence with different amplitudes or on a trajectory initiating from a different location.

Note: The default standard deviation for the noise is 1.0, which is too large (in the sense that noise will dominate the intrinsic dynamics) relative to the range of our Model's state variables.

In [5]:
heunstochint = integrators.HeunStochastic(dt=2**-5)

# examine integrator's attributes
a[ 2.1828125]
tau[ 1.873125]
c[ 0.]
e[ 3.]
d[ 0.02]
g[ 0.]
f[ 1.]
I[ 0.]
state_variable_range{'W': array([-6., 6.]), 'V': array([-2., 4.])}
beta[ 1.]
alpha[ 1.]
gamma[ 1.]
In [6]:
noiseAdditive(dt=None, ntau=0)

Relaunch the phase plane tool, but with the stochastic integrator

In [7]:
ppi_fig = PhasePlaneInteractive(model=oscillator, integrator=heunstochint)
In [8]:
nsig[ 1.]

Simulate and Visualize

Finally, we can use the objects created above in a simulation:

In [17]:
sim = simulator.Simulator(
    model = oscillator, 
    connectivity = connectivity.Connectivity(load_default=True),
    coupling = coupling.Linear(a=0.0152), 
    integrator = heunstochint, 
    monitors = monitors.TemporalAverage(period=2**-1),

# run
(tavg_time, tavg_data), =

# plot
plot(tavg_time, tavg_data[:, 0, :, 0], 'k', alpha=0.1)
xlabel('Time (ms)')
ylabel("Temporal average")
WARNING  File 'hemispheres' not found in ZIP.
<matplotlib.text.Text at 0x254e5588>

As long as the interactive phase plane figure isn't closed, the parameters can be tuned and the simulation rerun to iterate between the local dynamics of a node and integration scheme and the global dynamics of the entire network.

This website does not host notebooks, it only renders notebooks available on other websites.

Delivered by Fastly, Rendered by Rackspace

nbviewer GitHub repository.

nbviewer version: aa567da

nbconvert version: 5.3.1

Rendered (Thu, 15 Nov 2018 12:47:50 UTC)

nsig[ 0.00015234]