浏览代码

remove compressionspec for now, docstrings

/v2-staging-rebase
Chris Elion 4 年前
当前提交
fc8a278b
共有 5 个文件被更改,包括 162 次插入48 次删除
  1. 142
      com.unity.ml-agents/Runtime/InplaceArray.cs
  2. 1
      com.unity.ml-agents/Runtime/Sensors/ISensor.cs
  3. 56
      com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs
  4. 8
      com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs
  5. 3
      com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs.meta

142
com.unity.ml-agents/Runtime/InplaceArray.cs


namespace Unity.MLAgents
{
/// <summary>
/// An array-like object that stores up to four elements.
/// This is a value type that does not allocate any additional memory.
/// </summary>
/// <remarks>
/// This does not implement any interfaces such as IList, in order to avoid any accidental boxing allocations.
/// </remarks>
/// <typeparam name="T"></typeparam>
private T m_elem0;
private T m_elem1;
private T m_elem2;
private T m_elem3;
private T m_Elem0;
private T m_Elem1;
private T m_Elem2;
private T m_Elem3;
/// <summary>
/// Create a length-1 array.
/// </summary>
/// <param name="elem0"></param>
m_elem0 = elem0;
m_elem1 = new T {};
m_elem2 = new T {};
m_elem3 = new T {};
m_Elem0 = elem0;
m_Elem1 = new T {};
m_Elem2 = new T {};
m_Elem3 = new T {};
/// <summary>
/// Create a length-2 array.
/// </summary>
/// <param name="elem0"></param>
/// <param name="elem1"></param>
m_elem0 = elem0;
m_elem1 = elem1;
m_elem2 = new T {};
m_elem3 = new T {};
m_Elem0 = elem0;
m_Elem1 = elem1;
m_Elem2 = new T {};
m_Elem3 = new T {};
/// <summary>
/// Create a length-3 array.
/// </summary>
/// <param name="elem0"></param>
/// <param name="elem1"></param>
/// <param name="elem2"></param>
m_elem0 = elem0;
m_elem1 = elem1;
m_elem2 = elem2;
m_elem3 = new T {};
m_Elem0 = elem0;
m_Elem1 = elem1;
m_Elem2 = elem2;
m_Elem3 = new T {};
/// <summary>
/// Create a length-3 array.
/// </summary>
/// <param name="elem0"></param>
/// <param name="elem1"></param>
/// <param name="elem2"></param>
/// <param name="elem3"></param>
m_elem0 = elem0;
m_elem1 = elem1;
m_elem2 = elem2;
m_elem3 = elem3;
m_Elem0 = elem0;
m_Elem1 = elem1;
m_Elem2 = elem2;
m_Elem3 = elem3;
/// <summary>
/// Construct an InplaceArray from an IList (e.g. Array or List).
/// The source must be non-empty and have at most 4 elements.
/// </summary>
/// <param name="elems"></param>
/// <returns></returns>
/// <exception cref="ArgumentOutOfRangeException"></exception>
public static InplaceArray<T> FromList(IList<T> elems)
{
switch (elems.Count)

}
}
/// <summary>
/// Per-element access.
/// </summary>
/// <param name="index"></param>
/// <exception cref="IndexOutOfRangeException"></exception>
public T this[int index]
{
get

switch (index)
{
case 0:
return m_elem0;
return m_Elem0;
return m_elem1;
return m_Elem1;
return m_elem2;
return m_Elem2;
return m_elem3;
return m_Elem3;
default:
throw new IndexOutOfRangeException();
}

switch (index)
{
case 0:
m_elem0 = value;
m_Elem0 = value;
m_elem1 = value;
m_Elem1 = value;
m_elem2 = value;
m_Elem2 = value;
m_elem3 = value;
m_Elem3 = value;
break;
default:
throw new IndexOutOfRangeException();

/// <summary>
/// The length of the array.
/// </summary>
/// <summary>
/// Returns a string representation of the array's elements.
/// </summary>
/// <returns></returns>
/// <exception cref="IndexOutOfRangeException"></exception>
return $"[{m_elem0}]";
return $"[{m_Elem0}]";
return $"[{m_elem0}, {m_elem1}]";
return $"[{m_Elem0}, {m_Elem1}]";
return $"[{m_elem0}, {m_elem1}, {m_elem2}]";
return $"[{m_Elem0}, {m_Elem1}, {m_Elem2}]";
return $"[{m_elem0}, {m_elem1}, {m_elem2}, {m_elem3}]";
return $"[{m_Elem0}, {m_Elem1}, {m_Elem2}, {m_Elem3}]";
/// <summary>
/// Check that the arrays have the same length and have all equal values.
/// </summary>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>Whether the arrays are equivalent.</returns>
public static bool operator==(InplaceArray<T> lhs, InplaceArray<T> rhs)
{
if (lhs.Length != rhs.Length)

return true;
}
/// <summary>
/// Check that the arrays are not equivalent.
/// </summary>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns>Whether the arrays are not equivalent</returns>
/// <summary>
/// Check that the arrays are equivalent.
/// </summary>
/// <param name="other"></param>
/// <returns>Whether the arrays are not equivalent</returns>
/// <summary>
/// Check that the arrays are equivalent.
/// </summary>
/// <param name="other"></param>
/// <returns>Whether the arrays are not equivalent</returns>
/// <summary>
/// Get a hashcode for the array.
/// </summary>
/// <returns></returns>
return Tuple.Create(m_elem0, m_elem1, m_elem2, m_elem3, Length).GetHashCode();
return Tuple.Create(m_Elem0, m_Elem1, m_Elem2, m_Elem3, Length).GetHashCode();
}
}
}

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


