Soar Kernel  9.3.2 08-06-12
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes
soar_module::bla_object_memory< T, N, R > Class Template Reference

#include <soar_module.h>

Inherits soar_module::object_memory< T, N >.

Public Member Functions

 bla_object_memory ()
double get_object_activation (T *obj, bool log_result)
bool set_decay_rate (double new_decay_rate)
bool set_decay_thresh (double new_decay_thresh)
bool set_petrov (bool new_petrov)
bool set_pow_cache_bound (uint64_t new_pow_cache_bound)
- Public Member Functions inherited from soar_module::object_memory< T, N >
void forget ()
object_set::iterator forgotten_begin ()
object_set::iterator forgotten_end ()
void initialize ()
 object_memory ()
void process_buffered_references ()
bool reference_object (const T *obj, object_reference num)
void remove_object (const T *obj)
void teardown ()
void time_back ()
void time_forward ()

Protected Types

typedef object_memory< T, N >
::object_history 
object_history
typedef object_memory< T, N >
::object_reference 
object_reference
typedef object_memory< T, N >
::time_step 
time_step
- Protected Types inherited from soar_module::object_memory< T, N >
typedef struct
soar_module::object_memory::object_history_struct 
object_history
typedef struct
soar_module::object_memory::object_time_reference_struct 
object_time_reference

Protected Member Functions

void _down ()
void _init ()
time_step estimate_forgetting_time (const object_history *h, time_step t, bool fresh_reference)
bool should_forget (const object_history *h, time_step t)
- Protected Member Functions inherited from soar_module::object_memory< T, N >
time_step get_current_time ()
const object_historyget_history (const T *obj)
unsigned int history_next (unsigned int current)
unsigned int history_prev (unsigned int current)
bool is_initialized ()

Private Member Functions

double _pow (time_step t_diff)
double compute_history_activation (const object_history *h, time_step t, bool log_result)

Private Attributes

double activation_low
double activation_none
time_step approx_cache [R]
double decay_rate
double decay_thresh
double decay_thresh_exp
double * pow_cache
uint64_t pow_cache_bound
unsigned int pow_cache_size
double time_sum_none
bool use_petrov

Additional Inherited Members

- Public Types inherited from soar_module::object_memory< T, N >
typedef uint64_t object_reference
typedef std::set< const T * > object_set
typedef uint64_t time_step

Detailed Description

template<class T, int N, unsigned int R>
class soar_module::bla_object_memory< T, N, R >

Definition at line 1413 of file soar_module.h.

Member Typedef Documentation

template<class T , int N, unsigned int R>
typedef object_memory<T, N>::object_history soar_module::bla_object_memory< T, N, R >::object_history
protected

Definition at line 1419 of file soar_module.h.

template<class T , int N, unsigned int R>
typedef object_memory<T, N>::object_reference soar_module::bla_object_memory< T, N, R >::object_reference
protected

Definition at line 1418 of file soar_module.h.

template<class T , int N, unsigned int R>
typedef object_memory<T, N>::time_step soar_module::bla_object_memory< T, N, R >::time_step
protected

Definition at line 1417 of file soar_module.h.

Constructor & Destructor Documentation

template<class T , int N, unsigned int R>
soar_module::bla_object_memory< T, N, R >::bla_object_memory ( )
inline

Definition at line 1432 of file soar_module.h.

: activation_none( 1.0 ), activation_low( -1000000000 ), time_sum_none( 2.71828182845905 ), use_petrov( true ), decay_rate( -0.5 ), decay_thresh( -2.0 ), pow_cache_bound( 10 )
{
}

Member Function Documentation

template<class T , int N, unsigned int R>
void soar_module::bla_object_memory< T, N, R >::_down ( )
inlineprotectedvirtual

Implements soar_module::object_memory< T, N >.

Definition at line 1535 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::pow_cache.

{
// release power array memory
delete[] pow_cache;
}
template<class T , int N, unsigned int R>
void soar_module::bla_object_memory< T, N, R >::_init ( )
inlineprotectedvirtual

Implements soar_module::object_memory< T, N >.

Definition at line 1492 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::approx_cache, soar_module::bla_object_memory< T, N, R >::decay_rate, soar_module::bla_object_memory< T, N, R >::decay_thresh, soar_module::bla_object_memory< T, N, R >::decay_thresh_exp, soar_module::bla_object_memory< T, N, R >::pow_cache, soar_module::bla_object_memory< T, N, R >::pow_cache_bound, and soar_module::bla_object_memory< T, N, R >::pow_cache_size.

