CMath Class Reference

Inheritance diagram for CMath:

Inheritance graph
[legend]

List of all members.


Detailed Description

Mathematical Functions. Class which collects generic mathematical functions

Definition at line 107 of file Mathematics.h.


Public Member Functions

template<>
void display_vector (BYTE *vector, INT n, const char *name)
template<>
void display_vector (INT *vector, INT n, const char *name)
template<>
void display_vector (LONG *vector, INT n, const char *name)
template<>
void display_vector (SHORTREAL *vector, INT n, const char *name)
template<>
void display_vector (DREAL *vector, INT n, const char *name)
template<>
void display_matrix (INT *matrix, INT rows, INT cols, const char *name)
template<>
void display_matrix (DREAL *matrix, INT rows, INT cols, const char *name)
Constructor/Destructor.
 CMath ()
 Constructor - initializes log-table.
virtual ~CMath ()
 Destructor - frees logtable.

Static Public Member Functions

static double mutual_info (DREAL *p1, DREAL *p2, INT len)
static double relative_entropy (DREAL *p, DREAL *q, INT len)
static double entropy (DREAL *p, INT len)
 returns entropy of p which is given in logspace
static UINT get_seed ()
 returns number generator seed
min/max/abs functions.
template<class T>
static T min (T a, T b)
 return the minimum of two integers
template<class T>
static T max (T a, T b)
 return the maximum of two integers
template<class T>
static T clamp (T value, T lb, T ub)
 return the value clamped to interval [lb,ub]
template<class T>
static T abs (T a)
 return the maximum of two integers
misc functions
static UINT crc32 (BYTE *data, INT len)
 crc32
static DREAL round (DREAL d)
static DREAL floor (DREAL d)
static DREAL ceil (DREAL d)
template<class T>
static T sign (T a)
 signum of type T variable a
template<class T>
static void swap (T &a, T &b)
 swap e.g. floats a and b
template<class T>
static T sq (T x)
 x^2
static SHORTREAL sqrt (SHORTREAL x)
 x^0.5
static DREAL sqrt (DREAL x)
 x^0.5
static LONGREAL sqrt (LONGREAL x)
 x^0.5
static long double powl (long double x, long double n)
 x^n
static INT pow (INT x, INT n)
static DREAL pow (DREAL x, DREAL n)
static DREAL log10 (DREAL v)
static DREAL log2 (DREAL v)
static DREAL log (DREAL v)
template<class T>
static void transpose_matrix (T *&matrix, INT &num_feat, INT &num_vec)
static LONG factorial (INT n)
static void init_random (UINT initseed=0)
static LONG random ()
static INT random (INT min_value, INT max_value)
static SHORTREAL random (SHORTREAL min_value, SHORTREAL max_value)
static DREAL random (DREAL min_value, DREAL max_value)
template<class T>
static void fill_vector (T *vec, INT len, T value)
template<class T>
static void range_fill_vector (T *vec, INT len, T start=0)
template<class T>
static void random_vector (T *vec, INT len, T min_value, T max_value)
static INTrandperm (INT n)
static LONG nchoosek (INT n, INT k)
template<class T>
static void vec1_plus_scalar_times_vec2 (T *vec1, T scalar, const T *vec2, INT n)
 x=x+alpha*y
static DREAL dot (const DREAL *v1, const DREAL *v2, INT n)
 compute dot product between v1 and v2 (blas optimized)
static SHORTREAL dot (const SHORTREAL *v1, const SHORTREAL *v2, INT n)
 compute dot product between v1 and v2 (blas optimized)
template<class T>
static void add (T *target, T alpha, const T *v1, T beta, const T *v2, INT len)
 target=alpha*vec1 + beta*vec2
template<class T>
static void add_scalar (T alpha, T *vec, INT len)
 add scalar to vector inplace
template<class T>
static void scale_vector (T alpha, T *vec, INT len)
 scale vector inplace
template<class T>
static T sum (T *vec, INT len)
 return sum(vec)
template<class T>
static T max (T *vec, INT len)
 return max(vec)
template<class T>
static T sum_abs (T *vec, INT len)
 return sum(abs(vec))
