using Unity.MLAgents.Sensors;
namespace Unity.MLAgentsExamples
{
///
/// A simple sensor that provides a number default implementations.
///
public abstract class SensorBase : ISensor
{
///
/// Write the observations to the output buffer. This size of the buffer will be product
/// of the Shape array values returned by .
///
///
public abstract void WriteObservation(float[] output);
///
public abstract ObservationSpec GetObservationSpec();
///
public abstract string GetName();
///
/// Default implementation of Write interface. This creates a temporary array,
/// calls WriteObservation, and then writes the results to the ObservationWriter.
///
///
/// The number of elements written.
public virtual int Write(ObservationWriter writer)
{
// TODO reuse buffer for similar agents
var numFloats = this.ObservationSize();
float[] buffer = new float[numFloats];
WriteObservation(buffer);
writer.AddList(buffer);
return numFloats;
}
///
public void Update() { }
///
public void Reset() { }
///
public virtual byte[] GetCompressedObservation()
{
return null;
}
///
public virtual CompressionSpec GetCompressionSpec()
{
return CompressionSpec.Default();
}
}
}