Robot Simulator of the Robotics Group for Self-Organization of Control  0.8.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
controller_misc.h File Reference
#include <selforg/matrix.h>
#include <assert.h>
#include <stdlib.h>
#include <cmath>
#include "stl_adds.h"
#include "noisegenerator.h"
#include "inspectable.h"
Include dependency graph for controller_misc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<typename T >
sign (T v)
 
template<typename T >
sqr (T v)
 
template<typename T >
clip (T x, T lobound, T highbound)
 
double one_over (double x)
 calculates 1/x More...
 
double constant (double c, double)
 returns c (useful for Matrix::mapP to fill matrix with constant value) More...
 
double power (void *c, double x)
 returns x the power c (as a double) More...
 
double power3 (double x)
 power 3 for matrix::map More...
 
double random_minusone_to_one (double)
 creates random number from -1 to 1 More...
 
double random_minusone_to_one (void *, double)
 creates random number from -1 to 1 More...
 
double clip (double r, double)
 clipping function to the interval [-r, r] (for use with mapP) More...
 
double lowercutof (void *theta, double)
 cutof function for mapP More...
 
double toBinaryWithProbability (void *r, double x)
 returns -1 if probability is to low, otherwise 1 for mapP More...
 
double toBinaryWithThreshold (double x, double threshold)
 returns -1 if below threshold, otherwise 1 for map2 More...
 
double plus_ (double b, double a)
 plus function for mapP More...
 
std::list< matrix::Dstore4x4AndDiagonal (const matrix::Matrix &m)
 stores at least left top 4x4 submatrix (row-wise) (if exists) and then the rest of the diagonal elements into a list More...
 
matrix::I store4x4AndDiagonal (const matrix::Matrix &m, matrix::D *buffer, matrix::I len)
 stores at least left top 4x4 submatrix (row-wise) (if exists) and then the rest of the diagonal elements More...
 
matrix::I get4x4AndDiagonalSize (const matrix::Matrix &m)
 returns the number of elements stored by store4x4AndDiagonal (should be min(getN(),4)*min(getM(),4)+ max(0,min(getM()-4,getN()-4))) More...
 
std::list< Inspectable::iparamkeystore4x4AndDiagonalFieldNames (const matrix::Matrix &m, const std::string &matrixName)
 writes the names of the fields stored by store4x4AndDiagonal into a list More...
 
matrix::I store4x4AndDiagonalFieldNames (const matrix::Matrix &m, const std::string &matrixName, char **keylist, matrix::I len)
 stores the names of the fields stored by store4x4AndDiagonal More...
 
std::list< Inspectable::iparamkeystoreMatrixFieldNames (const matrix::Matrix &m, const std::string &matrixName)
 stores the names of all matrix fieldnames in the order produced by convertToBuffer (row-wise) More...
 
std::list< Inspectable::iparamkeystoreVectorFieldNames (const matrix::Matrix &m, const std::string &vectorName)
 stores the names of all vector (mx1 or 1xn matrix) fieldnames in the order produced by convertToBuffer (row-wise) More...
 
matrix::I storeMatrixFieldNames (const matrix::Matrix &m, const char *matrixName, char **keylist, matrix::I len)
 stores the names of all matrix fieldnames in the order produced by convertToBuffer (row-wise) More...
 
matrix::I storeVectorFieldNames (const matrix::Matrix &m, const char *vectorName, char **keylist, matrix::I len)
 stores the names of all vector (mx1 or 1xn matrix) fieldnames in the order produced by convertToBuffer (row-wise) More...
 
bool storeMatrix (const matrix::Matrix &m, FILE *f)
 stores the Matrix into the given file stream (binary) More...
 
bool restoreMatrix (matrix::Matrix &m, FILE *f)
 reads a Matrix from the given file stream (binary) More...
 
matrix::Matrix noiseMatrix (matrix::I m, matrix::I n, NoiseGenerator &ng, double strength, double unused=0)
 returns a Matrix with values generated by the given noise generator More...
 
RandGensplitRandGen (RandGen *randGen)
 geneterates deterministically a new random generator from the given one. More...
 
double matrixNorm1 (const matrix::Matrix &m)
 calculates to linear matrix norm (sum of absolute values divided by number of values (m*n) ) More...
 
double matrixNorm2 (const matrix::Matrix &m)
 calculates to square matrix norm (sum of square values divided by number of values (m*n) ) More...
 
