LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::sparseHistogram Class Reference
[Aggregate Data Types]

Simple sparse multidimensional histogram. More...

#include <ltiSparseHistogram.h>

Inheritance diagram for lti::sparseHistogram:
Inheritance graph
[legend]
Collaboration diagram for lti::sparseHistogram:
Collaboration graph
[legend]

List of all members.

Classes

struct  cless
 Comparator for C-strings (null-terminated char array). More...
class  const_iterator
 Similar to the const_iterators of the sparse matrix, these iterators allow read-only access the non-sparse cells of the histogram. More...
class  iterator
 Similar to the iterators of the sparse matrix, these iterators allow to access the non-sparse cells of the histogram. More...

Public Member Functions

 sparseHistogram ()
 sparseHistogram (const int dim, const int numberOfBins)
 sparseHistogram (const ivector &bins)
 sparseHistogram (const int numberOfBins, const dvector &min, const dvector &max)
 sparseHistogram (const ivector &numberOfBins, const dvector &min, const dvector &max)
 sparseHistogram (const sparseHistogram &other)
virtual ~sparseHistogram ()
sparseHistogramcopy (const sparseHistogram &other)
void resize (const int dim, const int numberOfBins)
void resize (const ivector &bins)
void resize (const int numberOfBins, const dvector &min, const dvector &max)
void resize (const ivector &numberOfBins, const dvector &min, const dvector &max)
float get (const ivector &index) const
void put (const ivector &index, float value=0.0f)
void clear (const ivector &index)
void add (const ivector &index, float value=1.0)
void multiply (const ivector &index, const float &value)
void divide (const ivector &index, const float &value)
void divide (const float &sum)
const char * getTypeName () const
const float & at (const ivector &x) const
float & at (const ivector &x)
const float & at (const dvector &x) const
float & at (const dvector &x)
int dimensions () const
const_iterator begin () const
iterator begin ()
const_iterator end () const
iterator end ()
float get (const dvector &index) const
void put (const dvector &index, float value=0.0)
void add (const dvector &index, float value=1.0)
void multiply (const dvector &index, const float &value)
void clear ()
virtual mathObjectclone () const
virtual bool write (ioHandler &handler, const bool complete=true) const
virtual bool read (ioHandler &handler, const bool complete=true)

Protected Types

typedef std::map< const char
*, float, cless
mapType

Detailed Description

Simple sparse multidimensional histogram.

It can be indexed via int and double vectors. It can handle index spaces of arbitrary dimensions.

The maximum number of bins per dimension is limited to 64.

The accumulated type is always float.

See also:
sparseMatrix

Member Typedef Documentation

typedef std::map<const char*,float,cless> lti::sparseHistogram::mapType [protected]

index map type


Constructor & Destructor Documentation

lti::sparseHistogram::sparseHistogram (  ) 

Default constructor.

Creates an empty histogram. You need to resize it before using it

lti::sparseHistogram::sparseHistogram ( const int  dim,
const int  numberOfBins 
)

Constructor.

Required parameters are the number of bins per dimension and the number of dimensions.

The maximum number of bins per dimension is limited to 64.

Parameters:
dim number of dimensions
numberOfBins number of bins per dimension
lti::sparseHistogram::sparseHistogram ( const ivector bins  ) 

Constructor.

The vector gives the number of bins for each dimension.

lti::sparseHistogram::sparseHistogram ( const int  numberOfBins,
const dvector min,
const dvector max 
)

Constructor.

Required parameters are the number of bins per dimension. Furthermore, you must give the lower and upper bounds of the hyperbox which is supposed to be occupied by the histogram. This will be used to access the histogram by vectors with double elements.

The maximum number of bins per dimension is limited to 64.

lti::sparseHistogram::sparseHistogram ( const ivector numberOfBins,
const dvector min,
const dvector max 
)

Constructor.

The first vector gives the number of bins for each dimension. The second and third vector give the lower and upper bounds of the hyperbox which is supposed to be occupied by the histogram.

The maximum number of bins per dimension is limited to 64.

lti::sparseHistogram::sparseHistogram ( const sparseHistogram other  ) 

copy constructor

virtual lti::sparseHistogram::~sparseHistogram (  )  [virtual]

destructor


Member Function Documentation

void lti::sparseHistogram::add ( const dvector index,
float  value = 1.0 
) [inline]

Adds the value to the value at the given index.

References add().

void lti::sparseHistogram::add ( const ivector index,
float  value = 1.0 
)

Adds the value to the value at the given index.

Referenced by add().

float& lti::sparseHistogram::at ( const dvector x  )  [inline]

access element x of the histogram

Parameters:
x index of the histogram element to be accessed. It should be between getFirstCell() and getLastCell()
Returns:
the number of entries in the given cell

References at().

const float& lti::sparseHistogram::at ( const dvector x  )  const [inline]

read-only access to the element x of the histogram

Parameters:
x index of the histogram element to be accessed. It should be between getFirstCell() and getLastCell()
Returns:
the number of entries in the given cell

References at().

float& lti::sparseHistogram::at ( const ivector x  ) 

access element x of the histogram

Parameters:
x index of the histogram element to be accessed. It should be between getFirstCell() and getLastCell()
Returns:
the number of entries in the given cell
const float& lti::sparseHistogram::at ( const ivector x  )  const

read-only access to the element x of the histogram

Parameters:
x index of the histogram element to be accessed. It should be between getFirstCell() and getLastCell()
Returns:
the number of entries in the given cell

Referenced by at().

iterator lti::sparseHistogram::begin (  )  [inline]