static DREAL mean (DREAL *vec, INT len)
static DREAL trace (DREAL *mat, INT cols, INT rows)
static void sort (INT *a, INT cols, INT sort_col=0)
static void sort (DREAL *a, INT *idx, INT N)
template<class T>
static void radix_sort (T *array, size_t size)
template<class T>
static BYTE byte (T word, unsigned short p)
template<class T>
static void radix_sort_helper (T *array, size_t size, unsigned short i)
template<class T>
static void insertion_sort (T *output, INT size)
template<class T>
static void qsort (T *output, INT size)
template<class T>
static void display_vector (T *vector, INT n, const char *name="vector")
 display vector (useful for debugging)
template<class T>
static void display_matrix (T *matrix, INT rows, INT cols, const char *name="matrix")
 display matrix (useful for debugging)
template<class T1, class T2>
static void qsort_index (T1 *output, T2 *index, UINT size)
template<class T1, class T2>
static void * parallel_qsort_index (void *p)
template<class T1, class T2>
static void qsort_backward_index (T1 *output, T2 *index, INT size)
template<class T>
static void min (DREAL *output, T *index, INT size)
template<class T>
static void nmin (DREAL *output, T *index, INT size, INT n)
template<class T>
static INT unique (T *output, INT size)
template<class T>
static INT binary_search_helper (T *output, INT size, T elem)
template<class T>
static INT binary_search (T *output, INT size, T elem)
template<class T>
static INT binary_search_max_lower_equal (T *output, INT size, T elem)
static DREAL Align (CHAR *seq1, CHAR *seq2, INT l1, INT l2, DREAL gapCost)
static INT calcroc (DREAL *fp, DREAL *tp, DREAL *output, INT *label, INT &size, INT &possize, INT &negsize, DREAL &tresh, FILE *rocfile)
summing functions
static DREAL logarithmic_sum (DREAL p, DREAL q)

Static Public Attributes

static CParallel parallel
static CIO io
static CVersion version
constants
static const DREAL INFTY = -log(0.0)
 infinity
static const DREAL ALMOST_INFTY = +1e+20
static const DREAL ALMOST_NEG_INFTY = -1000
 almost neg (log) infinity
static INT LOGRANGE = 0
 range for logtable: log(1+exp(x)) -LOGRANGE <= x <= 0
static UINT seed = 0
 random generator seed
static CHARrand_state = NULL

Constructor & Destructor Documentation

CMath::CMath (  ) 

Constructor - initializes log-table.

Definition at line 54 of file Mathematics.cpp.

CMath::~CMath (  )  [virtual]

Destructor - frees logtable.

Definition at line 86 of file Mathematics.cpp.


Member Function Documentation

template<class T>
static T CMath::min ( a,
b 
) [static]

return the minimum of two integers

Definition at line 127 of file Mathematics.h.

template<class T>
static T CMath::max ( a,
b 
) [static]

return the maximum of two integers

Definition at line 134 of file Mathematics.h.

template<class T>
static T CMath::clamp ( value,
lb,
ub 
) [static]

return the value clamped to interval [lb,ub]

Definition at line 141 of file Mathematics.h.

template<class T>
static T CMath::abs ( a  )  [static]

return the maximum of two integers

Definition at line 153 of file Mathematics.h.

UINT CMath::crc32 ( BYTE data,
INT  len 
) [static]

crc32

Definition at line 350 of file Mathematics.cpp.

static DREAL CMath::round ( DREAL  d  )  [static]

Definition at line 172 of file Mathematics.h.

static DREAL CMath::floor ( DREAL  d  )  [static]

Definition at line 177 of file Mathematics.h.

static DREAL CMath::ceil ( DREAL  d  )  [static]

Definition at line 182 of file Mathematics.h.

template<class T>
static T CMath::sign ( a  )  [static]

signum of type T variable a

Definition at line 189 of file Mathematics.h.

template<class T>
static void CMath::swap ( T &  a,
T &  b 
) [static]

swap e.g. floats a and b

Definition at line 198 of file Mathematics.h.

template<class T>
static T CMath::sq ( x  )  [static]

