Machine Learning Library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
CDenseVector< Type > Class Template Reference

Template object for vectors of single and double precision and integer. More...

#include <CDenseVector.h>

Inheritance diagram for CDenseVector< Type >:
CVector< Type > CObject< Type >

Public Member Functions

 CDenseVector (int iDim=0)
 
 CDenseVector (int iDim, const Type *ptData)
 
 CDenseVector (int iDim, Type tValue)
 
 CDenseVector (const vector< Type > &rtVec)
 
 CDenseVector (const CDenseVector< Type > &tVec)
 
 CDenseVector (const CVector< Type > &vec)
 
virtual string className () const
 Returns the class name. More...
 
virtual ~CDenseVector ()
 
CVector< Type > * clone () const
 destructor More...
 
void zeros (void)
 
void ones (void)
 
CVector< double > * toDouble () const
 
CVector< float > * toFloat () const
 
vector< Type > toSTL () const
 
CDenseVector< int > sort ()
 
CDenseVector< Type > & operator= (const CDenseVector< Type > &tSrc)
 
int dimension () const
 
CMatrix< Type > asMatrix () const
 
Type getElement (int iIndex) const
 
const Type & operator[] (int i) const
 return constant reference to n'th vector element More...
 
Type & operator[] (int i)
 
void setElement (int iIndex, Type tValue)
 
void resize (int iNewDim)
 
void operator+= (Type tScalar)
 
bool isNaN () const
 
CVector< Type > & operator*= (const CVector< Type > &v2)
 
CVector< Type > & operator/= (const CVector< Type > &v2)
 
virtual CVector< Type > & operator*= (const Type &)
 multiply every element with scalar More...
 
virtual CVector< Type > & operator/= (const Type &)
 divide every element by scalar More...
 
void operator-= (Type tScalar)
 
CDenseVector< Type > & operator+= (const CVector< Type > &tVec)
 
CDenseVector< Type > & operator-= (const CVector< Type > &tVec)
 
Type manhattenDistance (const CDenseVector< Type > &rtVec) const
 
Type maximumDistance (const CDenseVector< Type > &rtVec) const
 
Type sumElements () const
 
void cat (const CDenseVector< Type > &tVec)
 
Type minElement () const
 
Type maxElement () const
 
int minElementIndex () const
 
int maxElementIndex () const
 
CDenseVector< Type > squareroot () const
 
CDenseVector< Type > power (int iPower=2) const
 
CDenseVector< Type > maxElements (const CDenseVector< Type > &rtVec) const
 
CDenseVector< Type > minElements (const CDenseVector< Type > &rtVec) const
 
CDenseVector< Type > subVector (int iStart, int iElements) const
 
Type mean () const
 
Type stdDev () const
 
CDenseVector< Type > shiftLeft (int iNumElements=1)
 
CDenseVector< Type > shiftRight (int iNumElements=1)
 
CDenseVector< Type > scale (const CDenseVector< Type > &tCurrentMin, const CDenseVector< Type > &tCurrentMax, const CDenseVector< Type > &tNewMin, const CDenseVector< Type > &tNewMax) const
 
int importFromMatFile (const char *acPath, const char *acVarname)
 
bool exportToMatFile (const char *acPath, const char *acVarname, bool bAppend)
 
void dump (ostream &ostr=cout) const
 
Type * _data () const
 
void _setData (Type *ptNewData)
 
bool serialize (fstream &stream, IO_MODE mode=READ)
 Read/write from binary stream. More...
 
bool serialize2 (CArchiv &tA)
 
bool isSparse () const
 
int getNumNonZero () const
 returns the number of non-zero entries More...
 
Type euclideanLength (bool bQuad=false) const
 returns euclidean length of vector More...
 
Type * begin ()
 
Type * end ()
 
Type const * begin () const
 
Type const * end () const
 
- Public Member Functions inherited from CVector< Type >
virtual ~CVector ()
 
virtual bool operator== (const CVector< Type > &rhs) const
 returns true if rhs has the same elements More...
 
Type operator* (const CVector< Type > &) const
 scalar product with vector More...
 
CVector< Type > & operator*= (const CVector< Type > &)
 multiply vectors elementwise More...
 
CVector< Type > & operator/= (const CVector< Type > &)
 divide vectors elementwise More...
 
Type euclideanDistance (const CVector< Type > &, bool b=false) const
 
Type coCosineDistance (const CVector< Type > &) const
 returns common cosine distance of the two vectors More...
 
