DaNNet
Functions
Misc

Miscellaneous functions. More...

Functions

std::string dnn::version_info (void)
 Generate DaNNet version string. More...
 
template<typename T >
void dnn::pol2cart (const T phi, const T r, T &x, T &y)
 Polar to cartesian convertion. More...
 
template<typename T >
void dnn::pol2cart (const arma::Mat< T > phi, const arma::Mat< T > r, arma::Mat< T > &x, arma::Mat< T > &y)
 Polar to cartesian convertion (matrix) More...
 
template<typename T >
void dnn::cart2pol (const T x, const T y, T &phi, T &r)
 Cartesian to polar convertion. More...
 
template<typename T >
void dnn::cart2pol (const arma::Mat< T > x, const arma::Mat< T > y, arma::Mat< T > &phi, arma::Mat< T > &r)
 Cartesian to polar convertion (matrix) More...
 
arma_inline arma::Mat< DNN_Dtypednn::row2col (const arma::Mat< DNN_Dtype > &A)
 Flattens a matrix row-wise to a one column matrix. More...
 
arma_inline arma::Mat< DNN_Dtypednn::col2col (const arma::Mat< DNN_Dtype > &A)
 Flattens a matrix col-wise to a one column matrix. More...
 
arma_inline arma::Mat< DNN_Dtypednn::mat2mat (const arma::Mat< DNN_Dtype > &A, const arma::uword rows, const arma::uword cols)
 Reshapes a matrix. More...
 
arma_inline arma::Cube< DNN_Dtypednn::mat2cube (const arma::Mat< DNN_Dtype > &A, const arma::uword rows, const arma::uword cols, const arma::uword slices)
 Converts a matrix to a cube. More...
 
arma_inline arma::Mat< DNN_Dtypednn::cube2mat (arma::Cube< DNN_Dtype > &A, const arma::uword rows, const arma::uword cols)
 Converts a cube to a matrix. More...
 
void dnn::gen_spiral (arma::Mat< DNN_Dtype > &X, arma::Mat< DNN_Dtype > &T, arma::uword N, arma::uword K, const double ph_var=0.1, const double r_min=0.1, const double ph_max=7)
 Dataset generator: a rotating spiral with K classes. More...
 
uint32_t dnn::swap_endian (uint32_t i)
 Endian converter for IDX1 and IDX3 file. More...
 
bool dnn::read_idx3 (std::string fname, arma::Cube< DNN_Dtype > &img, const double frac=1.0)
 Reads a IDX3 file. More...
 
bool dnn::read_idx1 (std::string fname, arma::ivec &label, const double frac=1.0)
 Reads a IDX1 file. More...
 
void dnn::read_MNIST (std::string fname_X, std::string fname_T, arma::Mat< DNN_Dtype > &X, arma::Mat< DNN_Dtype > &T, double frac=1.0)
 Reads a MNIST digit dataset. More...
 
void dnn::progress_bar (const std::string str, double p)
 Console progress bar. More...
 
void dnn::progress_bar (const std::string str, arma::uword num, arma::uword maxnum)
 Console progress bar. More...
 
void dnn::remove_progress_bar (void)
 Clears progress bar. More...
 

Detailed Description

Miscellaneous functions.

Function Documentation

◆ cart2pol() [1/2]

template<typename T >
void dnn::cart2pol ( const T  x,
const T  y,
T &  phi,
T &  r 
)

Cartesian to polar convertion.

Parameters
[in]x,yCartesian coordiate
[out]phi,rAngle (in radians) and radius

Converts between cartesian and polar format

Definition at line 69 of file dnn_misc.h.

◆ cart2pol() [2/2]

template<typename T >
void dnn::cart2pol ( const arma::Mat< T >  x,
const arma::Mat< T >  y,
arma::Mat< T > &  phi,
arma::Mat< T > &  r 
)

Cartesian to polar convertion (matrix)

Parameters
[in]x,yCartesian coordiate
[out]phi,rAngle (in radians) and radius

Converts between cartesian and polar format for matrix data

Definition at line 83 of file dnn_misc.h.

◆ col2col()

arma_inline arma::Mat<DNN_Dtype> dnn::col2col ( const arma::Mat< DNN_Dtype > &  A)

Flattens a matrix col-wise to a one column matrix.

Parameters
[in]AInput matrix [M,N]
Returns
Output matrix [M*N,1]

Concatenates cols in the matrix A[M,N] to A[M*N,1]

Definition at line 110 of file dnn_misc.h.

◆ cube2mat()

arma_inline arma::Mat<DNN_Dtype> dnn::cube2mat ( arma::Cube< DNN_Dtype > &  A,
const arma::uword  rows,
const arma::uword  cols 
)

Converts a cube to a matrix.

Parameters
[in]AInput cube [M,N,P]
[in]rowsNumber of rows
[in]colsNumber of columns
Returns
Output matrix [K,L]

Reshapes the cube layer-wise A[M,N,P] to A[M*N*P,1] and then to A[K,L] K*L must be equal to M*N*P

Definition at line 158 of file dnn_misc.h.

◆ gen_spiral()

void dnn::gen_spiral ( arma::Mat< DNN_Dtype > &  X,
arma::Mat< DNN_Dtype > &  T,
arma::uword  N,
arma::uword  K,
const double  ph_var = 0.1,
const double  r_min = 0.1,
const double  ph_max = 7 
)

Dataset generator: a rotating spiral with K classes.

Parameters
[in]NNumber of test samples
[in]KNumber of classes (fans)
[in]ph_varModel param, phase variance
[in]r_minModel param, radius start value
[in]ph_maxModel param, maximum phase offset
[out]XMatrix with x and y value for each sample, size [2,N]
[out]TMatrix with class category for each sample, size [K,N]

