SumTree< T > Class Template Reference

Implementation of SumTree. More...

Inheritance diagram for SumTree< T >:

Public Member Functions

 SumTree ()
 Default constructor. More...

 
 SumTree (const size_t capacity)
 Construct an instance of SumTree class. 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...

 
size_t FindPrefixSum (T mass)
 Find the highest index idx in the array such that sum(arr[0] + arr[1] + ... More...

 
Get (size_t idx)
 Get the data array with idx. More...

 
void Set (size_t idx, const T value)
 Set the data array with idx. 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. 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...

 

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.

Definition at line 32 of file sumtree.hpp.

Constructor & Destructor Documentation

◆ SumTree() [1/2]

SumTree ( )
inline

Default constructor.

Definition at line 38 of file sumtree.hpp.

◆ SumTree() [2/2]

SumTree ( const size_t  capacity)
inline

Construct an instance of SumTree class.

Parameters
capacitySize of data.

Definition at line 46 of file sumtree.hpp.

Member Function Documentation

◆ BatchUpdate()

void 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.

Definition at line 75 of file sumtree.hpp.

Referenced by PrioritizedReplay< EnvironmentType >::UpdatePriorities().

◆ FindPrefixSum()

size_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.

Definition at line 163 of file sumtree.hpp.

Referenced by PrioritizedReplay< EnvironmentType >::SampleProportional().

◆ Get()

T Get ( size_t  idx)
inline

Get the data array with idx.

Parameters
idxThe array idx to get data.

Definition at line 93 of file sumtree.hpp.

Referenced by PrioritizedReplay< EnvironmentType >::Sample().

◆ Set()

void 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.

Definition at line 57 of file sumtree.hpp.

Referenced by PrioritizedReplay< EnvironmentType >::Store().

◆ Sum() [1/2]

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.

Definition at line 143 of file sumtree.hpp.

Referenced by PrioritizedReplay< EnvironmentType >::Sample(), and PrioritizedReplay< EnvironmentType >::SampleProportional().

◆ Sum() [2/2]

T Sum ( )
inline

Shortcut for calculating the sum of whole array.

Definition at line 152 of file sumtree.hpp.

Referenced by SumTree< double >::Sum().

◆ SumHelper()

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.

Definition at line 108 of file sumtree.hpp.

Referenced by SumTree< double >::Sum(), and SumTree< double >::SumHelper().


The documentation for this class was generated from the following file:
  • /home/jenkins-mlpack/mlpack.org/_src/mlpack-3.2.1/src/mlpack/methods/reinforcement_learning/replay/sumtree.hpp