HDIM  1.0.0
Packages for High Dimensional Linear Regression
generics.hpp File Reference

Generic linear algebra functions. More...

#include <fenv.h>
#include <chrono>
#include <fstream>
#include <vector>
#include <eigen3/Eigen/Dense>

Go to the source code of this file.

Classes

struct  hdim::Binarize< T >
 Functor to convert vector of values into support vector. More...
 
struct  hdim::SoftThres< T >
 Soft Threshold functor used to apply hdim::soft_threshold to each element in a matrix or vector. More...
 
struct  hdim::SupportSift< T >
 

Functions

template<typename T >
hdim::StdDev (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &vect)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > hdim::Normalize (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat)
 Set the mean of a matrix to 0 and the standard deviation to 1. More...
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > hdim::Normalize (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > hdim::Normalize (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &mat)
 Overloaded version of hdim::Normalize to accomadate vectors.
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > hdim::Normalize (Eigen::Matrix< T, Eigen::Dynamic, 1 > &mat)
 Overloaded version of hdim::Normalize to accomadate vectors.
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > hdim::build_matrix (unsigned int num_rows, unsigned int num_cols, T(*mat_func)(unsigned int, unsigned int))
 Generate a matrix using a function that depends on row and column indices. More...
 
template<typename T >
void hdim::sweep_matrix (Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat, T(*mat_func)(unsigned int, unsigned int))
 sweep_matrix More...
 
template<typename T >
hdim::square (T &val)
 Compute the square of a value. More...
 
template<typename T >
std::vector< T > hdim::LogScaleVector (T lower_bound, T upper_bound, unsigned int num_elements)
 Generate a vector of logarithmically equally spaced points. More...
 
template<typename T >
hdim::sgn (T val)
 The sign function defined as. More...
 
template<typename T >
hdim::pos_part (T x)
 The positive part function defined as. More...
 
template<typename T >
hdim::soft_threshold (T x, T y)
 The proximal ( soft thresholding ) operator defined as. More...
 
template<typename T >
hdim::prox (T x, T lambda)
 A functional equivalent of hdim::soft_threshold, but possibly faster.
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > hdim::soft_threshold_mat (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &mat, const T lambda)
 
template<typename T >
Eigen::Matrix< int, Eigen::Dynamic, 1 > hdim::GenerateSupport (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &coefficients, T cut_off)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > hdim::negative_index (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &mat_in, int index)
 
template<typename T >
hdim::duality_gap (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &X, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &Y, const Eigen::Matrix< T, Eigen::Dynamic, 1 > &Beta, T r_stats_it)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > hdim::slice (const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &org, const std::vector< unsigned int > &indices)
 
template<typename T >
Eigen::Matrix< T, Eigen::Dynamic, 1 > hdim::slice (const Eigen::Matrix< T, Eigen::Dynamic, 1 > &org, const std::vector< unsigned int > &indices)
 

Detailed Description

Generic linear algebra functions.

Definition in file generics.hpp.

Function Documentation

template<typename T >
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> hdim::build_matrix ( unsigned int  num_rows,
unsigned int  num_cols,
T(*)(unsigned int, unsigned int)  mat_func 
)

Generate a matrix using a function that depends on row and column indices.

That is $ \forall i, j A_{i,j} = f( i, j ) $ for some function f and an input matrix A.

Parameters
num_rowsNumber of rows the output matrix should have
num_colsNumber of columns the output matrix should have
Returns
A matrix populated with values assigned by mat_func( i, j )

Definition at line 131 of file generics.hpp.

template<typename T >
std::vector< T > hdim::LogScaleVector ( lower_bound,
upper_bound,
unsigned int  num_elements 
)

Generate a vector of logarithmically equally spaced points.

There will be num_element points, beginning at log10( lower_bound ) and ending at log10( upper_bound ).

This function is semantically equivalent to the R function 'logspace'.

Parameters
lower_bound10^x for x = smallest element in vector
upper_bound10^x for x = largest element in vector
num_elementsnumber of elements in the generated vector
Returns

Vector of logarithmically equally spaced points

Definition at line 198 of file generics.hpp.

template<typename T >
Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> hdim::Normalize ( const Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  mat)

Set the mean of a matrix to 0 and the standard deviation to 1.

Note this function is done in place, that is the input matrix is modified.

Parameters
matAn n x m matrix to be normalized.

Definition at line 67 of file generics.hpp.

template<typename T >
T hdim::pos_part ( x)

The positive part function defined as.

\[ x^{+} \equiv \begin{cases} x & \text{if } x \geq 0\\ 0 & \text{if } x < 0\\ \end{cases} \]

Definition at line 262 of file generics.hpp.

template<typename T >
T hdim::sgn ( val)

The sign function defined as.

\[ sgn(x) \equiv \begin{cases} 1 & \text{if } x > 0 \\ 0 & \text{if } x = 0 \\ -1& \text{if } x < 0 \end{cases} \]

Definition at line 246 of file generics.hpp.

template<typename T >
T hdim::soft_threshold ( x,
y 
)

The proximal ( soft thresholding ) operator defined as.

\[ \tau( x, y ) \equiv sgn(x) \left( \lvert x \rvert - y \right)^{+} \]

Parameters
val
Returns

Definition at line 276 of file generics.hpp.

template<typename T >
T hdim::square ( T &  val)

Compute the square of a value.

Parameters
valvalue to square
Returns
The squared quantity

Definition at line 169 of file generics.hpp.

template<typename T >
void hdim::sweep_matrix ( Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > &  mat,
T(*)(unsigned int, unsigned int)  mat_func 
)

sweep_matrix

Parameters
mat

Definition at line 150 of file generics.hpp.