|
| 1 | +# Parameters |
| 2 | + |
| 3 | +Model parameters in `neurolib` are stored as a dictionary-like object `params` as one of a model's attributes. Changing parameters is straightforward: |
| 4 | + |
| 5 | +``` python |
| 6 | +from neurolib.models.aln import ALNModel # Import the model |
| 7 | +model = ALNModel() # Create an instance |
| 8 | + |
| 9 | +model.params['duration'] = 10 * 1000 # in ms |
| 10 | +model.run() # Run it |
| 11 | +``` |
| 12 | + |
| 13 | +Parameters are `dotdict` objects that can also be accessed using the more simple syntax `model.params.parameter_name = 123` (see [Collections](/utils/collections/)). |
| 14 | + |
| 15 | +## Default parameters |
| 16 | + |
| 17 | +The default parameters of a model are stored in the `loadDefaultParams.py` within each model's directory. This function is called by the `model.py` file upon initialisation and returns all necessary parameters of the model. |
| 18 | + |
| 19 | +Below is an example function that prepares the structural connectivity matrices `Cmat` and `Dmat`, all parameters of the model, and its initial values. |
| 20 | + |
| 21 | +``` python |
| 22 | +def loadDefaultParams(Cmat=None, Dmat=None, seed=None): |
| 23 | + """Load default parameters for a model |
| 24 | +
|
| 25 | + :param Cmat: Structural connectivity matrix (adjacency matrix) of coupling strengths, will be normalized to 1. If not given, then a single node simulation will be assumed, defaults to None |
| 26 | + :type Cmat: numpy.ndarray, optional |
| 27 | + :param Dmat: Fiber length matrix, will be used for computing the delay matrix together with the signal transmission speed parameter `signalV`, defaults to None |
| 28 | + :type Dmat: numpy.ndarray, optional |
| 29 | + :param seed: Seed for the random number generator, defaults to None |
| 30 | + :type seed: int, optional |
| 31 | +
|
| 32 | + :return: A dictionary with the default parameters of the model |
| 33 | + :rtype: dict |
| 34 | + """ |
| 35 | + |
| 36 | + params = dotdict({}) |
| 37 | + |
| 38 | + ### runtime parameters |
| 39 | + params.dt = 0.1 # ms 0.1ms is reasonable |
| 40 | + params.duration = 2000 # Simulation duration (ms) |
| 41 | + np.random.seed(seed) # seed for RNG of noise and ICs |
| 42 | + # set seed to 0 if None, pypet will complain otherwise |
| 43 | + params.seed = seed or 0 |
| 44 | + |
| 45 | + # make sure that seed=0 remains None |
| 46 | + if seed == 0: |
| 47 | + seed = None |
| 48 | + |
| 49 | + # ------------------------------------------------------------------------ |
| 50 | + # global whole-brain network parameters |
| 51 | + # ------------------------------------------------------------------------ |
| 52 | + |
| 53 | + # the coupling parameter determines how nodes are coupled. |
| 54 | + # "diffusive" for diffusive coupling, "additive" for additive coupling |
| 55 | + params.coupling = "diffusive" |
| 56 | + |
| 57 | + params.signalV = 20.0 |
| 58 | + params.K_gl = 0.6 # global coupling strength |
| 59 | + |
| 60 | + if Cmat is None: |
| 61 | + params.N = 1 |
| 62 | + params.Cmat = np.zeros((1, 1)) |
| 63 | + params.lengthMat = np.zeros((1, 1)) |
| 64 | + |
| 65 | + else: |
| 66 | + params.Cmat = Cmat.copy() # coupling matrix |
| 67 | + np.fill_diagonal(params.Cmat, 0) # no self connections |
| 68 | + params.N = len(params.Cmat) # number of nodes |
| 69 | + params.lengthMat = Dmat |
| 70 | + |
| 71 | + # ------------------------------------------------------------------------ |
| 72 | + # local node parameters |
| 73 | + # ------------------------------------------------------------------------ |
| 74 | + |
| 75 | + # external input parameters: |
| 76 | + params.tau_ou = 5.0 # ms Timescale of the Ornstein-Uhlenbeck noise process |
| 77 | + params.sigma_ou = 0.0 # mV/ms/sqrt(ms) noise intensity |
| 78 | + params.x_ou_mean = 0.0 # mV/ms (OU process) [0-5] |
| 79 | + params.y_ou_mean = 0.0 # mV/ms (OU process) [0-5] |
| 80 | + |
| 81 | + # neural mass model parameters |
| 82 | + params.a = 0.25 # Hopf bifurcation parameter |
| 83 | + params.w = 0.2 # Oscillator frequency, 32 Hz at w = 0.2 |
| 84 | + |
| 85 | + # ------------------------------------------------------------------------ |
| 86 | + |
| 87 | + # initial values of the state variables |
| 88 | + params.xs_init = 0.5 * np.random.uniform(-1, 1, (params.N, 1)) |
| 89 | + params.ys_init = 0.5 * np.random.uniform(-1, 1, (params.N, 1)) |
| 90 | + |
| 91 | + # Ornstein-Uhlenbeck noise state variables |
| 92 | + params.x_ou = np.zeros((params.N,)) |
| 93 | + params.y_ou = np.zeros((params.N,)) |
| 94 | + |
| 95 | + # values of the external inputs |
| 96 | + params.x_ext = np.zeros((params.N,)) |
| 97 | + params.y_ext = np.zeros((params.N,)) |
| 98 | + |
| 99 | + return params |
| 100 | + |
| 101 | +``` |
0 commit comments