neuro_toolbox
Functions
NTB Namespace Reference

Functions

template<typename T >
std::vector< T > load_vector (std::string filename)
 
bool file_exists (const std::string &filename)
 
template<typename T >
std::vector< std::vector< T > > load_matrix (const std::string filename, const int row, const int col)
 
template<typename T >
std::vector< std::vector< T > > adjmat_to_adjlist (const std::vector< std::vector< T >> &A, const double threshold=1e-8, std::string in_degree="row")
 
template<typename T >
void write_matrix_to_file (const std::vector< std::vector< T >> &A, const std::string filename)
 
template<typename T >
void write_vector_to_file (const std::vector< T > &v, const std::string filename)
 
void spikes_to_file (const std::string filename, const std::vector< std::vector< double >> &spikes)
 
std::vector< float > rand_uniform (const double low, const double high, const int size, const int seed=-1)
 
std::vector< int > randint (const int low, const int high, const int size, const int seed=-1)
 
void make_signal (std::vector< double > &signal, const int fs, const int num_points=1024, const double f1=50.25, const double f2=80.5, const double a1=1.0, const double a2=0.5)
 
void fft (const std::vector< double > &signal, std::vector< double > &frequencies, std::vector< double > &amplitudes, const double fs)
 
template<typename T >
std::vector< T > flatten (const std::vector< std::vector< T >> &vec)
 
std::vector< double > angle_arr (const fftw_complex *z, const int n, bool deg=false)
 
template<typename T >
double average (const std::vector< T > &vec, const int index=0)
 
void hilbert_transform (const std::vector< double > &in_vec, fftw_complex *out_array)
 
std::vector< double > unwrap (const std::vector< double > &in_vec)
 
double calculate_phase_difference (const std::vector< double > &x)
 
double calculate_phase_synchrony (const std::vector< std::vector< double >> &voltages)
 
double get_wall_time ()
 
double get_cpu_time ()
 
void display_timing (double wtime, double cptime)
 

Function Documentation

◆ adjmat_to_adjlist()

template<typename T >
std::vector<std::vector<T> > NTB::adjmat_to_adjlist ( const std::vector< std::vector< T >> &  A,
const double  threshold = 1e-8,
std::string  in_degree = "row" 
)

return adjacency list of given adjacency matrix

Parameters
Ainput adjacency matrix
thresholdthreshold for binarizing
in_degree"row" or "col" to consider input edges on row or col, respectively
Returns
adjacency list as a vector of vector

example adjmat_to_adjlist<int>(A);

◆ angle_arr()

std::vector<double> NTB::angle_arr ( const fftw_complex *  z,
const int  n,
bool  deg = false 
)

Return the angle of the complex argument.

◆ average()

template<typename T >
double NTB::average ( const std::vector< T > &  vec,
const int  index = 0 
)
inline

average the vector from element "index" to end of the vector

Parameters
vecinput vector
indexindex to drop elements before that
Returns
[double] average value of input vector

◆ calculate_phase_difference()

double NTB::calculate_phase_difference ( const std::vector< double > &  x)

◆ calculate_phase_synchrony()

double NTB::calculate_phase_synchrony ( const std::vector< std::vector< double >> &  voltages)

◆ display_timing()

void NTB::display_timing ( double  wtime,
double  cptime 
)

Display wall time and cpu time on terminal

◆ fft()

void NTB::fft ( const std::vector< double > &  signal,
std::vector< double > &  frequencies,
std::vector< double > &  amplitudes,
const double  fs 
)

discrete Fourier transform (DFT) from 1d read signal

Parameters
signal[Input] input signal
freq[input/output] output as frequency
amplitudes[input/output] output as amplitudes
fsfrequency sampling in [s^1]

◆ file_exists()

bool NTB::file_exists ( const std::string &  filename)
inline

check whether file with given name exist

Parameters
filename[string] input file name
Returns
true if input file exists

◆ flatten()

template<typename T >
std::vector<T> NTB::flatten ( const std::vector< std::vector< T >> &  vec)

Return a copy of the vector collapsed into one dimension

Parameters
vecinput vector of vectors
Returns
A copy of the input vector, flattened to one dimension.

