浏览代码

add NaN checks to reward and observation in C# (#3221)

/asymm-envs
GitHub 5 年前
当前提交
fbb5022a
共有 2 个文件被更改,包括 19 次插入1 次删除
  1. 14
      UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
  2. 6
      UnitySDK/Assets/ML-Agents/Scripts/Sensor/VectorSensor.cs

14
UnitySDK/Assets/ML-Agents/Scripts/Agent.cs


/// <param name="reward">The new value of the reward.</param>
public void SetReward(float reward)
{
#if DEBUG
if (float.IsNaN(reward))
{
throw new ArgumentException("NaN reward passed to SetReward.");
}
#endif
m_CumulativeReward += (reward - m_Reward);
m_Reward = reward;
}

/// <param name="increment">Incremental reward value.</param>
public void AddReward(float increment)
{
#if DEBUG
if (float.IsNaN(increment))
{
throw new ArgumentException("NaN reward passed to AddReward.");
}
#endif
m_Reward += increment;
m_CumulativeReward += increment;
}

/// <param name="buffer"> A float array that will be used as buffer when generating the observations. Must
/// be at least the same length as the total number of uncompressed floats in the observations</param>
/// <param name="adapter"> The WriteAdapter that will be used to write the ISensor data to the observations</param>
/// <param name="observations"> A list of observations outputs. This argument will be modified by this method.</param>//
/// <param name="observations"> A list of observations outputs. This argument will be modified by this method.</param>//
public static void GenerateSensorData(List<ISensor> sensors, float[] buffer, WriteAdapter adapter, List<Observation> observations)
{
int floatsWritten = 0;

6
UnitySDK/Assets/ML-Agents/Scripts/Sensor/VectorSensor.cs


void AddFloatObs(float obs)
{
#if DEBUG
if (float.IsNaN(obs))
{
throw new System.ArgumentException("NaN value passed to observation.");
}
#endif
m_Observations.Add(obs);
}

正在加载...
取消
保存