/// <see cref="SensorCompressionType.None"/>.
/// </summary>
/// <returns>Compression type used by the sensor.</returns>
// TODO OBSOLETE replace with GetCompressionSpec().SensorCompressionType
SensorCompressionType GetCompressionType();
/// <summary>

56
com.unity.ml-agents/Runtime/Sensors/ObservationSpec.cs


namespace Unity.MLAgents.Sensors
{
/// <summary>
/// This is the simplest approach, but there's possible user error if Shape.Length != DimensionProperties.Length
/// A description of the observations that an ISensor produces.
/// This includes the size of the observation, the properties of each dimension, and how the observation
/// should be used for training.
public ObservationType ObservationType;
/// <summary>
/// The size of the observations that will be generated.
/// For example, a sensor that observes the velocity of a rigid body (in 3D) would use [3].
/// A sensor that returns an RGB image would use [Height, Width, 3].
/// </summary>
/// <summary>
/// The properties of each dimensions of the observation.
/// The length of the array must be equal to the rank of the observation tensor.
/// </summary>
/// <remarks>
/// It is generally recommended to not modify this from the default values,
/// as not all combinations of DimensionProperty may be supported by the trainer.
/// </remarks>
/// <summary>
/// The type of the observation, e.g. whether they are generic or
/// help determine the goal for the Agent.
/// </summary>
public ObservationType ObservationType;
/// <summary>
/// The number of dimensions of the observation.
/// </summary>
/// <summary>
/// Construct an ObservationSpec for 1-D observations of the requested length.
/// </summary>
/// <param name="length"></param>
/// <returns></returns>
public static ObservationSpec Vector(int length)
{
InplaceArray<int> shape = new InplaceArray<int>(length);

/// <summary>
/// Construct an ObservationSpec for variable-length observations.
/// </summary>
/// <param name="obsSize"></param>
/// <param name="maxNumObs"></param>
/// <returns></returns>
public static ObservationSpec VariableLength(int obsSize, int maxNumObs)
{
InplaceArray<int> shape = new InplaceArray<int>(obsSize, maxNumObs);

/// <summary>
/// Construct an ObservationSpec for visual-like observations, e.g. observations
/// with a height, width, and possible multiple channels.
/// </summary>
/// <param name="height"></param>
/// <param name="width"></param>
/// <param name="channels"></param>
/// <returns></returns>
public static ObservationSpec Visual(int height, int width, int channels)
{
InplaceArray<int> shape = new InplaceArray<int>(height, width, channels);

return new ObservationSpec(shape, dimProps);
}
/// <summary>
/// Create a general ObservationSpec from the shape, dimension properties, and observation type.
/// </summary>
/// <param name="shape"></param>
/// <param name="dimensionProperties"></param>
/// <param name="observationType"></param>
/// <exception cref="UnityAgentsException"></exception>
internal ObservationSpec(
InplaceArray<int> shape,
InplaceArray<DimensionProperty> dimensionProperties,

ObservationType = observationType;
}
}
}

8
com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs


namespace Unity.MLAgents.Sensors
{
public struct CompressionSpec
{
public SensorCompressionType SensorCompressionType;
public int[] CompressedChannelMapping;
}
}

3
com.unity.ml-agents/Runtime/Sensors/CompressionSpec.cs.meta


fileFormatVersion: 2
guid: 30f2a27e7468474b91c9b470f8775a04
timeCreated: 1615412780
正在加载...
取消
保存