x^2

Definition at line 207 of file Mathematics.h.

static SHORTREAL CMath::sqrt ( SHORTREAL  x  )  [static]

x^0.5

Definition at line 213 of file Mathematics.h.

static DREAL CMath::sqrt ( DREAL  x  )  [static]

x^0.5

Definition at line 219 of file Mathematics.h.

static LONGREAL CMath::sqrt ( LONGREAL  x  )  [static]

x^0.5

Definition at line 225 of file Mathematics.h.

static long double CMath::powl ( long double  x,
long double  n 
) [static]

x^n

Definition at line 238 of file Mathematics.h.

static INT CMath::pow ( INT  x,
INT  n 
) [static]

Definition at line 249 of file Mathematics.h.

static DREAL CMath::pow ( DREAL  x,
DREAL  n 
) [static]

Definition at line 259 of file Mathematics.h.

static DREAL CMath::log10 ( DREAL  v  )  [static]

Definition at line 264 of file Mathematics.h.

static DREAL CMath::log2 ( DREAL  v  )  [static]

Definition at line 275 of file Mathematics.h.

static DREAL CMath::log ( DREAL  v  )  [static]

Definition at line 281 of file Mathematics.h.

template<class T>
static void CMath::transpose_matrix ( T *&  matrix,
INT num_feat,
INT num_vec 
) [static]

Definition at line 286 of file Mathematics.h.

static LONG CMath::factorial ( INT  n  )  [static]

Definition at line 329 of file Mathematics.h.

static void CMath::init_random ( UINT  initseed = 0  )  [static]

Definition at line 337 of file Mathematics.h.

static LONG CMath::random (  )  [static]

Definition at line 354 of file Mathematics.h.

static INT CMath::random ( INT  min_value,
INT  max_value 
) [static]

Definition at line 363 of file Mathematics.h.

static SHORTREAL CMath::random ( SHORTREAL  min_value,
SHORTREAL  max_value 
) [static]

Definition at line 370 of file Mathematics.h.

static DREAL CMath::random ( DREAL  min_value,
DREAL  max_value 
) [static]

Definition at line 380 of file Mathematics.h.

template<class T>
static void CMath::fill_vector ( T *  vec,
INT  len,
value 
) [static]

Definition at line 391 of file Mathematics.h.

template<class T>
static void CMath::range_fill_vector ( T *  vec,
INT  len,
start = 0 
) [static]

Definition at line 397 of file Mathematics.h.

template<class T>
static void CMath::random_vector ( T *  vec,
INT  len,
min_value,
max_value 
) [static]

Definition at line 404 of file Mathematics.h.

static INT* CMath::randperm ( INT  n  )  [static]

Definition at line 410 of file Mathematics.h.

static LONG CMath::nchoosek ( INT  n,
INT  k 
) [static]

Definition at line 423 of file Mathematics.h.

template<class T>
static void CMath::vec1_plus_scalar_times_vec2 ( T *  vec1,
scalar,
const T *  vec2,
INT  n 
) [static]

x=x+alpha*y

Definition at line 435 of file Mathematics.h.

static DREAL CMath::dot ( const DREAL v1,
const DREAL v2,
INT  n 
) [static]

compute dot product between v1 and v2 (blas optimized)

Definition at line 443 of file Mathematics.h.

static SHORTREAL CMath::dot ( const SHORTREAL v1,
const SHORTREAL v2,
INT  n 
) [static]

compute dot product between v1 and v2 (blas optimized)

Definition at line 457 of file Mathematics.h.

template<class T>
static void CMath::add ( T *  target,
alpha,
const T *  v1,
beta,
const T *  v2,
INT  len 
) [static]

target=alpha*vec1 + beta*vec2

Definition at line 472 of file Mathematics.h.

template<class T>
static void CMath::add_scalar ( alpha,
T *  vec,
INT  len 
) [static]

add scalar to vector inplace

Definition at line 480 of file Mathematics.h.

template<class T>
static void CMath::scale_vector ( alpha,
T *  vec,
INT  len 
) [static]

scale vector inplace

Definition at line 488 of file Mathematics.h.