matrix::Matrix matrixNormalized (const matrix::Matrix &m)
 Matrix/matrixNorm2 ) More...
 
double getKthLargestElement (matrix::Matrix &matrix, matrix::I k)
 returns the k. More...
 
double getKthSmallestElement (matrix::Matrix &matrix, matrix::I k)
 returns the k. More...
 
matrix::I argmin (const matrix::Matrix &v)
 considers the matrix as vector (mx1) and returns the index of the smallest element More...
 
matrix::I argmax (const matrix::Matrix &v)
 considers the matrix as vector (mx1) and returns the index of the largest element More...
 
double min (const matrix::Matrix &v)
 returns the smallest element More...
 
double min (double a, double b)
 minimum function for doubles without templates More...
 
double max (const matrix::Matrix &v)
 returns the largest element More...
 
double max (double a, double b)
 maximum function for doubles without templates More...
 
matrix::I sample (const matrix::Matrix &pdf)
 samples from the pdf (rowwise stored with sum = 1) More...
 
double adapt (double p, double actual, double nominal, double up_rate, double down_rate)
 parameter adaptation algorithm. More...
 
double adaptMinMax (double p, double actual, double _min, double _max, double up_rate, double down_rate)
 like adapt but that the adaption is just done if the actual value is outside the given interval (_min, _max) More...
 
std::list< Inspectable::iparamvalconvertArrayToList (double *array, int arraySize)
 Helper function for converting an array with double values to a list. More...
 
std::list< Inspectable::iparamkeygetArrayNames (int arraySize, const char *name)
 Helper function for getting the array names of an array Is used for the method getInternalParamNames() interface inspectable. More...
 

Function Documentation

double adapt ( double  p,
double  actual,
double  nominal,
double  up_rate,
double  down_rate 
)

parameter adaptation algorithm.

double adaptMinMax ( double  p,
double  actual,
double  _min,
double  _max,
double  up_rate,
double  down_rate 
)

like adapt but that the adaption is just done if the actual value is outside the given interval (_min, _max)

matrix::I argmax ( const matrix::Matrix v)

considers the matrix as vector (mx1) and returns the index of the largest element

matrix::I argmin ( const matrix::Matrix v)

considers the matrix as vector (mx1) and returns the index of the smallest element

T clip ( x,
lobound,
highbound 
)
inline
double clip ( double  r,
double  x 
)

clipping function to the interval [-r, r] (for use with mapP)

clipping function to the interval [-r, r] (for use with mapP)

double constant ( double  c,
double   
)

returns c (useful for Matrix::mapP to fill matrix with constant value)

std::list<Inspectable::iparamval> convertArrayToList ( double *  array,
int  arraySize 
)

Helper function for converting an array with double values to a list.

Is used for the method getInternalParams() interface inspectable.

matrix::I get4x4AndDiagonalSize ( const matrix::Matrix m)

returns the number of elements stored by store4x4AndDiagonal (should be min(getN(),4)*min(getM(),4)+ max(0,min(getM()-4,getN()-4)))

std::list<Inspectable::iparamkey> getArrayNames ( int  arraySize,
const char *  name 
)

Helper function for getting the array names of an array Is used for the method getInternalParamNames() interface inspectable.

double getKthLargestElement ( matrix::Matrix matrix,
matrix::I  k 
)

returns the k.

largest element of the matrix Attention: it will detroy the given matrix! (sorting) Assumption: k>0 and k<=matrixsize

double getKthSmallestElement ( matrix::Matrix matrix,
matrix::I  k 
)

returns the k.

smallest element of the matrix Attention: it will detroy the given matrix! (sorting) Assumption: k>0 and k<=matrixsize

double lowercutof ( void *  theta,
double   
)

cutof function for mapP

double matrixNorm1 ( const matrix::Matrix m)

calculates to linear matrix norm (sum of absolute values divided by number of values (m*n) )

double matrixNorm2 ( const matrix::Matrix m)

calculates to square matrix norm (sum of square values divided by number of values (m*n) )

matrix::Matrix matrixNormalized ( const matrix::Matrix m)

Matrix/matrixNorm2 )

double max ( const matrix::Matrix v)

returns the largest element

double max ( double  a,
double  b 
)

maximum function for doubles without templates

double min ( const matrix::Matrix v)

returns the smallest element

