浏览代码

Merge pull request #2833 from Unity-Technologies/release-0.11.0

Release 0.11.0
/develop
GitHub 5 年前
当前提交
495873e5
共有 581 个文件被更改,包括 7986 次插入8641 次删除
  1. 117
      .circleci/config.yml
  2. 25
      .pre-commit-config.yaml
  3. 1
      README.md
  4. 4
      SURVEY.md
  5. 61
      UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs
  6. 214
      UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs
  7. 30
      UnitySDK/Assets/ML-Agents/Editor/DemonstrationDrawer.cs
  8. 4
      UnitySDK/Assets/ML-Agents/Editor/DemonstrationImporter.cs
  9. 2
      UnitySDK/Assets/ML-Agents/Editor/Tests/DemonstrationTests.cs
  10. 15
      UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorApplier.cs
  11. 44
      UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorGenerator.cs
  12. 94
      UnitySDK/Assets/ML-Agents/Editor/Tests/MLAgentsEditModeTest.cs
  13. 29
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBall.prefab
  14. 25
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBallHardNew.prefab
  15. 51
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity
  16. 6
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBallHard.unity
  17. 34
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  18. 25
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs
  19. 599
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHard.nn
  20. 497
      UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBall.nn
  21. 24
      UnitySDK/Assets/ML-Agents/Examples/Basic/Prefabs/Basic.prefab
  22. 4
      UnitySDK/Assets/ML-Agents/Examples/Basic/Scenes/Basic.unity
  23. 13
      UnitySDK/Assets/ML-Agents/Examples/Basic/Scripts/BasicAgent.cs
  24. 20
      UnitySDK/Assets/ML-Agents/Examples/Basic/TFModels/Basic.nn
  25. 24
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Prefabs/Environment.prefab
  26. 4
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scenes/Bouncer.unity
  27. 10
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
  28. 148
      UnitySDK/Assets/ML-Agents/Examples/Bouncer/TFModels/Bouncer.nn
  29. 25
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/DynamicPlatform.prefab
  30. 24
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Prefabs/FixedPlatform.prefab
  31. 4
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerDynamicTarget.unity
  32. 4
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scenes/CrawlerStaticTarget.unity
  33. 2
      UnitySDK/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  34. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn
  35. 1001
      UnitySDK/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn
  36. 125
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/Prefabs/FoodCollectorArea.prefab
  37. 868
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/Prefabs/VisualFoodCollectorArea.prefab
  38. 5
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/Scenes/FoodCollector.unity
  39. 94
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/Scenes/VisualFoodCollector.unity
  40. 102
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  41. 718
      UnitySDK/Assets/ML-Agents/Examples/FoodCollector/TFModels/FoodCollector.nn
  42. 843
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scenes/GridWorld.unity
  43. 113
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAcademy.cs
  44. 32
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  45. 1001
      UnitySDK/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.nn
  46. 25
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Prefabs/SymbolFinderArea.prefab
  47. 43
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Prefabs/VisualSymbolFinderArea.prefab
  48. 4
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Scenes/Hallway.unity
  49. 80
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Scenes/VisualHallway.unity
  50. 57
      UnitySDK/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs
  51. 25
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockArea.prefab
  52. 37
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockVisualArea.prefab
  53. 4
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlock.unity
  54. 60
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scenes/VisualPushBlock.unity
  55. 21
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
  56. 1001
      UnitySDK/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlock.nn
  57. 25
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Prefabs/AreaPB.prefab
  58. 55
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Prefabs/VisualAreaPyramids.prefab
  59. 4
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Scenes/Pyramids.unity
  60. 74
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Scenes/VisualPyramids.unity
  61. 65
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/Scripts/PyramidAgent.cs
  62. 1001
      UnitySDK/Assets/ML-Agents/Examples/Pyramids/TFModels/Pyramids.nn
  63. 25
      UnitySDK/Assets/ML-Agents/Examples/Reacher/Prefabs/Agent.prefab
  64. 4
      UnitySDK/Assets/ML-Agents/Examples/Reacher/Scenes/Reacher.unity
  65. 585
      UnitySDK/Assets/ML-Agents/Examples/Reacher/TFModels/Reacher.nn
  66. 9
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception.cs
  67. 9
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception2D.cs
  68. 4
      UnitySDK/Assets/ML-Agents/Examples/SharedAssets/Scripts/RayPerception3D.cs
  69. 100
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
  70. 6
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity
  71. 50
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab
  72. 4
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scenes/Tennis.unity
  73. 9
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  74. 541
      UnitySDK/Assets/ML-Agents/Examples/Tennis/TFModels/Tennis.nn
  75. 25
      UnitySDK/Assets/ML-Agents/Examples/Walker/Prefabs/WalkerPair.prefab
  76. 4
      UnitySDK/Assets/ML-Agents/Examples/Walker/Scenes/Walker.unity
  77. 1001
      UnitySDK/Assets/ML-Agents/Examples/Walker/TFModels/Walker.nn
  78. 31
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Prefabs/WallJumpArea.prefab
  79. 12
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Scenes/WallJump.unity
  80. 37
      UnitySDK/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
  81. 1001
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJump.nn
  82. 1001
      UnitySDK/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJump.nn
  83. 2
      UnitySDK/Assets/ML-Agents/Plugins/Barracuda.Core/Barracuda.md
  84. 2
      UnitySDK/Assets/ML-Agents/Plugins/Barracuda.Core/LICENSE.md
  85. 10
      UnitySDK/Assets/ML-Agents/Plugins/Barracuda.Core/ReleaseNotes.md
  86. 334
      UnitySDK/Assets/ML-Agents/Scripts/Academy.cs
  87. 399
      UnitySDK/Assets/ML-Agents/Scripts/Agent.cs
  88. 39
      UnitySDK/Assets/ML-Agents/Scripts/Demonstration.cs
  89. 4
      UnitySDK/Assets/ML-Agents/Scripts/DemonstrationRecorder.cs
  90. 120
      UnitySDK/Assets/ML-Agents/Scripts/ICommunicator.cs
  91. 23
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/ApplierImpl.cs
  92. 354
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/BarracudaModelParamLoader.cs
  93. 61
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/GeneratorImpl.cs
  94. 14
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorApplier.cs
  95. 33
      UnitySDK/Assets/ML-Agents/Scripts/InferenceBrain/TensorGenerator.cs
  96. 25
      UnitySDK/Assets/ML-Agents/Scripts/ResetParameters.cs
  97. 69
      UnitySDK/Assets/ML-Agents/Scripts/Utilities.cs
  98. 4
      UnitySDK/README.md
  99. 1
      UnitySDK/UnitySDK.sln.DotSettings
  100. 8
      config/gail_config.yaml

