examples/example_24_large_scale_brian2_simulation/clusternet.py
def _compute_fano_factor(spike_res, neuron_id, time_window, start_time, end_time):
        """Computes Fano Factor for one neuron.

        :param spike_res:

            Result containing the spiketimes of all neurons

        :param neuron_id:

            Index of neuron for which FF is computed

        :param time_window:

            Length of the consecutive time windows to compute the FF

        :param start_time:

            Start time of measurement to consider

        :param end_time:

            End time of measurement to consider

        :return:

            Fano Factor (float) or
            returns 0 if mean firing activity is 0.

        """
        assert(end_time >= start_time+time_window)

        # Number of time bins
        bins = (end_time-start_time)/time_window
        bins = int(np.floor(bins))

        # Arrays for binning of spike counts
        binned_spikes = np.zeros(bins)

        # DataFrame only containing spikes of the particular neuron
        spike_array_neuron = spike_res.t[spike_res.i==neuron_id]

        for bin in range(bins):
            # We iterate over the bins to calculate the spike counts
            lower_time = start_time+time_window*bin
            upper_time = start_time+time_window*(bin+1)

            # Filter the spikes
            spike_array_interval = spike_array_neuron[spike_array_neuron >= lower_time]
            spike_array_interval = spike_array_interval[spike_array_interval < upper_time]

            # Add count to bins
            spikes = len(spike_array_interval)
            binned_spikes[bin]=spikes


        var = np.var(binned_spikes)
        avg = np.mean(binned_spikes)

        if avg > 0:
            return var/float(avg)
        else:
            return 0
def _compute_fano_factor(spike_res, neuron_id, time_window, start_time, end_time):
        """Computes Fano Factor for one neuron.

        :param spike_res:

            Result containing the spiketimes of all neurons

        :param neuron_id:

            Index of neuron for which FF is computed

        :param time_window:

            Length of the consecutive time windows to compute the FF

        :param start_time:

            Start time of measurement to consider

        :param end_time:

            End time of measurement to consider

        :return:

            Fano Factor (float) or
            returns 0 if mean firing activity is 0.

        """
        assert(end_time >= start_time+time_window)

        # Number of time bins
        bins = (end_time-start_time)/time_window
        bins = int(np.floor(bins))

        # Arrays for binning of spike counts
        binned_spikes = np.zeros(bins)

        # DataFrame only containing spikes of the particular neuron
        spike_array_neuron = spike_res.t[spike_res.i==neuron_id]

        for bin in range(bins):
            # We iterate over the bins to calculate the spike counts
            lower_time = start_time+time_window*bin
            upper_time = start_time+time_window*(bin+1)

            # Filter the spikes
            spike_array_interval = spike_array_neuron[spike_array_neuron >= lower_time]
            spike_array_interval = spike_array_interval[spike_array_interval < upper_time]

            # Add count to bins
            spikes = len(spike_array_interval)
            binned_spikes[bin]=spikes


        var = np.var(binned_spikes)
        avg = np.mean(binned_spikes)

        if avg > 0:
            return var/float(avg)
        else:
            return 0
Computes Fano Factor for one neuron.

        :param spike_res:

            Result containing the spiketimes of all neurons

        :param neuron_id:

            Index of neuron for which FF is computed

        :param time_window:

            Length of the consecutive time windows to compute the FF

        :param start_time:

            Start time of measurement to consider

        :param end_time:

            End time of measurement to consider

        :return:

            Fano Factor (float) or
            returns 0 if mean firing activity is 0.