Cypress  1.0
C++ Spiking Neural Network Simulation Framework
spiking_utils.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2018 Christoph Ostrau
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #ifndef CYPRESS_UTIL_SPIKING_UTILS_HPP
22 #define CYPRESS_UTIL_SPIKING_UTILS_HPP
23 
24 #include <cypress/core/network.hpp>
26 
27 namespace cypress {
28 class SpikingUtils {
29 public:
39  template <typename T>
41  Network &network, const NeuronParameter &neuronParams,
42  const size_t size,
43  const typename T::Signals &rec_signal =
44  typename T::Signals().record_spikes())
45  {
46  using Parameters = typename T::Parameters;
47  return network.create_population<T>(
48  size, Parameters(neuronParams.parameter()), rec_signal);
49  }
50 
60  template <typename T>
62  Network &network, const NeuronParameter &neuronParams,
63  const size_t size);
64 
71  static const NeuronType &detect_type(std::string neuron_type_str);
72 
85  const std::string neuron_type_str, Network &network,
86  const NeuronParameter &neuronParams, const size_t size,
87  const std::string record_signal = "");
88 
98  static bool rerun_fixed_number_trials(Network &network, Backend &backend,
99  Real time, size_t n_trials = 3);
100 
111  static int calc_num_spikes(const std::vector<cypress::Real> &spiketrain,
112  const cypress::Real start = 0.0,
113  const cypress::Real end = 0.0);
114 
125  template <typename T>
126  static std::vector<int> calc_num_spikes_vec(
127  const cypress::Matrix<T> &spiketrains, const cypress::Real start = 0.0,
128  const cypress::Real end = std::numeric_limits<cypress::Real>::max())
129  {
130  std::vector<int> res;
131  size_t rows = spiketrains.rows();
132  size_t colls = spiketrains.cols();
133  for (size_t i = 0; i < rows; i++) {
134  int counter = 0;
135  for (size_t j = 0; j < colls; j++) {
136  if ((spiketrains[i * colls + j] >= start - 0.001) &&
137  (spiketrains[i * colls + j] <= end + 0.001)) {
138  counter++;
139  }
140  }
141  res.push_back(counter);
142  }
143  return res;
144  }
145 
159  template <typename T>
160  static std::vector<T> spike_time_binning(
161  const Real &start, const Real &stop, const size_t &n_bins,
162  const std::vector<cypress::Real> &spike_times)
163  {
164  Real bin_size = (stop - start) / n_bins;
165  std::vector<T> bin_counts(n_bins, 0);
166  for (Real spike : spike_times) {
167  if (spike >= stop || spike < start) {
168  continue;
169  }
170  size_t bin_idx = size_t((spike - start) / bin_size);
171  bin_counts[bin_idx]++;
172  }
173  return bin_counts;
174  }
175 
189  static std::vector<Real> spike_time_binning_TTFS(
190  const Real &start, const Real &stop, const size_t &n_bins,
191  const std::vector<cypress::Real> &spike_times);
192 };
193 } // namespace cypress
194 
195 #endif /* CYPRESS_UTIL_SPIKING_UTILS_HPP */
Definition: neurons_base.hpp:54
static cypress::PopulationBase add_population(const std::string neuron_type_str, Network &network, const NeuronParameter &neuronParams, const size_t size, const std::string record_signal="")
const std::vector< Real > & parameter() const
Definition: neuron_parameters.hpp:60
Definition: backend.hpp:50
static const NeuronType & detect_type(std::string neuron_type_str)
double Real
Definition: types.hpp:56
static PopulationBase add_typed_population(Network &network, const NeuronParameter &neuronParams, const size_t size, const typename T::Signals &rec_signal=typename T::Signals().record_spikes())
Definition: spiking_utils.hpp:40
Definition: matrix.hpp:51
size_t rows() const
Definition: matrix.hpp:339
size_t cols() const
Definition: matrix.hpp:344
Definition: neuron_parameters.hpp:46
Definition: network_base_objects.hpp:53
Population< T > create_population(size_t size, const typename T::Parameters &params, const typename T::Signals &signals, const char *name="")
Definition: network.hpp:452
static cypress::PopulationBase add_typed_population_no_record(Network &network, const NeuronParameter &neuronParams, const size_t size)
Definition: network.hpp:349
Definition: brainscales_lib.hpp:39
static bool rerun_fixed_number_trials(Network &network, Backend &backend, Real time, size_t n_trials=3)
static std::vector< Real > spike_time_binning_TTFS(const Real &start, const Real &stop, const size_t &n_bins, const std::vector< cypress::Real > &spike_times)
Definition: spiking_utils.hpp:28
static std::vector< T > spike_time_binning(const Real &start, const Real &stop, const size_t &n_bins, const std::vector< cypress::Real > &spike_times)
Definition: spiking_utils.hpp:160
static std::vector< int > calc_num_spikes_vec(const cypress::Matrix< T > &spiketrains, const cypress::Real start=0.0, const cypress::Real end=std::numeric_limits< cypress::Real >::max())
Calculate the number of spikes in a vector of spiketrains in intervall [start,stop].
Definition: spiking_utils.hpp:126
static int calc_num_spikes(const std::vector< cypress::Real > &spiketrain, const cypress::Real start=0.0, const cypress::Real end=0.0)
Calculate the number of spikes of spiketrain in interval [start,stop].