117
.circleci/config.yml


keys:
# Parameterize the cache so that different python versions can get different versions of the packages
- v1-dependencies-py<< parameters.pyversion >>-{{ checksum "python_deps.txt" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-py<< parameters.pyversion >>-
- run:
name: Install Dependencies

. venv/bin/activate
pre-commit run --hook-stage manual markdown-link-check --all-files
protobuf_generation_check:
docker:
- image: circleci/python:3.7.3
working_directory: ~/repo/
steps:
- checkout
- run:
name: Combine proto files for caching
command: cat protobuf-definitions/proto/mlagents/envs/communicator_objects/*.proto > /tmp/proto_deps.txt
- restore_cache:
keys:
- v1-protobuf-gen-dependencies-{{ checksum "/tmp/proto_deps.txt" }}
- v1-protobuf-gen-dependencies-
- run:
name: Install Dependencies
command: |
sudo apt-get install nuget
nuget install Grpc.Tools -Version 1.14.1 -OutputDirectory protobuf-definitions/
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install grpcio-tools==1.13.0 --progress-bar=off
pip install mypy-protobuf==1.16.0 --progress-bar=off
- save_cache:
paths:
- ./venv
key: v1-protobuf-gen-dependencies-{{ checksum "/tmp/proto_deps.txt" }}
- run:
name: Generate protobufs
command: |
. venv/bin/activate
cd protobuf-definitions
chmod +x Grpc.Tools.1.14.1/tools/linux_x64/protoc
chmod +x Grpc.Tools.1.14.1/tools/linux_x64/grpc_csharp_plugin
COMPILER=Grpc.Tools.1.14.1/tools/linux_x64 ./make.sh
CS_PROTO_PATH=UnitySDK/Assets/ML-Agents/Scripts/Grpc/CommunicatorObjects
git diff --exit-code --quiet -- :/ ":(exclude,top)$CS_PROTO_PATH/*.meta" \
|| { GIT_ERR=$?; echo "protobufs need to be regenerated, apply the patch uploaded to artifacts."; \
echo "Apply the patch with the command: git apply proto.patch"; \
git diff -- :/ ":(exclude,top)$CS_PROTO_PATH/*.meta" > /tmp/proto.patch; \
exit $GIT_ERR; }
- store_artifacts:
path: /tmp/proto.patch
destination: proto.patch
deploy:
parameters:
directory:
type: string
description: Local directory to use for publishing (e.g. ml-agents)
docker:
- image: circleci/python:3.6
steps:
- checkout
- run:
name: install python dependencies
command: |
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip
pip install setuptools wheel twine
- run:
name: verify git tag vs. version
command: |
python3 -m venv venv
. venv/bin/activate
cd << parameters.directory >>
python setup.py verify
- run:
name: create packages
command: |
. venv/bin/activate
cd << parameters.directory >>
python setup.py sdist
python setup.py bdist_wheel
- run:
name: upload to pypi
# To upload to test, just add the following flag to twine upload:
# --repository-url https://test.pypi.org/legacy/
# and change the username to "mlagents-test"
command: |
. venv/bin/activate
cd << parameters.directory >>
twine upload -u mlagents -p $PYPI_PASSWORD dist/*
version: 2
workflow:
jobs:
- build_python:

# Test python 3.7 with the newest supported versions
pip_constraints: test_constraints_max_version.txt
- markdown_link_check
- protobuf_generation_check
- deploy:
name: deploy ml-agents-envs
directory: ml-agents-envs
filters:
tags:
only: /[0-9]+(\.[0-9]+)*(\.dev[0-9]+)*/
branches:
ignore: /.*/
- deploy:
name: deploy ml-agents
directory: ml-agents
filters:
tags:
only: /[0-9]+(\.[0-9]+)*(\.dev[0-9]+)*/
branches:
ignore: /.*/
- deploy:
name: deploy gym-unity
directory: gym-unity
filters:
tags:
only: /[0-9]+(\.[0-9]+)*(\.dev[0-9]+)*/
branches:
ignore: /.*/

25
.pre-commit-config.yaml


rev: 19.3b0
hooks:
- id: black
exclude: >
(?x)^(
.*_pb2.py|
.*_pb2_grpc.py
)$
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.720
hooks:

name: mypy-gym-unity
files: "gym-unity/.*"
args: [--ignore-missing-imports, --disallow-incomplete-defs]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.2.3
hooks:

.*cs.meta|
.*.css
.*.css|
.*.meta
)$
args: [--fix=lf]
- id: flake8

.*_pb2_grpc.py
)$
additional_dependencies: [flake8-comprehensions]
- id: trailing-whitespace
name: trailing-whitespace-markdown
types: [markdown]
- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.4.1 # Use the ref you want to point at
hooks:
- id: python-check-mock-methods
# "Local" hooks, see https://pre-commit.com/#repository-local-hooks
- repo: local
hooks:

exclude: ".*localized.*"
# Only run manually, e.g. pre-commit run --hook-stage manual markdown-link-check
stages: [manual]
- id: validate-versions
name: validate library versions
language: script
entry: utils/validate_versions.py
files: ".*/setup.py"

1
README.md


* Support for multiple environment configurations and training scenarios
* Train memory-enhanced agents using deep reinforcement learning
* Easily definable Curriculum Learning and Generalization scenarios
* Broadcasting of agent behavior for supervised learning
* Built-in support for Imitation Learning
* Flexible agent control with On Demand Decision Making
* Visualizing network outputs within the environment

4
SURVEY.md


