浏览代码

Merge branch 'master' into develop-centralizedcritic-mm

/develop/centralizedcritic
Ervin Teng 3 年前
当前提交
330fc1d0
共有 242 个文件被更改,包括 1042 次插入1014 次删除
  1. 17
      .github/workflows/pytest.yml
  2. 15
      .yamato/com.unity.ml-agents-test.yml
  3. 3
      .yamato/protobuf-generation-test.yml
  4. 10
      DevProject/Packages/manifest.json
  5. 9
      Dockerfile
  6. 1
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  7. 1
      Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs
  8. 7
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  9. 1001
      Project/Assets/ML-Agents/Examples/FoodCollector/Demos/ExpertFood.demo
  10. 62
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/FoodCollectorArea.prefab
  11. 52
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/GridFoodCollectorArea.prefab
  12. 32
      Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab
  13. 73
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  14. 18
      Project/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity
  15. 3
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridArea.cs
  16. 4
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Agent.cs
  17. 1
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Drawer.cs
  18. 2
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3TileSelector.cs
  19. 1
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  20. 1
      Project/Assets/ML-Agents/Examples/Template/Scripts/TemplateAgent.cs
  21. 10
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
  22. 1
      Project/Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureSensor.cs
  23. 1
      Project/Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureSensorComponent.cs
  24. 17
      README.md
  25. 2
      com.unity.ml-agents.extensions/Documentation~/Grid-Sensor.md
  26. 2
      com.unity.ml-agents.extensions/Documentation~/Match3.md
  27. 8
      com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md
  28. 2
      com.unity.ml-agents.extensions/Editor/EditorExample.cs
  29. 1
      com.unity.ml-agents.extensions/Editor/RigidBodySensorComponentEditor.cs
  30. 2
      com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs
  31. 1
      com.unity.ml-agents.extensions/Runtime/Sensors/CountingGridSensor.cs
  32. 2
      com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsBodySensor.cs
  33. 1
      com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodyJointExtractor.cs
  34. 4
      com.unity.ml-agents.extensions/Tests/Editor/Match3/AbstractBoardTests.cs
  35. 2
      com.unity.ml-agents.extensions/Tests/Editor/Match3/Match3SensorTests.cs
  36. 48
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotPerceiveTests.cs
  37. 3
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotShapeTests.cs
  38. 47
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelPerceiveTests.cs
  39. 1
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelShapeTests.cs
  40. 10
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorPerceiveTests.cs
  41. 1
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorShapeTests.cs
  42. 5
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridObservationPerceiveTests.cs
  43. 9
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridSensorTestUtils.cs
  44. 2
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/PoseExtractorTests.cs
  45. 5
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodyPoseExtractorTests.cs
  46. 8
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodySensorTests.cs
  47. 4
      com.unity.ml-agents.extensions/Tests/Runtime/RuntimeExampleTest.cs
  48. 2
      com.unity.ml-agents.extensions/package.json
  49. 37
      com.unity.ml-agents/CHANGELOG.md
  50. 6
      com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
  51. 3
      com.unity.ml-agents/Editor/BehaviorParametersEditor.cs
  52. 6
      com.unity.ml-agents/Editor/BrainParametersDrawer.cs
  53. 1
      com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs
  54. 14
      com.unity.ml-agents/Editor/DemonstrationDrawer.cs
  55. 1
      com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs
  56. 10
      com.unity.ml-agents/Runtime/Academy.cs
  57. 13
      com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
  58. 2
      com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
  59. 1
      com.unity.ml-agents/Runtime/Actuators/ActuatorDiscreteActionMask.cs
  60. 7
      com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
  61. 7
      com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
  62. 2
      com.unity.ml-agents/Runtime/Actuators/IActuator.cs
  63. 2
      com.unity.ml-agents/Runtime/Actuators/IDiscreteActionMask.cs
  64. 4
      com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
  65. 104
      com.unity.ml-agents/Runtime/Agent.cs
  66. 18
      com.unity.ml-agents/Runtime/Agent.deprecated.cs
  67. 61
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  68. 3
      com.unity.ml-agents/Runtime/Communicator/ICommunicator.cs
  69. 15
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  70. 1
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationMetaData.cs
  71. 4
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs
  72. 3
      com.unity.ml-agents/Runtime/DiscreteActionMasker.cs
  73. 33
      com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/Observation.cs
  74. 6
      com.unity.ml-agents/Runtime/Inference/BarracudaModelExtensions.cs
  75. 21
      com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs
  76. 2
      com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs
  77. 12
      com.unity.ml-agents/Runtime/Inference/ModelRunner.cs
  78. 3
      com.unity.ml-agents/Runtime/Inference/TensorApplier.cs
  79. 25
      com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs
  80. 5
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  81. 40
      com.unity.ml-agents/Runtime/Policies/BrainParameters.cs
  82. 2
      com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs
  83. 3
      com.unity.ml-agents/Runtime/Sampler.cs
  84. 1
      com.unity.ml-agents/Runtime/SensorHelper.cs
  85. 2
      com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
  86. 1
      com.unity.ml-agents/Runtime/Sensors/Reflection/EnumReflectionSensor.cs
  87. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/IntReflectionSensor.cs
  88. 2
      com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs
  89. 2
      com.unity.ml-agents/Runtime/Utilities.cs
  90. 1
      com.unity.ml-agents/Tests/Editor/Actuators/ActuatorDiscreteActionMaskTests.cs
  91. 15
      com.unity.ml-agents/Tests/Editor/Actuators/ActuatorManagerTests.cs
  92. 1
      com.unity.ml-agents/Tests/Editor/Actuators/VectorActuatorTests.cs
  93. 9
      com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs
  94. 7
      com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs
  95. 2
      com.unity.ml-agents/Tests/Editor/DemonstrationTests.cs
  96. 2
      com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorApplier.cs
  97. 4
      com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorGenerator.cs
  98. 8
      com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs
  99. 2
      com.unity.ml-agents/Tests/Editor/ModelRunnerTest.cs
  100. 4
      com.unity.ml-agents/Tests/Editor/ParameterLoaderTest.cs

17
.github/workflows/pytest.yml


strategy:
matrix:
python-version: [3.6.x, 3.7.x, 3.8.x]
include:
- python-version: 3.6.x
pip_constraints: test_constraints_min_version.txt
- python-version: 3.7.x
pip_constraints: test_constraints_max_tf1_version.txt
- python-version: 3.8.x
pip_constraints: test_constraints_max_tf2_version.txt
steps:
- uses: actions/checkout@v2
- name: Set up Python

# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('ml-agents/setup.py', 'ml-agents-envs/setup.py', 'gym-unity/setup.py', 'test_requirements.txt', matrix.pip_constraints) }}
key: ${{ runner.os }}-pip-${{ hashFiles('ml-agents/setup.py', 'ml-agents-envs/setup.py', 'gym-unity/setup.py', 'test_requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-

# pin pip to workaround https://github.com/pypa/pip/issues/9180
python -m pip install pip==20.2
python -m pip install --upgrade setuptools
python -m pip install --progress-bar=off -e ./ml-agents-envs -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./ml-agents -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -r test_requirements.txt -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./gym-unity -c ${{ matrix.pip_constraints }}
python -m pip install --progress-bar=off -e ./ml-agents-envs
python -m pip install --progress-bar=off -e ./ml-agents
python -m pip install --progress-bar=off -r test_requirements.txt
python -m pip install --progress-bar=off -e ./gym-unity
- name: Save python dependencies
run: |
pip freeze > pip_versions-${{ matrix.python-version }}.txt

15
.yamato/com.unity.ml-agents-test.yml


enableCodeCoverage: !!bool false
# We want some scene tests to run in the DevProject, but packages there only support 2019+
testProject: Project
enableNoDefaultPackages: !!bool false
enableNoDefaultPackages: !!bool true
enableNoDefaultPackages: !!bool true
enableNoDefaultPackages: !!bool true
trunk_editor:
- version: trunk

{% else %}
{% assign coverageOptions = "" %}
{% endif %}
{% if editor.enableNoDefaultPackages %}
{% assign noDefaultPackagesOptions = "--extra-create-project-arg='-upmNoDefaultPackages'" %}
{% else %}
{% assign noDefaultPackagesOptions = "" %}
{% endif %}
test_{{ package.name }}_{{ platform.name }}_{{ editor.version }}:
name : {{ package.name }} test {{ editor.version }} on {{ platform.name }}
agent:

commands:
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} {{ noDefaultPackagesOptions }} --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}

- python -m pip install unity-downloader-cli --index-url https://artifactory.prd.it.unity3d.com/artifactory/api/pypi/pypi/simple --upgrade
- unity-downloader-cli -u trunk -c editor --wait --fast
- npm install upm-ci-utils@stable -g --registry https://artifactory.prd.cds.internal.unity3d.com/artifactory/api/npm/upm-npm
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-utr-arg "reruncount=2"
- upm-ci project test -u {{ editor.version }} --project-path {{ editor.testProject }} --package-filter {{ package.name }} {{ coverageOptions }} --extra-create-project-arg="-upmNoDefaultPackages" --extra-utr-arg "reruncount=2"
{% if editor.enableCodeCoverage %}
- python3 ml-agents/tests/yamato/check_coverage_percent.py upm-ci~/test-results/ {{ package.minCoveragePct }}
{% endif %}

3
.yamato/protobuf-generation-test.yml


name: Protobuf Generation Tests
agent:
type: Unity::VM::osx
image: ml-agents/ml-agents-bokken-mac:0.1.4-492264
image: package-ci/mac:stable
HOMEBREW_NO_AUTO_UPDATE: "1"
commands:
- |
brew install nuget

10
DevProject/Packages/manifest.json


"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ads": "3.4.7",
"com.unity.ads": "3.4.9",
"com.unity.analytics": "3.3.5",
"com.unity.coding": "0.1.0-preview.13",
"com.unity.collab-proxy": "1.2.16",

"com.unity.ml-agents.extensions": "file:../../com.unity.ml-agents.extensions",
"com.unity.multiplayer-hlapi": "1.0.6",
"com.unity.package-manager-doctools": "1.1.1-preview.3",
"com.unity.package-validation-suite": "0.14.0-preview",
"com.unity.purchasing": "2.0.6",
"com.unity.test-framework": "1.1.14",
"com.unity.package-manager-doctools": "1.7.0-preview",
"com.unity.package-validation-suite": "0.19.0-preview",
"com.unity.purchasing": "2.1.0",
"com.unity.test-framework": "1.1.16",
"com.unity.test-framework.performance": "2.2.0-preview",
"com.unity.testtools.codecoverage": "0.2.2-preview",
"com.unity.textmeshpro": "2.0.1",

9
Dockerfile


FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
# From https://gitlab.com/nvidia/container-images/cuda/blob/master/doc/supported-tags.md
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
RUN yes | unminimize

apt-get install -y --no-install-recommends wget curl tmux vim git gdebi-core \
build-essential python3-pip unzip google-cloud-sdk htop mesa-utils xorg-dev xorg \
libglvnd-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev && \
libglvnd-dev libgl1-mesa-dev libegl1-mesa-dev libgles2-mesa-dev xvfb && \
wget http://security.ubuntu.com/ubuntu/pool/universe/x/xorg-server/xvfb_1.18.4-0ubuntu0.10_amd64.deb && \
yes | gdebi libxfont1_1.5.1-1ubuntu0.16.04.4_amd64.deb && \
yes | gdebi xvfb_1.18.4-0ubuntu0.10_amd64.deb
yes | gdebi libxfont1_1.5.1-1ubuntu0.16.04.4_amd64.deb
RUN python3 -m pip install --upgrade pip
RUN pip install setuptools==41.0.0

1
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;

1
Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs


using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using UnityEngine.Serialization;
/// <summary>

7
Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.Barracuda;

Vector3 avgVel = Vector3.zero;
//ALL RBS
int numOfRB = 0;
int numOfRb = 0;
numOfRB++;
numOfRb++;
avgVel = velSum / numOfRB;
avgVel = velSum / numOfRb;
return avgVel;
}