template<class T>
static T CMath::sum ( T *  vec,
INT  len 
) [static]

return sum(vec)

Definition at line 496 of file Mathematics.h.

template<class T>
static T CMath::max ( T *  vec,
INT  len 
) [static]

return max(vec)

Definition at line 507 of file Mathematics.h.

template<class T>
static T CMath::sum_abs ( T *  vec,
INT  len 
) [static]

return sum(abs(vec))

Definition at line 520 of file Mathematics.h.

static DREAL CMath::mean ( DREAL vec,
INT  len 
) [static]

Definition at line 529 of file Mathematics.h.

static DREAL CMath::trace ( DREAL mat,
INT  cols,
INT  rows 
) [static]

Definition at line 540 of file Mathematics.h.

void CMath::sort ( INT a,
INT  cols,
INT  sort_col = 0 
) [static]

performs a bubblesort on a given matrix a. it is sorted in ascending order from top to bottom and left to right

Definition at line 127 of file Mathematics.cpp.

void CMath::sort ( DREAL a,
INT idx,
INT  N 
) [static]

Definition at line 147 of file Mathematics.cpp.

template<class T>
static void CMath::radix_sort ( T *  array,
size_t  size 
) [static]

performs a in-place radix sort in ascending order

Definition at line 562 of file Mathematics.h.

template<class T>
static BYTE CMath::byte ( word,
unsigned short  p 
) [static]

Definition at line 568 of file Mathematics.h.

template<class T>
static void CMath::radix_sort_helper ( T *  array,
size_t  size,
unsigned short  i 
) [static]

Definition at line 574 of file Mathematics.h.

template<class T>
static void CMath::insertion_sort ( T *  output,
INT  size 
) [static]

performs insertion sort of an array output of length size it is sorted from in ascending (for type T)

Definition at line 674 of file Mathematics.h.

template<class T>
static void CMath::qsort ( T *  output,
INT  size 
) [static]

performs a quicksort on an array output of length size it is sorted from in ascending (for type T)

Definition at line 695 of file Mathematics.h.

template<class T>
static void CMath::display_vector ( T *  vector,
INT  n,
const char *  name = "vector" 
) [static]

display vector (useful for debugging)

template<class T>
static void CMath::display_matrix ( T *  matrix,
INT  rows,
INT  cols,
const char *  name = "matrix" 
) [static]

display matrix (useful for debugging)

template<class T1, class T2>
void CMath::qsort_index ( T1 *  output,
T2 *  index,
UINT  size 
) [static]

performs a quicksort on an array output of length size it is sorted in ascending order (for type T1) and returns the index (type T2) matlab alike [sorted,index]=sort(output)

Definition at line 1070 of file Mathematics.h.

template<class T1, class T2>
void * CMath::parallel_qsort_index ( void *  p  )  [static]

Definition at line 970 of file Mathematics.h.

template<class T1, class T2>
void CMath::qsort_backward_index ( T1 *  output,
T2 *  index,
INT  size 
) [static]

performs a quicksort on an array output of length size it is sorted in ascending order (for type T1) and returns the index (type T2) matlab alike [sorted,index]=sort(output)

Definition at line 1110 of file Mathematics.h.

template<class T>
void CMath::min ( DREAL output,
T *  index,
INT  size 
) [static]

Definition at line 1162 of file Mathematics.h.

template<class T>
void CMath::nmin ( DREAL output,
T *  index,
INT  size,
INT  n 
) [static]

Definition at line 1151 of file Mathematics.h.

template<class T>
static INT CMath::unique ( T *  output,
INT  size 
) [static]

Definition at line 768 of file Mathematics.h.

template<class T>
static INT CMath::binary_search_helper ( T *  output,
INT  size,
elem 
) [static]

Definition at line 781 of file Mathematics.h.

template<class T>
static INT CMath::binary_search ( T *  output,
INT  size,
elem 
) [static]

Definition at line 810 of file Mathematics.h.

template<class T>
static INT CMath::binary_search_max_lower_equal ( T *  output,
INT  size,
elem 
) [static]

Definition at line 823 of file Mathematics.h.

