realvec Class Reference
[Core classes which are not MarSystems]

Vector of mrs_real values. More...

#include <realvec.h>


Vector/Matrix Algebra and Statistics



void abs ()
void correlation (realvec &res) const
void covariance (realvec &res) const
void covariance2 (realvec &res) const
mrs_real det () const
void fliplr ()
void flipud ()
mrs_natural invert (realvec &res)
mrs_real maxval (mrs_natural *index=NULL) const
mrs_real mean () const
mrs_real median () const
mrs_real minval () const
void norm (mrs_real mean, mrs_real std)
void norm ()
void normMaxMin ()
void pow (mrs_real exp)
void renorm (mrs_real old_mean, mrs_real old_std, mrs_real new_mean, mrs_real new_std)
void sort ()
void sqr ()
void sqroot ()
mrs_real std () const
mrs_real sum () const
mrs_real trace () const
void transpose ()
mrs_real var () const
static void matrixMulti (const mrs_realvec &a, const mrs_realvec &b, mrs_realvec &out)
 matrix Multiplication

Output functions



void debug_info ()
void dump ()
void dumpDataOnly (std::ostream &o=std::cout, std::string columnSep=" ", std::string rowSep="\n") const
 Dump the realvec data (without header) to an output stream.
bool read (std::string filename)
bool readText (std::string filename)
 input function for line-separated text files
bool write (std::string filename) const
bool writeText (std::string filename)
 output function for line-separated text files
marsyas_EXPORT friend
std::ostream & 
operator<< (std::ostream &, const realvec &)
marsyas_EXPORT friend
std::istream & 
operator>> (std::istream &, realvec &)

Vector Operations



bool operator!= (const realvec &v1) const
realvecoperator*= (const mrs_real val)
realvecoperator*= (const realvec &vec)
realvecoperator+= (const mrs_real val)
realvecoperator+= (const realvec &vec)
realvecoperator-= (const mrs_real val)
realvecoperator-= (const realvec &vec)
realvecoperator/= (const mrs_real val)
realvecoperator/= (const realvec &vec)
bool operator== (const realvec &v1) const
marsyas_EXPORT friend realvec operator* (const realvec &vec1, const realvec &vec2)
marsyas_EXPORT friend realvec operator+ (const realvec &vec1, const realvec &vec2)
marsyas_EXPORT friend realvec operator- (const realvec &vec1, const realvec &vec2)
marsyas_EXPORT friend realvec operator/ (const realvec &vec1, const realvec &vec2)

Public Member Functions

 realvec ()
 constructor
Memory allocation


void allocate (mrs_natural rows, mrs_natural cols)
void allocate (mrs_natural size)
void create (mrs_real val, mrs_natural rows, mrs_natural cols)
 allocate(rows,cols) + fill with val
void create (mrs_natural rows, mrs_natural cols)
 allocate(rows,cols) + fill with zeros
void create (mrs_natural size)
 allocate(size) + fill with zeros
void stretch (mrs_natural size)
 allocate(size) + keep old vals. May also be used to shrink realvec.
void stretch (mrs_natural rows, mrs_natural cols)
 allocate(size) + keep old vals. May also be used to shrink realvec.
void stretchWrite (const mrs_natural r, const mrs_natural c, const mrs_real val)
 write to array, stretching the array if necessary
void stretchWrite (const mrs_natural pos, const mrs_real val)
 write to array, stretching the array if necessary
Modify values in array


void appendRealvec (const realvec newValues)
void setval (mrs_real val)
 set all entries to val
void setval (mrs_natural start, mrs_natural end, mrs_real val)
 set all entries to val
other


void apply (mrs_real(*func)(mrs_real))
 apply a given function to all the elements
Indexing


void getCol (const mrs_natural c, realvec &res) const
 vector indexing
void getRow (const mrs_natural r, realvec &res) const
 vector indexing
void getSubMatrix (const mrs_natural r, const mrs_natural c, realvec &res)
 get submatrix
realvec operator() (std::string r)
 matlab-like
realvec operator() (std::string r, std::string c)
 matlab-like
void setCol (const mrs_natural c, const realvec src)
void setRow (const mrs_natural r, const realvec src)
void setSubMatrix (const mrs_natural r, const mrs_natural c, const realvec src)
Getting information


mrs_natural getCols () const
mrs_real * getData () const
 dirty for easy integration
mrs_natural getRows () const
mrs_natural getSize () const
realvec getSubVector (mrs_natural startPos, mrs_natural length) const
 extracts a subset of a realvec. One-dimensional realvecs only.
Item access


mrs_real & getValueFenced (const mrs_natural r, const mrs_natural c)
 Get reference to value at position (r, c) or raise Exception when out of bounds.
mrs_real & getValueFenced (const mrs_natural i)
 Get reference to value at index i or raise Exception when out of bounds.