# Unity ML-Agents Toolkit Survey
Your opinion matters a great deal to us. Only by hearing your thoughts on the Unity ML-Agents Toolkit can we continue to improve and grow. Please take a few minutes to let us know about it.
Your opinion matters a great deal to us. Only by hearing your thoughts on the Unity ML-Agents Toolkit can we continue to improve and grow. Please take a few minutes to let us know about it.
[Fill out the survey](https://goo.gl/forms/qFMYSYr5TlINvG6f1)
[Fill out the survey](https://goo.gl/forms/qFMYSYr5TlINvG6f1)

61
UnitySDK/Assets/ML-Agents/Editor/AgentEditor.cs


using UnityEngine;
using UnityEditor;
using Barracuda;
/*
This code is meant to modify the behavior of the inspector on Brain Components.
Depending on the type of brain that is used, the available fields will be modified in the inspector accordingly.
*/
/*
This code is meant to modify the behavior of the inspector on Agent Components.
*/
[CustomEditor(typeof(Agent), true)]
[CanEditMultipleObjects]
public class AgentEditor : Editor

var serializedAgent = serializedObject;
serializedAgent.Update();
var brain = serializedAgent.FindProperty("brain");
var actionsPerDecision = serializedAgent.FindProperty(
"agentParameters.numberOfActionsBetweenDecisions");
var maxSteps = serializedAgent.FindProperty(

var isOdd = serializedAgent.FindProperty(
"agentParameters.onDemandDecision");
var cameras = serializedAgent.FindProperty(
"agentParameters.agentCameras");
var renderTextures = serializedAgent.FindProperty(
"agentParameters.agentRenderTextures");
EditorGUILayout.PropertyField(brain);
if (cameras.arraySize > 0 && renderTextures.arraySize > 0)
{
EditorGUILayout.HelpBox("Brain visual observations created by first getting all cameras then all render textures.", MessageType.Info);
}
EditorGUILayout.LabelField("Agent Cameras");
for (var i = 0; i < cameras.arraySize; i++)
{
EditorGUILayout.PropertyField(
cameras.GetArrayElementAtIndex(i),
new GUIContent("Camera " + (i + 1) + ": "));
}
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Add Camera", EditorStyles.miniButton))
{
cameras.arraySize++;
}
if (GUILayout.Button("Remove Camera", EditorStyles.miniButton))
{
cameras.arraySize--;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.LabelField("Agent RenderTextures");
for (var i = 0; i < renderTextures.arraySize; i++)
{
EditorGUILayout.PropertyField(
renderTextures.GetArrayElementAtIndex(i),
new GUIContent("RenderTexture " + (i + 1) + ": "));
}
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Add RenderTextures", EditorStyles.miniButton))
{
renderTextures.arraySize++;
}
if (GUILayout.Button("Remove RenderTextures", EditorStyles.miniButton))
{
renderTextures.arraySize--;
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.PropertyField(

214
UnitySDK/Assets/ML-Agents/Editor/BrainParametersDrawer.cs


// The height of a line in the Unity Inspectors
private const float k_LineHeight = 17f;
private const int k_VecObsNumLine = 3;
private const string k_CamResPropName = "cameraResolutions";
private const string k_CamWidthPropName = "width";
private const string k_CamHeightPropName = "height";
private const string k_CamGrayPropName = "blackAndWhite";
private const int k_DefaultCameraWidth = 84;
private const int k_DefaultCameraHeight = 84;
private const bool k_DefaultCameraGray = false;
if (property.isExpanded)
{
return k_LineHeight +
GetHeightDrawVectorObservation() +
GetHeightDrawVisualObservation(property) +
GetHeightDrawVectorAction(property) +
GetHeightDrawVectorActionDescriptions(property);
}
return k_LineHeight;
return GetHeightDrawVectorObservation() +
GetHeightDrawVectorAction(property);
property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
position.y += k_LineHeight;
if (property.isExpanded)
{
EditorGUI.BeginProperty(position, label, property);
EditorGUI.indentLevel++;
// Vector Observations
DrawVectorObservation(position, property);
position.y += GetHeightDrawVectorObservation();
EditorGUI.BeginProperty(position, label, property);
EditorGUI.indentLevel++;
//Visual Observations
DrawVisualObservations(position, property);
position.y += GetHeightDrawVisualObservation(property);
// Vector Observations
DrawVectorObservation(position, property);
position.y += GetHeightDrawVectorObservation();
// Vector Action
DrawVectorAction(position, property);
position.y += GetHeightDrawVectorAction(property);
// Vector Action
DrawVectorAction(position, property);
position.y += GetHeightDrawVectorAction(property);
// Vector Action Descriptions
DrawVectorActionDescriptions(position, property);
position.y += GetHeightDrawVectorActionDescriptions(property);
EditorGUI.EndProperty();
}
EditorGUI.EndProperty();
EditorGUI.indentLevel = indent;
}

}
/// <summary>
/// Draws the Visual Observations parameters for the Brain Parameters
/// </summary>
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>
/// <param name="property">The SerializedProperty of the BrainParameters
/// to make the custom GUI for.</param>
private static void DrawVisualObservations(Rect position, SerializedProperty property)
{
EditorGUI.LabelField(position, "Visual Observations");
position.y += k_LineHeight;
var quarter = position.width / 4;
var resolutions = property.FindPropertyRelative(k_CamResPropName);
DrawVisualObsButtons(position, resolutions);
position.y += k_LineHeight;
// Display the labels for the columns : Index, Width, Height and Gray
var indexRect = new Rect(position.x, position.y, quarter, position.height);
var widthRect = new Rect(position.x + quarter, position.y, quarter, position.height);
var heightRect = new Rect(position.x + 2 * quarter, position.y, quarter, position.height);
var bwRect = new Rect(position.x + 3 * quarter, position.y, quarter, position.height);
EditorGUI.indentLevel++;
if (resolutions.arraySize > 0)
{
EditorGUI.LabelField(indexRect, "Index");
indexRect.y += k_LineHeight;
EditorGUI.LabelField(widthRect, "Width");
widthRect.y += k_LineHeight;
EditorGUI.LabelField(heightRect, "Height");
heightRect.y += k_LineHeight;
EditorGUI.LabelField(bwRect, "Gray");
bwRect.y += k_LineHeight;
}
// Iterate over the resolutions
for (var i = 0; i < resolutions.arraySize; i++)
{
EditorGUI.LabelField(indexRect, "Obs " + i);
indexRect.y += k_LineHeight;
var res = resolutions.GetArrayElementAtIndex(i);
var w = res.FindPropertyRelative("width");
w.intValue = EditorGUI.IntField(widthRect, w.intValue);
widthRect.y += k_LineHeight;
var h = res.FindPropertyRelative("height");
h.intValue = EditorGUI.IntField(heightRect, h.intValue);
heightRect.y += k_LineHeight;
var bw = res.FindPropertyRelative("blackAndWhite");
bw.boolValue = EditorGUI.Toggle(bwRect, bw.boolValue);
bwRect.y += k_LineHeight;
}
EditorGUI.indentLevel--;
}
/// <summary>
/// Draws the buttons to add and remove the visual observations parameters
/// </summary>
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>
/// <param name="resolutions">The SerializedProperty of the resolution array
/// to make the custom GUI for.</param>
private static void DrawVisualObsButtons(Rect position, SerializedProperty resolutions)
{
var widthEighth = position.width / 8;
var addButtonRect = new Rect(position.x + widthEighth, position.y,
3 * widthEighth, position.height);
var removeButtonRect = new Rect(position.x + 4 * widthEighth, position.y,
3 * widthEighth, position.height);
if (resolutions.arraySize == 0)
{
addButtonRect.width *= 2;
}
// Display the buttons
if (GUI.Button(addButtonRect, "Add New", EditorStyles.miniButton))
{
resolutions.arraySize += 1;
var newRes = resolutions.GetArrayElementAtIndex(resolutions.arraySize - 1);
newRes.FindPropertyRelative(k_CamWidthPropName).intValue = k_DefaultCameraWidth;
newRes.FindPropertyRelative(k_CamHeightPropName).intValue = k_DefaultCameraHeight;
newRes.FindPropertyRelative(k_CamGrayPropName).boolValue = k_DefaultCameraGray;
}
if (resolutions.arraySize > 0)
{
if (GUI.Button(removeButtonRect, "Remove Last", EditorStyles.miniButton))
{
resolutions.arraySize -= 1;
}
}
}
/// <summary>
/// The Height required to draw the Visual Observations parameters
/// </summary>
/// <returns>The height of the drawer of the Visual Observations </returns>
private static float GetHeightDrawVisualObservation(SerializedProperty property)
{
var visObsSize = property.FindPropertyRelative(k_CamResPropName).arraySize + 2;
if (property.FindPropertyRelative(k_CamResPropName).arraySize > 0)
{
visObsSize += 1;
}
return k_LineHeight * visObsSize;
}
/// <summary>
/// Draws the Vector Actions parameters for the Brain Parameters
/// </summary>
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>

actionSize += 1;
}
return actionSize * k_LineHeight;
}
/// <summary>
/// Draws the Vector Actions descriptions for the Brain Parameters
/// </summary>
/// <param name="position">Rectangle on the screen to use for the property GUI.</param>
/// <param name="property">The SerializedProperty of the BrainParameters
/// to make the custom GUI for.</param>
private static void DrawVectorActionDescriptions(Rect position, SerializedProperty property)
{
var bpVectorActionType = property.FindPropertyRelative(k_ActionTypePropName);
var vecActionSize = property.FindPropertyRelative(k_ActionSizePropName);
var numberOfDescriptions = 0;
if (bpVectorActionType.enumValueIndex == 1)
{
numberOfDescriptions = vecActionSize.GetArrayElementAtIndex(0).intValue;
}
else
{
numberOfDescriptions = vecActionSize.arraySize;
}
EditorGUI.indentLevel++;
var vecActionDescriptions =
property.FindPropertyRelative(k_ActionDescriptionPropName);
vecActionDescriptions.arraySize = numberOfDescriptions;
if (bpVectorActionType.enumValueIndex == 1)
{
//Continuous case :
EditorGUI.PropertyField(
position,
vecActionDescriptions,
new GUIContent("Action Descriptions",
"A list of strings used to name the available actionsm for the Brain."),
true);
position.y += k_LineHeight;
}
else
{
// Discrete case :
EditorGUI.PropertyField(
position,
vecActionDescriptions,
new GUIContent("Branch Descriptions",
"A list of strings used to name the available branches for the Brain."),
true);
position.y += k_LineHeight;
}
}
/// <summary>
/// The Height required to draw the Action Descriptions
/// </summary>
/// <returns>The height of the drawer of the Action Descriptions </returns>
private static float GetHeightDrawVectorActionDescriptions(SerializedProperty property)
{
var descriptionSize = 1;
if (property.FindPropertyRelative(k_ActionDescriptionPropName).isExpanded)
{
var descriptions = property.FindPropertyRelative(k_ActionDescriptionPropName);
descriptionSize += descriptions.arraySize + 1;
}
return descriptionSize * k_LineHeight;
}
}
}