returns first element as an iterator The use of the interators is similar to the iterators of the Standard Template Library (STL).

If you need to iterate on all non-sparse elements of the histogram use following code:

   float tmp,accu;                   // temporal variables
   lti::sparseHistogram myHist(3,6); // a 3D Histogram with 6 bins
                                     // per dimension (216 cells)
   // fill the histogram
   ivector idx(3,1);
   myHist.put(idx,5); // at (1,1,1) set 5
   ...

   lti::sparseHistogram::iterator it;  // an iterator
   accu = 0;
   for (it=myVct.begin();it!=myVct.end();it++) {
     tmp = *it;                    // tmp has value of element pointed
                                   // by the iterator.
     accu += tmp;
     (*it) *= 5                    // change the value in the vector.

    }

Please note that if you define it as a const_iterator, you can not make something like (*it)*=5.

const_iterator lti::sparseHistogram::begin (  )  const [inline]

returns first element as a const_iterator.

Note that you can not change the values of the vector elements when you use a const_iterator. See also begin()

void lti::sparseHistogram::clear (  ) 

Erases all elements from the histogram.

void lti::sparseHistogram::clear ( const ivector index  ) 

Set the entry value at the given index to the sparse value.

Note that the put(index,0.0f) inserts a "non-sparse" cell with the value zero. If you really want to delete the cell, you need to clear it explicitelly.

virtual mathObject* lti::sparseHistogram::clone (  )  const [virtual]

Returns an identical copy of this histogram.

Implements lti::mathObject.

sparseHistogram& lti::sparseHistogram::copy ( const sparseHistogram other  ) 

copy data of "other" histogram.

Parameters:
other the clustering to be copied
Returns:
a reference to this clustering object

Reimplemented from lti::ioObject.

int lti::sparseHistogram::dimensions (  )  const [inline]

returns the number of dimensions of this histogram

References lti::genericVector< T >::size().

void lti::sparseHistogram::divide ( const float &  sum  ) 

Divides all entries by the given value.

void lti::sparseHistogram::divide ( const ivector index,
const float &  value 
)

Divides the value with the value at the given index.

iterator lti::sparseHistogram::end (  )  [inline]

returns last index as an iterator For an example see begin()

const_iterator lti::sparseHistogram::end (  )  const [inline]

returns last index as a const iterator.

For an example see begin()

float lti::sparseHistogram::get ( const dvector index  )  const [inline]

Returns the value stored at the given index.

float lti::sparseHistogram::get ( const ivector index  )  const

Returns the value stored at the given index.

const char* lti::sparseHistogram::getTypeName ( void   )  const [inline, virtual]

returns the name of this class: "sparseHistogram"

Reimplemented from lti::mathObject.

void lti::sparseHistogram::multiply ( const dvector index,
const float &  value 
) [inline]

Multiplies the value with the value at the given index.

References multiply().

void lti::sparseHistogram::multiply ( const ivector index,
const float &  value 
)

Multiplies the value with the value at the given index.

Referenced by multiply().

void lti::sparseHistogram::put ( const dvector index,
float  value = 0.0 
) [inline]

Sets the value at the given index.

References put().

void lti::sparseHistogram::put ( const ivector index,
float  value = 0.0f 
)

Sets the value at the given index.

Note that put(index,0.0f) inserts a "non-sparse" cell with the value zero. If you really want to delete the cell, you need to clear it explicitelly with the method clear(const ivector&).

Referenced by put().

virtual bool lti::sparseHistogram::read ( ioHandler handler,
const bool  complete = true 
) [virtual]

read the histogram from the given ioHandler

Parameters:
handler the ioHandler to be used
complete if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written.
Returns:
true if write was successful

Reimplemented from lti::mathObject.

void lti::sparseHistogram::resize ( const ivector numberOfBins,
const dvector min,
const dvector max 
)

Clear and resize the histogram.

The first vector gives the number of bins for each dimension. The second and third vector give the lower and upper bounds of the hyperbox which is supposed to be occupied by the histogram. This will be used to access the histogram by vectors with double elements.

The maximum number of bins per dimension is limited to 64.

void lti::sparseHistogram::resize ( const int  numberOfBins,
const dvector min,
const dvector max 
)

Clear and resize the histogram.

The new histogram will have the given numbers of bins per dimension, for a number of dimensions equal min.size() or max.size() (which must have the same number of elements). Furthermore, you must give the lower and upper bounds of the hyperbox which is supposed to be occupied by the histogram. This will be used to access the histogram by vectors with double elements.

The maximum number of bins per dimension is limited to 64.

void lti::sparseHistogram::resize ( const ivector bins  ) 

Clear and resize the histogram to the number of dimensions equal to the size of the vector bins, and having at each dimension the number of bins given at each component of bins vector.

The maximum number of bins per dimension is limited to 64.

void lti::sparseHistogram::resize ( const int  dim,
const int  numberOfBins 
)

Clear the previous content of the histogram and resize it to the given dimensions and bins per dimensions.

The maximum number of bins per dimension is limited to 64.

Parameters:
dim number of dimensions
numberOfBins number of bins per dimension
virtual bool lti::sparseHistogram::write ( ioHandler handler,
const bool  complete = true 
) const [virtual]

write the histogram in the given ioHandler

Parameters:
handler the ioHandler to be used
complete if true (the default) the enclosing begin/end will be also written, otherwise only the data block will be written.
Returns:
true if write was successful

Reimplemented from lti::mathObject.


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

Generated on Sat Apr 10 15:28:45 2010 for LTI-Lib by Doxygen 1.6.1