# Consistency Issues with Poisson Input in Timed Arrays

**URL:** <https://brian.discourse.group/t/consistency-issues-with-poisson-input-in-timed-arrays/1392>\
**Category:** Projects\
**Tags:** equations\
**Created:** [4 February 2025 01:03 UTC](https://brian.discourse.group/t/consistency-issues-with-poisson-input-in-timed-arrays/1392 "2025-02-04T01:03:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![elnaz91](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/elnaz91/32/703_2.png) [@elnaz91](https://brian.discourse.group/u/elnaz91)\
**Post date:** [4 February 2025 01:03 UTC](https://brian.discourse.group/t/consistency-issues-with-poisson-input-in-timed-arrays/1392/1 "2025-02-04T01:03:39Z")

</div>

Hello ,

I’m working on a neural simulation where my input is a variable firing rate for the first and second half of Poisson neurons. Here’s what I intend:

1. **Input Parameters:**

2. **Issue:**  
I have constructed the `input_timeArray` function to generate the timed array based on these settings (see code below). My problem is understanding why the average firing rate, in the case where the input is the same for both periods (`sim=True`), shows a difference. Shouldn’t the rates be the same?

**Code Snippet:**

```python
def input_timeArray(input, amp_inp, bg_inp_rate, dur_rep, dt=0.1*ms, sim=True):
    def generate_period_input(input, amp_inp, bg_inp_rate):
        result = np.array([amp * inp + bg for amp, inp, bg in zip(amp_inp, input, bg_inp_rate)])
        return result.reshape(1, -1)

    n_time_points = int(dur_rep / dt)
    if sim is True:
        period_input = np.tile(generate_period_input(input, amp_inp, bg_inp_rate), (n_time_points, 1))
        full_input_array = np.tile(period_input, (2, 1))
    elif sim is None:
        period_input = np.tile(generate_period_input(input, amp_inp, bg_inp_rate), (n_time_points, 1))
        background_input = np.tile(np.array([bg for bg in bg_inp_rate]), (n_time_points, 1))
        full_input_array = np.vstack([period_input, background_input])
    else:
        full_input_list = []
        for inp in input:
            period_input = np.tile(generate_period_input(inp, amp_inp, bg_inp_rate), (n_time_points, 1))
            full_input_list.append(period_input)
        full_input_array = np.vstack(full_input_list)

    return TimedArray(full_input_array * Hz, dt=dt)

# Example Usage
input_array = input_timeArray(network_ginput, amp_inp, bg_inp_rate, durations[0], sim=True)

```

**Neuron Group Configuration:**

```python
inp_eqs = '''
    unit_idx : integer (constant)
    x : 1
    y : 1
    rate = input_array(t, i) : Hz 
    '''

p_in_v1_l4 = NeuronGroup(neuron_population_sizes['input'], inp_eqs, threshold='rand() < rate*dt', 
                         method='euler', name='poisson_input_v1_l4')

```

Could anyone provide insights or suggest modifications to ensure the consistency of firing rates across similar periods?

Thank you in advance!

 ![image](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/008f0045643d8e41708c4d0d6bf2f183478445cf.png)  
 ![image](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/fb8835026b0aabc7424f53169a2113fb80920a69.png)

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [4 February 2025 10:04 UTC](https://brian.discourse.group/t/consistency-issues-with-poisson-input-in-timed-arrays/1392/2 "2025-02-04T10:04:22Z")

</div>

Hi @elnaz91. I am not entirely sure that I understand what makes you say that the average firing rate “shows a difference” over time. Is it because your “Population Firing Rates” plot varies over time? I think this is normal, given that you have random Poisson firing and a relatively small population. Here’s an example run/plot I did, where I plot the average firing rate with different smoothing windows:

```python
# Example Usage
input_array = input_timeArray(np.repeat([5, 10], 100), np.repeat([1, 2], 100), np.repeat([5, 5], 100), 500*ms, sim=True)
inp_eqs = 'rate = input_array(t, i) : Hz'
p_in_v1_l4 = NeuronGroup(200, inp_eqs, threshold='rand() < rate*dt', 
                         method='euler', name='poisson_input_v1_l4')
spike_mon = SpikeMonitor(p_in_v1_l4)
rate_mon = PopulationRateMonitor(p_in_v1_l4)
run(1000*ms)
fig, axs = plt.subplots(2, 1, sharex=True)
axs[0].plot(spike_mon.t/ms, spike_mon.i, '.k')
axs[1].plot(rate_mon.t/ms, rate_mon.smooth_rate(width=5*ms)/Hz)
axs[1].plot(rate_mon.t/ms, rate_mon.smooth_rate(width=10*ms)/Hz)
axs[1].plot(rate_mon.t/ms, rate_mon.smooth_rate(width=20*ms)/Hz)
axs[1].plot(rate_mon.t/ms, rate_mon.smooth_rate(width=40*ms)/Hz)
axs[1].set_ylim(0, 25)
show()

```

 ![Figure_1](https://global.discourse-cdn.com/free1/uploads/brian/original/1X/06e82bc2be80c06ac87ce55538170153bc6c3183.png)  
As you can see, it varies quite a bit, but I’d say this is normal.

---

<div class="post-metadata">

**Author:** ![elnaz91](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/elnaz91/32/703_2.png) [@elnaz91](https://brian.discourse.group/u/elnaz91)\
**Post date:** [5 February 2025 10:13 UTC](https://brian.discourse.group/t/consistency-issues-with-poisson-input-in-timed-arrays/1392/3 "2025-02-05T10:13:25Z")

</div>

Hi Marcel, thank you! I think you’re right—something was cached when I generated the plot, but it’s fine now.  
As for your question, yes, I was referring to the variations in the “Population Firing Rates” plot over time.  
Thank you for clarifying and for sharing the example plot with the different smoothing windows—it’s very helpful!