1001
Project/Assets/ML-Agents/Examples/FoodCollector/Demos/ExpertFood.demo
文件差异内容过多而无法显示
查看文件

62
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/FoodCollectorArea.prefab


m_BrainParameters:
VectorObservationSize: 4
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 3210b528a2bc44a86bd6bd1d571070f8, type: 3}
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114176228333253036
MonoBehaviour:

myLaser: {fileID: 1081721624670010}
contribute: 1
useVectorObs: 1
useVectorFrozenFlag: 0
--- !u!114 &114725457980523372
MonoBehaviour:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 4
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 3210b528a2bc44a86bd6bd1d571070f8, type: 3}
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114711827726849508
MonoBehaviour:

myLaser: {fileID: 1941433838307300}
contribute: 0
useVectorObs: 1
useVectorFrozenFlag: 0
--- !u!114 &114443152683847924
MonoBehaviour:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 4
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 3210b528a2bc44a86bd6bd1d571070f8, type: 3}
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114542632553128056
MonoBehaviour:

myLaser: {fileID: 1421240237750412}
contribute: 0
useVectorObs: 1
useVectorFrozenFlag: 0
--- !u!114 &114986980423924774
MonoBehaviour:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 4
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 3210b528a2bc44a86bd6bd1d571070f8, type: 3}
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114189751434580810
MonoBehaviour:

myLaser: {fileID: 1617924810425504}
contribute: 0
useVectorObs: 1
useVectorFrozenFlag: 0
--- !u!114 &114644889237473510
MonoBehaviour:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 4
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: 36ab3e93020504f48858d0856f939685, type: 3}
VectorActionSpaceType: 1
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 3210b528a2bc44a86bd6bd1d571070f8, type: 3}
m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &114235147148547996
MonoBehaviour:

myLaser: {fileID: 1045923826166930}
contribute: 0
useVectorObs: 1
useVectorFrozenFlag: 0
--- !u!114 &114276061479012222
MonoBehaviour:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1819751139121548}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 12.3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

52
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/GridFoodCollectorArea.prefab


m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: 699f852e79b5ba642871514fb1fb9843, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 75910f45f20be49b18e2b95879a217b2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GridFoodCollector

myLaser: {fileID: 1081721624670010}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 0
--- !u!114 &8297075921230369060
MonoBehaviour:
m_ObjectHideFlags: 0

- {r: 0, g: 0, b: 0, a: 0}
GizmoYOffset: 0
ShowGizmos: 0
CompressionType: 1
--- !u!1 &1482701732800114
GameObject:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: 699f852e79b5ba642871514fb1fb9843, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 75910f45f20be49b18e2b95879a217b2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GridFoodCollector

myLaser: {fileID: 1941433838307300}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 0
--- !u!114 &259154752087955944
MonoBehaviour:
m_ObjectHideFlags: 0

- {r: 0, g: 0, b: 0, a: 0}
GizmoYOffset: 0
ShowGizmos: 0
CompressionType: 1
--- !u!1 &1528397385587768
GameObject:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: 699f852e79b5ba642871514fb1fb9843, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 75910f45f20be49b18e2b95879a217b2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GridFoodCollector

myLaser: {fileID: 1421240237750412}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 0
--- !u!114 &5519119940433428255
MonoBehaviour:
m_ObjectHideFlags: 0

- {r: 0, g: 0, b: 0, a: 0}
GizmoYOffset: 0
ShowGizmos: 0
CompressionType: 1
--- !u!1 &1617924810425504
GameObject:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: 699f852e79b5ba642871514fb1fb9843, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 75910f45f20be49b18e2b95879a217b2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GridFoodCollector

myLaser: {fileID: 1617924810425504}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 0
--- !u!114 &5884750436653390196
MonoBehaviour:
m_ObjectHideFlags: 0

- {r: 0, g: 0, b: 0, a: 0}
GizmoYOffset: 0
ShowGizmos: 0
CompressionType: 1
--- !u!1 &1688105343773098
GameObject:
m_ObjectHideFlags: 0

m_BrainParameters:
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: 699f852e79b5ba642871514fb1fb9843, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 75910f45f20be49b18e2b95879a217b2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: GridFoodCollector

myLaser: {fileID: 1045923826166930}
contribute: 0
useVectorObs: 0
useVectorFrozenFlag: 0
--- !u!114 &4768752321433982785
MonoBehaviour:
m_ObjectHideFlags: 0

- {r: 0, g: 0, b: 0, a: 0}
GizmoYOffset: 0
ShowGizmos: 0
CompressionType: 1
--- !u!1 &1729825611722018
GameObject:
m_ObjectHideFlags: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1819751139121548}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 12.3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

32
Project/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab


m_BrainParameters:
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: ec4b31b5d66ca4e51ae3ac41945facb2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: VisualFoodCollector

m_BrainParameters:
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: ec4b31b5d66ca4e51ae3ac41945facb2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: VisualFoodCollector

m_BrainParameters:
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: ec4b31b5d66ca4e51ae3ac41945facb2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: VisualFoodCollector

m_BrainParameters:
VectorObservationSize: 1
NumStackedVectorObservations: 1
VectorActionSize: 03000000030000000300000002000000
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
m_Model: {fileID: 11400000, guid: c3b1eb0bcf06b4c0488599c7ab806de7, type: 3}
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: ec4b31b5d66ca4e51ae3ac41945facb2, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: VisualFoodCollector

73
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;

return new Color32(r, g, b, 255);
}
public void MoveAgent(ActionSegment<int> act)
public void MoveAgent(ActionBuffers actionBuffers)
{
m_Shoot = false;

var dirToGo = Vector3.zero;
var rotateDir = Vector3.zero;
var continuousActions = actionBuffers.ContinuousActions;
var discreteActions = actionBuffers.DiscreteActions;
var shootCommand = false;
var forwardAxis = (int)act[0];
var rightAxis = (int)act[1];
var rotateAxis = (int)act[2];
var shootAxis = (int)act[3];
switch (forwardAxis)
{
case 1:
dirToGo = transform.forward;
break;
case 2:
dirToGo = -transform.forward;
break;
}
var forward = Mathf.Clamp(continuousActions[0], -1f, 1f);
var right = Mathf.Clamp(continuousActions[1], -1f, 1f);
var rotate = Mathf.Clamp(continuousActions[2], -1f, 1f);
switch (rightAxis)
{
case 1:
dirToGo = transform.right;
break;
case 2:
dirToGo = -transform.right;
break;
}
dirToGo = transform.forward * forward;
dirToGo += transform.right * right;
rotateDir = -transform.up * rotate;
switch (rotateAxis)
{
case 1:
rotateDir = -transform.up;
break;
case 2:
rotateDir = transform.up;
break;
}
switch (shootAxis)
{
case 1:
shootCommand = true;
break;
}
var shootCommand = (int)discreteActions[0] > 0;
if (shootCommand)
{
m_Shoot = true;

public override void OnActionReceived(ActionBuffers actionBuffers)
{
MoveAgent(actionBuffers.DiscreteActions);
MoveAgent(actionBuffers);
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
discreteActionsOut[1] = 0;
discreteActionsOut[2] = 0;
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = 0;
continuousActionsOut[1] = 0;
continuousActionsOut[2] = 0;
discreteActionsOut[2] = 2;
continuousActionsOut[2] = 1;
discreteActionsOut[0] = 1;
continuousActionsOut[0] = 1;
discreteActionsOut[2] = 1;
continuousActionsOut[2] = -1;
discreteActionsOut[0] = 2;
continuousActionsOut[0] = -1;
discreteActionsOut[3] = Input.GetKey(KeyCode.Space) ? 1 : 0;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = Input.GetKey(KeyCode.Space) ? 1 : 0;
}
public override void OnEpisodeBegin()

18
Project/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44971168, g: 0.4997775, b: 0.57563686, a: 1}
m_IndirectSpecularColor: {r: 0.44971228, g: 0.49977815, b: 0.57563734, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:

agentParameters:
maxStep: 100
hasUpgradedFromAgentParameters: 1
maxStep: 100
MaxStep: 100
area: {fileID: 1795599557}
timeBetweenDecisionsAtInference: 0.15
renderCamera: {fileID: 797520692}

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 0
numStackedVectorObservations: 1
vectorActionSize: 05000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
VectorObservationSize: 0
NumStackedVectorObservations: 1
VectorActionSize: 05000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: a812f1ce7763a4a0c912717f3594fe20, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0

m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &125487791
MonoBehaviour:
m_ObjectHideFlags: 0

m_RenderTexture: {fileID: 8400000, guid: 114608d5384404f89bff4b6f88432958, type: 2}
m_SensorName: RenderTextureSensor
m_Grayscale: 0
m_ObservationStacks: 1
m_Compression: 1
--- !u!1 &260425459
GameObject:

trueAgent: {fileID: 125487785}
goalPref: {fileID: 1508142483324970, guid: 1ec4e4e96e7514d45b7ebc3ba5a9a481, type: 3}
pitPref: {fileID: 1811317785436014, guid: d13ee2db77b3a4dcc8664d2fe2a0f219, type: 3}
numberOfObstacles: 1
--- !u!4 &1795599558
Transform:
m_ObjectHideFlags: 0

3
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridArea.cs


public GameObject goalPref;
public GameObject pitPref;
GameObject[] m_Objects;
public int numberOfObstacles = 1;
GameObject m_Plane;
GameObject m_Sn;

transform.position = m_InitialPosition * (m_ResetParams.GetWithDefault("gridSize", 5f) + 1);
var playersList = new List<int>();
for (var i = 0; i < (int)m_ResetParams.GetWithDefault("numObstacles", 1); i++)
for (var i = 0; i < (int)m_ResetParams.GetWithDefault("numObstacles", numberOfObstacles); i++)
{
playersList.Add(1);
}

4
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Agent.cs


m_TimeUntilMove = MoveTime;
var nextState = State.Invalid;
State nextState;
switch (m_CurrentState)
{
case State.FindMatches:

bool HasValidMoves()
{
foreach (var move in Board.ValidMoves())
foreach (var unused in Board.ValidMoves())
{
return true;
}

1
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Drawer.cs


using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents.Extensions.Match3;
namespace Unity.MLAgentsExamples
{

2
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3TileSelector.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

{
AllTilesOff();
emptyTile.SetActive(true);
return;
}
else
{

1
Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;

1
Project/Assets/ML-Agents/Examples/Template/Scripts/TemplateAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;

10
Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs


const float m_maxWalkingSpeed = 10; //The max walking speed
//Should the agent sample a new goal velocity each episode?
//If true, walkSpeed will be randomly set between zero and m_maxWalkingSpeed in OnEpisodeBegin()
//If true, walkSpeed will be randomly set between zero and m_maxWalkingSpeed in OnEpisodeBegin()
//If false, the goal velocity will be walkingSpeed
public bool randomizeWalkSpeedEachEpisode;

//ragdoll's avg vel
var avgVel = GetAvgVelocity();
//current ragdoll velocity. normalized
//current ragdoll velocity. normalized
sensor.AddObservation(Vector3.Distance(velGoal, avgVel));
//avg body vel relative to cube
sensor.AddObservation(m_OrientationCube.transform.InverseTransformDirection(avgVel));

Vector3 avgVel = Vector3.zero;
//ALL RBS
int numOfRB = 0;
int numOfRb = 0;
numOfRB++;
numOfRb++;
avgVel = velSum / numOfRB;
avgVel = velSum / numOfRb;
return avgVel;
}

1
Project/Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureSensor.cs


using UnityEngine;
using Unity.MLAgents.Sensors;
using Unity.MLAgents;
public class TestTextureSensor : ISensor
{

1
Project/Assets/ML-Agents/TestScenes/TestCompressedTexture/TestTextureSensorComponent.cs


using UnityEngine;
using UnityEngine.Serialization;
using Unity.MLAgents.Sensors;

17
README.md


# Unity ML-Agents Toolkit
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/)
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/)
[![license badge](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)

## Releases & Documentation
**Our latest, stable release is `Release 10`. Click
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Readme.md)
**Our latest, stable release is `Release 12`. Click
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/Readme.md)
to get started with the latest release of ML-Agents.**
The table below lists all our releases, including our `master` branch which is

| **Version** | **Release Date** | **Source** | **Documentation** | **Download** |
|:-------:|:------:|:-------------:|:-------:|:------------:|
| **master (unstable)** | -- | [source](https://github.com/Unity-Technologies/ml-agents/tree/master) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/master/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/master.zip) |
| **Release 10** | **November 18, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_10)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_10.zip)** |
| **Release 12** | **December 22, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_12)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_12.zip)** |
| **Release 11** | December 21, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_11) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_11_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_11.zip) |
| **Release 10** | November 18, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_10) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_10.zip) |
| **Release 4** | July 15, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_4) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_4_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_4.zip) |
## Citation