void adaptToVec (const CVector< Type > &, float fEps1, float fEps2)
 
- Public Member Functions inherited from CObject< Type >
 CObject ()
 Constructor. More...
 
virtual ~CObject ()
 Destructor. More...
 
void setVerbose (VERBOSE_LEVEL tVerbose)
 Set the verbose level. More...
 
VERBOSE_LEVEL verbose (void) const
 Return current verbose level. More...
 
virtual bool isA (const char *acClass) const
 Check if the object is an instance of the class with given name. More...
 
DATATYPE dataType () const
 Returns the template data type. More...
 

Protected Member Functions

void copy (const CVector< Type > &vec)
 

Protected Attributes

int iDim
 
Type * ptData
 
- Protected Attributes inherited from CObject< Type >
unsigned char ucVerbose
 

Additional Inherited Members

- Static Protected Attributes inherited from CVector< Type >
static const CVectorOperations
< Type > & 
op_table
 

Detailed Description

template<class Type>
class CDenseVector< Type >

Template object for vectors of single and double precision and integer.

Constructor & Destructor Documentation

template<class Type>
CDenseVector< Type >::CDenseVector ( int  iDim = 0)
explicit

Constructor – Constructs a new instance of a vector object.

Parameters
iDimDimension of vector.
template<class Type>
CDenseVector< Type >::CDenseVector ( int  iDim,
const Type *  ptData 
)

Constructor – Constructs a new instance of a vector object.

Parameters
iDimDimension of vector (default 1).
ptDataArray of dimension iDim with initial data
template<class Type>
CDenseVector< Type >::CDenseVector ( int  iDim,
Type  tValue 
)

Constructor – Constructs a new instance of a vector object. Each element is initialized with value of tValue.

Parameters
iDimDimension of vector (default 1).
ptDataArray of dimension iDim with initial data (default: NULL)
template<class Type>
CDenseVector< Type >::CDenseVector ( const vector< Type > &  rtVec)

Constructor – Constructs a new vector instance of a vector. The vector is initialized with the values from a stl vector.

Parameters
rtVecReference on a stl vector to clone.
template<class Type>
CDenseVector< Type >::CDenseVector ( const CDenseVector< Type > &  tVec)

Constructor – Constructs a new vector instance which is an exact clone of a second vector.

Parameters
tVecReference on vector to clone.
template<class Type>
CDenseVector< Type >::CDenseVector ( const CVector< Type > &  vec)
template<class Type>
virtual CDenseVector< Type >::~CDenseVector ( )
virtual

Destructor

Member Function Documentation

template<class Type>
Type* CDenseVector< Type >::_data ( ) const
inline

Return pointer to data array. NO FORGET IT, DON'T USE IT !!

template<class Type>
void CDenseVector< Type >::_setData ( Type *  ptNewData)
template<class Type>
CMatrix<Type> CDenseVector< Type >::asMatrix ( ) const

Returns vector as dim x 1 matrix.

Returns
Dimension of vector.
template<class Type>
Type* CDenseVector< Type >::begin ( )
inline
template<class Type>
Type const* CDenseVector< Type >::begin ( ) const
inline
template<class Type>
void CDenseVector< Type >::cat ( const CDenseVector< Type > &  tVec)

Append vector

template<class Type>
virtual string CDenseVector< Type >::className ( ) const
inlinevirtual

Returns the class name.

Reimplemented from CVector< Type >.

template<class Type>
CVector<Type>* CDenseVector< Type >::clone ( ) const
virtual

destructor

create identical copy

Implements CVector< Type >.

template<class Type>
void CDenseVector< Type >::copy ( const CVector< Type > &  vec)
protected
template<class Type>
int CDenseVector< Type >::dimension ( void  ) const
inlinevirtual

Returns the dimension of the vector.

Returns
Dimension of vector.

Implements CVector< Type >.

template<class Type>
void CDenseVector< Type >::dump ( ostream &  ostr = cout) const

Sets the elements of the vector to zero Makes a dump of the vector to Sets the elements of the vector to zero

template<class Type>
Type* CDenseVector< Type >::end ( )
inline
template<class Type>
Type const* CDenseVector< Type >::end ( ) const
inline
template<class Type>
Type CDenseVector< Type >::euclideanLength ( bool  bQuad = false) const
virtual

returns euclidean length of vector

Implements CVector< Type >.