30
UnitySDK/Assets/ML-Agents/Editor/DemonstrationDrawer.cs


return actionLabel.ToString();
}
/// <summary>
/// Constructs complex label for each CameraResolution object.
/// An example of this could be `[ 84 X 84 ]`
/// for a single camera with 84 pixels height and width.
/// </summary>
private static string BuildCameraResolutionLabel(SerializedProperty cameraArray)
{
var numCameras = cameraArray.arraySize;
var cameraLabel = new StringBuilder("[ ");
for (var i = 0; i < numCameras; i++)
{
var camHeightPropName =
cameraArray.GetArrayElementAtIndex(i).FindPropertyRelative("height");
cameraLabel.Append(camHeightPropName.intValue);
cameraLabel.Append(" X ");
var camWidthPropName =
cameraArray.GetArrayElementAtIndex(i).FindPropertyRelative("width");
cameraLabel.Append(camWidthPropName.intValue);
if (i < numCameras - 1)
{
cameraLabel.Append(", ");
}
}
cameraLabel.Append(" ]");
return cameraLabel.ToString();
}
/// <summary>
/// Renders Inspector UI for Brain Parameters of Demonstration.

var vecObsSizeProp = property.FindPropertyRelative("vectorObservationSize");
var numStackedProp = property.FindPropertyRelative("numStackedVectorObservations");
var actSizeProperty = property.FindPropertyRelative("vectorActionSize");
var camResProp = property.FindPropertyRelative("cameraResolutions");
var actSpaceTypeProp = property.FindPropertyRelative("vectorActionSpaceType");
var vecObsSizeLabel = vecObsSizeProp.displayName + ": " + vecObsSizeProp.intValue;

