浏览代码

Fix the reporting of histogram stats and adding a test (#5410)

* Fix the reporting of histogram stats and adding a test

* Appending to the Changelog
/develop/area-manager
GitHub 4 年前
当前提交
2933f235
共有 3 个文件被更改,包括 32 次插入0 次删除
  1. 1
      com.unity.ml-agents/CHANGELOG.md
  2. 7
      ml-agents/mlagents/trainers/agent_processor.py
  3. 24
      ml-agents/mlagents/trainers/tests/test_stats.py

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


- The calculation of the target entropy of SAC with continuous actions was incorrect and has been fixed. (#5372)
- RigidBodySensorComponent now displays a warning if it's used in a way that won't generate useful observations. (#5387)
- Update the documentation with a note saying that `GridSensor` does not work in 2D environments. (#5396)
- Fixed an issue where the histogram stats would not be reported correctly in TensorBoard. (#5410)
## [2.0.0-exp.1] - 2021-04-22

7
ml-agents/mlagents/trainers/agent_processor.py


StatsAggregationMethod,
EnvironmentStats,
)
from mlagents.trainers.exception import UnityTrainerException
from mlagents.trainers.trajectory import AgentStatus, Trajectory, AgentExperience
from mlagents.trainers.policy import Policy
from mlagents.trainers.action_info import ActionInfo, ActionInfoOutputs

self._stats_reporter.add_stat(stat_name, val, agg_type)
elif agg_type == StatsAggregationMethod.SUM:
self._stats_reporter.add_stat(stat_name, val, agg_type)
elif agg_type == StatsAggregationMethod.HISTOGRAM:
self._stats_reporter.add_stat(stat_name, val, agg_type)
else:
raise UnityTrainerException(
f"Unknown StatsAggregationMethod encountered. {agg_type}"
)

24
ml-agents/mlagents/trainers/tests/test_stats.py


import unittest
import time
from mlagents.trainers.stats import (
StatsReporter,
TensorboardWriter,

StatsPropertyType,
StatsAggregationMethod,
)
from mlagents.trainers.env_manager import AgentManager
def test_stat_reporter_add_summary_write():

"category1", StatsPropertyType.HYPERPARAMETERS, {"example": 1.0}
)
assert mock_summary.return_value.add_text.call_count >= 1
@pytest.mark.parametrize("aggregation_type", list(StatsAggregationMethod))
def test_agent_manager_stats_report(aggregation_type):
stats_reporter = StatsReporter("recorder_name")
manager = AgentManager(None, "behaviorName", stats_reporter)
values = range(5)
env_stats = {"stat": [(i, aggregation_type) for i in values]}
manager.record_environment_stats(env_stats, 0)
summary = stats_reporter.get_stats_summaries("stat")
aggregation_result = {
StatsAggregationMethod.AVERAGE: sum(values) / len(values),
StatsAggregationMethod.MOST_RECENT: values[-1],
StatsAggregationMethod.SUM: sum(values),
StatsAggregationMethod.HISTOGRAM: sum(values) / len(values),
}
assert summary.aggregated_value == aggregation_result[aggregation_type]
stats_reporter.write_stats(0)
def test_tensorboard_writer_clear(tmp_path):

正在加载...
取消
保存