{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# PyNEST Microcircuit: Network Parameters\n\nA dictionary with base network and neuron parameters is enhanced with derived\nparameters.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\n\n\ndef get_exc_inh_matrix(val_exc, val_inh, num_pops):\n    \"\"\" Creates a matrix for excitatory and inhibitory values.\n\n    Parameters\n    ----------\n    val_exc\n        Excitatory value.\n    val_inh\n        Inhibitory value.\n    num_pops\n        Number of populations.\n\n    Returns\n    -------\n    matrix\n        A matrix of of size (num_pops x num_pops).\n\n    \"\"\"\n    matrix = np.zeros((num_pops, num_pops))\n    matrix[:, 0:num_pops:2] = val_exc\n    matrix[:, 1:num_pops:2] = val_inh\n    return matrix\n\n\nnet_dict = {\n    # factor to scale the number of neurons\n    'N_scaling': 0.1,\n    # factor to scale the indegrees\n    'K_scaling': 0.1,\n    # neuron model\n    'neuron_model': 'iaf_psc_exp',\n    # names of the simulated neuronal populations\n    'populations': ['L23E', 'L23I', 'L4E', 'L4I', 'L5E', 'L5I', 'L6E', 'L6I'],\n    # number of neurons in the different populations (same order as\n    # 'populations')\n    'full_num_neurons':\n        np.array([20683, 5834, 21915, 5479, 4850, 1065, 14395, 2948]),\n    # mean rates of the different populations in the non-scaled version of the\n    # microcircuit (in spikes/s; same order as in 'populations');\n    # necessary for the scaling of the network.\n    # The values were optained by running this PyNEST microcircuit with 12 MPI\n    # processes and both 'N_scaling' and 'K_scaling' set to 1.\n    'full_mean_rates':\n        np.array([0.943, 3.026, 4.368, 5.882, 7.733, 8.664, 1.096, 7.851]),\n    # connection probabilities (the first index corresponds to the targets\n    # and the second to the sources)\n    'conn_probs':\n        np.array(\n            [[0.1009, 0.1689, 0.0437, 0.0818, 0.0323, 0., 0.0076, 0.],\n             [0.1346, 0.1371, 0.0316, 0.0515, 0.0755, 0., 0.0042, 0.],\n             [0.0077, 0.0059, 0.0497, 0.135, 0.0067, 0.0003, 0.0453, 0.],\n             [0.0691, 0.0029, 0.0794, 0.1597, 0.0033, 0., 0.1057, 0.],\n             [0.1004, 0.0622, 0.0505, 0.0057, 0.0831, 0.3726, 0.0204, 0.],\n             [0.0548, 0.0269, 0.0257, 0.0022, 0.06, 0.3158, 0.0086, 0.],\n             [0.0156, 0.0066, 0.0211, 0.0166, 0.0572, 0.0197, 0.0396, 0.2252],\n             [0.0364, 0.001, 0.0034, 0.0005, 0.0277, 0.008, 0.0658, 0.1443]]),\n    # mean amplitude of excitatory postsynaptic potential (in mV)\n    'PSP_exc_mean': 0.15,\n    # relative standard deviation of the weight\n    'weight_rel_std': 0.1,\n    # relative inhibitory weight\n    'g': -4,\n    # mean delay of excitatory connections (in ms)\n    'delay_exc_mean': 1.5,\n    # mean delay of inhibitory connections (in ms)\n    'delay_inh_mean': 0.75,\n    # relative standard deviation of the delay of excitatory and\n    # inhibitory connections\n    'delay_rel_std': 0.5,\n\n    # turn Poisson input on or off (True or False)\n    # if False: DC input is applied for compensation\n    'poisson_input': True,\n    # indegree of external connections to the different populations (same order\n    # as in 'populations')\n    'K_ext': np.array([1600, 1500, 2100, 1900, 2000, 1900, 2900, 2100]),\n    # rate of the Poisson generator (in spikes/s)\n    'bg_rate': 8.,\n    # delay from the Poisson generator to the network (in ms)\n    'delay_poisson': 1.5,\n\n    # initial conditions for the membrane potential, options are:\n    # 'original': uniform mean and standard deviation for all populations as\n    #             used in earlier implementations of the model\n    # 'optimized': population-specific mean and standard deviation, allowing a\n    #              reduction of the initial activity burst in the network\n    #              (default)\n    'V0_type': 'optimized',\n    # parameters of the neuron model\n    'neuron_params': {\n        # membrane potential average for the neurons (in mV)\n        'V0_mean': {'original': -58.0,\n                    'optimized': [-68.28, -63.16, -63.33, -63.45,\n                                  -63.11, -61.66, -66.72, -61.43]},\n        # standard deviation of the average membrane potential (in mV)\n        'V0_std': {'original': 10.0,\n                   'optimized': [5.36, 4.57, 4.74, 4.94,\n                                 4.94, 4.55, 5.46, 4.48]},\n        # reset membrane potential of the neurons (in mV)\n        'E_L': -65.0,\n        # threshold potential of the neurons (in mV)\n        'V_th': -50.0,\n        # membrane potential after a spike (in mV)\n        'V_reset': -65.0,\n        # membrane capacitance (in pF)\n        'C_m': 250.0,\n        # membrane time constant (in ms)\n        'tau_m': 10.0,\n        # time constant of postsynaptic currents (in ms)\n        'tau_syn': 0.5,\n        # refractory period of the neurons after a spike (in ms)\n        't_ref': 2.0}}\n\n# derive matrix of mean PSPs,\n# the mean PSP of the connection from L4E to L23E is doubled\nPSP_matrix_mean = get_exc_inh_matrix(\n    net_dict['PSP_exc_mean'],\n    net_dict['PSP_exc_mean'] * net_dict['g'],\n    len(net_dict['populations']))\nPSP_matrix_mean[0, 2] = 2. * net_dict['PSP_exc_mean']\n\nupdated_dict = {\n    # matrix of mean PSPs\n    'PSP_matrix_mean': PSP_matrix_mean,\n\n    # matrix of mean delays\n    'delay_matrix_mean': get_exc_inh_matrix(\n        net_dict['delay_exc_mean'],\n        net_dict['delay_inh_mean'],\n        len(net_dict['populations']))}\n\nnet_dict.update(updated_dict)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.6.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}