template<class Type>
bool CDenseVector< Type >::exportToMatFile ( const char *  acPath,
const char *  acVarname,
bool  bAppend 
)

Save vector with name acVarname in the MAT-formated file acPath. if bAppend is true, the data is appended to an existing file

template<class Type>
Type CDenseVector< Type >::getElement ( int  iIndex) const
virtual

Returns the element of the vector at position iIndex. The index of the vector elements starts with 0.

Returns
Value of element at position iIndex.

Implements CVector< Type >.

template<class Type>
int CDenseVector< Type >::getNumNonZero ( ) const
virtual

returns the number of non-zero entries

Implements CVector< Type >.

template<class Type>
int CDenseVector< Type >::importFromMatFile ( const char *  acPath,
const char *  acVarname 
)

Import vector named acVarname from Matlab MAT-formated file acPath

template<class Type>
bool CDenseVector< Type >::isNaN ( ) const
virtual

Checks for NaN elements

Returns
True if one or more elements are NaN, false otherwise

Implements CVector< Type >.

template<class Type>
bool CDenseVector< Type >::isSparse ( ) const
inline
template<class Type>
Type CDenseVector< Type >::manhattenDistance ( const CDenseVector< Type > &  rtVec) const

Calculates the manhatten distance between two vectors.

Parameters
Referenceto vector instance B.
Returns
Distance.
template<class Type>
Type CDenseVector< Type >::maxElement ( ) const

Returns the greatest value of the vector elements.

Returns
Maximal value of elements.
template<class Type>
int CDenseVector< Type >::maxElementIndex ( ) const

Returns the index of the element containing the smallest value.

Returns
Index of element.
template<class Type>
CDenseVector<Type> CDenseVector< Type >::maxElements ( const CDenseVector< Type > &  rtVec) const

Returns the vector of componentwise maximum values of two vectors.

Returns
Maxima vector.
template<class Type>
Type CDenseVector< Type >::maximumDistance ( const CDenseVector< Type > &  rtVec) const

Calculates the maximum distance between two vectors.

Parameters
Referenceto vector instance B.
Returns
Distance.
template<class Type>
Type CDenseVector< Type >::mean ( ) const

Returns the mean value of the vector elements.

Returns
Mean value.
template<class Type>
Type CDenseVector< Type >::minElement ( ) const

Returns the smallest value of the vector elements.

Returns
Minimal value of elements.
template<class Type>
int CDenseVector< Type >::minElementIndex ( ) const

Returns the index of the element containing the smallest value.

Returns
Index of element.
template<class Type>
CDenseVector<Type> CDenseVector< Type >::minElements ( const CDenseVector< Type > &  rtVec) const

Returns the vector of componentwise maximum values of two vectors.

Returns
Maxima vector.
template<class Type>
void CDenseVector< Type >::ones ( void  )

Initializes all vector elements with 1.

template<class Type>
CVector<Type>& CDenseVector< Type >::operator*= ( const CVector< Type > &  v2)
inline
template<class Type>
virtual CVector<Type>& CDenseVector< Type >::operator*= ( const Type &  )
virtual

multiply every element with scalar

Implements CVector< Type >.

template<class Type>
void CDenseVector< Type >::operator+= ( Type  tScalar)

Adds a scalar to each vector element.

Parameters
tScalar
template<class Type>
CDenseVector<Type>& CDenseVector< Type >::operator+= ( const CVector< Type > &  tVec)

Adds two vectors.

Parameters
tVec
template<class Type>
void CDenseVector< Type >::operator-= ( Type  tScalar)

Subtract scalar from each vector element.

Parameters
tScalar
template<class Type>
CDenseVector<Type>& CDenseVector< Type >::operator-= ( const CVector< Type > &  tVec)

Subtracts two vectors.

Parameters
tVec
template<class Type>
CVector<Type>& CDenseVector< Type >::operator/= ( const CVector< Type > &  v2)
inline
template<class Type>
virtual CVector<Type>& CDenseVector< Type >::operator/= ( const Type &  )
virtual

divide every element by scalar

Implements CVector< Type >.

template<class Type>
CDenseVector<Type>& CDenseVector< Type >::operator= ( const CDenseVector< Type > &  tSrc)

Assignment operator – Assigns a vector instance A to a varible B. The dimension of B does not have to match the dimension of B, since the size of B is adjusted according A.

Parameters
Referenceon vector B.
template<class Type>
const Type& CDenseVector< Type >::operator[] ( int  n) const
inlinevirtual