For any other questions or feedback, connect directly with the ML-Agents team at
ml-agents@unity3d.com.
## Privacy
In order to improve the developer experience for Unity ML-Agents Toolkit, we have added in-editor analytics.
Please refer to "Information that is passively collected by Unity" in the
[Unity Privacy Policy](https://unity3d.com/legal/privacy-policy).
## License

2
com.unity.ml-agents.extensions/Documentation~/Grid-Sensor.md


An image can be thought of as a matrix of a predefined width (W) and a height (H) and each pixel can be thought of as simply an array of length 3 (in the case of RGB), `[Red, Green, Blue]` holding the different channel information of the color (channel) intensities at that pixel location. Thus an image is just a 3 dimensional matrix of size WxHx3. A Grid Observation can be thought of as a generalization of this setup where in place of a pixel there is a "cell" which is an array of length N representing different channel intensities at that cell position. From a Convolutional Neural Network point of view, the introduction of multiple channels in an "image" isn't a new concept. One such example is using an RGB-Depth image which is used in several robotics applications. The distinction of Grid Observations is what the data within the channels represents. Instead of limiting the channels to color intensities, the channels within a cell of a Grid Observation generalize to any data that can be represented by a single number (float or int).
Before jumping into the details of the Grid Sensor, an important thing to note is the agent performance and qualitatively different behavior over raycasts. Unity MLAgent's comes with a suite of example environments. One in particular, the [Food Collector](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Learning-Environment-Examples.md#food-collector), has been the focus of the Grid Sensor development.
Before jumping into the details of the Grid Sensor, an important thing to note is the agent performance and qualitatively different behavior over raycasts. Unity MLAgent's comes with a suite of example environments. One in particular, the [Food Collector](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/Learning-Environment-Examples.md#food-collector), has been the focus of the Grid Sensor development.
The Food Collector environment can be described as:
* Set-up: A multi-agent environment where agents compete to collect food.

2
com.unity.ml-agents.extensions/Documentation~/Match3.md


This implementation includes:
* C# implementation catered toward a Match-3 setup including concepts around encoding for moves based on [Human Like Playtesting with Deep Learning](https://www.researchgate.net/publication/328307928_Human-Like_Playtesting_with_Deep_Learning)
* An example Match-3 scene with ML-Agents implemented (located under /Project/Assets/ML-Agents/Examples/Match3). More information, on Match-3 example [here](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/docs/Learning-Environment-Examples.md#match-3).
* An example Match-3 scene with ML-Agents implemented (located under /Project/Assets/ML-Agents/Examples/Match3). More information, on Match-3 example [here](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/docs/Learning-Environment-Examples.md#match-3).
### Feedback
If you are a Match-3 developer and are trying to leverage ML-Agents for this scenario, [we want to hear from you](https://forms.gle/TBsB9jc8WshgzViU9). Additionally, we are also looking for interested Match-3 teams to speak with us for 45 minutes. If you are interested, please indicate that in the [form](https://forms.gle/TBsB9jc8WshgzViU9). If selected, we will provide gift cards as a token of appreciation.

8
com.unity.ml-agents.extensions/Documentation~/com.unity.ml-agents.extensions.md


recommended ways to install the package:
### Local Installation
[Clone the repository](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Installation.md#clone-the-ml-agents-toolkit-repository-optional) and follow the
[Local Installation for Development](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/Installation.md#advanced-local-installation-for-development-1)
[Clone the repository](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/Installation.md#clone-the-ml-agents-toolkit-repository-optional) and follow the
[Local Installation for Development](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/Installation.md#advanced-local-installation-for-development-1)
![Package Manager git URL](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/images/unity_package_manager_git_url.png)
![Package Manager git URL](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/images/unity_package_manager_git_url.png)
In the dialog that appears, enter
```
git+https://github.com/Unity-Technologies/ml-agents.git?path=com.unity.ml-agents.extensions

none
## Need Help?
The main [README](https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/README.md) contains links for contacting the team or getting support.
The main [README](https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/README.md) contains links for contacting the team or getting support.

2
com.unity.ml-agents.extensions/Editor/EditorExample.cs


using Unity.MLAgents;
namespace Unity.MLAgents.Extensions.Editor
{

1
com.unity.ml-agents.extensions/Editor/RigidBodySensorComponentEditor.cs


using UnityEngine;
using UnityEditor;
using Unity.MLAgents.Editor;
using Unity.MLAgents.Extensions.Sensors;

2
com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs


/// </summary>
[FormerlySerializedAs("ForceRandom")]
[Tooltip("Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.")]
public bool ForceHeuristic = false;
public bool ForceHeuristic;
/// <inheritdoc/>
public override IActuator CreateActuator()

1
com.unity.ml-agents.extensions/Runtime/Sensors/CountingGridSensor.cs


using System;
using UnityEngine;
using UnityEngine.Assertions;
namespace Unity.MLAgents.Extensions.Sensors
{

2
com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsBodySensor.cs


using System.Collections.Generic;
#if UNITY_2020_1_OR_NEWER
#endif
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Extensions.Sensors

1
com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodyJointExtractor.cs


using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents.Sensors;

4
com.unity.ml-agents.extensions/Tests/Editor/Match3/AbstractBoardTests.cs


public override int GetCellType(int row, int col)
{
var character = m_Board[m_Board.Length - 1 - row][col];
return (int)(character - '0');
return (character - '0');
return (int)(character - '0');
return (character - '0');
}
}

2
com.unity.ml-agents.extensions/Tests/Editor/Match3/Match3SensorTests.cs


using System;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Extensions.Match3;
using UnityEngine;
using Unity.MLAgents.Extensions.Tests.Sensors;

48
com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotPerceiveTests.cs


{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { -0.1f };
dummyData.Data = new[] { -0.1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { 1.1f };
dummyData.Data = new[] { 1.1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { .2f };
dummyData.Data = new[] { .2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .2f }, 4);
float[] expectedDefault = new float[] { 0 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .2f }, 4);
float[] expectedDefault = new[] { 0.0f };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { -1f };
dummyData.Data = new[] { -1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 4f };
dummyData.Data = new[] { 4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 2f };
dummyData.Data = new[] { 2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 3, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
int[] subarrayIndicies = new[] { 77, 78, 87, 88 };
float[] expectedDefault = new float[] { 1, 0, 0 };
float[] expectedDefault = new[] { 1.0f, 0.0f, 0.0f };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 2.4f };
dummyData.Data = new[] { 2.4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 1 };
dummyData.Data = new float[] { .4f, .3f };
dummyData.Data = new[] { .4f, .3f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .4f, .3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .4f, .3f }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 3 };
dummyData.Data = new float[] { .4f, 4f };
dummyData.Data = new[] { .4f, 4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 3 };
dummyData.Data = new float[] { .4f, 1f };
dummyData.Data = new[] { .4f, 1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 4, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .4f, 0, 1, 0 }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .4f, 0, 1, 0 }, 4);
float[] expectedDefault = new float[] { 0, 1, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3, 1 };
dummyData.Data = new float[] { 1f, .4f };
dummyData.Data = new[] { 1f, .4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 4, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 0, 1, 0, .4f }, 4);
int[] subarrayIndicies = new[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 0, 1, 0, .4f }, 4);
float[] expectedDefault = new float[] { 1, 0, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3, 3 };
dummyData.Data = new float[] { 1f, 2.2f };
dummyData.Data = new[] { 1f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 5, 1, 3 };
dummyData.Data = new float[] { 3f, .6f, 2.2f };
dummyData.Data = new[] { 3f, .6f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 9, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4);
float[] expectedDefault = new float[] { 1, 0, 0, 0, 0, 0, 1, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 5, 1, 3 };
dummyData.Data = new float[] { 3f, .6f, 2.2f };
dummyData.Data = new[] { 3f, .6f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.ChannelHot,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 9, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 0, 0, 0, 1, 0, .6f, 0, 0, 1 }, 4);
float[] expectedDefault = new float[] { 1, 0, 0, 0, 0, 0, 1, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);

3
com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelHotShapeTests.cs


using NUnit.Framework;
using UnityEngine;
using Unity.MLAgents.Extensions.Sensors;
using NUnit.Framework.Internal;
using UnityEngine.TestTools;
using System.Collections;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

47
com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelPerceiveTests.cs


using UnityEngine.TestTools;
using Unity.MLAgents.Extensions.Sensors;
using Unity.MLAgents.Extensions.TestUtils.Sensors;
using System.Linq;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { -0.1f };
dummyData.Data = new[] { -0.1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { 1.1f };
dummyData.Data = new[] { 1.1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1 };
dummyData.Data = new float[] { .2f };
dummyData.Data = new[] { .2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .2f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .2f }, 4);
float[] expectedDefault = new float[] { 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { -1f };
dummyData.Data = new[] { -1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 4f };
dummyData.Data = new[] { 4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 2f };
dummyData.Data = new[] { 2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 2f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 2f / 3f }, 4);
float[] expectedDefault = new float[] { 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3 };
dummyData.Data = new float[] { 2.4f };
dummyData.Data = new[] { 2.4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 2.4f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 2.4f / 3f }, 4);
float[] expectedDefault = new float[] { 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 1 };
dummyData.Data = new float[] { .4f, .3f };
dummyData.Data = new[] { .4f, .3f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .4f, .3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .4f, .3f }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 3 };
dummyData.Data = new float[] { .4f, 4f };
dummyData.Data = new[] { .4f, 4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

{
string[] tags = { k_Tag1 };
int[] depths = { 1, 3 };
dummyData.Data = new float[] { .4f, 1f };
dummyData.Data = new[] { .4f, 1f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .4f, 1f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .4f, 1f / 3f }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3, 1 };
dummyData.Data = new float[] { 1f, .4f };
dummyData.Data = new[] { 1f, .4f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f / 3f, .4f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f / 3f, .4f }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 3, 3 };
dummyData.Data = new float[] { 1f, 2.2f };
dummyData.Data = new[] { 1f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f / 3f, 2.2f / 3 }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f / 3f, 2.2f / 3 }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 5, 1, 3 };
dummyData.Data = new float[] { 3f, .6f, 2.2f };
dummyData.Data = new[] { 3f, .6f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 3, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 3f / 5f, .6f, 2.2f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 3f / 5f, .6f, 2.2f / 3f }, 4);
float[] expectedDefault = new float[] { 0, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

{
string[] tags = { k_Tag1 };
int[] depths = { 5, 1, 3 };
dummyData.Data = new float[] { 3f, .6f, 2.2f };
dummyData.Data = new[] { 3f, .6f, 2.2f };
Color[] colors = { Color.red, Color.magenta };
gridSensor.SetParameters(tags, depths, GridSensor.GridDepthType.Channel,
1f, 1f, 10, 10, LayerMask.GetMask("Default"), false, colors);

Assert.AreEqual(10 * 10 * 3, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 3f / 5f, .6f, 2.2f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 3f / 5f, .6f, 2.2f / 3f }, 4);
float[] expectedDefault = new float[] { 0, 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);

1
com.unity.ml-agents.extensions/Tests/Editor/Sensors/ChannelShapeTests.cs


using NUnit.Framework;
using UnityEngine;
using Unity.MLAgents.Extensions.Sensors;
using NUnit.Framework.Internal;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

10
com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorPerceiveTests.cs


Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f }, 4);
float[] expectedDefault = new float[] { 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f }, 4);
float[] expectedDefault = new float[] { 0 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f }, 4);
float[] expectedDefault = new float[] { 0f };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .5f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .5f }, 4);
float[] expectedDefault = new float[] { 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

Assert.AreEqual(10 * 10 * 2, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { .5f, 1 }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { .5f, 1 }, 4);
float[] expectedDefault = new float[] { 0, 0 };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

1
com.unity.ml-agents.extensions/Tests/Editor/Sensors/CountingGridSensorShapeTests.cs


using UnityEngine;
using NUnit.Framework;
using Unity.MLAgents.Extensions.Sensors;
using NUnit.Framework.Internal;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

5
com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridObservationPerceiveTests.cs


using UnityEngine;
using UnityEngine.TestTools;
using Unity.MLAgents.Extensions.Sensors;
using System.Linq;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 2f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 2f / 3f }, 4);
float[] expectedDefault = new float[] { 0f };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

Assert.AreEqual(10 * 10 * 1, output.Length);
int[] subarrayIndicies = new int[] { 77, 78, 87, 88 };
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new float[] { 1f / 3f }, 4);
float[][] expectedSubarrays = GridObsTestUtils.DuplicateArray(new[] { 1f / 3f }, 4);
float[] expectedDefault = new float[] { 0f };
GridObsTestUtils.AssertSubarraysAtIndex(output, subarrayIndicies, expectedSubarrays, expectedDefault);
}

9
com.unity.ml-agents.extensions/Tests/Editor/Sensors/GridSensorTestUtils.cs


using NUnit.Framework;
using System;
using System.Diagnostics;
using System.Linq;
namespace Unity.MLAgents.Extensions.Tests.Sensors

/// </summary>
/// <param name="arr">The array to convert to string</param>
/// <param name="initialIndex">The initial index. Default 0</param>
/// <param name="numOfElements">The number of elements to print</param>
/// <param name="maxNumberOfElements">The number of elements to print</param>
/// <returns>Human readable string</returns>
public static string Array2Str<T>(T[] arr, int initialIndex = 0, int maxNumberOfElements = int.MaxValue)
{

/// If the total array is data from a 4x4x2 grid observation, total will be an array of size 32 and each sub array will have a size of 2.
/// Let 3 cells at indicies (0, 1), (2, 2), and (3, 0) with values ([.1, .5]), ([.9, .7]), ([0, .2]), respectively.
/// If the default values of cells are ([0, 0]) then the grid observation will be as follows:
/// [ [0, 0], [.1, .5], [ 0, 0 ], [0, 0],
/// [ [0, 0], [.1, .5], [ 0, 0 ], [0, 0],
///
///
///
///
/// The indicies of the activated cells in the flattened array will be 1, 10, and 12
///
/// So to verify that the total array is as expected, AssertSubarraysAtIndex should be called as

2
com.unity.ml-agents.extensions/Tests/Editor/Sensors/PoseExtractorTests.cs


{
Assert.Throws<UnityAgentsException>(() =>
{
var bad = new BadPoseExtractor();
var unused = new BadPoseExtractor();
});
}

5
com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodyPoseExtractorTests.cs


using UnityEngine;
using NUnit.Framework;
using Unity.MLAgents.Extensions.Sensors;
using UnityEditor;
namespace Unity.MLAgents.Extensions.Tests.Sensors
{

Assert.AreEqual(0, poseExtractor.NumPoses);
// Add an RB under the other GameObject. Constructor will find a rigid body, but not the root.
var otherRb = otherGameObj.AddComponent<Rigidbody>();
otherGameObj.AddComponent<Rigidbody>();
poseExtractor = new RigidBodyPoseExtractor(rootRb, otherGameObj);
Assert.AreEqual(0, poseExtractor.NumPoses);
}

var rb1 = rootObj.AddComponent<Rigidbody>();
var go2 = new GameObject();
var rb2 = go2.AddComponent<Rigidbody>();
go2.AddComponent<Rigidbody>();
go2.transform.SetParent(rootObj.transform);
var joint = go2.AddComponent<ConfigurableJoint>();

8
com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodySensorTests.cs


public static void CompareObservation(ISensor sensor, float[] expected)
{
string errorMessage;
bool isOK = SensorHelper.CompareObservation(sensor, expected, out errorMessage);
Assert.IsTrue(isOK, errorMessage);
bool isOk = SensorHelper.CompareObservation(sensor, expected, out errorMessage);
Assert.IsTrue(isOk, errorMessage);
bool isOK = SensorHelper.CompareObservation(sensor, expected, out errorMessage);
Assert.IsTrue(isOK, errorMessage);
bool isOk = SensorHelper.CompareObservation(sensor, expected, out errorMessage);
Assert.IsTrue(isOk, errorMessage);
}
}

4
com.unity.ml-agents.extensions/Tests/Runtime/RuntimeExampleTest.cs


using UnityEngine;
using UnityEditor;
using UnityEngine.TestTools;
using System.Collections;
namespace Unity.MLAgents.Extensions.Tests
{

2
com.unity.ml-agents.extensions/package.json


"unity": "2018.4",
"description": "A source-only package for new features based on ML-Agents",
"dependencies": {
"com.unity.ml-agents": "1.6.0-preview"
"com.unity.ml-agents": "1.7.2-preview"
}
}

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


### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- TensorFlow trainers have been removed, please use the Torch trainers instead. (#4707)
### Minor Changes
#### com.unity.ml-agents / com.unity.ml-agents.extensions (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
### Bug Fixes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
## [1.7.2-preview] - 2020-12-22
### Bug Fixes
#### com.unity.ml-agents (C#)
- Add analytics package dependency to the package manifest. (#4794)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Fixed the docker build process. (#4791)
## [1.7.0-preview] - 2020-12-21
### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
The `.onnx` models generated by the trainers of this release are incompatible with versions of Barracuda before `1.2.1-preview`. If you upgrade the trainers, you must upgrade the version of the Barracuda package as well (which can be done by upgrading the `com.unity.ml-agents` package).
- Agent with both continuous and discrete actions is now supported. You can specify
continuous and discrete action sizes repectively in Behavior Parameters. (#4702, #4718)
- Agents with both continuous and discrete actions are now supported. You can specify
both continuous and discrete action sizes in Behavior Parameters. (#4702, #4718)
- In order to improve the developer experience for Unity ML-Agents Toolkit, we have added in-editor analytics.
Please refer to "Information that is passively collected by Unity" in the
[Unity Privacy Policy](https://unity3d.com/legal/privacy-policy). (#4677)
- The FoodCollector example environment now uses continuous actions for moving and
discrete actions for shooting. (#4746)
- `ActionSpec.validate_action()` now enforces that `UnityEnvironment.set_action_for_agent()` receives a 1D `np.array`.
- `ActionSpec.validate_action()` now enforces that `UnityEnvironment.set_action_for_agent()` receives a 1D `np.array`. (#4691)
- Removed noisy warnings about API minor version mismatches in both the C# and python code. (#4688)
#### ml-agents / ml-agents-envs / gym-unity (Python)

6
com.unity.ml-agents/Documentation~/com.unity.ml-agents.md


the documentation, you can checkout our [GitHub Repository], which also includes
a number of ways to [connect with us] including our [ML-Agents Forum].
In order to improve the developer experience for Unity ML-Agents Toolkit, we have added in-editor analytics.
Please refer to "Information that is passively collected by Unity" in the
[Unity Privacy Policy](https://unity3d.com/legal/privacy-policy).
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Installation.md
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Installation.md
[github repository]: https://github.com/Unity-Technologies/ml-agents
[python package]: https://github.com/Unity-Technologies/ml-agents
[execution order of event functions]: https://docs.unity3d.com/Manual/ExecutionOrder.html

3
com.unity.ml-agents/Editor/BehaviorParametersEditor.cs


using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors.Reflection;
using UnityEngine;
namespace Unity.MLAgents.Editor
{

var so = serializedObject;
so.Update();
bool needPolicyUpdate; // Whether the name, model, inference device, or BehaviorType changed.
bool needBrainParametersUpdate; // Whether the brain parameters changed
// Drawing the Behavior Parameters
EditorGUI.indentLevel++;

EditorGUILayout.PropertyField(so.FindProperty(k_BrainParametersName), true);
}
EditorGUI.EndDisabledGroup();
needBrainParametersUpdate = EditorGUI.EndChangeCheck();
EditorGUI.BeginChangeCheck();
{

6
com.unity.ml-agents/Editor/BrainParametersDrawer.cs


/// to make the custom GUI for.</param>
static void DrawVectorAction(Rect position, SerializedProperty property)
{
EditorGUI.LabelField(position, "Vector Action");
EditorGUI.LabelField(position, "Actions");
position.y += k_LineHeight;
EditorGUI.indentLevel++;
var actionSpecProperty = property.FindPropertyRelative(k_ActionSpecName);

EditorGUI.PropertyField(
position,
continuousActionSize,
new GUIContent("Continuous Action Size", "Length of continuous action vector."));
new GUIContent("Continuous Actions", "Number of continuous actions."));
}
/// <summary>

{
var branchSizes = property.FindPropertyRelative(k_DiscreteBranchSizeName);
var newSize = EditorGUI.IntField(
position, "Discrete Branch Size", branchSizes.arraySize);
position, "Discrete Branches", branchSizes.arraySize);
// This check is here due to:
// https://fogbugz.unity3d.com/f/cases/1246524/

1
com.unity.ml-agents/Editor/CameraSensorComponentEditor.cs


using UnityEngine;
using UnityEditor;
using Unity.MLAgents.Sensors;

14
com.unity.ml-agents/Editor/DemonstrationDrawer.cs


using System.Text;
using UnityEditor;
using Unity.MLAgents.Demonstrations;
using Unity.MLAgents.Policies;
namespace Unity.MLAgents.Editor

const string k_NumberStepsName = "numberSteps";
const string k_NumberEpisodesName = "numberEpisodes";
const string k_MeanRewardName = "meanReward";
const string k_ActionSpecName = "ActionSpec";
const string k_ActionSpecName = "m_ActionSpec";
const string k_NumDiscreteActionsName = "m_NumDiscreteActions";
const string k_NumDiscreteActionsName = "BranchSizes";
const string k_ShapeName = "shape";

var actSpecProperty = property.FindPropertyRelative(k_ActionSpecName);
var continuousSizeProperty = actSpecProperty.FindPropertyRelative(k_NumContinuousActionsName);
var discreteSizeProperty = actSpecProperty.FindPropertyRelative(k_NumDiscreteActionsName);
var continuousSizeLabel =
continuousSizeProperty.displayName + ": " + continuousSizeProperty.intValue;
var discreteSizeLabel = discreteSizeProperty.displayName + ": " +
discreteSizeProperty.intValue;
var continuousSizeLabel = "Continuous Actions: " + continuousSizeProperty.intValue;
var discreteSizeLabel = "Discrete Action Branches: ";
discreteSizeLabel += discreteSizeProperty == null ? "[]" : BuildIntArrayLabel(discreteSizeProperty);
EditorGUILayout.LabelField(continuousSizeLabel);
EditorGUILayout.LabelField(discreteSizeLabel);
}

1
com.unity.ml-agents/Editor/RenderTextureSensorComponentEditor.cs


using UnityEngine;
using UnityEditor;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Editor

10
com.unity.ml-agents/Runtime/Academy.cs


* API. For more information on each of these entities, in addition to how to
* set-up a learning environment and train the behavior of characters in a
* Unity scene, please browse our documentation pages on GitHub:
* https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/docs/
* https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/docs/
*/
namespace Unity.MLAgents

/// fall back to inference or heuristic decisions. (You can also set agents to always use
/// inference or heuristics.)
/// </remarks>
[HelpURL("https://github.com/Unity-Technologies/ml-agents/tree/release_10_docs/" +
[HelpURL("https://github.com/Unity-Technologies/ml-agents/tree/release_12_docs/" +
"docs/Learning-Environment-Design.md")]
public class Academy : IDisposable
{

/// </item>
/// <item>
/// <term>1.3.0</term>
/// <description>Support action spaces with both continuous and discrete actions.</description>
/// <description>Support both continuous and discrete actions.</description>
/// </item>
/// </list>
/// </remarks>

/// Unity package version of com.unity.ml-agents.
/// This must match the version string in package.json and is checked in a unit test.
/// </summary>
internal const string k_PackageVersion = "1.6.0-preview";
internal const string k_PackageVersion = "1.7.2-preview";
const int k_EditorTrainingPort = 5004;

/// NNModel and the InferenceDevice as provided.
/// </summary>
/// <param name="model">The NNModel the ModelRunner must use.</param>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
/// <param name="inferenceDevice">
/// The inference device (CPU or GPU) the ModelRunner will use.
/// </param>

13
com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs


namespace Unity.MLAgents.Actuators
{
/// <summary>
/// Defines the structure of an Action Space to be used by the Actuator system.
/// Defines the structure of the actions to be used by the Actuator system.
/// </summary>
[Serializable]
public struct ActionSpec

/// <summary>
/// An array of branch sizes for our action space.
/// An array of branch sizes for discrete actions.
/// For an IActuator that uses a Discrete <see cref="SpaceType"/>, the number of
/// For an IActuator that uses discrete actions, the number of
/// branches is the Length of the Array and each index contains the branch size.
/// The cumulative sum of the total number of discrete actions can be retrieved
/// by the <see cref="SumOfDiscreteBranchSizes"/> property.

public int[] BranchSizes;
/// <summary>
/// The number of actions for a Continuous <see cref="SpaceType"/>.
/// The number of continuous actions that an Agent can take.
/// The number of branches for a Discrete <see cref="SpaceType"/>.
/// The number of branches for discrete actions that an Agent can take.
/// </summary>
public int NumDiscreteActions { get { return BranchSizes == null ? 0 : BranchSizes.Length; } }

/// Creates a Discrete <see cref="ActionSpec"/> with the array of branch sizes that
/// represents the action space.
/// </summary>
/// <param name="branchSizes">The array of branch sizes for the discrete action space. Each index
/// <param name="branchSizes">The array of branch sizes for the discrete actions. Each index
var numActions = branchSizes.Length;
var actuatorSpace = new ActionSpec(0, branchSizes);
return actuatorSpace;
}

2
com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs


public abstract IActuator CreateActuator();
/// <summary>
/// The specification of the Action space for this ActuatorComponent.
/// The specification of the possible actions for this ActuatorComponent.
/// This must produce the same results as the corresponding IActuator's ActionSpec.
/// </summary>
/// <seealso cref="ActionSpec"/>

1
com.unity.ml-agents/Runtime/Actuators/ActuatorDiscreteActionMask.cs


using System;
using System.Collections.Generic;
using System.Linq;
namespace Unity.MLAgents.Actuators
{

7
com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs


}
/// <summary>
/// This method validates that all <see cref="IActuator"/>s have unique names and equivalent action space types
/// This method validates that all <see cref="IActuator"/>s have unique names
/// if the `DEBUG` preprocessor macro is defined, and allocates the appropriate buffers to manage the actions for
/// all of the <see cref="IActuator"/>s that may live on a particular object.
/// </summary>

}
#if DEBUG
// Make sure the names are actually unique
// Make sure all Actuators have the same SpaceType
ValidateActuators();
#endif

/// <summary>
/// Iterates through all of the IActuators in this list and calls their
/// <see cref="IActionReceiver.OnActionReceived"/> method on them with the appropriate
/// <see cref="ActionSegment{T}"/>s depending on their <see cref="IActionReceiver.ActionSpec"/>.
/// <see cref="ActionSegment{T}"/>s depending on their <see cref="ActionSpec"/>.
/// </summary>
public void ExecuteActions()
{

}
/// <summary>
/// Validates that the IActuators managed by this object have unique names and equivalent action space types.
/// Validates that the IActuators managed by this object have unique names.
/// Each Actuator needs to have a unique name in order for this object to ensure that the storage of action
/// buffers, and execution of Actuators remains deterministic across different sessions of running.
/// </summary>

7
com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs


/// </summary>
/// <param name="actionSpec"><see cref="ActionSpec"/> of the <see cref="ActionBuffers"/></param>
/// <param name="actions">The float array of all actions, including discrete and continuous actions.</param>
/// <returns>An <see cref="ActionBuffers"/> instance initialized with a <see cref="ActionSpec"/> and a float array.
/// <returns>An <see cref="ActionBuffers"/> instance initialized with a <see cref="ActionSpec"/> and a float array.</returns>
internal static ActionBuffers FromActionSpec(ActionSpec actionSpec, float[] actions)
{
if (actions == null)

/// <summary>
/// Check if the <see cref="ActionBuffers"/> is empty.
/// </summary>
/// <returns>Whether the buffers are empty.</returns>
public bool IsEmpty()
{
return ContinuousActions.IsEmpty() && DiscreteActions.IsEmpty();

/// <param name="destination">A float array to pack actions into whose length is greater than or
/// equal to the addition of the Lengths of this objects <see cref="ContinuousActions"/> and
/// <see cref="DiscreteActions"/> segments.</param>
/// [Obsolete("PackActions has been deprecated.")]
[Obsolete("PackActions has been deprecated.")]
public void PackActions(in float[] destination)
{
Debug.Assert(destination.Length >= ContinuousActions.Length + DiscreteActions.Length,

///
/// See [Agents - Actions] for more information on masking actions.
///
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <seealso cref="IActionReceiver.OnActionReceived"/>
void WriteDiscreteActionMask(IDiscreteActionMask actionMask);

2
com.unity.ml-agents/Runtime/Actuators/IActuator.cs


public interface IActuator : IActionReceiver
{
/// <summary>
/// The specification of the Action space for this IActuator.
/// The specification of the actions for this IActuator.
/// </summary>
/// <seealso cref="ActionSpec"/>
ActionSpec ActionSpec { get; }

2
com.unity.ml-agents/Runtime/Actuators/IDiscreteActionMask.cs


///
/// See [Agents - Actions] for more information on masking actions.
///
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <param name="branch">The branch for which the actions will be masked.</param>
/// <param name="actionIndices">The indices of the masked actions.</param>

4
com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs


using System;
using Unity.MLAgents.Policies;
namespace Unity.MLAgents.Actuators
{
/// <summary>

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


internal struct AgentInfo
{
/// <summary>
/// Keeps track of the last vector action taken by the Brain.
/// Keeps track of the last actions taken by the Brain.
public ActionBuffers storedVectorActions;
public ActionBuffers storedActions;
/// <summary>
/// For discrete control, specifies the actions that the agent cannot take.

public void ClearActions()
{
storedVectorActions.Clear();
storedActions.Clear();
var continuousActions = storedVectorActions.ContinuousActions;
var continuousActions = storedActions.ContinuousActions;
var discreteActions = storedVectorActions.DiscreteActions;
var discreteActions = storedActions.DiscreteActions;
for (var i = 0; i < actionBuffers.DiscreteActions.Length; i++)
{
discreteActions[i] = actionBuffers.DiscreteActions[i];

/// [OnDisable()]: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnDisable.html]
/// [OnBeforeSerialize()]: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnBeforeSerialize.html
/// [OnAfterSerialize()]: https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnAfterSerialize.html
/// [Agents]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md
/// [Reinforcement Learning in Unity]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design.md
/// [Agents]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md
/// [Reinforcement Learning in Unity]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design.md
/// [Unity ML-Agents Toolkit manual]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Readme.md
/// [Unity ML-Agents Toolkit manual]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Readme.md
[HelpURL("https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/" +
[HelpURL("https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/" +
"docs/Learning-Environment-Design-Agents.md")]
[Serializable]
[RequireComponent(typeof(BehaviorParameters))]

InitializeSensors();
}
m_Info.storedVectorActions = new ActionBuffers(
m_Info.storedActions = new ActionBuffers(
new float[m_ActuatorManager.NumContinuousActions],
new int[m_ActuatorManager.NumDiscreteActions]
);

m_CumulativeReward = 0f;
m_RequestAction = false;
m_RequestDecision = false;
m_Info.storedVectorActions.Clear();
m_Info.storedActions.Clear();
}
/// <summary>

/// for information about mixing reward signals from curiosity and Generative Adversarial
/// Imitation Learning (GAIL) with rewards supplied through this method.
///
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
/// </remarks>
/// <param name="reward">The new value of the reward.</param>
public void SetReward(float reward)

/// for information about mixing reward signals from curiosity and Generative Adversarial
/// Imitation Learning (GAIL) with rewards supplied through this method.
///
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
///</remarks>
/// <param name="increment">Incremental reward value.</param>
public void AddReward(float increment)

/// implementing a simple heuristic function can aid in debugging agent actions and interactions
/// with its environment.
///
/// [Demonstration Recorder]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Demonstration Recorder]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// </remarks>
/// <example>

/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void Heuristic(in ActionBuffers actionsOut)
{
// For backward compatibility
// Disable deprecation warnings so we can call the legacy overload.
#pragma warning disable CS0618
// The default implementation of Heuristic calls the
// obsolete version for backward compatibility
switch (m_PolicyFactory.BrainParameters.VectorActionSpaceType)
{
case SpaceType.Continuous:

actionsOut.ContinuousActions.Clear();
break;
}
#pragma warning restore CS0618
}
/// <summary>

CollectObservations(collectObservationsSensor);
}
}
using (TimerStack.Instance.Scoped("CollectDiscreteActionMasks"))
using (TimerStack.Instance.Scoped("WriteActionMask"))
{
m_ActuatorManager.WriteActionMask();
}

/// For more information about observations, see [Observations and Sensors].
///
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// [Observations and Sensors]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#observations-and-sensors
/// [Observations and Sensors]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#observations-and-sensors
/// </remarks>
public virtual void CollectObservations(VectorSensor sensor)
{

}
/// <summary>
/// Implement `CollectDiscreteActionMasks()` to collects the masks for discrete
/// Implement `WriteDiscreteActionMask()` to collects the masks for discrete
/// actions. When using discrete actions, the agent will not perform the masked
/// action.
/// </summary>

/// <remarks>
/// When using Discrete Control, you can prevent the Agent from using a certain
/// action by masking it with <see cref="DiscreteActionMasker.SetMask(int, IEnumerable{int})"/>.
/// action by masking it with <see cref="IDiscreteActionMask.WriteMask(int, IEnumerable{int})"/>.
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <seealso cref="IActionReceiver.OnActionReceived"/>
public virtual void WriteDiscreteActionMask(IDiscreteActionMask actionMask)

m_ActionMasker = new DiscreteActionMasker(actionMask);
}
// Disable deprecation warnings so we can call the legacy overload.
#pragma warning disable CS0618
#pragma warning restore CS0618
}
/// <summary>

/// <remarks>
/// An action is passed to this function in the form of an array vector. Your
/// implementation must use the array to direct the agent's behavior for the
/// An action is passed to this function in the form of an <seealso cref="ActionBuffers"/>.
/// Your implementation must use the array to direct the agent's behavior for the
/// You decide how many elements you need in the action array to control your
/// You decide how many elements you need in the ActionBuffers to control your
/// three values in the action array to use as the force components. During
/// training, the agent's policy learns to set those particular elements of
/// three values in ActionBuffers.ContinuousActions array to use as the force components.
/// During training, the agent's policy learns to set those particular elements of
/// Actions for an agent can be either *Continuous* or *Discrete*. Specify which
/// type of action space an agent uses, along with the size of the action array,
/// in the <see cref="BrainParameters"/> of the agent's associated
/// An Agent can use continuous and/or discrete actions. Configure this along with the size
/// of the action array, in the <see cref="BrainParameters"/> of the agent's associated
/// When an agent uses the continuous action space, the values in the action
/// When an agent uses continuous actions, the values in the ActionBuffers.ContinuousActions
/// When an agent uses the discrete action space, the values in the action array
/// When an agent uses discrete actions, the values in the ActionBuffers.DiscreteActions array
/// are integers that each represent a specific, discrete action. For example,
/// you could define a set of discrete actions such as:
///

/// </code>
///
/// When making a decision, the agent picks one of the five actions and puts the
/// corresponding integer value in the action vector. For example, if the agent
/// decided to move left, the action vector parameter would contain an array with
/// corresponding integer value in the ActionBuffers.DiscreteActions array. For example, if the agent
/// decided to move left, the ActionBuffers.DiscreteActions parameter would be an array with
/// a single element with the value 1.
///
/// You can define multiple sets, or branches, of discrete actions to allow an

///
/// The action vector of a discrete action space contains one element for each
/// branch. The value of each element is the integer representing the chosen
/// action for that branch. The agent always chooses one action for each
/// branch.
/// The ActionBuffers.DiscreteActions array of an agent with discrete actions contains one
/// element for each branch. The value of each element is the integer representing the
/// chosen action for that branch. The agent always chooses one action for each branch.
/// When you use the discrete action space, you can prevent the training process
/// When you use the discrete actions, you can prevent the training process
/// implementing the <see cref="CollectDiscreteActionMasks(DiscreteActionMasker)"/>
/// function. For example, if your agent is next to a wall, you could mask out any
/// implementing the <see cref="WriteDiscreteActionMask(IDiscreteActionMask)"/>
/// method. For example, if your agent is next to a wall, you could mask out any
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <param name="actions">
/// Struct containing the buffers of actions to be executed at this step.

var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec;
// For continuous and discrete actions together, we don't need to fall back to the legacy method
if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0)
{
// Nothing implemented.
return;
}
if (!actions.ContinuousActions.IsEmpty())
{
m_LegacyActionCache = actions.ContinuousActions.Array;

m_LegacyActionCache = Array.ConvertAll(actions.DiscreteActions.Array, x => (float)x);
}
// Disable deprecation warnings so we can call the legacy overload.
#pragma warning disable CS0618
#pragma warning restore CS0618
}
/// <summary>

18
com.unity.ml-agents/Runtime/Agent.deprecated.cs


/// Deprecated, use <see cref="WriteDiscreteActionMask"/> instead.
/// </summary>
/// <param name="actionMasker"></param>
[Obsolete("CollectDiscreteActionMasks has been deprecated, please use WriteDiscreteActionMask.")]
/// Deprecated, use <see cref="Heuristic(in ActionBuffers)"/> instead.
/// Deprecated, use <see cref="Heuristic(in Actuators.ActionBuffers)"/> instead.
[Obsolete("The float[] version of Heuristic has been deprecated, please use the ActionBuffers version instead.")]
public virtual void Heuristic(float[] actionsOut)
{
Debug.LogWarning("Heuristic method called but not implemented. Returning placeholder actions.");

/// <summary>
/// Deprecated, use <see cref="OnActionReceived(ActionBuffers)"/> instead.
/// Deprecated, use <see cref="OnActionReceived(Actuators.ActionBuffers)"/> instead.
[Obsolete("The float[] version of OnActionReceived has been deprecated, please use the ActionBuffers version instead.")]
public virtual void OnActionReceived(float[] vectorAction) { }
/// <summary>

/// The last action that was decided by the Agent (or null if no decision has been made).
/// </returns>
/// <seealso cref="OnActionReceived(ActionBuffers)"/>
// [Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers, Or GetStoredDiscreteActions.")]
[Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers instead.")]
var storedAction = m_Info.storedVectorActions;
var actionSpec = m_PolicyFactory.BrainParameters.ActionSpec;
// For continuous and discrete actions together, this shouldn't be called because we can only return one.
if (actionSpec.NumContinuousActions > 0 && actionSpec.NumDiscreteActions > 0)
{
Debug.LogWarning("Agent.GetAction() when both continuous and discrete actions are in use. Use Agent.GetStoredActionBuffers() instead.");
}
var storedAction = m_Info.storedActions;
if (!storedAction.ContinuousActions.IsEmpty())
{
return storedAction.ContinuousActions.Array;

61
com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs


var agentActionProto = new AgentActionProto();
if (!ai.storedVectorActions.IsEmpty())
if (!ai.storedActions.IsEmpty())
if (!ai.storedVectorActions.ContinuousActions.IsEmpty())
if (!ai.storedActions.ContinuousActions.IsEmpty())
agentActionProto.ContinuousActions.AddRange(ai.storedVectorActions.ContinuousActions.Array);
agentActionProto.ContinuousActions.AddRange(ai.storedActions.ContinuousActions.Array);
if (!ai.storedVectorActions.DiscreteActions.IsEmpty())
if (!ai.storedActions.DiscreteActions.IsEmpty())
agentActionProto.DiscreteActions.AddRange(ai.storedVectorActions.DiscreteActions.Array);
agentActionProto.DiscreteActions.AddRange(ai.storedActions.DiscreteActions.Array);
}
}

/// <param name="isTraining">Whether or not the Brain is training.</param>
public static BrainParametersProto ToProto(this BrainParameters bp, string name, bool isTraining)
{
// Disable deprecation warnings so we can set legacy fields
#pragma warning disable CS0618
var brainParametersProto = new BrainParametersProto
{
VectorActionSpaceTypeDeprecated = (SpaceTypeProto)bp.VectorActionSpaceType,

{
brainParametersProto.VectorActionDescriptionsDeprecated.AddRange(bp.VectorActionDescriptions);
}
#pragma warning restore CS0618
return brainParametersProto;
}

/// <returns>The BrainInfoProto generated.</returns>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
/// <param name="name">The name of the brain.</param>
/// <param name="isTraining">Whether or not the Brain is training.</param>
public static BrainParametersProto ToBrainParametersProto(this ActionSpec actionSpec, string name, bool isTraining)

/// <returns>A BrainParameters struct.</returns>
public static BrainParameters ToBrainParameters(this BrainParametersProto bpp)
{
ActionSpec actionSpec;
if (bpp.ActionSpec == null)
{
var spaceType = (SpaceType)bpp.VectorActionSpaceTypeDeprecated;
if (spaceType == SpaceType.Continuous)
{
actionSpec = ActionSpec.MakeContinuous(bpp.VectorActionSizeDeprecated.ToArray()[0]);
}
else
{
actionSpec = ActionSpec.MakeDiscrete(bpp.VectorActionSizeDeprecated.ToArray());
}
}
else
{
actionSpec = ToActionSpec(bpp.ActionSpec);
}
ActionSpec = ToActionSpec(bpp.ActionSpec),
ActionSpec = actionSpec,
};
return bp;
}

/// <summary>
/// Convert a ActionSpec struct to a ActionSpecProto.
/// </summary>
/// <param name="actionSpecProto">An instance of an action spec struct.</param>
/// <param name="actionSpec">An instance of an action spec struct.</param>
/// <returns>An ActionSpecProto.</returns>
public static ActionSpecProto ToActionSpecProto(this ActionSpec actionSpec)
{

{
if (!s_HaveWarnedTrainerCapabilitiesMultiPng)
{
Debug.LogWarning($"Attached trainer doesn't support multiple PNGs. Switching to uncompressed observations for sensor {sensor.GetName()}.");
Debug.LogWarning(
$"Attached trainer doesn't support multiple PNGs. Switching to uncompressed observations for sensor {sensor.GetName()}. " +
"Please find the versions that work best together from our release page: " +
"https://github.com/Unity-Technologies/ml-agents/releases"
);
s_HaveWarnedTrainerCapabilitiesMultiPng = true;
}
compressionType = SensorCompressionType.None;

{
if (!s_HaveWarnedTrainerCapabilitiesMapping)
{
Debug.LogWarning($"The sensor {sensor.GetName()} is using non-trivial mapping and " +
Debug.LogWarning(
$"The sensor {sensor.GetName()} is using non-trivial mapping and " +
"Switching to uncompressed observations.");
"Switching to uncompressed observations. " +
"Please find the versions that work best together from our release page: " +
"https://github.com/Unity-Technologies/ml-agents/releases"
);
s_HaveWarnedTrainerCapabilitiesMapping = true;
}
compressionType = SensorCompressionType.None;

if (compressibleSensor != null)
{
observationProto.CompressedChannelMapping.AddRange(compressibleSensor.GetCompressedChannelMapping());
}
}
// Add the dimension properties if any to the observationProto
var dimensionPropertySensor = sensor as IDimensionPropertiesSensor;
if (dimensionPropertySensor != null)
{
var dimensionProperties = dimensionPropertySensor.GetDimensionProperties();
int[] intDimensionProperties = new int[dimensionProperties.Length];
for (int i = 0; i < dimensionProperties.Length; i++)
{
observationProto.DimensionProperties.Add((int)dimensionProperties[i]);
}
}
observationProto.Shape.AddRange(shape);

3
com.unity.ml-agents/Runtime/Communicator/ICommunicator.cs


using System;
using System.Collections.Generic;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents

/// Registers a new Brain to the Communicator.
/// </summary>
/// <param name="name">The name or key uniquely identifying the Brain.</param>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
void SubscribeBrain(string name, ActionSpec actionSpec);
/// <summary>

15
com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs


using Unity.MLAgents.Actuators;
using Unity.MLAgents.CommunicatorObjects;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Policies;
using Unity.MLAgents.SideChannels;
using Google.Protobuf;

}
else if (unityVersion.Minor != pythonVersion.Minor)
{
// Even if we initialize, we still want to check to make sure that we inform users of minor version
// changes. This will surface any features that may not work due to minor version incompatibilities.
Debug.LogWarningFormat(
"WARNING: The communication API versions between Unity and python differ at the minor version level. " +
"Python API: {0}, Unity API: {1} Python Library Version: {2} .\n" +
"This means that some features may not work unless you upgrade the package with the lower version." +
"Please find the versions that work best together from our release page.\n" +
"https://github.com/Unity-Technologies/ml-agents/releases",
pythonApiVersion, unityCommunicationVersion, pythonLibraryVersion
);
// If a feature is used in Unity but not supported in the trainer,
// we will warn at the point it's used. Don't warn here to avoid noise.
}
return true;
}

/// Adds the brain to the list of brains which will be sending information to External.
/// </summary>
/// <param name="brainKey">Brain key.</param>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
public void SubscribeBrain(string brainKey, ActionSpec actionSpec)
{
if (m_BehaviorNames.Contains(brainKey))

1
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationMetaData.cs


using System;
using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Demonstrations

4
com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs


/// See [Imitation Learning - Recording Demonstrations] for more information.
///
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// [Imitation Learning - Recording Demonstrations]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs//Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Imitation Learning - Recording Demonstrations]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs//Learning-Environment-Design-Agents.md#recording-demonstrations
/// </remarks>
[RequireComponent(typeof(Agent))]
[AddComponentMenu("ML Agents/Demonstration Recorder", (int)MenuGroup.Default)]

/// </summary>
[Tooltip("Number of steps to record. The editor will stop playing when it reaches this threshold. " +
"Set to zero to record indefinitely.")]
public int NumStepsToRecord = 0;
public int NumStepsToRecord;
/// <summary>
/// Base demonstration file name. If multiple files are saved, the additional filenames

3
com.unity.ml-agents/Runtime/DiscreteActionMasker.cs


using System;
using System.Collections.Generic;
using Unity.MLAgents.Actuators;

///
/// See [Agents - Actions] for more information on masking actions.
///
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_10_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_12_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <param name="branch">The branch for which the actions will be masked.</param>
/// <param name="actionIndices">The indices of the masked actions.</param>

33
com.unity.ml-agents/Runtime/Grpc/CommunicatorObjects/Observation.cs


byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"CjRtbGFnZW50c19lbnZzL2NvbW11bmljYXRvcl9vYmplY3RzL29ic2VydmF0",
"aW9uLnByb3RvEhRjb21tdW5pY2F0b3Jfb2JqZWN0cyKdAgoQT2JzZXJ2YXRp",
"aW9uLnByb3RvEhRjb21tdW5pY2F0b3Jfb2JqZWN0cyK7AgoQT2JzZXJ2YXRp",
"KAUaGQoJRmxvYXREYXRhEgwKBGRhdGEYASADKAJCEgoQb2JzZXJ2YXRpb25f",
"ZGF0YSopChRDb21wcmVzc2lvblR5cGVQcm90bxIICgROT05FEAASBwoDUE5H",
"EAFCJaoCIlVuaXR5Lk1MQWdlbnRzLkNvbW11bmljYXRvck9iamVjdHNiBnBy",
"b3RvMw=="));
"KAUSHAoUZGltZW5zaW9uX3Byb3BlcnRpZXMYBiADKAUaGQoJRmxvYXREYXRh",
"EgwKBGRhdGEYASADKAJCEgoQb2JzZXJ2YXRpb25fZGF0YSopChRDb21wcmVz",
"c2lvblR5cGVQcm90bxIICgROT05FEAASBwoDUE5HEAFCJaoCIlVuaXR5Lk1M",
"QWdlbnRzLkNvbW11bmljYXRvck9iamVjdHNiBnByb3RvMw=="));
new pbr::GeneratedClrTypeInfo(typeof(global::Unity.MLAgents.CommunicatorObjects.ObservationProto), global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Parser, new[]{ "Shape", "CompressionType", "CompressedData", "FloatData", "CompressedChannelMapping" }, new[]{ "ObservationData" }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Types.FloatData), global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Types.FloatData.Parser, new[]{ "Data" }, null, null, null)})
new pbr::GeneratedClrTypeInfo(typeof(global::Unity.MLAgents.CommunicatorObjects.ObservationProto), global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Parser, new[]{ "Shape", "CompressionType", "CompressedData", "FloatData", "CompressedChannelMapping", "DimensionProperties" }, new[]{ "ObservationData" }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Types.FloatData), global::Unity.MLAgents.CommunicatorObjects.ObservationProto.Types.FloatData.Parser, new[]{ "Data" }, null, null, null)})
}));
}
#endregion

shape_ = other.shape_.Clone();
compressionType_ = other.compressionType_;
compressedChannelMapping_ = other.compressedChannelMapping_.Clone();
dimensionProperties_ = other.dimensionProperties_.Clone();
switch (other.ObservationDataCase) {
case ObservationDataOneofCase.CompressedData:
CompressedData = other.CompressedData;

get { return compressedChannelMapping_; }
}
/// <summary>Field number for the "dimension_properties" field.</summary>
public const int DimensionPropertiesFieldNumber = 6;
private static readonly pb::FieldCodec<int> _repeated_dimensionProperties_codec
= pb::FieldCodec.ForInt32(50);
private readonly pbc::RepeatedField<int> dimensionProperties_ = new pbc::RepeatedField<int>();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public pbc::RepeatedField<int> DimensionProperties {
get { return dimensionProperties_; }
}
private object observationData_;
/// <summary>Enum of possible cases for the "observation_data" oneof.</summary>
public enum ObservationDataOneofCase {

if (CompressedData != other.CompressedData) return false;
if (!object.Equals(FloatData, other.FloatData)) return false;
if(!compressedChannelMapping_.Equals(other.compressedChannelMapping_)) return false;
if(!dimensionProperties_.Equals(other.dimensionProperties_)) return false;
if (ObservationDataCase != other.ObservationDataCase) return false;
return Equals(_unknownFields, other._unknownFields);
}

if (observationDataCase_ == ObservationDataOneofCase.CompressedData) hash ^= CompressedData.GetHashCode();
if (observationDataCase_ == ObservationDataOneofCase.FloatData) hash ^= FloatData.GetHashCode();
hash ^= compressedChannelMapping_.GetHashCode();
hash ^= dimensionProperties_.GetHashCode();
hash ^= (int) observationDataCase_;
if (_unknownFields != null) {
hash ^= _unknownFields.GetHashCode();

output.WriteMessage(FloatData);
}
compressedChannelMapping_.WriteTo(output, _repeated_compressedChannelMapping_codec);
dimensionProperties_.WriteTo(output, _repeated_dimensionProperties_codec);
if (_unknownFields != null) {
_unknownFields.WriteTo(output);
}

size += 1 + pb::CodedOutputStream.ComputeMessageSize(FloatData);
}
size += compressedChannelMapping_.CalculateSize(_repeated_compressedChannelMapping_codec);
size += dimensionProperties_.CalculateSize(_repeated_dimensionProperties_codec);
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}

CompressionType = other.CompressionType;
}
compressedChannelMapping_.Add(other.compressedChannelMapping_);
dimensionProperties_.Add(other.dimensionProperties_);
switch (other.ObservationDataCase) {
case ObservationDataOneofCase.CompressedData:
CompressedData = other.CompressedData;

case 42:
case 40: {
compressedChannelMapping_.AddEntriesFrom(input, _repeated_compressedChannelMapping_codec);
break;
}
case 50:
case 48: {
dimensionProperties_.AddEntriesFrom(input, _repeated_dimensionProperties_codec);
break;
}
}

6
com.unity.ml-agents/Runtime/Inference/BarracudaModelExtensions.cs


}
/// <summary>
/// Check if the model supports hybrid action spaces.
/// Check if the model supports both continuous and discrete actions.
/// <returns>True if the model supports hybrid action spaces.</returns>
/// <returns>True if the model supports both continuous and discrete actions.</returns>
public static bool SupportsContinuousAndDiscrete(this Model model)
{
return model == null ||

/// <param name="model">
/// The Barracuda engine model for loading static parameters.
/// </param>
/// <param name="failedModelChecks">Output list of failure messages</param>
///
/// <returns>True if the model contains all the expected tensors.</returns>
public static bool CheckExpectedTensors(this Model model, List<string> failedModelChecks)
{

21
com.unity.ml-agents/Runtime/Inference/BarracudaModelParamLoader.cs


/// <param name="memory">
/// The memory size that the model is expecting.
/// </param>
/// <param name="isContinuous">
/// Whether the model is expecting continuous or discrete control.
/// </param>
/// <param name="observableAttributeTotalSize">Total size of ObservableAttributes</param>
/// <returns>
/// A IEnumerable of string corresponding to the failed input presence checks.
/// </returns>

/// The BrainParameters that are used verify the compatibility with the InferenceEngine
/// </param>
/// <param name="actuatorComponents">Array of attached actuator components.</param>
/// <param name="isContinuous">
/// Whether the model is expecting continuous or discrete control.
/// </param>
/// <param name="modelContinuousActionSize">
/// The size of the continuous action output that is expected by the model.
/// </param>
/// <param name="modelSumDiscreteBranchSizes">
/// The size of the discrete action output that is expected by the model.
/// </param>
/// <returns>
/// A IEnumerable of string corresponding to the incompatible shapes between model
/// and BrainParameters.

/// The BrainParameters that are used verify the compatibility with the InferenceEngine
/// </param>
/// <param name="actuatorComponents">Array of attached actuator components.</param>
/// <param name="shape"> The tensor shape that is expected by the model</param>
/// <param name="modelContinuousActionSize">
/// The size of the continuous action output that is expected by the model.
/// </param>
/// <param name="modelSumDiscreteBranchSizes">
/// The size of the discrete action output that is expected by the model.
/// </param>

/// The BrainParameters that are used verify the compatibility with the InferenceEngine
/// </param>
/// <param name="actuatorComponents">Array of attached actuator components.</param>
/// <param name="shape"> The tensor shape that is expected by the model</param>
/// </param>
/// <param name="modelSumDiscreteBranchSizes">
/// The size of the discrete action output that is expected by the model.
/// </param>
/// <returns>If the Check failed, returns a string containing information about why the
/// check failed. If the check passed, returns null.</returns>

2
com.unity.ml-agents/Runtime/Inference/GeneratorImpl.cs


foreach (var infoSensorPair in infos)
{
var info = infoSensorPair.agentInfo;
var pastAction = info.storedVectorActions.DiscreteActions;
var pastAction = info.storedActions.DiscreteActions;
if (!pastAction.IsEmpty())
{
for (var j = 0; j < actionSize; j++)

12
com.unity.ml-agents/Runtime/Inference/ModelRunner.cs


/// the agents
/// </summary>
/// <param name="model"> The Barracuda model to load </param>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
/// <param name="inferenceDevice"> Inference execution device. CPU is the fastest
/// option for most of ML Agents models. </param>
/// <param name="seed"> The seed that will be used to initialize the RandomNormal

seed, m_TensorAllocator, m_Memories, barracudaModel);
m_TensorApplier = new TensorApplier(
actionSpec, seed, m_TensorAllocator, m_Memories, barracudaModel);
}
public InferenceDevice InferenceDevice
{
get { return m_InferenceDevice; }
}
public NNModel Model
{
get { return m_Model; }
}
static Dictionary<string, Tensor> PrepareBarracudaInputs(IEnumerable<TensorProxy> infInputs)

3
com.unity.ml-agents/Runtime/Inference/TensorApplier.cs


using System.Collections.Generic;
using Unity.Barracuda;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
namespace Unity.MLAgents.Inference

/// <summary>
/// Returns a new TensorAppliers object.
/// </summary>
/// <param name="actionSpec"> Description of the action spaces for the Agent.</param>
/// <param name="actionSpec"> Description of the actions for the Agent.</param>
/// <param name="seed"> The seed the Appliers will be initialized with.</param>
/// <param name="allocator"> Tensor allocator</param>
/// <param name="memories">Dictionary of AgentInfo.id to memory used to pass to the inference model.</param>

25
com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs


using System;
using Unity.Barracuda;
using System.Collections.Generic;
using Unity.MLAgents.Actuators;

List<int[]> m_SensorShapes;
ActionSpec m_ActionSpec;
private string m_BehaviorName;
/// <summary>
/// Whether or not we've tried to send analytics for this model. We only ever try to send once per policy,
/// and do additional deduplication in the analytics code.
/// </summary>
private bool m_AnalyticsSent;
InferenceDevice inferenceDevice)
InferenceDevice inferenceDevice,
string behaviorName
)
m_BehaviorName = behaviorName;
m_ActionSpec = actionSpec;
}

if (!m_AnalyticsSent)
{
m_AnalyticsSent = true;
Analytics.InferenceAnalytics.InferenceModelSet(
m_ModelRunner.Model,
m_BehaviorName,
m_ModelRunner.InferenceDevice,
sensors,
m_ActionSpec
);
}
m_AgentId = info.episodeId;
m_ModelRunner?.PutObservations(info, sensors);
}

5
com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs


"Either assign a model, or change to a different Behavior Type."
);
}
return new BarracudaPolicy(actionSpec, m_Model, m_InferenceDevice);
return new BarracudaPolicy(actionSpec, m_Model, m_InferenceDevice, m_BehaviorName);
}
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)

if (m_Model != null)
{
return new BarracudaPolicy(actionSpec, m_Model, m_InferenceDevice);
return new BarracudaPolicy(actionSpec, m_Model, m_InferenceDevice, m_BehaviorName);
}
else
{

}
agent.ReloadPolicy();
}
}
}

40
com.unity.ml-agents/Runtime/Policies/BrainParameters.cs


namespace Unity.MLAgents.Policies
{
/// <summary>
/// Whether the action space is discrete or continuous.
/// This is deprecated. Agents can now use both continuous and discrete actions together.
[Obsolete("Continuous and discrete actions on the same Agent are now supported; see ActionSpec.")]
public enum SpaceType
{
/// <summary>

internal ActionSpec m_ActionSpec = new ActionSpec(0, null);
/// <summary>
/// The specification of the Action space for the BrainParameters.
/// The specification of the Actions for the BrainParameters.
/// </summary>
public ActionSpec ActionSpec
{

}
/// <summary>
/// (Deprecated) The size of the action space.
/// (Deprecated) The number of possible actions.
/// the agent uses the continuous or the discrete action space.</remarks>
/// the agent uses the continuous or the discrete actions.</remarks>
/// For the continuous action space: the length of the float vector that represents
/// For the continuous actions: the length of the float vector that represents
/// For the discrete action space: the number of branches in the action space.
/// For the discrete actions: the number of branches.
/// [Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")]
[Obsolete("VectorActionSize has been deprecated, please use ActionSpec instead.")]
[FormerlySerializedAs("vectorActionSize")]
public int[] VectorActionSize = new[] { 1 };

/// <summary>
/// (Deprecated) Defines if the action is discrete or continuous.
/// </summary>
/// [Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")]
[Obsolete("VectorActionSpaceType has been deprecated, please use ActionSpec instead.")]
[FormerlySerializedAs("vectorActionSpaceType")]
public SpaceType VectorActionSpaceType = SpaceType.Discrete;

/// <summary>
/// (Deprecated) The number of actions specified by this Brain.
/// </summary>
/// [Obsolete("NumActions has been deprecated, please use ActionSpec instead.")]
[Obsolete("NumActions has been deprecated, please use ActionSpec instead.")]
public int NumActions
{
get

/// <returns> A new BrainParameter object with the same values as the original.</returns>
public BrainParameters Clone()
{
// Disable deprecation warnings so we can read/write the old fields.
#pragma warning disable CS0618
return new BrainParameters
{
VectorObservationSize = VectorObservationSize,

VectorActionSize = (int[])VectorActionSize.Clone(),
VectorActionSpaceType = VectorActionSpaceType,
};
#pragma warning restore CS0618
}
/// <summary>

{
if (!hasUpgradedBrainParametersWithActionSpec)
// Disable deprecation warnings so we can read the old fields.
#pragma warning disable CS0618
if (!hasUpgradedBrainParametersWithActionSpec
&& m_ActionSpec.NumContinuousActions == 0
&& m_ActionSpec.BranchSizes == null)
{
if (VectorActionSpaceType == SpaceType.Continuous)
{

if (VectorActionSpaceType == SpaceType.Discrete)
{
m_ActionSpec.NumContinuousActions = 0;
m_ActionSpec.BranchSizes = VectorActionSize;
m_ActionSpec.BranchSizes = (int[])VectorActionSize.Clone();
hasUpgradedBrainParametersWithActionSpec = true;
hasUpgradedBrainParametersWithActionSpec = true;
#pragma warning restore CS0618
}
/// <summary>

{
// Disable deprecation warnings so we can read the old fields.
#pragma warning disable CS0618
VectorActionSize = ActionSpec.BranchSizes;
VectorActionSize = (int[])ActionSpec.BranchSizes.Clone();
VectorActionSpaceType = SpaceType.Discrete;
}
else if (m_ActionSpec.NumDiscreteActions == 0)

{
VectorActionSize = null;
}
#pragma warning restore CS0618
}
/// <summary>

2
com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs


using UnityEngine;
using System;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;

3
com.unity.ml-agents/Runtime/Sampler.cs


using System;
using System.Collections.Generic;
using Unity.MLAgents.Inference.Utils;
using UnityEngine;
using Random = System.Random;
namespace Unity.MLAgents

// Will be used to normalize intervalFuncs
float sumIntervalSizes = 0;
//The number of intervals
int numIntervals = (int)(intervals.Count / 2);
int numIntervals = (intervals.Count / 2);
// List that will store interval lengths
float[] intervalSizes = new float[numIntervals];
// List that will store uniform distributions

1
com.unity.ml-agents/Runtime/SensorHelper.cs


using UnityEngine;
using Unity.Barracuda;
namespace Unity.MLAgents.Sensors

2
com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs


}
else if (shape.Length == 2)
{
m_TensorShape = new TensorShape(new int[] { m_Batch, 1, shape[0], shape[1] });
m_TensorShape = new TensorShape(new[] { m_Batch, 1, shape[0], shape[1] });
}
else
{

1
com.unity.ml-agents/Runtime/Sensors/Reflection/EnumReflectionSensor.cs


using System;
using UnityEngine;
namespace Unity.MLAgents.Sensors.Reflection
{

2
com.unity.ml-agents/Runtime/Sensors/Reflection/IntReflectionSensor.cs


internal override void WriteReflectedField(ObservationWriter writer)
{
var intVal = (System.Int32)GetReflectedValue();
writer[0] = (float)intVal;
writer[0] = intVal;
}
}
}

2
com.unity.ml-agents/Runtime/Sensors/StackingSensor.cs


{
if (wrappedNumChannel == 1)
{
wrappedMapping = new int[] { 0, 0, 0 };
wrappedMapping = new[] { 0, 0, 0 };
}
else
{

2
com.unity.ml-agents/Runtime/Utilities.cs


using System;
using UnityEngine;
using Unity.MLAgents.Sensors;
namespace Unity.MLAgents
{

1
com.unity.ml-agents/Tests/Editor/Actuators/ActuatorDiscreteActionMaskTests.cs


using System;
using System.Collections.Generic;
using NUnit.Framework;
using Unity.MLAgents.Actuators;

15
com.unity.ml-agents/Tests/Editor/Actuators/ActuatorManagerTests.cs


using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Unity.MLAgents.Policies;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = UnityEngine.Assertions.Assert;

Assert.IsTrue(13 == manager.SumOfDiscreteBranchSizes);
Assert.IsTrue(0 == manager.StoredActions.ContinuousActions.Length);
Assert.IsTrue(7 == manager.StoredActions.DiscreteActions.Length);
}
[Test]
public void TestAllowMixedActions()
{
// Make sure discrete + continuous actuators are allowed.
var manager = new ActuatorManager();
var actuator1 = new TestActuator(ActionSpec.MakeDiscrete(new[] { 1, 2, 3, 4 }), "actuator1");
var actuator2 = new TestActuator(ActionSpec.MakeContinuous(3), "actuator2");
manager.Add(actuator1);
manager.Add(actuator2);
manager.ReadyActuatorsForExecution(new[] { actuator1, actuator2 }, 3, 10, 4);
}
[Test]

1
com.unity.ml-agents/Tests/Editor/Actuators/VectorActuatorTests.cs


using System.Linq;
using NUnit.Framework;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using Assert = UnityEngine.Assertions.Assert;
namespace Unity.MLAgents.Tests.Actuators

9
com.unity.ml-agents/Tests/Editor/Communicator/GrpcExtensionsTests.cs


using NUnit.Framework;
using UnityEngine;
using Unity.MLAgents.Policies;
using Unity.MLAgents.Demonstrations;
using Unity.MLAgents.Actuators;

var sparseChannelSensor = new DummySparseChannelSensor();
sparseChannelSensor.Mapping = null;
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), true);
sparseChannelSensor.Mapping = new int[] { 0, 0, 0 };
sparseChannelSensor.Mapping = new[] { 0, 0, 0 };
sparseChannelSensor.Mapping = new int[] { 0, 1, 2, 3, 4 };
sparseChannelSensor.Mapping = new[] { 0, 1, 2, 3, 4 };
sparseChannelSensor.Mapping = new int[] { 1, 2, 3, 4, -1, -1 };
sparseChannelSensor.Mapping = new[] { 1, 2, 3, 4, -1, -1 };
sparseChannelSensor.Mapping = new int[] { 0, 0, 0, 1, 1, 1 };
sparseChannelSensor.Mapping = new[] { 0, 0, 0, 1, 1, 1 };
Assert.AreEqual(GrpcExtensions.IsTrivialMapping(sparseChannelSensor), false);
}
}

7
com.unity.ml-agents/Tests/Editor/Communicator/RpcCommunicatorTests.cs


using System;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.TestTools;
namespace Unity.MLAgents.Tests.Communicator

Assert.IsTrue(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,
pythonVerStr,
pythonPackageVerStr));
// Ensure that a warning was printed.
LogAssert.Expect(LogType.Warning, new Regex("(.\\s)+"));
LogAssert.NoUnexpectedReceived();
unityVerStr = "2.0.0";
Assert.IsFalse(RpcCommunicator.CheckCommunicationVersionsAreCompatible(unityVerStr,

2
com.unity.ml-agents/Tests/Editor/DemonstrationTests.cs


done = true,
episodeId = 5,
maxStepReached = true,
storedVectorActions = new ActionBuffers(null, new int[] { 0, 1 }),
storedActions = new ActionBuffers(null, new[] { 0, 1 }),
};

2
com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorApplier.cs


[Test]
public void ApplyHybridActionOutput()
{
var actionSpec = new ActionSpec(3, new int[] { 2, 3 });
var actionSpec = new ActionSpec(3, new[] { 2, 3 });
var continuousInputTensor = new TensorProxy()
{
shape = new long[] { 2, 3 },

4
com.unity.ml-agents/Tests/Editor/EditModeTestInternalBrainTensorGenerator.cs


var infoA = new AgentInfo
{
storedVectorActions = new ActionBuffers(null, new[] { 1, 2 }),
storedActions = new ActionBuffers(null, new[] { 1, 2 }),
storedVectorActions = new ActionBuffers(null, new[] { 3, 4 }),
storedActions = new ActionBuffers(null, new[] { 3, 4 }),
discreteActionMasks = new[] { true, false, false, false, false },
};

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


Assert.AreEqual(numSteps, agent1.sensor1.numWriteCalls);
Assert.AreEqual(numSteps, agent1.sensor2.numCompressedCalls);
// Disable deprecation warnings so we can read/write the old fields.
#pragma warning disable CS0618
Assert.AreEqual(
agent1.collectObservationsCallsForEpisode,
agent1.GetStoredActionBuffers().ContinuousActions[0]
);
#pragma warning restore CS0618
}
}

2
com.unity.ml-agents/Tests/Editor/ModelRunnerTest.cs


ActionSpec GetHybrid0vis53vec_3c_2dActionSpec()
{
return new ActionSpec(3, new int[] { 2 });
return new ActionSpec(3, new[] { 2 });
}
[SetUp]

4
com.unity.ml-agents/Tests/Editor/ParameterLoaderTest.cs


var validBrainParameters = new BrainParameters();
validBrainParameters.VectorObservationSize = 53;
validBrainParameters.NumStackedVectorObservations = 1;
validBrainParameters.ActionSpec = new ActionSpec(3, new int[] { 2 });
validBrainParameters.ActionSpec = new ActionSpec(3, new[] { 2 });
return validBrainParameters;
}

var model = ModelLoader.Load(hybridONNXModel);
var brainParameters = GetHybridBrainParameters();
brainParameters.ActionSpec = new ActionSpec(3, new int[] { 3 }); ; // Invalid discrete action size
brainParameters.ActionSpec = new ActionSpec(3, new[] { 3 }); // Invalid discrete action size
var errors = BarracudaModelParamLoader.CheckModel(model, brainParameters, new SensorComponent[] { sensor_21_20_3, sensor_20_22_3 }, new ActuatorComponent[0]);
Assert.Greater(errors.Count(), 0);

部分文件因为文件数量过多而无法显示

正在加载...
取消
保存