var camResLabel = camResProp.displayName + ": " + BuildCameraResolutionLabel(camResProp);
var actSpaceTypeLabel = actSpaceTypeProp.displayName + ": " +
(SpaceType)actSpaceTypeProp.enumValueIndex;

EditorGUILayout.LabelField(camResLabel);
EditorGUILayout.LabelField(actSpaceTypeLabel);
}

4
UnitySDK/Assets/ML-Agents/Editor/DemonstrationImporter.cs


Stream reader = File.OpenRead(ctx.assetPath);
var metaDataProto = DemonstrationMetaProto.Parser.ParseDelimitedFrom(reader);
var metaData = new DemonstrationMetaData(metaDataProto);
var metaData = metaDataProto.ToDemonstrationMetaData();
var brainParameters = new BrainParameters(brainParamsProto);
var brainParameters = brainParamsProto.ToBrainParameters();
reader.Close();

2
UnitySDK/Assets/ML-Agents/Editor/Tests/DemonstrationTests.cs


{
vectorObservationSize = 3,
numStackedVectorObservations = 2,
cameraResolutions = new[] {new Resolution()},
vectorActionDescriptions = new[] {"TestActionA", "TestActionB"},
vectorActionSize = new[] {2, 2},
vectorActionSpaceType = SpaceType.Discrete

var agentInfo = new AgentInfo
{
reward = 1f,
visualObservations = new List<Texture2D>(),
actionMasks = new[] {false, true},
done = true,
id = 5,

15
UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorApplier.cs


using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using System.Reflection;

}
}
private Dictionary<Agent, AgentInfo> GetFakeAgentInfos()
private List<Agent> GetFakeAgentInfos()
var infoA = new AgentInfo();
var infoB = new AgentInfo();
return new Dictionary<Agent, AgentInfo>(){{agentA, infoA}, {agentB, infoB}};
return new List<Agent> {agentA, agentB};
}
[Test]

var applier = new ContinuousActionOutputApplier();
applier.Apply(inputTensor, agentInfos);
var agents = agentInfos.Keys.ToList();
var agents = agentInfos;
var agent = agents[0] as TestAgent;
Assert.NotNull(agent);

var alloc = new TensorCachingAllocator();
var applier = new DiscreteActionOutputApplier(new[] {2, 3}, 0, alloc);
applier.Apply(inputTensor, agentInfos);
var agents = agentInfos.Keys.ToList();
var agents = agentInfos;
var agent = agents[0] as TestAgent;
Assert.NotNull(agent);

var applier = new MemoryOutputApplier();
applier.Apply(inputTensor, agentInfos);
var agents = agentInfos.Keys.ToList();
var agents = agentInfos;
var agent = agents[0] as TestAgent;
Assert.NotNull(agent);

var applier = new ValueEstimateApplier();
applier.Apply(inputTensor, agentInfos);
var agents = agentInfos.Keys.ToList();
var agents = agentInfos;
var agent = agents[0] as TestAgent;
Assert.NotNull(agent);

44
UnitySDK/Assets/ML-Agents/Editor/Tests/EditModeTestInternalBrainTensorGenerator.cs


