Reinforcement Learning Toolbox 2.0
last updated:
General
Documentation
Manual
Tutorial
Class Reference
Master Thesis
Examples
Related Papers
Downloads
Links
News
mailto:webmaster
Main Page     Class Hierarchy   Compound List   File List   Compound Members   File Members

CFeatureList Class Reference

Class for storing features as sparse array. More...

#include <cfeaturefunction.h>

List of all members.



Public Types

typedef CFeatureList::iterator  iterator
typedef CFeatureList::reverse_iterator  reverse_iterator


Public Member Functions

  CFeatureList (int initMemSize=0, bool isSorted=false, bool sortAbs=false)
  Create a new feature list.

  ~CFeatureList ()
CFeatureList::iterator  getFeaturePos (unsigned int feature)
  Returns iterator pointing on the given feature (if its in the list, other wise end will be returned).

void  add (CFeature *feature)
  Add a CFeature object to the list.

void  add (CFeatureList *featureList, double factor=1.0)
  Add all features of the given list to the current feature list. Thre feature factors of the given list are multiplied by "factor".

void  set (int feature, double factor)
  Set the given feature to the given factor.

void  multFactor (double factor)
  Multiply all feature factors with the given factor.

double  multFeatureList (CFeatureList *featureList)
  Multiply all feature of the given list with the features of the current list.

void  addIndexOffset (int Offset)
  Add to all features the given index offset.

void  update (int feature, double factor)
  Add the given feature factor to the given feature.

double  getFeatureFactor (int featureIndex)
  Returns the feature factor of the given feature.

CFeature getFeature (int featureIndex)
  Returns the whole CFeature object with the given factor.

void  remove (CFeature *feature)
  removes the given feature from the list

void  remove (int feature)
void  clear ()
  clears the feature list

void  clearAndDelete ()
  clears the feature list and deletes all CFeature objects

void  saveASCII (FILE *stream)
  save the feature list to a ascii stream

void  loadASCII (FILE *stream)
  load the feature list to a ascii stream

void  normalize ()
  normalizes the feature list (sum of all factors = 1)

double  getLength ()
  returns the euklidean length of the feature space

CFeatureList::iterator  begin ()
CFeatureList::iterator  end ()
CFeatureList::reverse_iterator  rbegin ()
CFeatureList::reverse_iterator  rend ()
int  size ()


Protected Member Functions

CFeature getFreeFeatureResource ()
  Internal function, used for resource management.

void  sortFeature (CFeature *feature)
  insert the given feature in the correct position.



Protected Attributes

std::list< CFeature * > *  freeResources
std::list< CFeature * > *  allResources
std::map< int, CFeature * > *  featureMap
bool  isSorted
bool  sortAbs

Detailed Description

Class for storing features as sparse array.

The class maintains represents a list of features and is often used for gradient calculatation. In a feature list, not all features have to be included, the features which are not in the list have automatically the value 0.0. Every feature in the list is stored as a CFeature object, so the index and the feature factor are stored. The CFeatureList class also contains methods for directly setting (set), updating (adding a factor, update) or getting (getFeatureFactor) feature factors, without the need of CFeature objects. CFeatureList implements all functionality of the std::list class, so iterators can be used in the same way. The class provides its own resource management, so it always uses its own CFeature objects, so you don't have to care about where the CFeature objects come from or where they will go (cleaning up). If the feature list gets too small, it automatically allocates new resources. If the list gets smaller again, it always holds the allocated resources (even if you call clear) because its likely that the resources will be needed again. The allocated CFeature resources get deleted only when the feature list itself is deleted or clearAndDelete is called. For performance reasons the feature list also contains a map of CFeature object, with its feature index as search index. So the access to a particular feature is very quick. All features that are in the list are always in the map too. You have also the possibility to add another feature list to the current list (feature factors are added, non existant features in one list count as feature factor 0, or to multiply 2 feature lists (needed for gradient multiplication). The multiplied feature list naturally contains only the features which are in both components of the product. Feature lists can also be sorted by the feature factor. This is done for example in the case of etraces. If you need a sorted feature list, set the isSortet flag of the constructor to true. The first feature in the list will then always be the one with the highest factor.


