using Unity.MLAgents.SideChannels;
namespace Unity.MLAgents
{
///
/// Determines the behavior of how multiple stats within the same summary period are combined.
///
public enum StatAggregationMethod
{
///
/// Values within the summary period are averaged before reporting.
///
Average = 0,
///
/// Only the most recent value is reported.
/// To avoid conflicts when training with multiple concurrent environments, only
/// stats from worker index 0 will be tracked.
///
MostRecent = 1,
///
/// Values within the summary period are summed up before reporting.
///
Sum = 2
}
///
/// Add stats (key-value pairs) for reporting. These values will sent these to a StatsReporter
/// instance, which means the values will appear in the TensorBoard summary, as well as trainer
/// gauges. You can nest stats in TensorBoard by adding "/" in the name (e.g. "Agent/Health"
/// and "Agent/Wallet"). Note that stats are only written to TensorBoard each summary_frequency
/// steps (a trainer configuration). If a stat is received multiple times, within that period
/// then the values will be aggregated using the provided.
///
public sealed class StatsRecorder
{
///
/// The side channel that is used to receive the new parameter values.
///
readonly StatsSideChannel m_Channel;
///
/// Constructor.
///
internal StatsRecorder()
{
m_Channel = new StatsSideChannel();
SideChannelManager.RegisterSideChannel(m_Channel);
}
///
/// Add a stat value for reporting.
///
/// The stat name.
///
/// The stat value. You can nest stats in TensorBoard by using "/".
///
///
/// How multiple values sent in the same summary window should be treated.
///
public void Add(
string key,
float value,
StatAggregationMethod aggregationMethod = StatAggregationMethod.Average)
{
m_Channel.AddStat(key, value, aggregationMethod);
}
internal void Dispose()
{
SideChannelManager.UnregisterSideChannel(m_Channel);
}
}
}