{
public class EditModeTestInternalBrainTensorGenerator
{
private class TestAgent : Agent
{
}
private Dictionary<Agent, AgentInfo> GetFakeAgentInfos()
private static IEnumerable<Agent> GetFakeAgentInfos()
var infoA = new AgentInfo()
var infoA = new AgentInfo
stackedVectorObservation = (new[] {1f, 2f, 3f}).ToList(),
stackedVectorObservation = new[] { 1f, 2f, 3f }.ToList(),
storedVectorActions = new[] {1f, 2f},
actionMasks = null,
storedVectorActions = new[] { 1f, 2f },
actionMasks = null
var infoB = new AgentInfo()
var infoB = new AgentInfo
stackedVectorObservation = (new[] {4f, 5f, 6f}).ToList(),
memories = (new[] {1f, 1f, 1f}).ToList(),
storedVectorActions = new[] {3f, 4f},
actionMasks = new[] {true, false, false, false, false},
stackedVectorObservation = new[] { 4f, 5f, 6f }.ToList(),
memories = new[] { 1f, 1f, 1f }.ToList(),
storedVectorActions = new[] { 3f, 4f },
actionMasks = new[] { true, false, false, false, false },
agentA.Info = infoA;
agentB.Info = infoB;
return new Dictionary<Agent, AgentInfo>(){{agentA, infoA}, {agentB, infoB}};
return new List<Agent> { agentA, agentB };
}
[Test]

[Test]
public void GenerateVectorObservation()
{
var inputTensor = new TensorProxy()
var inputTensor = new TensorProxy
shape = new long[] {2, 3}
shape = new long[] { 2, 3 }
};
const int batchSize = 4;
var agentInfos = GetFakeAgentInfos();

[Test]
public void GenerateRecurrentInput()
{
var inputTensor = new TensorProxy()
var inputTensor = new TensorProxy
shape = new long[] {2, 5}
shape = new long[] { 2, 5 }
};
const int batchSize = 4;
var agentInfos = GetFakeAgentInfos();

[Test]
public void GeneratePreviousActionInput()
{
var inputTensor = new TensorProxy()
var inputTensor = new TensorProxy
shape = new long[] {2, 2},
shape = new long[] { 2, 2 },
valueType = TensorProxy.TensorType.Integer
};
const int batchSize = 4;

[Test]
public void GenerateActionMaskInput()
{
var inputTensor = new TensorProxy()
var inputTensor = new TensorProxy
shape = new long[] {2, 5},
shape = new long[] { 2, 5 },
valueType = TensorProxy.TensorType.FloatingPoint
};
const int batchSize = 4;

94
UnitySDK/Assets/ML-Agents/Editor/Tests/MLAgentsEditModeTest.cs


using UnityEngine;
using NUnit.Framework;
using System.Reflection;
using MLAgents.Sensor;
using MLAgents.InferenceBrain;
namespace MLAgents.Tests
{

public override void AcademyReset()
{
}
public override void AcademyStep()

public override void InitializeAgent()
{
initializeAgentCalls += 1;
// Add in some custom sensors so we can confirm they get sorted as expected.
var sensor1 = new TestSensor("testsensor1");
var sensor2 = new TestSensor("testsensor2");
m_Sensors.Add(sensor2);
m_Sensors.Add(sensor1);
AddVectorObs(0f);
}
public override void AgentAction(float[] vectorAction, string textAction)

{
agentOnDoneCalls += 1;
}
public override float[] Heuristic()
{
return new float[0];
}
// This is an empty class for testing the behavior of agents and academy
// It is left empty because we are not testing any brain behavior
public class TestBrain : Brain
public class TestSensor : ISensor
public int numberOfCallsToInitialize;
public int numberOfCallsToDecideAction;
public static TestBrain Instantiate()
public string sensorName;
public TestSensor(string n)
return CreateInstance<TestBrain>();
sensorName = n;
protected override void Initialize()
public int[] GetFloatObservationShape()
numberOfCallsToInitialize++;
return new[] { 1 };
protected override void DecideAction()
public void WriteToTensor(TensorProxy tensorProxy, int agentIndex) { }
public byte[] GetCompressedObservation()
numberOfCallsToDecideAction++;
m_AgentInfos.Clear();
return null;
}
public SensorCompressionType GetCompressionType()
{
return SensorCompressionType.None;
}
public string GetName()
{
return sensorName;
}
}
public class EditModeTestGeneration
{

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
aca.resetParameters = new ResetParameters();
Assert.AreEqual(0, aca.initializeAcademyCalls);
Assert.AreEqual(0, aca.GetStepCount());
Assert.AreEqual(0, aca.GetEpisodeCount());

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
var brain = TestBrain.Instantiate();
brain.brainParameters = new BrainParameters();
brain.brainParameters.vectorObservationSize = 0;
agent1.GiveBrain(brain);
agent2.GiveBrain(brain);
aca.resetParameters = new ResetParameters();
Assert.AreEqual(false, agent1.IsDone());
Assert.AreEqual(false, agent2.IsDone());

Assert.AreEqual(1, agent2.initializeAgentCalls);
Assert.AreEqual(0, agent1.agentActionCalls);
Assert.AreEqual(0, agent2.agentActionCalls);
// Make sure the sensors were sorted
Assert.AreEqual(agent1.m_Sensors[0].GetName(), "testsensor1");
Assert.AreEqual(agent1.m_Sensors[1].GetName(), "testsensor2");
}
}

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
aca.resetParameters = new ResetParameters();
var academyInitializeMethod = typeof(Academy).GetMethod("InitializeEnvironment",
BindingFlags.Instance | BindingFlags.NonPublic);
academyInitializeMethod?.Invoke(aca, new object[] { });

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
var brain = TestBrain.Instantiate();
aca.resetParameters = new ResetParameters();
var agentEnableMethod = typeof(Agent).GetMethod(

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
brain.brainParameters = new BrainParameters();
// We use event based so the agent will now try to send anything to the brain
agent1.agentParameters.onDemandDecision = false;
agent1.agentParameters.numberOfActionsBetweenDecisions = 2;

brain.brainParameters.vectorObservationSize = 0;
brain.brainParameters.cameraResolutions = new Resolution[0];
agent1.GiveBrain(brain);
agent2.GiveBrain(brain);
agentEnableMethod?.Invoke(agent1, new object[] { aca });
academyInitializeMethod?.Invoke(aca, new object[] { });

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
aca.resetParameters = new ResetParameters();
var academyInitializeMethod = typeof(Academy).GetMethod(
"InitializeEnvironment", BindingFlags.Instance | BindingFlags.NonPublic);
academyInitializeMethod?.Invoke(aca, new object[] { });

}
stepsSinceReset += 1;
academyStepMethod.Invoke((object)aca, new object[] { });
academyStepMethod.Invoke(aca, new object[] { });
}
}

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
var brain = TestBrain.Instantiate();
aca.resetParameters = new ResetParameters();
var agentEnableMethod = typeof(Agent).GetMethod(

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
brain.brainParameters = new BrainParameters();
// agent2 will request decisions only when RequestDecision is called
brain.brainParameters.vectorObservationSize = 0;
brain.brainParameters.cameraResolutions = new Resolution[0];
agent1.GiveBrain(brain);
agent2.GiveBrain(brain);
agentEnableMethod?.Invoke(agent2, new object[] { aca });
academyInitializeMethod?.Invoke(aca, new object[] { });

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
var brain = TestBrain.Instantiate();
aca.resetParameters = new ResetParameters();
var agentEnableMethod = typeof(Agent).GetMethod(

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
brain.brainParameters = new BrainParameters();
// We use event based so the agent will now try to send anything to the brain
agent1.agentParameters.onDemandDecision = false;
// agent1 will take an action at every step and request a decision every steps

//Here we specify that the agent does not reset when done
agent1.agentParameters.resetOnDone = false;
agent2.agentParameters.resetOnDone = false;
brain.brainParameters.vectorObservationSize = 0;
brain.brainParameters.cameraResolutions = new Resolution[0];
agent1.GiveBrain(brain);
agent2.GiveBrain(brain);
agentEnableMethod?.Invoke(agent2, new object[] { aca });
academyInitializeMethod?.Invoke(aca, new object[] { });

var acaGo = new GameObject("TestAcademy");
acaGo.AddComponent<TestAcademy>();
var aca = acaGo.GetComponent<TestAcademy>();
var brain = TestBrain.Instantiate();
aca.resetParameters = new ResetParameters();
var agentEnableMethod = typeof(Agent).GetMethod(

agent1.agentParameters = new AgentParameters();
agent2.agentParameters = new AgentParameters();
brain.brainParameters = new BrainParameters();
// We use event based so the agent will now try to send anything to the brain
agent1.agentParameters.onDemandDecision = false;
agent1.agentParameters.numberOfActionsBetweenDecisions = 3;

agent1.agentParameters.maxStep = 20;
brain.brainParameters.vectorObservationSize = 0;
brain.brainParameters.cameraResolutions = new Resolution[0];
agent1.GiveBrain(brain);
agent2.GiveBrain(brain);
agentEnableMethod?.Invoke(agent2, new object[] { aca });
academyInitializeMethod?.Invoke(aca, new object[] { });

29
UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBall.prefab


m_Component:
- component: {fileID: 4780098186595842}
- component: {fileID: 65010516625723872}
- component: {fileID: 114259948429386406}
- component: {fileID: 114368073295828880}
- component: {fileID: 114715123104194396}
m_Layer: 0
m_Name: Agent
m_TagString: Untagged

serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114259948429386406
--- !u!114 &114368073295828880
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1424713891854676}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 8
numStackedVectorObservations: 1
vectorActionSize: 02000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
m_Model: {fileID: 11400000, guid: 20a7b83be6b0c493d9271c65c897eb9b, type: 3}
m_InferenceDevice: 0
m_UseHeuristic: 0
m_BehaviorName: 3DBall
--- !u!114 &114715123104194396
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}

m_Script: {fileID: 11500000, guid: aaba48bf82bee4751aa7b89569e57f73, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 11400000, guid: 383c589e8bb76464eadc2525b5b0f2c1, type: 2}
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0

25
UnitySDK/Assets/ML-Agents/Examples/3DBall/Prefabs/3DBallHardNew.prefab


m_Component:
- component: {fileID: 4895942152145390}
- component: {fileID: 65170961617201804}
- component: {fileID: 114284317994838100}
- component: {fileID: 114466000339026140}
m_Layer: 0
m_Name: Agent

serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &114284317994838100
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1829721031899636}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5d1c4e0b1822b495aa52bc52839ecb30, type: 3}
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 5
numStackedVectorObservations: 9
vectorActionSize: 02000000
vectorActionDescriptions: []
vectorActionSpaceType: 1
m_Model: {fileID: 11400000, guid: 27d49984757ed46b181090a532ef48e5, type: 3}
m_InferenceDevice: 0
m_UseHeuristic: 0
m_BehaviorName: 3DBallHard
--- !u!114 &114466000339026140
MonoBehaviour:
m_ObjectHideFlags: 1