A 2D dataset for a spiral pattern with K classes is generated

Spiral.png

Definition at line 179 of file dnn_misc.h.

◆ mat2cube()

arma_inline arma::Cube<DNN_Dtype> dnn::mat2cube ( const arma::Mat< DNN_Dtype > &  A,
const arma::uword  rows,
const arma::uword  cols,
const arma::uword  slices 
)

Converts a matrix to a cube.

Parameters
[in]AInput matrix [K,L]
[in]rowsNumber of rows
[in]colsNumber of columns
[in]slicesNumber of columns
Returns
Output cube [M,N,P]

Reshapes the matrix col-wise A[K,L] to A[K*L,1] and then to A[M,N,P] K*L must be equal to M*N*P

Definition at line 142 of file dnn_misc.h.

◆ mat2mat()

arma_inline arma::Mat<DNN_Dtype> dnn::mat2mat ( const arma::Mat< DNN_Dtype > &  A,
const arma::uword  rows,
const arma::uword  cols 
)

Reshapes a matrix.

Parameters
[in]AInput matrix [K,L]
[in]rowsNumber of rows
[in]colsNumber of columns
Returns
Output matrix [M,N]

Reshapes the matrix col-wise A[K,L] to A[K*L,1] and then to A[M,N] K*L must be equal to M*N

Definition at line 125 of file dnn_misc.h.

◆ pol2cart() [1/2]

template<typename T >
void dnn::pol2cart ( const T  phi,
const T  r,
T &  x,
T &  y 
)

Polar to cartesian convertion.

Parameters
[in]phi,rAngle (in radians) and radius
[out]x,yCartesian coordiate

Converts between polar and cartesian format

Definition at line 42 of file dnn_misc.h.

◆ pol2cart() [2/2]

template<typename T >
void dnn::pol2cart ( const arma::Mat< T >  phi,
const arma::Mat< T >  r,
arma::Mat< T > &  x,
arma::Mat< T > &  y 
)

Polar to cartesian convertion (matrix)

Parameters
[in]phi,rAngle (in radians) and radius
[out]x,yCartesian coordiate

Converts between polar and cartesian format for matrix data

Definition at line 55 of file dnn_misc.h.

◆ progress_bar() [1/2]

void dnn::progress_bar ( const std::string  str,
double  p 
)

Console progress bar.

Parameters
[in]strInfo string
[in]pProgress quota

Prints a progress bar at stdout

Definition at line 382 of file dnn_misc.h.

◆ progress_bar() [2/2]

void dnn::progress_bar ( const std::string  str,
arma::uword  num,
arma::uword  maxnum 
)

Console progress bar.

Parameters
[in]strInfo string
[in]numCurrent iteration
[in]maxnumTarget (100%) iterations

Prints a progress bar at stdout

Definition at line 412 of file dnn_misc.h.

◆ read_idx1()

bool dnn::read_idx1 ( std::string  fname,
arma::ivec &  label,
const double  frac = 1.0 
)

Reads a IDX1 file.

Parameters
[in]fnameFile name
[in]fracNumber of images in dataset to read [0..1]
[out]labelLabels stored in a vector
Returns
true if successful

Reads a IDX1 file, as used by MNIST digit dataset See http://yann.lecun.com/exdb/mnist/

Definition at line 305 of file dnn_misc.h.

◆ read_idx3()

bool dnn::read_idx3 ( std::string  fname,
arma::Cube< DNN_Dtype > &  img,
const double  frac = 1.0 
)

Reads a IDX3 file.

Parameters
[in]fnameFile name
[in]fracNumber of images in dataset to read [0..1]
[out]imgImages stored in a cube [R,C,N]
Returns
true if successful

Reads a IDX3 file, as used by MNIST digit dataset See http://yann.lecun.com/exdb/mnist/

Definition at line 246 of file dnn_misc.h.

◆ read_MNIST()

void dnn::read_MNIST ( std::string  fname_X,
std::string  fname_T,
arma::Mat< DNN_Dtype > &  X,
arma::Mat< DNN_Dtype > &  T,
double  frac = 1.0 
)

Reads a MNIST digit dataset.

Parameters
[in]fname_XFile name of the data
[in]fname_TFile name of the label
[in]fracNumber of images in dataset to read [0..1]
[out]XImages stored in a matrix [R*C,N]
[out]TImages stored in a matrix [10,N]

Reads MNIST digit dataset, returns a data matrix scaled to [0..1] and a label matrix one-hot-encoded. Download data from http://yann.lecun.com/exdb/mnist/

Definition at line 352 of file dnn_misc.h.

◆ remove_progress_bar()

void dnn::remove_progress_bar ( void  )

Clears progress bar.

Clears the progress bar from stdout

Definition at line 422 of file dnn_misc.h.

◆ row2col()

arma_inline arma::Mat<DNN_Dtype> dnn::row2col ( const arma::Mat< DNN_Dtype > &  A)

Flattens a matrix row-wise to a one column matrix.

Parameters
[in]AInput matrix [M,N]
Returns
Output matrix [M*N,1]

Concatenates rows in the matrix A[M,N] to A[M*N,1]

Definition at line 97 of file dnn_misc.h.

◆ swap_endian()

uint32_t dnn::swap_endian ( uint32_t  i)

Endian converter for IDX1 and IDX3 file.

Definition at line 226 of file dnn_misc.h.

◆ version_info()

std::string dnn::version_info ( void  )

Generate DaNNet version string.

Returns
Version string

Definition at line 29 of file dnn_misc.h.