{
// Pre-compute the integer powers of the decay exponent in order to avoid
// repeated calls to pow() at runtime
{
// determine cache size
{
// computes how many powers to compute
// basic idea: solve for the time that would just fall below the decay threshold, given decay rate and assumption of max references/time step
// t = e^( ( thresh - ln( max_refs ) ) / -decay_rate )
double cache_full = static_cast<double>( exp( ( decay_thresh - log( static_cast<double>( R ) ) ) / decay_rate ) );
// we bound this by the max-pow-cache parameter to control the space vs. time tradeoff the cache supports
// max-pow-cache is in MB, so do the conversion:
// MB * 1024 bytes/KB * 1024 KB/MB
double cache_bound_unit = ( static_cast<unsigned int>( pow_cache_bound * 1024 * 1024 ) / static_cast<unsigned int>( sizeof( double ) ) );
pow_cache_size = static_cast< unsigned int >( ceil( ( cache_full > cache_bound_unit )?( cache_bound_unit ):( cache_full ) ) );
}
pow_cache = new double[ pow_cache_size ];
pow_cache[0] = 0.0;
for( unsigned int i=1; i<pow_cache_size; i++ )
{
pow_cache[ i ] = pow( static_cast<double>( i ), decay_rate );
}
}
// calculate the pre-log'd forgetting threshold, to avoid most
// calls to log
// approximation cache
{
approx_cache[0] = 0;
for ( int i=1; i<R; i++ )
{
approx_cache[i] = static_cast< time_step >( ceil( exp( static_cast<double>( decay_thresh - log( static_cast<double>(i) ) ) / static_cast<double>( decay_rate ) ) ) );
}
}
}
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::_pow ( time_step  t_diff)
inlineprivate
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::compute_history_activation ( const object_history h,
time_step  t,
bool  log_result 
)
inlineprivate

Definition at line 1653 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::_pow(), soar_module::bla_object_memory< T, N, R >::activation_low, soar_module::bla_object_memory< T, N, R >::activation_none, soar_module::bla_object_memory< T, N, R >::decay_rate, soar_module::object_memory< T, N >::object_history_struct::first_reference, soar_module::object_memory< T, N >::object_history_struct::history_ct, soar_module::object_memory< T, N >::history_prev(), soar_module::object_memory< T, N >::object_history_struct::history_references, soar_module::object_memory< T, N >::object_history_struct::next_p, soar_module::object_memory< T, N >::object_time_reference_struct::num_references, soar_module::object_memory< T, N >::object_history_struct::reference_history, soar_module::object_memory< T, N >::object_time_reference_struct::t_step, soar_module::bla_object_memory< T, N, R >::time_sum_none, soar_module::object_memory< T, N >::object_history_struct::total_references, and soar_module::bla_object_memory< T, N, R >::use_petrov.

Referenced by soar_module::bla_object_memory< T, N, R >::get_object_activation(), and soar_module::bla_object_memory< T, N, R >::should_forget().

{
double return_val = ( ( log_result )?( activation_none ):( time_sum_none ) );
if ( h && h->history_ct )
{
return_val = 0.0;
// sum history
{
unsigned int p = h->next_p;
unsigned int counter = h->history_ct;
time_step t_diff = 0;
//
while ( counter )
{
p = this->history_prev( p );
t_diff = ( t - h->reference_history[ p ].t_step );
assert( t_diff > 0 );
return_val += ( h->reference_history[ p ].num_references * _pow( t_diff ) );
counter--;
}
// tail approximation for a bounded history, see (Petrov 2006)
if ( use_petrov )
{
// if ( n > k )
if ( h->total_references > h->history_references )
{
// ( n - k ) * ( tn^(1-d) - tk^(1-d) )
// -----------------------------------
// ( 1 - d ) * ( tn - tk )
// decay_rate is negated (for nice printing)
double d_inv = ( 1 + decay_rate );
return_val += ( ( ( h->total_references - h->history_references ) * ( pow( static_cast<double>( t - h->first_reference ), d_inv ) - pow( static_cast<double>( t_diff ), d_inv ) ) ) /
( d_inv * ( ( t - h->first_reference ) - t_diff ) ) );
}
}
}
if ( log_result )
{
if ( return_val > 0.0 )
{
return_val = log( return_val );
if ( return_val < activation_low )
{
return_val = activation_low;
}
}
else
{
return_val = activation_low;
}
}
}
return return_val;
}
template<class T , int N, unsigned int R>
time_step soar_module::bla_object_memory< T, N, R >::estimate_forgetting_time ( const object_history h,
time_step  t,
bool  fresh_reference 
)
inlineprotectedvirtual

Implements soar_module::object_memory< T, N >.

Definition at line 1541 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::approx_cache, soar_module::object_memory< T, N >::object_history_struct::history_ct, soar_module::object_memory< T, N >::history_prev(), soar_module::object_memory< T, N >::object_history_struct::next_p, soar_module::object_memory< T, N >::object_time_reference_struct::num_references, soar_module::object_memory< T, N >::object_history_struct::reference_history, soar_module::bla_object_memory< T, N, R >::should_forget(), and soar_module::object_memory< T, N >::object_time_reference_struct::t_step.