m_Script: {fileID: 11500000, guid: edf26e11cf4ed42eaa3ffb7b91bb4676, type: 3}
m_Name:
m_EditorClassIdentifier:
brain: {fileID: 11400000, guid: 4f74e089fbb75455ebf6f0495e30be6e, type: 2}
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0

51
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4497121, g: 0.4997778, b: 0.5756369, a: 1}
m_IndirectSpecularColor: {r: 0.44971162, g: 0.49977726, b: 0.5756362, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_Name
value: 3DBall (7)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}

propertyPath: m_Name
value: 3DBall (5)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

propertyPath: m_Name
value: 3DBall (6)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_Name
value: 3DBall (3)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}

propertyPath: m_Name
value: 3DBall (8)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_Name
value: 3DBall (9)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}

propertyPath: m_Name
value: 3DBall (10)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

propertyPath: m_Name
value: 3DBall (1)
objectReference: {fileID: 0}
- target: {fileID: 0}
propertyPath: m_BrainParameters.numStackedVectorObservations
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

propertyPath: m_Name
value: 3DBall (11)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

propertyPath: m_Name
value: 3DBall (4)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
m_IsPrefabParent: 0

m_Script: {fileID: 11500000, guid: eb15e3c3d55e54abaafb74c635b6a458, type: 3}
m_Name:
m_EditorClassIdentifier:
broadcastHub:
broadcastingBrains:
- {fileID: 11400000, guid: 383c589e8bb76464eadc2525b5b0f2c1, type: 2}
m_BrainsToControl: []
m_MaxSteps: 0
m_TrainingConfiguration:
width: 300
height: 200

- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_Name
value: 3DBall (2)
objectReference: {fileID: 0}
- target: {fileID: 1321468028730240, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: cfa81c019162c4e3caf6e2999c6fdf48, type: 2}

6
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBallHard.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.4497121, g: 0.4997778, b: 0.5756369, a: 1}
m_IndirectSpecularColor: {r: 0.44971162, g: 0.49977726, b: 0.5756362, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
broadcastHub:
broadcastingBrains:
brainsToControl:
m_BrainsToControl: []
m_MaxSteps: 0
m_TrainingConfiguration:
width: 300
height: 200

34
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


public override void AgentAction(float[] vectorAction, string textAction)
{
if (brain.brainParameters.vectorActionSpaceType == SpaceType.Continuous)
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ);
}
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))
{
gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ);
}
if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) ||
(gameObject.transform.rotation.x > -0.25f && actionX < 0f))
{
gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX);
}
if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) ||
(gameObject.transform.rotation.x > -0.25f && actionX < 0f))
{
gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX);
}
if ((ball.transform.position.y - gameObject.transform.position.y) < -2f ||
Mathf.Abs(ball.transform.position.x - gameObject.transform.position.x) > 3f ||

+ gameObject.transform.position;
//Reset the parameters when the Agent is reset.
SetResetParameters();
}
public override float[] Heuristic()
{
var action = new float[2];
action[0] = -Input.GetAxis("Horizontal");
action[1] = Input.GetAxis("Vertical");
return action;
}
public void SetBall()

25
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs


