21 #ifndef SNABSUITE_UTIL_UTILITIES_HPP    22 #define SNABSUITE_UTIL_UTILITIES_HPP    24 #include <cypress/cypress.hpp>    54     static std::vector<std::string> &
split(
const std::string &s, 
char delim,
    55                                            std::vector<std::string> &elems);
    62     static std::vector<std::string> 
split(
const std::string &s, 
char delim);
    83                                      double &avg, 
double &std_dev)
    85         if (data.size() > 1) {
    87             max = *std::max_element(data.begin(), data.end());
    88             min = *std::min_element(data.begin(), data.end());
    89             avg = double(std::accumulate(data.begin(), data.end(), 0.0)) /
    92             std::for_each(data.begin(), data.end(), [&](
const T val) {
    93                 std_dev += (val - avg) * (val - avg);
    95             std_dev = std::sqrt(
double(std_dev) / 
double(data.size() - 1));
    97         else if (data.size() == 1) {
   111     template <
typename T>
   124         file.open(file_name, std::ofstream::out);
   126             for (
auto i : data) {
   127                 file << 
i << std::endl;
   132             std::cerr << 
"Could not open file " << file_name
   133                       << 
"for writing csv!" << std::endl;
   137     template <
typename T>
   148                                      std::string first_line = 
"")
   151         file.open(file_name, std::ofstream::out);
   153             if (first_line != 
"") {
   154                 file << first_line << std::endl;
   156             for (
auto i : data) {
   164             std::cerr << 
"Could not open file " << file_name
   165                       << 
"for writing csv!" << std::endl;
   178     static Json 
merge_json(
const Json &a, 
const Json &b);
   211     static void plot_histogram(std::string filename, std::string simulator,
   212                                bool normalized, 
int n_bins, std::string 
title);
   226                                      std::string simulator, 
size_t mem_col = 1,
   228                                      std::string spikes_file = 
"",
   229                                      size_t spikes_col = 0);
   240     static void plot_1d_curve(std::string filename, std::string simulator,
   241                               size_t x_col, 
size_t y_col, 
int std_dev_vol = -1);
 
static Json manipulate_backend_string(std::string &backend, Json &json)
Merge the backend strings with a provided json object. Note: options already included in backend will...
static void progress_callback(double p)
Funtion for generating a progress bar on terminal. 
static void write_vector_to_csv(T &data, std::string file_name)
Writes a vector to a csv. 
Collection of usefull Utilities not directly related to spiking networks. 
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)
Splits a string s into parts devided by delim and stores the result in elems and returns it...
static void plot_histogram(std::string filename, std::string simulator, bool normalized, int n_bins, std::string title)
Plotting a histogram a one dimensional data in a csv. 
static void plot_1d_curve(std::string filename, std::string simulator, size_t x_col, size_t y_col, int std_dev_vol=-1)
Plotting a curve with optional standard deviation. 
static Json merge_json(const Json &a, const Json &b)
Merge two json objects. Note: Values already included in a will be overwritten! See github for source...
static void plot_voltages_spikes(std::string filename, std::string simulator, size_t mem_col=1, size_t t_col=0, std::string spikes_file="", size_t spikes_col=0)
Plotting membrane voltage and (optional) plotting vertical lines for spikes on top. 
static void calculate_statistics(const std::vector< T > &data, T &min, T &max, double &avg, double &std_dev)
Calculating statistics of a vector, using an estimator for std_dev (sample covariance) ...
static void plot_spikes(std::string filename, std::string simulator)
Given a filename of a csv with list of spikes this will produce a raster plot. 
static void write_vector2_to_csv(T &data, std::string file_name, std::string first_line="")
Writes a 2D vector to a csv.