module emote.memory.strategy

Classes

class Strategy(ABC):

A generalized strategy that may be specialized for sampling or ejection from a memory buffer.

Methods

def __init__(self) -> None
def track(self, identity, sequence_length) -> None

Track a sequence given by identity and sequence_length that exists in the memory.

Arguments:

  • identity(int): an identity that is globally unique
  • sequence_length(int): the number of transitions in the sequence identified by identity
def forget(self, identity) -> None

Forget the sequence of transitions given by identity.

Arguments:

  • identity(int)
def on_sample(self, ids_and_offsets, transition_count, advantages) -> None

Called after a sampling strategy has been invoked, to give the strategy a chance to update sampling weights in case it uses prioritized sampling.

Arguments:

  • ids_and_offsets(Sequence[SamplePoint])
  • transition_count(int)
  • advantages(Optional[Matrix])
def post_import(self) -> None

Post-import validation of invariants and cleanup. This has to forget any imported negative ids, anything else is implementation-defined.

def state(self) -> dict

Serialize the strategy state to a dictionary.

def load_state(self, state) -> None

Load the strategy state from a dictionary.

Arguments:

  • state(dict)
def clear(self) -> None

Clear the strategy's internal state.

def begin_simple_import(self) -> None

Called before a simple import, to allow the strategy to prepare itself.

def end_simple_import(self) -> None

Called after a simple import, to allow the strategy to cleanup.

class SampleStrategy(Strategy):

A strategy specialized for sampling.

Methods

def sample(self, count, transition_count) -> Sequence[SamplePoint]

Apply the sampling strategy to the memory metadata, returning count identities and offsets to use when sampling from the memory.

Arguments:

  • count(int)
  • transition_count(int)

class EjectionStrategy(Strategy):

A strategy specialized for ejection sampling.

Methods

def sample(self, count) -> Sequence[int]

Apply the sampling strategy to the memory metadata, returning a list of identities that shall be ejected from the memory to remove at least "count" transitions.

Arguments:

  • count(int)