return constant reference to n'th vector element

Implements CVector< Type >.

template<class Type>
Type& CDenseVector< Type >::operator[] ( int  i)
inline

Returns a reference on the element of the vector at position iIndex. The index of the vector elements starts with 0.

Returns
Value of element at position iIndex.
template<class Type>
CDenseVector<Type> CDenseVector< Type >::power ( int  iPower = 2) const

Return vector of elementwise power.

Returns
Vector.
template<class Type>
void CDenseVector< Type >::resize ( int  iNewDim)

Resizes dimension of vector. If the new vector is smaller, elements at the end of the vector are removed according the new size. If the new vector is larger, elements with value zero are appended to the existing vector data.

Parameters
iNewDimNew vector dimension
template<class Type>
CDenseVector<Type> CDenseVector< Type >::scale ( const CDenseVector< Type > &  tCurrentMin,
const CDenseVector< Type > &  tCurrentMax,
const CDenseVector< Type > &  tNewMin,
const CDenseVector< Type > &  tNewMax 
) const

Scales each element according the give intervall edition. If the current value of element i is in the interval tCurrentMin_i to tCurrentMax_i, the new element value is calculated by scaling tCurrentMin, tCurrentMax to tNewMin, tNewMax.

Parameters
tCurrentMin,tCurrentMaxMin/max values of the intervals from which each element value can be taken.
tNewMin,tNewMaxNew min/max values for the elementwise intervals.
Returns
Vector scaled according the new bmin/max values.
template<class Type>
bool CDenseVector< Type >::serialize ( fstream &  stream,
IO_MODE  mode = READ 
)
virtual

Read/write from binary stream.

The functions handles different data types e.g for reading float objects in a double instance, etc.

Parameters
fstreamReference to binary stream
modeSwitches between reading and writing
Returns
True if successful, false otherwise

Reimplemented from CVector< Type >.

Referenced by CDataset< Type >::serialize().

template<class Type>
bool CDenseVector< Type >::serialize2 ( CArchiv tA)
virtual

Reimplemented from CObject< Type >.

template<class Type>
void CDenseVector< Type >::setElement ( int  iIndex,
Type  tValue 
)

Assigns the element at postion iIndex a new value.

Parameters
iIndexIndex of element.
tValueNew value of element.

Referenced by CDataset< Type >::read().

template<class Type>
CDenseVector<Type> CDenseVector< Type >::shiftLeft ( int  iNumElements = 1)

Returns a new vector contraining the elements of the current vector shifted by iNumElements to the left. Elements pushed out at the left end will be inserted at the right end.

Parameters
Numberof elements to shift.
Returns
Shifted vector.
template<class Type>
CDenseVector<Type> CDenseVector< Type >::shiftRight ( int  iNumElements = 1)

Returns a new vector contraining the elements of the current vector shifted by iNumElements to the right. Elements pushed out at the right end will be inserted at the left end.

Parameters
Numberof elements to shift.
Returns
Shifted vector.
template<class Type>
CDenseVector<int> CDenseVector< Type >::sort ( )
virtual

Implements CVector< Type >.

template<class Type>
CDenseVector<Type> CDenseVector< Type >::squareroot ( ) const

Return vector of elementwise squareroot.

Returns
Vector.
template<class Type>
Type CDenseVector< Type >::stdDev ( ) const

Returns the standard deviation of the vector elements.

Returns
Standard deviation value.
template<class Type>
CDenseVector<Type> CDenseVector< Type >::subVector ( int  iStart,
int  iElements 
) const

Return a subvector containing iElements elements starting from iStart (inclusive iStart)

Returns
Subvector.
template<class Type>
Type CDenseVector< Type >::sumElements ( ) const

Sum of elements

template<class Type>
CVector<double>* CDenseVector< Type >::toDouble ( ) const
virtual

Returns copy of vector using double values

Implements CVector< Type >.

template<class Type>
CVector<float>* CDenseVector< Type >::toFloat ( ) const
virtual

Returns copy of vector using float values

Implements CVector< Type >.

template<class Type>
vector<Type> CDenseVector< Type >::toSTL ( ) const
virtual

Reimplemented from CVector< Type >.

template<class Type>
void CDenseVector< Type >::zeros ( void  )

Initializes all vector elements with 0.

Member Data Documentation

template<class Type>
int CDenseVector< Type >::iDim
protected
template<class Type>
Type* CDenseVector< Type >::ptData
protected

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