Recording spikes only when a condition is met

Assuming each sample will run 1.0 second until a condition is satisfied, e.g. for 2 samples:

   for i in range(2):
        while True:
            if condition_is_not_met_for_sample_i:
                 run(1.0*second)
            else:
                break

To met the condition, sample#1 run 1.0s and sample#2 run 3 rounds of 1.0s. Then the spikes recorded in t = 1s - 4s are all from the sample#2. Is it possible for spikemonitor to only record spikes from the run when the condition is met? In another word, can the spike is recorded in such a way that t = 0-1s are from sample#1 and t = 1s-2s are from the successful run of sample#2?

The purpose is for the convenience of correlating sample ID with spikes in analysis. If each sample run only 1.0s, one know the t = 0-1s and 1s-2s are for sample#1 and sample#2, respectively. When condition is added, one need to record manually the time period that corresponds to a sample. For example, one need to record that t = 1s - 4s are produced when running on sample#2.

Thanks

I am not 100% I sure I understood, but if you only know whether you need the spikes after the simulation has been run, it will be difficult to do much on the level of Brian. There’s one exception, though: if the different “attempts” for each sample do not directly depend on the previous ones, you could use the store/restore mechanism which “resets time” including for the monitors. So something like

   for i in range(2):
        store()
        while True:
            if condition_is_not_met_for_sample_i:
                restore()
                # ... change something
                run(1.0*second)
            else:
                break

You’d then only end up with the “succesful” 1s for each sample.

Thanks Marcel. Each run actual depends on each other because the synaptic weights are updated continuously sample by sample. In this case, I will just save the timing and sample ID in a separate files.

Ok, makes sense. One other approach would be to store the spike information separately in a way that you only have 1s per sample. Something along the lines of:

all_times = []
all_indices = []
for i in range(2):
    while True:
        if condition_is_not_met_for_sample_i:
             run(1.0*second)
        else:
            # store last second
            all_times.extend(spike_mon.t[spike_mon.t>=magic_network.t - 1*second]
            all_indices.extend(spike_mon.i[spike_mon.t>=magic_network.t - 1*second]
            break

By subtracting from the times before storing them you could also shift them to get a seemingly continuous list of spike times.

1 Like