
Quickstart
==========

This tutorial provides a brief overview over the basic functionality of this
package.

Matplotlib is imported for visualization

.. code:: python

    import matplotlib.pyplot as plt


Network generation
------------------

The layered model can be imported form the ``connectome.model`` package

.. code:: python

    from connectome.model import LL

The parameters of a model can be pre-defined

.. code:: python

    ll = LL(nr_neurons=2000, inh_ratio=.1,
            p_exc=.2, p_inh=.5, reciprocity_exc=.2)
    ll



.. parsed-literal::

    <LL nr_neurons=2000, p_exc=0.2, reciprocity_exc=0.2, inh_ratio=0.1, p_inh=0.5, nr_exc_subpopulations=∅>



A network with three layers can now be generated

.. code:: python

    network = ll(nr_exc_subpopulations=3)
    network



.. parsed-literal::

    <Network nr_exc=1800, nr_inh=200>

and visualized


.. code:: python

    plt.matshow(network.adjacency_matrix, cmap="RdBu");



.. image:: quickstart_files/quickstart_10_0.png


Similarly, a network with five layers is generated and visualized, executing

.. code:: python

    network_5 = ll(nr_exc_subpopulations=5)
    plt.matshow(network_5.adjacency_matrix, cmap="RdBu");



.. image:: quickstart_files/quickstart_12_0.png


Please note that some parameters in the second call were still specified from
the first call and therefore not passed again.

Network analysis
----------------

Summary statistics of a network are calculated with the help of the ``connectome.analysis`` package.

.. code:: python

    from connectome.analysis import RelativeCycleAnalysis

The number of cycles, relative to chance is computed with

.. code:: python

    cycle_analysis = RelativeCycleAnalysis(length=5)
    cycle_analysis




.. parsed-literal::

    <RelativeCycleAnalysis length=5, network=∅>



.. code:: python

    cycle_analysis(network=network)




.. parsed-literal::

    {'relative_cycles_5': 0.19235267510727008}



The network contains less cycles of length 5 than expected by chance.
A value above 1 indicates more cycles than expected by chance,
a value below 1 indicates less cycles than expected by chance.
The network's reciprocity is calculated executing

.. code:: python

    from connectome.analysis import RelativeReciprocityEstimator
    RelativeReciprocityEstimator(network=network)()




.. parsed-literal::

    {'relative_reciprocity_ee': 1.0030832455128713,
     'relative_reciprocity_ei': 0.9991984266639169,
     'relative_reciprocity_ie': 0.999198426663917,
     'relative_reciprocity_ii': 0.9993940697569447}


The reciprocity obtained here, is close to the one expected from a pairwise
random network.

Noise
-----

Noise models are implemented in the ``connectome.noise`` package

.. code:: python

    from connectome.noise import RemoveAddNoiseAndSubsample

Random removal of half of the network's connections with simultaneous
reshuffling of 20% of the connections is simulated via

.. code:: python

    noise = RemoveAddNoiseAndSubsample(subsampling_fraction=.5, fraction_remove_and_add=.2)
    noise



.. parsed-literal::

    <RemoveAddNoiseAndSubsample subsampling_fraction=<InputChannel: subsampling_fraction=0.5>, network=<InputChannel: network=∅>, fraction_remove_and_add=<InputChannel: fraction_remove_and_add=0.2>>



.. code:: python

    noisy_network = noise(network=network)
    noisy_network




.. parsed-literal::

    <Network nr_exc=900, nr_inh=100>



This network has after perturbation only 1000 instead of 2000 neurons before.

.. code:: python

    plt.matshow(noisy_network.adjacency_matrix, cmap="RdBu");



.. image:: quickstart_files/quickstart_30_0.png


Additionally, connections on off-diagonal blocks appear;
these were generated by the shuffling procedure.
The number of cycles is also altered:

.. code:: python

    cycle_analysis(network=noisy_network)




.. parsed-literal::

    {'relative_cycles_5': 0.68771057755341169}



The perturbed network has more cycles than the noise free version (0.192, see above).
