Class VectorSensor
A sensor implementation for vector observations.
Namespace: Unity.MLAgents.Sensors
Syntax
public class VectorSensor : object, ISensor, IBuiltInSensorConstructors
VectorSensor(Int32, String, ObservationType)
Initializes the sensor.
Declaration
public VectorSensor(int observationSize, string name = null, ObservationType observationType = default(ObservationType))Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | observationSize | Number of vector observations. | 
| String | name | Name of the sensor. | 
| ObservationType | observationType | 
Methods
AddObservation(IList<Single>)
Adds a list or array of float observations to the vector observations of the agent.
Declaration
public void AddObservation(IList<float> observation)Parameters
| Type | Name | Description | 
|---|---|---|
| IList<Single> | observation | Observation. | 
AddObservation(Quaternion)
Adds a quaternion observation to the vector observations of the agent.
Declaration
public void AddObservation(Quaternion observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Quaternion | observation | Observation. | 
AddObservation(Boolean)
Adds a boolean observation to the vector observation of the agent.
Declaration
public void AddObservation(bool observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Boolean | observation | Observation. | 
AddObservation(Int32)
Adds an integer observation to the vector observations of the agent.
Declaration
public void AddObservation(int observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | observation | Observation. | 
AddObservation(Single)
Adds a float observation to the vector observations of the agent.
Declaration
public void AddObservation(float observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Single | observation | Observation. | 
AddObservation(Vector2)
Adds an Vector2 observation to the vector observations of the agent.
Declaration
public void AddObservation(Vector2 observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Vector2 | observation | Observation. | 
AddObservation(Vector3)
Adds an Vector3 observation to the vector observations of the agent.
Declaration
public void AddObservation(Vector3 observation)Parameters
| Type | Name | Description | 
|---|---|---|
| Vector3 | observation | Observation. | 
AddOneHotObservation(Int32, Int32)
Adds a one-hot encoding observation.
Declaration
public void AddOneHotObservation(int observation, int range)Parameters
| Type | Name | Description | 
|---|---|---|
| Int32 | observation | The index of this observation. | 
| Int32 | range | The max index for any observation. | 
GetBuiltInSensorType()
Declaration
public BuiltInSensorType GetBuiltInSensorType()Returns
| Type | Description | 
|---|---|
| BuiltInSensorType | 
GetCompressedObservation()
Return a compressed representation of the observation. For small observations, this should generally not be implemented. However, compressing large observations (such as visual results) can significantly improve model training time.
Declaration
public virtual byte[] GetCompressedObservation()Returns
| Type | Description | 
|---|---|
| Byte[] | Compressed observation. | 
Implements
GetCompressionSpec()
Return information on the compression type being used. If no compression is used, return Default().
Declaration
public CompressionSpec GetCompressionSpec()Returns
| Type | Description | 
|---|---|
| CompressionSpec | An object describing the compression used by the sensor. | 
Implements
GetName()
Get the name of the sensor. This is used to ensure deterministic sorting of the sensors on an Agent, so the naming must be consistent across all sensors and agents.
Declaration
public string GetName()Returns
| Type | Description | 
|---|---|
| String | The name of the sensor. | 
Implements
GetObservationSpec()
Returns a description of the observations that will be generated by the sensor. See ObservationSpec for more details, and helper methods to create one.
Declaration
public ObservationSpec GetObservationSpec()Returns
| Type | Description | 
|---|---|
| ObservationSpec | An object describing the observation. | 
Implements
Reset()
Resets the internal state of the sensor. This is called at the end of an Agent's episode. Most implementations can leave this empty.
Declaration
public void Reset()Implements
Update()
Update any internal state of the sensor. This is called once per each agent step.
Declaration
public void Update()Implements
Write(ObservationWriter)
Write the observation data directly to the ObservationWriter. Note that this (and GetCompressedObservation()) may be called multiple times per agent step, so should not mutate any internal state.
Declaration
public int Write(ObservationWriter writer)Parameters
| Type | Name | Description | 
|---|---|---|
| ObservationWriter | writer | Where the observations will be written to. | 
Returns
| Type | Description | 
|---|---|
| Int32 | The number of elements written. |