using Unity.Barracuda;
namespace Unity.MLAgents.Sensors
{
///
/// This is the simplest approach, but there's possible user error if Shape.Length != DimensionProperties.Length
///
public struct ObservationSpec
{
public ObservationType ObservationType;
public InplaceArray Shape;
public InplaceArray DimensionProperties;
public int NumDimensions
{
get { return Shape.Length; }
}
public static ObservationSpec Vector(int length)
{
InplaceArray shape = new InplaceArray(length);
InplaceArray dimProps = new InplaceArray(DimensionProperty.None);
return new ObservationSpec(shape, dimProps);
}
public static ObservationSpec VariableSize(int obsSize, int maxNumObs)
{
InplaceArray shape = new InplaceArray(obsSize, maxNumObs);
InplaceArray dimProps = new InplaceArray(DimensionProperty.VariableSize, DimensionProperty.None);
return new ObservationSpec(shape, dimProps);
}
public static ObservationSpec Visual(int height, int width, int channels)
{
InplaceArray shape = new InplaceArray(height, width, channels);
InplaceArray dimProps = new InplaceArray(
DimensionProperty.TranslationalEquivariance, DimensionProperty.TranslationalEquivariance, DimensionProperty.None
);
return new ObservationSpec(shape, dimProps);
}
internal ObservationSpec(
InplaceArray shape,
InplaceArray dimensionProperties,
ObservationType observationType = ObservationType.Default
)
{
if (shape.Length != dimensionProperties.Length)
{
throw new UnityAgentsException("shape and dimensionProperties must have the same length.");
}
Shape = shape;
DimensionProperties = dimensionProperties;
ObservationType = observationType;
}
}
}