浏览代码

access to observations in Heuristic (#3825)

* access to observations in Heuristic

* changelog
/develop/dockerfile
GitHub 5 年前
当前提交
3a4a6792
共有 4 个文件被更改,包括 31 次插入2 次删除
  1. 6
      com.unity.ml-agents/CHANGELOG.md
  2. 12
      com.unity.ml-agents/Runtime/Agent.cs
  3. 10
      com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs
  4. 5
      com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs

6
com.unity.ml-agents/CHANGELOG.md


- Academy.InferenceSeed property was added. This is used to initialize the
random number generator in ModelRunner, and is incremented for each ModelRunner. (#3823)
- Updated Barracuda to 0.6.3-preview.
- Model updates can now happen asynchronously with environment steps for better performance. (#3690)
- `num_updates` and `train_interval` for SAC were replaced with `steps_per_update`. (#3690)
- Added `Agent.GetObservations(), which returns a read-only view of the observations
added in `CollectObservations()`. (#3825)
- Model updates can now happen asynchronously with environment steps for better performance. (#3690)
- `num_updates` and `train_interval` for SAC were replaced with `steps_per_update`. (#3690)
### Bug Fixes

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


using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
using Barracuda;
using MLAgents.Sensors;

/// </remarks>
public virtual void CollectObservations(VectorSensor sensor)
{
}
/// <summary>
/// Returns a read-only view of the observations that were generated in
/// <see cref="CollectObservations(VectorSensor)"/>. This is mainly useful inside of a
/// <see cref="Heuristic(float[])"/> method to avoid recomputing the observations.
/// </summary>
/// <returns>A read-only view of the observations list.</returns>
public ReadOnlyCollection<float> GetObservations()
{
return collectObservationsSensor.GetObservations();
}
/// <summary>

10
com.unity.ml-agents/Runtime/Sensors/VectorSensor.cs


using System.Collections.Generic;
using System.Collections.ObjectModel;
using UnityEngine;
namespace MLAgents.Sensors

}
adapter.AddRange(m_Observations);
return expectedObservations;
}
/// <summary>
/// Returns a read-only view of the observations that added.
/// </summary>
/// <returns>A read-only view of the observations list.</returns>
internal ReadOnlyCollection<float> GetObservations()
{
return m_Observations.AsReadOnly();
}
/// <inheritdoc/>

5
com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs


public override void Heuristic(float[] actionsOut)
{
var obs = GetObservations();
actionsOut[0] = obs[0];
heuristicCalls++;
}
}

Assert.AreEqual(numSteps, agent1.heuristicCalls);
Assert.AreEqual(numSteps, agent1.sensor1.numWriteCalls);
Assert.AreEqual(numSteps, agent1.sensor2.numCompressedCalls);
// Make sure the Heuristic method read the observation and set the action
Assert.AreEqual(agent1.collectObservationsCallsForEpisode, agent1.GetAction()[0]);
}
}

正在加载...
取消
保存