public override void AgentAction(float[] vectorAction, string textAction)
{
if (brain.brainParameters.vectorActionSpaceType == SpaceType.Continuous)
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ);
}
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))
{
gameObject.transform.Rotate(new Vector3(0, 0, 1), actionZ);
}
if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) ||
(gameObject.transform.rotation.x > -0.25f && actionX < 0f))
{
gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX);
}
if ((gameObject.transform.rotation.x < 0.25f && actionX > 0f) ||
(gameObject.transform.rotation.x > -0.25f && actionX < 0f))
{
gameObject.transform.Rotate(new Vector3(1, 0, 0), actionX);
}
if ((ball.transform.position.y - gameObject.transform.position.y) < -2f ||
Mathf.Abs(ball.transform.position.x - gameObject.transform.position.x) > 3f ||

599
UnitySDK/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHard.nn


vector_observation����-epsilon����action action_probsaction_output_shape������?action_output_shape memory_sizeversion_numberis_continuous_controlrunning_variance-- running_mean-1-clip_by_value/y^normalization_steps_mul_2/x`normalized_state/yamul_3/xbadd_5/ycmul_4/xdlog_sigma_squarede truediv_3/ygclip_by_value/Minimum/yhLog/xinormalized_state/Minimum/yjsub_3e�����?vector_observation running_meanadd_5d�����?normalization_stepsadd_5/y truediv_1g�����?running_varianceadd_5Sqrt2o�����? truediv_1 truediv_2g�����?sub_3Sqrtnormalized_state/Minimumn�����? truediv_2normalized_state/Minimum/ynormalized_stateo�����?normalized_state/Minimumnormalized_state/ymain_graph_0/hidden_0/BiasAdd�����?normalized_statemain_graph_0/hidden_0/kernel-�k�main_graph_0/hidden_0/bias���main_graph_0/hidden_0/Mul2 �����?main_graph_0/hidden_0/BiasAddmain_graph_0/hidden_1/BiasAdd�����?main_graph_0/hidden_0/Mulmain_graph_0/hidden_1/kernel��k@main_graph_0/hidden_1/bias�kW�main_graph_0/hidden_1/Mul2 �����?main_graph_0/hidden_1/BiasAdd dense/BiasAdd�����?main_graph_0/hidden_1/Mul dense/kernel��W
dense/bias�XExp2q�����?log_sigma_squaredSqrt_12o�����?Expmul_1f�����?Sqrt_1epsilonadd_6d�����? dense/BiasAddmul_1clip_by_value/Minimumn�����?add_6clip_by_value/Minimum/y clip_by_valueo�����?clip_by_value/Minimumclip_by_value/y truediv_3g�����? clip_by_value truediv_3/yaction2�����? truediv_3sub_4e�����?add_6 dense/BiasAddSquaref�����?sub_4sub_4mul_2f�����?mul_2/xSquare truediv_4g�����?mul_2ExpLog2r�����?Log/xmul_3f�����?mul_3/xLogsub_5e�����? truediv_4mul_3mul_4f�����?mul_4/xlog_sigma_squaredsub_6e�����?sub_5mul_4 action_probs2�����?sub_6@@�?<D�cDn��EL[oFյ�FԁDs�D4��E�LF���F~�D
�D�!�E͡+F�іF_ D�?D���E�]FE�F�UDʏDv�E��ES[�FD�D �D6��E5�EܚFX�DQ7D��Eh�EF��F=DE�D���E`ZE�s�F��D�D���E|�E;��F��w�D�;�
���lM@��@���w�%>�;���[�M@a+A��Ww�5,�;�*��/N@�kA�a�v���;]:����N@��A�+fu�`��;�I����N@V�A�f�s�/��;�X��FO@!HB� �q��[�;
g��Q�O@ΚB�k\o��߇;�t��6�O@�B�4�l��C�;���T>P@MC�@�@$�H���?�??8k0�{q,�@@@@��@�@��>�׀>,,��g��Zk���Ly��"�<ABB�^����q�==ѫ<{����=056==Uj��.���E��+>�N��2�ٽ��1��=4�ۡ����M>�e��%�>��&��R ���H�$1�=��\=����[��ɣ�*6�=�E׼}e�=��%�O5��^<2����<U�佯lּ����Z�=��F>Y�ս�� >
"�����=% =���?�"��b/���0��)�)S>O�����<g>�[�=W=����P/><��������=�&>��\����Q弽x�0�ij>N�=l��;x��3�u>.'����=<�������C}>�WB>�X�f���̂������a:2��>�p��G�����<[k=�cR��C/��V�=*fB�c�?>I��d�� �G=��½o%���h�h�=����o����<�͑\��z��Kb>��.>�p��� ��>��釡�=@>w��=�k�=F�%�ܐ��=���̶*�-��;
�0>�����S�p�;9���
��=�򦽻=g���"%#���&=_��=Tl�;�>� �>�3^�Ը$>�"i>),���Η=|@���|���/�[\w=�.>j^>a�[���>�=��2�S���<�z�;Ud<|��=J�W�Mf�G��������%>���<د�=�Pq>ۺ�<S���Pҽ��">`p�r�!�3@�}�=�\\>EG۽p:���O>6�.>������l>�}���p0�XX�w7�=I�n���@� y�<=S�~������=<�,�29�<��>q=�p��W=p�c��5\���:=�ꞽ����5=j����X���]>�
I� �� �@�&��>R#a>�w�=EnC����=��>����/��>2�U>p��="��<�>.�C�i�;>��;� ��D�0>��<��-=5��g�1�����Mu��T!=�xN>��w��4=���a>$��jv>�x���F��]��< �<�=�C>h�e>�����P��T|>���=��M�m���i!8�(c���H����� $>lG`���=]�!>&b<�҄<�⎾� @>kE�=8��=��A���">���=�� �2@�<v���@<��rG���D��@=����b;/��=? �=z]w>5Ķ=��=%���v���-���U�=���=H��<�a�;|�u�u;�>vjJ�6��������>|i|�GK��A%�=�cy� =�{��H ��^2�>g�;Qج>�v�>D��=��~ =�d�=]tD���нJ�&��f&<boW����<�oZ���ý���<���;�3�'�">|�=l�>��A>w+=|V>�>���=4��>�Z��� g=��>q�'�v6P��q��J4�>Y��F_�=}��<���=��!>o�7��
V��,��8#>A�1�i��=2,�=O�=���<_:=9oF�`寽�'>=��~�m�L=M�5�w���ī��1ͽ��9��=�|�<���=�TԼ�0_��Q�>$@;>�k<�O-�=�\�����l<>V����I��G 6=|�7�`��=�ߎ�ЎM>��7����=. B>P�3�(��=�B^��ȋ�2R�~ h>V�i�%?">7�9>��x��֗��?4>-�=J�]�c�(��&�>C��=�� ����=�`2��\98�=�>Kќ��7��^u�>b�<���<�Qn�m茽G>��E�T�Q>_�3=ΌI=e��;砑><�!�`���a �sb =Q���u��3d/>,,���U�)=�<McW<��J����5B1>��9�� �S��A@)�YN� �<���/�1>b�ƽ�� �� �Q8���U�:�f���Ž�c����<74a���g�<Y����&�J>������|c�,q->u-T�k}�>!������rL��?��aW���W>G$ѽ�풾S��= n�_)|�!:�=�1=ӛ�=��=U6
=��f= k�= �3���3�`(��g� ��X�>�Z���U�Q�&>�:�=6�E>��=�M�<�u<�BS,��R�=�L���>��=�=v��1RK���L#��)�*#�>xb4>U�$>^b>L�=�̅��M>�l�H貽aM�5��z�r=@]c�P}>���=c��ޖ�m��=