Class MemoryBelief<TReference, TObservation>
The MemoryBelief<TReference, TObservation> class represents the agent's belief of a single object, but with additional "memory" of previous observations. Some object reference is used to generate/update an observation (i.e., some piece of information on the game state as perceived by an agent). This belief also stores a limited amount of previous observations in memory.
public class MemoryBelief<TReference, TObservation> : Belief<TReference, TObservation>, IBelief where TReference : class
Type Parameters
TReference
The type of the reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by C# if
TReference
is an interface.TObservation
The type of the observation the belief represents.
- Inheritance
-
Belief<TReference, TObservation>MemoryBelief<TReference, TObservation>
- Implements
- Derived
- Inherited Members
Remarks
It supports implicit conversion to TObservation
.
Constructors
MemoryBelief(Metadata, TReference, Func<TReference, TObservation>, int)
Initializes a new instance of the MemoryBelief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and a condition on when the observation should be updated. Also initializes the memory array with a specified number of slots.
public MemoryBelief(Metadata metadata, TReference reference, Func<TReference, TObservation> getObservationFromReference, int framesToRemember)
Parameters
metadata
MetadataMetadata about this Belief, used to quickly display the goal in several contexts.
reference
TReferenceThe reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by C# if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes a reference and generates/updates a observation.
framesToRemember
intThe number of frames to remember back.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
MemoryBelief(Metadata, TReference, Func<TReference, TObservation>, int, Predicate<TReference>)
Initializes a new instance of the MemoryBelief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and a condition on when the observation should be updated. Also initializes the memory array with a specified number of slots.
public MemoryBelief(Metadata metadata, TReference reference, Func<TReference, TObservation> getObservationFromReference, int framesToRemember, Predicate<TReference> shouldUpdate)
Parameters
metadata
MetadataMetadata about this Belief, used to quickly display the goal in several contexts.
reference
TReferenceThe reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by C# if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes a reference and generates/updates a observation.
framesToRemember
intThe number of frames to remember back.
shouldUpdate
Predicate<TReference>A condition on when the observation should be updated. Takes the object reference of the belief as a parameter for the predicate.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
MemoryBelief(TReference, Func<TReference, TObservation>, int)
Initializes a new instance of the MemoryBelief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and a condition on when the observation should be updated. Also initializes the memory array with a specified number of slots.
public MemoryBelief(TReference reference, Func<TReference, TObservation> getObservationFromReference, int framesToRemember)
Parameters
reference
TReferenceThe reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by C# if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes a reference and generates/updates a observation.
framesToRemember
intThe number of frames to remember back.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
MemoryBelief(TReference, Func<TReference, TObservation>, int, Predicate<TReference>)
Initializes a new instance of the MemoryBelief<TReference, TObservation> class with an object reference, a function to generate/update the observation using the object reference, and a condition on when the observation should be updated. Also initializes the memory array with a specified number of slots.
public MemoryBelief(TReference reference, Func<TReference, TObservation> getObservationFromReference, int framesToRemember, Predicate<TReference> shouldUpdate)
Parameters
reference
TReferenceThe reference used to generate/update the observation. This must be a reference type, be aware that this is not enforced by C# if
TReference
is an interface.getObservationFromReference
Func<TReference, TObservation>A function that takes a reference and generates/updates a observation.
framesToRemember
intThe number of frames to remember back.
shouldUpdate
Predicate<TReference>A condition on when the observation should be updated. Takes the object reference of the belief as a parameter for the predicate.
Exceptions
- ArgumentException
Thrown when
reference
is not a reference type.
Fields
_memorizedObservations
A "memorized" resource, from the last time the belief was updated.
protected readonly ExposedQueue<TObservation> _memorizedObservations
Field Value
- ExposedQueue<TObservation>
Methods
GetAllMemories()
Gets all the memorized observations. The first element is the newest memory.
public TObservation[] GetAllMemories()
Returns
- TObservation[]
An array of all the memorized observations.
GetMemoryAt(int, bool)
Gets the memorized observation at a specific index. A higher index means a memory further back in time.
public TObservation GetMemoryAt(int index, bool clamp = false)
Parameters
index
intThe index of the memory to get.
clamp
boolIf true, the index will be clamped between 0 and the last memory index.
Returns
- TObservation
The memory of the observation at the specified index.
GetMostRecentMemory()
Gets the most recently memorized observation.
public TObservation GetMostRecentMemory()
Returns
- TObservation
The most recent memory of the observation.
UpdateBelief()
Generates/updates the observation. Also stores the previous observation in memory.
public override void UpdateBelief()