mlpack
Public Member Functions | List of all members
mlpack::rl::SumTree< T > Class Template Reference

Implementation of SumTree. More...

#include <sumtree.hpp>

Public Member Functions

 SumTree ()
 Default constructor.
 
 SumTree (const size_t capacity)
 Construct an instance of SumTree class. More...
 
void Set (size_t idx, const T value)
 Set the data array with idx. More...
 
void BatchUpdate (const arma::ucolvec &indices, const arma::Col< T > &data)
 Update the data with batch rather loop over the indices with set method. More...
 
Get (size_t idx)
 Get the data array with idx. More...
 
SumHelper (const size_t start, const size_t end, const size_t node, const size_t nodeStart, const size_t nodeEnd)
 Help function for the sum function. More...
 
Sum (const size_t start, size_t end)
 Calculate the sum of contiguous subsequence of the array. More...
 
Sum ()
 Shortcut for calculating the sum of whole array.
 
size_t FindPrefixSum (T mass)
 Find the highest index idx in the array such that sum(arr[0] + arr[1] + ... More...
 

Detailed Description

template<typename T>
class mlpack::rl::SumTree< T >

Implementation of SumTree.

Build a Segment Tree like data structure. https://en.wikipedia.org/wiki/Segment_tree

Used to maintain prefix-sum of an array.

Template Parameters
TThe array's element type.

Constructor & Destructor Documentation

◆ SumTree()

template<typename T>
mlpack::rl::SumTree< T >::SumTree ( const size_t  capacity)
inline

Construct an instance of SumTree class.

Parameters
capacitySize of data.

Member Function Documentation

◆ BatchUpdate()

template<typename T>
void mlpack::rl::SumTree< T >::BatchUpdate ( const arma::ucolvec &  indices,
const arma::Col< T > &  data 
)
inline

Update the data with batch rather loop over the indices with set method.

Parameters
indicesThe indices of data to be changed.
dataThe data that array with indices to be.

◆ FindPrefixSum()

template<typename T>
size_t mlpack::rl::SumTree< T >::FindPrefixSum ( mass)
inline

Find the highest index idx in the array such that sum(arr[0] + arr[1] + ...

  • arr[idx]) <= mass.
Parameters
massThe upper bound of segment array sum.

◆ Get()

template<typename T>
T mlpack::rl::SumTree< T >::Get ( size_t  idx)
inline

Get the data array with idx.

Parameters
idxThe array idx to get data.

◆ Set()

template<typename T>
void mlpack::rl::SumTree< T >::Set ( size_t  idx,
const T  value 
)
inline

Set the data array with idx.

Parameters
idxThe array idx to be changed.
valueThe data that array with idx to be.

◆ Sum()

template<typename T>
T mlpack::rl::SumTree< T >::Sum ( const size_t  start,
size_t  end 
)
inline

Calculate the sum of contiguous subsequence of the array.

Parameters
startThe starting position of subsequence.
endThe end position of subsequence.

◆ SumHelper()

template<typename T>
T mlpack::rl::SumTree< T >::SumHelper ( const size_t  start,
const size_t  end,
const size_t  node,
const size_t  nodeStart,
const size_t  nodeEnd 
)
inline

Help function for the sum function.

Parameters
startThe starting position of subsequence.
endThe end position of subsequence.
nodeReference position.
nodeStartStarting position of reference segment.
nodeEndEnd position of reference segment.

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