DREAL CMath::Align ( CHAR seq1,
CHAR seq2,
INT  l1,
INT  l2,
DREAL  gapCost 
) [static]

align two sequences seq1 & seq2 of length l1 and l2 using gapCost return alignment cost

Definition at line 167 of file Mathematics.cpp.

INT CMath::calcroc ( DREAL fp,
DREAL tp,
DREAL output,
INT label,
INT size,
INT possize,
INT negsize,
DREAL tresh,
FILE *  rocfile 
) [static]

calculates ROC into (fp,tp) from output and label of length size returns index with smallest error=fp+fn

Definition at line 211 of file Mathematics.cpp.

double CMath::mutual_info ( DREAL p1,
DREAL p2,
INT  len 
) [static]

returns the mutual information of p which is given in logspace where p,q are given in logspace

Definition at line 378 of file Mathematics.cpp.

double CMath::relative_entropy ( DREAL p,
DREAL q,
INT  len 
) [static]

returns the relative entropy H(P||Q), where p,q are given in logspace

Definition at line 389 of file Mathematics.cpp.

double CMath::entropy ( DREAL p,
INT  len 
) [static]

returns entropy of p which is given in logspace

Definition at line 399 of file Mathematics.cpp.

static UINT CMath::get_seed (  )  [static]

returns number generator seed

Definition at line 857 of file Mathematics.h.

static DREAL CMath::logarithmic_sum ( DREAL  p,
DREAL  q 
) [static]

sum logarithmic probabilities. Probability measures are summed up but are now given in logspace where direct summation of exp(operand) is not possible due to numerical problems, i.e. eg. exp(-1000)=0. Therefore we do log( exp(a) + exp(b)) = a + log (1 + exp (b-a)) where a = max(p,q) and b min(p,q).

Definition at line 900 of file Mathematics.h.

template<>
void CMath::display_vector ( BYTE vector,
INT  n,
const char *  name 
)

Definition at line 458 of file Mathematics.cpp.

template<>
void CMath::display_vector ( INT vector,
INT  n,
const char *  name 
)

Definition at line 468 of file Mathematics.cpp.

template<>
void CMath::display_vector ( LONG vector,
INT  n,
const char *  name 
)

Definition at line 478 of file Mathematics.cpp.

template<>
void CMath::display_vector ( SHORTREAL vector,
INT  n,
const char *  name 
)

Definition at line 488 of file Mathematics.cpp.

template<>
void CMath::display_vector ( DREAL vector,
INT  n,
const char *  name 
)

Definition at line 498 of file Mathematics.cpp.

template<>
void CMath::display_matrix ( INT matrix,
INT  rows,
INT  cols,
const char *  name 
)

Definition at line 508 of file Mathematics.cpp.

template<>
void CMath::display_matrix ( DREAL matrix,
INT  rows,
INT  cols,
const char *  name 
)

Definition at line 524 of file Mathematics.cpp.


Member Data Documentation

const DREAL CMath::INFTY = -log(0.0) [static]

infinity

Definition at line 945 of file Mathematics.h.

const DREAL CMath::ALMOST_INFTY = +1e+20 [static]

Definition at line 946 of file Mathematics.h.

const DREAL CMath::ALMOST_NEG_INFTY = -1000 [static]

almost neg (log) infinity

Definition at line 949 of file Mathematics.h.

INT CMath::LOGRANGE = 0 [static]

range for logtable: log(1+exp(x)) -LOGRANGE <= x <= 0

Definition at line 952 of file Mathematics.h.

UINT CMath::seed = 0 [static]

random generator seed

Definition at line 955 of file Mathematics.h.

CHAR * CMath::rand_state = NULL [static]

Definition at line 966 of file Mathematics.h.

CParallel CSGObject::parallel [static, inherited]

Definition at line 105 of file SGObject.h.

CIO CSGObject::io [static, inherited]

Definition at line 106 of file SGObject.h.

CVersion CSGObject::version [static, inherited]

Definition at line 107 of file SGObject.h.


The documentation for this class was generated from the following files:

SHOGUN Machine Learning Toolbox - Documentation