◆ get_cpu_time()

double NTB::get_cpu_time ( )

measure cpu passed time

Returns
cpu time in second

◆ get_wall_time()

double NTB::get_wall_time ( )

measure real passed time

Returns
wall time in second

◆ hilbert_transform()

void NTB::hilbert_transform ( const std::vector< double > &  in_vec,
fftw_complex *  out_array 
)

Compute the analytic signal, using the Hilbert transform. equivalent to scipy.signal.hilbert

Parameters
inputvector
out_arraycomplex analytic signal

◆ load_matrix()

template<typename T >
std::vector<std::vector<T> > NTB::load_matrix ( const std::string  filename,
const int  row,
const int  col 
)
inline

Read matrix into vector of vector

Parameters
filename[string] name of text file to read
row[int] number of rows
col[int] number of columns
Returns
vector of vector of specified type

example std::vector<std::vector<int>> A = Neuro::read_matrix<int>( "data/matrix_integer.txt", 4, 3);

◆ load_vector()

template<typename T >
std::vector<T> NTB::load_vector ( std::string  filename)
inline

Read numbers from single column text file

Parameters
filename[std::string] input file name
Returns
a vector of numbers of type specified

example:

std::vector<double> vec = read_from_file<double>("my_file.txt");

exit if it does not found the input file

◆ make_signal()

void NTB::make_signal ( std::vector< double > &  signal,
const int  fs,
const int  num_points = 1024,
const double  f1 = 50.25,
const double  f2 = 80.5,
const double  a1 = 1.0,
const double  a2 = 0.5 
)

Generate two sine waves of different frequencies and amplitudes.

Parameters
signal[input/output] 1d real vector as signal.
fsfrequency sampling [s^-1]
num_pointsthe numper of points in signal
f1frequency in [Hz]
f2frequency in [Hz]
a1amplitude
a2amplitude

◆ rand_uniform()

std::vector<float> NTB::rand_uniform ( const double  low,
const double  high,
const int  size,
const int  seed = -1 
)

Random number distribution that produces floating-point values according to a uniform distribution, which is described by the following probability density function: P(X|a, b) = 1/(b-a), a<= x < b This distribution (also know as rectangular distribution) produces random numbers in a range [a,b) where all intervals of the same length within it are equally probable.

Parameters
lowLower boundary of the output interval. All values generated will be greater than or equal to low.
highUpper boundary of the output interval. All values generated will be less than or equal to high.
sizeLengh of output random numbers.
seedif not defined a positive number, return the same random numbers

◆ randint()

std::vector<int> NTB::randint ( const int  low,
const int  high,
const int  size,
const int  seed = -1 
)

Random number distribution that produces integer values according to a uniform discrete distribution, which is described by the following probability mass function: P(i|a,b) = 1/(b-a+1), a <= i <= b

Parameters
lowLower boundary of the output interval. All values generated will be greater than or equal to low.
highUpper boundary of the output interval. All values generated will be less than or equal to high.
sizeLengh of output random numbers.
seedif not defined a positive number, return the same random numbers

◆ spikes_to_file()

void NTB::spikes_to_file ( const std::string  filename,
const std::vector< std::vector< double >> &  spikes 
)

◆ unwrap()

std::vector<double> NTB::unwrap ( const std::vector< double > &  in_vec)

Unwrap by changing deltas between values to 2*pi complement.

Unwrap radian phase in_vec by changing absolute jumps greater than pi to their 2*pi complement. equivalent to numpy.unwrap

Parameters
in_vecinput vector
Returns
out_vec output vector

◆ write_matrix_to_file()

template<typename T >
void NTB::write_matrix_to_file ( const std::vector< std::vector< T >> &  A,
const std::string  filename 
)

Write matrix to text file

Parameters
Ainput vector of vector of type T.
filenameoutput text file name.

◆ write_vector_to_file()

template<typename T >
void NTB::write_vector_to_file ( const std::vector< T > &  v,
const std::string  filename 
)

Write vector to text file

Parameters
vinput vector of type T
filenameoutput text file name.

Exit if it could not open file to write successfully.