{
time_step return_val = t;
// if new reference, we can cheaply under-estimate decay time
// by treating all reference time steps independently
// see AAAI FS: (Derbinsky & Laird 2011)
if ( fresh_reference )
{
time_step to_add = 0;
unsigned int p = h->next_p;
unsigned int counter = h->history_ct;
time_step t_diff = 0;
object_reference approx_ref;
while ( counter )
{
p = this->history_prev( p );
t_diff = ( return_val - h->reference_history[ p ].t_step );
approx_ref = ( ( h->reference_history[ p ].num_references < R )?( h->reference_history[ p ].num_references ):( R-1 ) );
if ( approx_cache[ approx_ref ] > t_diff )
{
to_add += ( approx_cache[ approx_ref ] - t_diff );
}
counter--;
}
return_val += to_add;
}
// if approximation wasn't useful, or we used it previously and are now
// beyond the underestimate, use binary parameter search to exactly
// compute the time of forgetting
if ( return_val == t )
{
time_step to_add = 1;
if ( !should_forget( h, ( return_val + to_add ) ) )
{
// find absolute upper bound
do
{
to_add *= 2;
} while ( !should_forget( h, ( return_val + to_add ) ) );
// vanilla binary search within range: (upper/2, upper)
time_step upper_bound = to_add;
time_step lower_bound, mid;
if ( to_add < 4 )
{
lower_bound = upper_bound;
}
else
{
lower_bound = ( to_add / 2 );
}
while ( lower_bound != upper_bound )
{
mid = ( ( lower_bound + upper_bound ) / 2 );
if ( should_forget( h, ( return_val + mid ) ) )
{
upper_bound = mid;
if ( upper_bound - lower_bound <= 1 )
{
lower_bound = mid;
}
}
else
{
lower_bound = mid;
if ( upper_bound - lower_bound <= 1 )
{
lower_bound = upper_bound;
}
}
}
to_add = upper_bound;
}
return_val += to_add;
}
return return_val;
}
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::get_object_activation ( T *  obj,
bool  log_result 
)
inline
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::set_decay_rate ( double  new_decay_rate)
inline

Definition at line 1450 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::decay_rate, and soar_module::object_memory< T, N >::is_initialized().

Referenced by rl_apoptosis_param::set_value().

{
if ( ( new_decay_rate > 0 ) && ( new_decay_rate < 1 ) && !this->is_initialized() )
{
decay_rate = -new_decay_rate;
return true;
}
return false;
}
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::set_decay_thresh ( double  new_decay_thresh)
inline

Definition at line 1462 of file soar_module.h.

References soar_module::bla_object_memory< T, N, R >::decay_thresh, and soar_module::object_memory< T, N >::is_initialized().

Referenced by rl_apoptosis_param::set_value().

{
if ( !this->is_initialized() )
{
decay_thresh = new_decay_thresh;
return true;
}
return false;
}
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::set_petrov ( bool  new_petrov)
inline

Definition at line 1437 of file soar_module.h.

References soar_module::object_memory< T, N >::is_initialized(), and soar_module::bla_object_memory< T, N, R >::use_petrov.

{
if ( !this->is_initialized() )
{
use_petrov = new_petrov;
return true;
}
return false;
}
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::set_pow_cache_bound ( uint64_t  new_pow_cache_bound)
inline

Definition at line 1475 of file soar_module.h.

References soar_module::object_memory< T, N >::is_initialized(), and soar_module::bla_object_memory< T, N, R >::pow_cache_bound.

{
if ( ( new_pow_cache_bound > 0 ) && !this->is_initialized() )
{
pow_cache_bound = new_pow_cache_bound;
return true;
}
return false;
}
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::should_forget ( const object_history h,
time_step  t 
)
inlineprotectedvirtual

Field Documentation

template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::activation_low
private
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::activation_none
private
template<class T , int N, unsigned int R>
time_step soar_module::bla_object_memory< T, N, R >::approx_cache[R]
private
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::decay_rate
private
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::decay_thresh
private
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::decay_thresh_exp
private
template<class T , int N, unsigned int R>
double* soar_module::bla_object_memory< T, N, R >::pow_cache
private
template<class T , int N, unsigned int R>
uint64_t soar_module::bla_object_memory< T, N, R >::pow_cache_bound
private
template<class T , int N, unsigned int R>
unsigned int soar_module::bla_object_memory< T, N, R >::pow_cache_size
private
template<class T , int N, unsigned int R>
double soar_module::bla_object_memory< T, N, R >::time_sum_none
private
template<class T , int N, unsigned int R>
bool soar_module::bla_object_memory< T, N, R >::use_petrov
private

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