Member Typedef Documentation

typedef CFeatureList::iterator CFeatureList::iterator
 
typedef CFeatureList::reverse_iterator CFeatureList::reverse_iterator
 

Constructor & Destructor Documentation

CFeatureList::CFeatureList int  initMemSize = 0,
bool  isSorted = false,
bool  sortAbs = false
 

Create a new feature list.

The parameter initMemSize specifies the number of CFeatures object that are allocated in the beginning. The second flag specifies wether the list is sorted.

CFeatureList::~CFeatureList  ) 
 

Member Function Documentation

void CFeatureList::add CFeatureList featureList,
double  factor = 1.0
 

Add all features of the given list to the current feature list. Thre feature factors of the given list are multiplied by "factor".

void CFeatureList::add CFeature feature  ) 
 

Add a CFeature object to the list.

The value of the feature is added to the feature in the list or, if the feature isn't already in the list, a new feature is added to the list. Even though a CFeature object is given, the feature list uses its own CFeature objects.

void CFeatureList::addIndexOffset int  Offset  ) 
 

Add to all features the given index offset.

CFeatureList::iterator CFeatureList::begin  ) 
 
void CFeatureList::clear  ) 
 

clears the feature list

The allocated CFeature objects remain in memory, they are just removed from the list and put in the freeResources list.

void CFeatureList::clearAndDelete  ) 
 

clears the feature list and deletes all CFeature objects

CFeatureList::iterator CFeatureList::end  ) 
 
CFeature* CFeatureList::getFeature int  featureIndex  ) 
 

Returns the whole CFeature object with the given factor.

If the specified feature isn't in the list, NULL is returned. Don't change any values or delete that CFeature object !!!

double CFeatureList::getFeatureFactor int  featureIndex  ) 
 

Returns the feature factor of the given feature.

CFeatureList::iterator CFeatureList::getFeaturePos unsigned int  feature  ) 
 

Returns iterator pointing on the given feature (if its in the list, other wise end will be returned).

CFeature* CFeatureList::getFreeFeatureResource  )  [protected]
 

Internal function, used for resource management.

Returns an unused or a new CFeature object.

double CFeatureList::getLength  ) 
 

returns the euklidean length of the feature space

void CFeatureList::loadASCII FILE *  stream  ) 
 

load the feature list to a ascii stream

void CFeatureList::multFactor double  factor  ) 
 

Multiply all feature factors with the given factor.

double CFeatureList::multFeatureList CFeatureList featureList  ) 
 

Multiply all feature of the given list with the features of the current list.

This calculation is like the dot product, features that are not in a list have the feature factors 0.0.

void CFeatureList::normalize  ) 
 

normalizes the feature list (sum of all factors = 1)

CFeatureList::reverse_iterator CFeatureList::rbegin  ) 
 
void CFeatureList::remove int  feature  ) 
 
void CFeatureList::remove CFeature feature  ) 
 

removes the given feature from the list

CFeatureList::reverse_iterator CFeatureList::rend  ) 
 
void CFeatureList::saveASCII FILE *  stream  ) 
 

save the feature list to a ascii stream

void CFeatureList::set int  feature,
double  factor
 

Set the given feature to the given factor.

If the feature is not already in the list a new CFeature object is requested (by the function getFreeFeatureResource.

int CFeatureList::size  )  [inline]
 
void CFeatureList::sortFeature CFeature feature  )  [protected]
 

insert the given feature in the correct position.

void CFeatureList::update int  feature,
double  factor
 

Add the given feature factor to the given feature.

If the feature is not already in the list a new CFeature object is requested (by the function getFreeFeatureResource) and the feature factor is set according to factor.


Member Data Documentation

std::list<CFeature *>* CFeatureList::allResources [protected]
 
std::map<int, CFeature *>* CFeatureList::featureMap [protected]
 
std::list<CFeature *>* CFeatureList::freeResources [protected]
 
bool CFeatureList::isSorted [protected]
 
bool CFeatureList::sortAbs [protected]
 

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