double min ( double  a,
double  b 
)

minimum function for doubles without templates

matrix::Matrix noiseMatrix ( matrix::I  m,
matrix::I  n,
NoiseGenerator ng,
double  strength,
double  unused = 0 
)

returns a Matrix with values generated by the given noise generator

double one_over ( double  x)

calculates 1/x

double plus_ ( double  b,
double  a 
)

plus function for mapP

double power ( void *  c,
double  x 
)

returns x the power c (as a double)

double power3 ( double  x)

power 3 for matrix::map

double random_minusone_to_one ( double  )

creates random number from -1 to 1

double random_minusone_to_one ( void *  ,
double   
)

creates random number from -1 to 1

bool restoreMatrix ( matrix::Matrix m,
FILE *  f 
)

reads a Matrix from the given file stream (binary)

matrix::I sample ( const matrix::Matrix pdf)

samples from the pdf (rowwise stored with sum = 1)

T sign ( v)
inline
RandGen* splitRandGen ( RandGen randGen)

geneterates deterministically a new random generator from the given one.

If null then rand() is used for the seed;

T sqr ( v)
inline
std::list<matrix::D> store4x4AndDiagonal ( const matrix::Matrix m)

stores at least left top 4x4 submatrix (row-wise) (if exists) and then the rest of the diagonal elements into a list

Returns
list of values
matrix::I store4x4AndDiagonal ( const matrix::Matrix m,
matrix::D buffer,
matrix::I  len 
)

stores at least left top 4x4 submatrix (row-wise) (if exists) and then the rest of the diagonal elements

Parameters
mmatrix to be stored
lenLength of the provided buffer (should be min(getN(),4)*min(getM(),4)+ max(0,min(getM()-4,getN()-4)))
Returns
number of actually written elements
std::list<Inspectable::iparamkey> store4x4AndDiagonalFieldNames ( const matrix::Matrix m,
const std::string &  matrixName 
)

writes the names of the fields stored by store4x4AndDiagonal into a list

Parameters
mmatrix to be stored
matrixNamename of the matrix (prefix for all fields)
Returns
list of keys
matrix::I store4x4AndDiagonalFieldNames ( const matrix::Matrix m,
const std::string &  matrixName,
char **  keylist,
matrix::I  len 
)

stores the names of the fields stored by store4x4AndDiagonal

Parameters
mmatrix to be stored
matrixNamename of the matrix (prefix for all fields)
keylistlist for field names
lenLength of the provided buffer (should be min(getN(),4)*min(getM(),4)+ max(0,min(getM()-4,getN()-4)))
Returns
number of actually written elements
bool storeMatrix ( const matrix::Matrix m,
FILE *  f 
)

stores the Matrix into the given file stream (binary)

std::list<Inspectable::iparamkey> storeMatrixFieldNames ( const matrix::Matrix m,
const std::string &  matrixName 
)

stores the names of all matrix fieldnames in the order produced by convertToBuffer (row-wise)

Returns
list of names
matrix::I storeMatrixFieldNames ( const matrix::Matrix m,
const char *  matrixName,
char **  keylist,
matrix::I  len 
)

stores the names of all matrix fieldnames in the order produced by convertToBuffer (row-wise)

Parameters
mmatrix to be stored
matrixNamename of the matrix (prefix for all fields)
keylistlist for field names
lenLength of the provided buffer (should be getN()*getM()
Returns
number of actually written elements
std::list<Inspectable::iparamkey> storeVectorFieldNames ( const matrix::Matrix m,
const std::string &  vectorName 
)

stores the names of all vector (mx1 or 1xn matrix) fieldnames in the order produced by convertToBuffer (row-wise)

Returns
list of names
matrix::I storeVectorFieldNames ( const matrix::Matrix m,
const char *  vectorName,
char **  keylist,
matrix::I  len 
)

stores the names of all vector (mx1 or 1xn matrix) fieldnames in the order produced by convertToBuffer (row-wise)

Parameters
mvector to be stored
vectorNamename of the vector (prefix for all fields)
keylistlist for field names
lenLength of the provided buffer (should be getM())
Returns
number of actually written elements
double toBinaryWithProbability ( void *  r,
double  x 
)

returns -1 if probability is to low, otherwise 1 for mapP

double toBinaryWithThreshold ( double  x,
double  threshold 
)

returns -1 if below threshold, otherwise 1 for map2