浏览代码

docstrings and cleanup around actuators (#4467)

* docstrings and cleanup around actuators

* move ActionSpec property from IActionReceiver to IActuator
/MLA-1734-demo-provider
GitHub 4 年前
当前提交
53c13a29
共有 5 个文件被更改,包括 48 次插入33 次删除
  1. 33
      com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
  2. 29
      com.unity.ml-agents/Runtime/Actuators/IActuator.cs
  3. 14
      com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
  4. 3
      com.unity.ml-agents/Runtime/Agent.cs
  5. 2
      com.unity.ml-agents/Runtime/Sensors/ISensor.cs

33
com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs


public static ActionBuffers FromDiscreteActions(float[] discreteActions)
{
return new ActionBuffers(ActionSegment<float>.Empty, discreteActions == null ? ActionSegment<int>.Empty
: new ActionSegment<int>(Array.ConvertAll(discreteActions,
x => (int)x)));
: new ActionSegment<int>(Array.ConvertAll(discreteActions,
x => (int)x)));
/// <summary>
/// Construct an <see cref="ActionBuffers"/> instance with the continuous and discrete actions that will
/// be used.
/// /// </summary>
/// <param name="continuousActions">The continuous actions to send to an <see cref="IActionReceiver"/>.</param>
/// <param name="discreteActions">The discrete actions to send to an <see cref="IActionReceiver"/>.</param>
public ActionBuffers(float[] continuousActions, int[] discreteActions)
: this(new ActionSegment<float>(continuousActions), new ActionSegment<int>(discreteActions)) { }

/// </summary>
public interface IActionReceiver
{
/// <summary>
/// The specification of the Action space for this IActionReceiver.
/// </summary>
/// <seealso cref="ActionSpec"/>
ActionSpec ActionSpec { get; }
/// <summary>
/// Method called in order too allow object to execute actions based on the
/// <see cref="ActionBuffers"/> contents. The structure of the contents in the <see cref="ActionBuffers"/>

/// </remarks>
/// <seealso cref="IActionReceiver.OnActionReceived"/>
void WriteDiscreteActionMask(IDiscreteActionMask actionMask);
}
/// <summary>
/// Helper methods to be shared by all classes that implement <see cref="IActionReceiver"/>.
/// </summary>
public static class ActionReceiverExtensions
{
/// <summary>
/// Returns the number of discrete branches + the number of continuous actions.
/// </summary>
/// <param name="actionReceiver"></param>
/// <returns></returns>
public static int TotalNumberOfActions(this IActionReceiver actionReceiver)
{
return actionReceiver.ActionSpec.NumContinuousActions + actionReceiver.ActionSpec.NumDiscreteActions;
}
}
}

29
com.unity.ml-agents/Runtime/Actuators/IActuator.cs


using System;
using UnityEngine;
namespace Unity.MLAgents.Actuators
{
/// <summary>

{
/// <summary>
/// The specification of the Action space for this IActuator.
/// </summary>
/// <seealso cref="ActionSpec"/>
ActionSpec ActionSpec { get; }
/// <summary>
/// <summary>
/// Resets the internal state of the actuator. This is called at the end of an Agent's episode.
/// Most implementations can leave this empty.
/// </summary>
}
/// <summary>
/// Helper methods to be shared by all classes that implement <see cref="IActuator"/>.
/// </summary>
public static class IActuatorExtensions
{
/// <summary>
/// Returns the number of discrete branches + the number of continuous actions.
/// </summary>
/// <param name="actuator"></param>
/// <returns></returns>
public static int TotalNumberOfActions(this IActuator actuator)
{
return actuator.ActionSpec.NumContinuousActions + actuator.ActionSpec.NumDiscreteActions;
}
}
}

14
com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs


namespace Unity.MLAgents.Actuators
{
public class VectorActuator : IActuator
/// <summary>
/// IActuator implementation that forwards to an <see cref="IActionReceiver"/>.
/// </summary>
internal class VectorActuator : IActuator
{
IActionReceiver m_ActionReceiver;

private set => m_ActionBuffers = value;
}
/// <summary>
/// Create a VectorActuator that forwards to the provided IActionReceiver.
/// </summary>
/// <param name="actionReceiver">The <see cref="IActionReceiver"/> used for OnActionReceived and WriteDiscreteActionMask.</param>
/// <param name="vectorActionSize">For discrete action spaces, the branch sizes for each action.
/// For continuous action spaces, the number of actions is the 0th element.</param>
/// <param name="spaceType"></param>
/// <param name="name"></param>
/// <exception cref="ArgumentOutOfRangeException">Thrown for invalid <see cref="SpaceType"/></exception>
public VectorActuator(IActionReceiver actionReceiver,
int[] vectorActionSize,
SpaceType spaceType,

3
com.unity.ml-agents/Runtime/Agent.cs


EndEpisodeAndReset(DoneReason.MaxStepReached);
}
/// <summary>
/// Internal method to end the episode and reset the Agent.
/// </summary>

}
CollectDiscreteActionMasks(m_ActionMasker);
}
ActionSpec IActionReceiver.ActionSpec { get; }
/// <summary>
/// Implement `OnActionReceived()` to specify agent behavior at every step, based

2
com.unity.ml-agents/Runtime/Sensors/ISensor.cs


void Update();
/// <summary>
/// Resets the internal states of the sensor. This is called at the end of an Agent's episode.
/// Resets the internal state of the sensor. This is called at the end of an Agent's episode.
/// Most implementations can leave this empty.
/// </summary>
void Reset();

正在加载...
取消
保存