using System; using System.Collections.Generic; using MLAgents.SideChannels; namespace MLAgents { /// /// A container for the Environment Parameters that may be modified during training. /// The keys for those parameters are defined in the trainer configurations and the /// the values are generated from the training process in features such as Curriculum Learning /// and Environment Parameter Randomization. /// /// One current assumption for all the environment parameters is that they are of type float. /// public sealed class EnvironmentParameters { /// /// The side channel that is used to receive the new parameter values. /// readonly EnvironmentParametersChannel m_Channel; /// /// Constructor. /// internal EnvironmentParameters() { m_Channel = new EnvironmentParametersChannel(); SideChannelsManager.RegisterSideChannel(m_Channel); } /// /// Returns the parameter value for the specified key. Returns the default value provided /// if this parameter key does not have a value. Only returns a parameter value if it is /// of type float. /// /// The parameter key /// Default value for this parameter. /// public float GetWithDefault(string key, float defaultValue) { return m_Channel.GetWithDefault(key, defaultValue); } /// /// Registers a callback action for the provided parameter key. Will overwrite any /// existing action for that parameter. The callback will be called whenever the parameter /// receives a value from the training process. /// /// The parameter key /// The callback action public void RegisterCallback(string key, Action action) { m_Channel.RegisterCallback(key, action); } /// /// Returns a list of all the parameter keys that have received values. /// /// List of parameter keys. public IList Keys() { return m_Channel.ListParameters(); } internal void Dispose() { SideChannelsManager.UnregisterSideChannel(m_Channel); } } }