mrs_real getValueFenced (const mrs_natural r, const mrs_natural c) const
 Get the value at position (r, c) or raise Exception when out of bounds.
mrs_real getValueFenced (const mrs_natural i) const
 Get the value at index i or raise Exception when out of bounds.
mrs_real operator() (const mrs_natural r, const mrs_natural c) const
mrs_real & operator() (const mrs_natural r, const mrs_natural c)
mrs_real operator() (const mrs_natural i) const
mrs_real & operator() (const mrs_natural i)
Observations statics


void meanObs (realvec &res) const
void normObs ()
void normObsMinMax ()
void normSpl (mrs_natural=0)
void normSplMinMax (mrs_natural=0)
void stdObs (realvec &res) const
void varObs (realvec &res) const
Communications


mrs_natural search (mrs_real val)
void send (Communicator *com)

Private Attributes

mrs_natural allocatedSize_
 total memory allocated for data_
mrs_natural cols_
 number of columns in array.
mrs_real * data_
 the actual array
mrs_natural rows_
 number of rows in array; for a one-dimensional array, this is 1.
mrs_natural size_
 total number of values in data_


Detailed Description

Vector of mrs_real values.

Array (vector in the numerical sense) of mrs_real values. Basic arithmetic operations and statistics are supported.

The values of the realvec are stored in "column-major" order, which means that the data is stored per column, which are in turn stored in sequence. This has practical consequences for the optimal accessing order for the realvec values. Accessing array elements that are contiguous in memory is usually faster than accessing elements which are not, due to caching. If the intended processing allows this, it is for example better to access the values with the column and row loops embedded like

   for (int c = 0; c < cols_; ++c) {
   for (int r = 0; r < rows_ ; ++r) {
   // do stuff with realvec(r, c);
   }
   }
than with the column and row loop swapped.

Todo:
Crash-proof certain functions in realvec (like calling median() on an empty realvec)
Todo:
document realvec functions. In detail. Using all the doxygen tricks. For something as basic as this, it's worth it.

Definition at line 72 of file realvec.h.


Member Function Documentation

void appendRealvec ( const realvec  newValues  ) 

appends values from the newValues realvec. Resizes the original realvec to make space for the new values. One-dimensional realvecs only.

Definition at line 117 of file realvec.cpp.

References realvec::data_, realvec::getSize(), realvec::size_, and realvec::stretch().

void dumpDataOnly ( std::ostream &  o = std::cout,
std::string  columnSep = " ",
std::string  rowSep = "\n" 
) const

Dump the realvec data (without header) to an output stream.

Dump the realvec data (only the data, no header info ) to an outputstream. Use the given column and row separators between columns and rows respectively.

Definition at line 888 of file realvec.cpp.

References realvec::data_.

mrs_real & getValueFenced ( const mrs_natural  r,
const mrs_natural  c 
)

Get reference to value at position (r, c) or raise Exception when out of bounds.

Returned reference can be used as left hand side value (lvalue).

Parameters:
r the row index of the position to get the value from.
c the column index of the position to get the value from.
Returns:
the value at the requested position.
Exceptions:
std::out_of_range is thrown when the row or column index are out of bounds.

Definition at line 1879 of file realvec.cpp.

References realvec::data_.

mrs_real & getValueFenced ( const mrs_natural  i  ) 

Get reference to value at index i or raise Exception when out of bounds.

Returned reference can be used as left hand side value (lvalue).

Parameters:
i the index to get the value at.
Returns:
the value at the requested index.
Exceptions:
std::out_of_range is thrown when the index is out of bounds.

Definition at line 1859 of file realvec.cpp.

References realvec::data_.

mrs_real getValueFenced ( const mrs_natural  r,
const mrs_natural  c 
) const

Get the value at position (r, c) or raise Exception when out of bounds.

Parameters:
r the row index of the position to get the value from.
c the column index of the position to get the value from.
Returns:
the value at the requested position.
Exceptions:
std::out_of_range is thrown when the row or column index are out of bounds.

Definition at line 1840 of file realvec.cpp.

References realvec::data_.

mrs_real getValueFenced ( const mrs_natural  i  )  const

Get the value at index i or raise Exception when out of bounds.

Parameters:
i the index to get the value at.
Returns:
the value at the requested index.
Exceptions:
std::out_of_range is thrown when the index is out of bounds.

Definition at line 1821 of file realvec.cpp.

References realvec::data_.

void matrixMulti ( const mrs_realvec a,
const mrs_realvec b,
mrs_realvec out 
) [static]

matrix Multiplication

Parameters:
a first input matrix
b second input matrix
out preallocated realvec for the output
Returns:
the value at the requested index.
Exceptions:
std::out_of_range is thrown when the index is out of bounds.

Definition at line 1789 of file realvec.cpp.

References realvec::getCols(), realvec::getRows(), and realvec::setval().


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

Generated on Wed May 23 00:02:23 2012 for Marsyas by  doxygen 1.5.6