浏览代码

Merge branch 'master' into hh/develop/loco-crawler-variable-speed

/hh-32-observation-crawler
HH 4 年前
当前提交
2080c287
共有 153 个文件被更改,包括 7443 次插入6886 次删除
  1. 20
      .circleci/config.yml
  2. 6
      .pre-commit-config.yaml
  3. 11
      DevProject/Assets/ML-Agents/Scripts/Tests/Performance/SensorPerformanceTests.cs
  4. 2
      Project/Assets/ML-Agents/Editor/DisableBurstFromMenu.cs
  5. 16
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  6. 9
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs
  7. 506
      Project/Assets/ML-Agents/Examples/3DBall/TFModels/3DBall.nn
  8. 566
      Project/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHard.nn
  9. 9
      Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs
  10. 19
      Project/Assets/ML-Agents/Examples/Basic/TFModels/Basic.nn
  11. 30
      Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
  12. 156
      Project/Assets/ML-Agents/Examples/Bouncer/TFModels/Bouncer.nn
  13. 34
      Project/Assets/ML-Agents/Examples/Crawler/Scripts/CrawlerAgent.cs
  14. 1001
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn
  15. 1001
      Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn
  16. 29
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  17. 2
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs
  18. 642
      Project/Assets/ML-Agents/Examples/FoodCollector/TFModels/FoodCollector.nn
  19. 31
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  20. 1000
      Project/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.nn
  21. 23
      Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs
  22. 992
      Project/Assets/ML-Agents/Examples/Hallway/TFModels/Hallway.nn
  23. 23
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
  24. 1000
      Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlock.nn
  25. 23
      Project/Assets/ML-Agents/Examples/Pyramids/Scripts/PyramidAgent.cs
  26. 997
      Project/Assets/ML-Agents/Examples/Pyramids/TFModels/Pyramids.nn
  27. 12
      Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs
  28. 549
      Project/Assets/ML-Agents/Examples/Reacher/TFModels/Reacher.nn
  29. 2
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AdjustTrainingTimescale.cs
  30. 4
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/DirectionIndicator.cs
  31. 14
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/JointDriveController.cs
  32. 20
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  33. 6
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Monitor.cs
  34. 2
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/OrientationCubeController.cs
  35. 2
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs
  36. 2
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/SensorBase.cs
  37. 8
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/TargetController.cs
  38. 31
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  39. 1001
      Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos.nn
  40. 6
      Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs
  41. 4
      Project/Assets/ML-Agents/Examples/Template/Scripts/TemplateAgent.cs
  42. 14
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs
  43. 20
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  44. 57
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
  45. 31
      Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
  46. 1001
      Project/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJump.nn
  47. 1001
      Project/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJump.nn
  48. 46
      Project/Assets/ML-Agents/Examples/Worm/Prefabs/PlatformWormDynamicTarget.prefab
  49. 29
      Project/Assets/ML-Agents/Examples/Worm/Scripts/WormAgent.cs
  50. 1001
      Project/Assets/ML-Agents/Examples/Worm/TFModels/WormDynamic.nn
  51. 1001
      Project/Assets/ML-Agents/Examples/Worm/TFModels/WormStatic.nn
  52. 5
      README.md
  53. 2
      com.unity.ml-agents.extensions/Runtime/Sensors/ArticulationBodyJointExtractor.cs
  54. 2
      com.unity.ml-agents.extensions/Runtime/Sensors/ArticulationBodyPoseExtractor.cs
  55. 2
      com.unity.ml-agents.extensions/Runtime/Sensors/ArticulationBodySensorComponent.cs
  56. 4
      com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsBodySensor.cs
  57. 4
      com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsSensorSettings.cs
  58. 10
      com.unity.ml-agents.extensions/Runtime/Sensors/PoseExtractor.cs
  59. 2
      com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodyJointExtractor.cs
  60. 4
      com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodyPoseExtractor.cs
  61. 4
      com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodySensorComponent.cs
  62. 2
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ArticulationBodyPoseExtractorTests.cs
  63. 2
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/ArticulationBodySensorTests.cs
  64. 10
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/PoseExtractorTests.cs
  65. 2
      com.unity.ml-agents.extensions/Tests/Editor/Sensors/RigidBodyPoseExtractorTests.cs
  66. 3
      com.unity.ml-agents.extensions/Tests/Runtime/RuntimeExampleTest.cs
  67. 16
      com.unity.ml-agents/CHANGELOG.md
  68. 7
      com.unity.ml-agents/CONTRIBUTING.md
  69. 2
      com.unity.ml-agents/Documentation~/com.unity.ml-agents.md
  70. 2
      com.unity.ml-agents/Editor/DemonstrationImporter.cs
  71. 20
      com.unity.ml-agents/Runtime/Academy.cs
  72. 3
      com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs
  73. 2
      com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
  74. 17
      com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
  75. 6
      com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
  76. 2
      com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
  77. 38
      com.unity.ml-agents/Runtime/Agent.cs
  78. 4
      com.unity.ml-agents/Runtime/Agent.deprecated.cs
  79. 6
      com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
  80. 36
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  81. 2
      com.unity.ml-agents/Runtime/Communicator/UnityRLCapabilities.cs
  82. 2
      com.unity.ml-agents/Runtime/Demonstrations/DemonstrationRecorder.cs
  83. 2
      com.unity.ml-agents/Runtime/DiscreteActionMasker.cs
  84. 20
      com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
  85. 2
      com.unity.ml-agents/Runtime/Policies/BrainParameters.cs
  86. 2
      com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
  87. 14
      com.unity.ml-agents/Runtime/Sampler.cs
  88. 4
      com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs
  89. 14
      com.unity.ml-agents/Runtime/Sensors/CameraSensorComponent.cs
  90. 2
      com.unity.ml-agents/Runtime/Sensors/ObservationWriter.cs
  91. 4
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs
  92. 2
      com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensorComponentBase.cs
  93. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/BoolReflectionSensor.cs
  94. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/FloatReflectionSensor.cs
  95. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/IntReflectionSensor.cs
  96. 10
      com.unity.ml-agents/Runtime/Sensors/Reflection/ObservableAttribute.cs
  97. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/QuaternionReflectionSensor.cs
  98. 6
      com.unity.ml-agents/Runtime/Sensors/Reflection/ReflectionSensorBase.cs
  99. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/Vector2ReflectionSensor.cs
  100. 2
      com.unity.ml-agents/Runtime/Sensors/Reflection/Vector3ReflectionSensor.cs

20
.circleci/config.yml


. venv/bin/activate
mkdir test-reports
pip freeze > test-reports/pip_versions.txt
pytest -n 2 --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=test-reports/junit.xml -p no:warnings
pytest --cov=ml-agents --cov=ml-agents-envs --cov=gym-unity --cov-report html --junitxml=test-reports/junit.xml -p no:warnings
- run:
name: Verify there are no hidden/missing metafiles.

# Need ruby for search-and-replace
sudo apt-get update
sudo apt-get install ruby-full
# install dotnet and the formatter - see https://docs.microsoft.com/en-us/dotnet/core/install/linux-debian#debian-9-
pushd ~
wget -O - https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
wget https://packages.microsoft.com/config/debian/9/prod.list
sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg
sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list
popd
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1 && \
dotnet tool install -g dotnet-format --version 4.1.131201
echo "Setting up venv"
python3 -m venv venv
. venv/bin/activate
pip install --upgrade pip

name: Check Code Style using pre-commit
command: |
. venv/bin/activate
export PATH="$PATH:~/.dotnet/tools"
pre-commit run --show-diff-on-failure --all-files
markdown_link_check:

6
.pre-commit-config.yaml


name: validate release links
language: script
entry: utils/validate_release_links.py
- id: dotnet-format
name: dotnet-format
language: script
entry: utils/run_dotnet_format.py
types: [c#]

11
DevProject/Assets/ML-Agents/Scripts/Tests/Performance/SensorPerformanceTests.cs


using NUnit.Framework;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Sensors.Reflection;

{
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
{
}
}

sensor.AddObservation(new Quaternion(1, 2, 3, 4));
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
{
}
}

[Observable]
public Quaternion QuaternionField = new Quaternion(1, 2, 3, 4);
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
{
}
}

get { return m_QuaternionField; }
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
{
}
}

{
using (Measure.ProfilerMarkers(s_Markers))
{
for(var i=0; i<k_MarkerTestSteps; i++)
for (var i = 0; i < k_MarkerTestSteps; i++)
{
RunAgent<CollectObservationsAgent>(k_NumAgentSteps, 7, ObservableAttributeOptions.Ignore);
}

2
Project/Assets/ML-Agents/Editor/DisableBurstFromMenu.cs


#if UNITY_CLOUD_BUILD
#if UNITY_CLOUD_BUILD
using UnityEditor;
public class DisableBurstFromMenu

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


using System;
using Unity.MLAgents.Actuators;
using Random = UnityEngine.Random;
public class Ball3DAgent : Agent
{

sensor.AddObservation(m_BallRb.velocity);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
var actionZ = 2f * Mathf.Clamp(actionBuffers.ContinuousActions[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(actionBuffers.ContinuousActions[1], -1f, 1f);
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))

SetResetParameters();
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = -Input.GetAxis("Horizontal");
actionsOut[1] = Input.GetAxis("Vertical");
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = -Input.GetAxis("Horizontal");
continuousActionsOut[1] = Input.GetAxis("Vertical");
}
public void SetBall()

9
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class Ball3DHardAgent : Agent

sensor.AddObservation((ball.transform.position - gameObject.transform.position));
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(vectorAction[1], -1f, 1f);
var continuousActions = actionBuffers.ContinuousActions;
var actionZ = 2f * Mathf.Clamp(continuousActions[0], -1f, 1f);
var actionX = 2f * Mathf.Clamp(continuousActions[1], -1f, 1f);
if ((gameObject.transform.rotation.z < 0.25f && actionZ > 0f) ||
(gameObject.transform.rotation.z > -0.25f && actionZ < 0f))

506
Project/Assets/ML-Agents/Examples/3DBall/TFModels/3DBall.nn
文件差异内容过多而无法显示
查看文件

566
Project/Assets/ML-Agents/Examples/3DBall/TFModels/3DBallHard.nn
文件差异内容过多而无法显示
查看文件

9
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>

/// Controls the movement of the GameObject based on the actions received.
/// </summary>
/// <param name="vectorAction"></param>
public void ApplyAction(float[] vectorAction)
public void ApplyAction(ActionSegment<int> vectorAction)
var movement = (int)vectorAction[0];
var movement = vectorAction[0];
var direction = 0;

if (Academy.Instance.IsCommunicatorOn)
{
// Apply the previous step's actions
ApplyAction(m_Agent.GetAction());
ApplyAction(m_Agent.GetStoredActionBuffers().DiscreteActions);
m_Agent?.RequestDecision();
}
else

// Apply the previous step's actions
ApplyAction(m_Agent.GetAction());
ApplyAction(m_Agent.GetStoredActionBuffers().DiscreteActions);
m_TimeSinceDecision = 0f;
m_Agent?.RequestDecision();

19
Project/Assets/ML-Agents/Examples/Basic/TFModels/Basic.nn


vector_observation���� action_masks����policy_1/concat_2/concatactionaction_output_shape������?
action_output_shape memory_sizeversion_numbertrainer_patch_versiontrainer_minor_versiontrainer_major_versionis_continuous_controlpolicy_1/add_2/ypolicy_1/Sum/reduction_indicespolicy_1/add/y $policy/main_graph_0/hidden_0/BiasAdd�����?vector_observation#policy/main_graph_0/hidden_0/kernel
�!policy/main_graph_0/hidden_0/bias� policy/main_graph_0/hidden_0/Mul2 �����?$policy/main_graph_0/hidden_0/BiasAddpolicy_1/dense/MatMul�����? policy/main_graph_0/hidden_0/Mulpolicy/dense/kernel�<policy_1/dense/MatMul/patch:0�policy_1/strided_slice������? action_maskspolicy_1/Softmax2�����?policy_1/dense/MatMul policy_1/addd�����?policy_1/Softmaxpolicy_1/add/y policy_1/Mulf�����? policy_1/addpolicy_1/strided_slice policy_1/Sum������? policy_1/Mulpolicy_1/Sum/reduction_indicespolicy_1/truedivg�����? policy_1/Mul policy_1/Sumpolicy_1/add_2d�����?policy_1/truedivpolicy_1/add_2/ypolicy_1/Log_12r�����?policy_1/add_2policy_1/concat_2/concat2�����?policy_1/Log_1action2�����?policy_1/concat_2/concat@@@�A���3�?���3��ƽl >_jX=�P��
��z�>����0>�����K�>s�>��Y>&�j>�M�����=,�����"����>�P�����>�ɹ<����8��c�==�����:)�y�x�>|\-<���xdO���"����{?=���=[�1>�l>>_����->�8���8��ž= �m>M�/>����H� =/��Nh���b_�4��>�]�܌<��>�Ӥ>�E��D>�T=�zO�����A�;Qd���Ͼ�{|��D;>Z�`�/�aV���o�>TJ�=Sa��xİ�5!)>�8�=� 侥Z�='�.�O�<��5n�A��|�=�����#��jfs>1x=��<)���g����K�>>z>���>���=�< Lb���>�ݘ>X=C=^JѾ��վ*�>�L�>�����`��%T�(Qz��'�>��k�����C�|>0�D�S:3<̋�>�D^=K8�Y^�>kX����f=b�=�׍�J9�=������=t:��
q�>�h`� �>�J��F��4.�� ��[@�;��+>}=��m>�В<xxW��ᔾ+�Q���>��=���>���>E�=��j�>�a�<����Ə<���u��� ,��FF��VG��� T�m^���&<�+g=Z ^>��u��>tFy>�f�=/{M>� ���վv��x���n)�=9�A>s�J���@>*� ��:�>��>A��P���q�>qI=�Z���H���l���e>��[>O�þ��:�G����(�)��>���>����G�����>��^=
�?�ٻ&��B�$>AW5>�٧���?s�=�E�>č�>�-/<��¾�{��#!O��u0>z�<>���>��=+� �r|�kV�fo�>��=F@Z>�j=V �> �6b��U�6='�?sզ��2�;M4��@�C>��?�-? �=x/>��ؾ�g5=c��=�v����c>$Bi>m�����I>ؖ��ou<=�o��cb����ؽ�m�EQ�S�K=�7�=�[��Q�>/*��7��>�j��#|>D�����|��=���W���� �>���=M�6=�W�>�<�>��=����>(���o��>U)�>���>�����-��2�>F>�<ؾ[�7?*��>��E>>1?i��>S�>�# ?� ?���>uTJ�W#�>+Y澷&)?�D?��L?���x���d��>��>:'�>�u?� ?r_�>�9@?j����>��>���Z �=��7��Ϟ�@�d�v>�>9O�>��z>H���ᝡ���p=��=J��>��?i(�>8���>%>��%��樾9���n����r>6^->�Х=Ng>�r>�ad>,{����>1��<1����!>ev�Z �=+-�� ���A����<��:>�1f�{J���c=��!� ���]3>�]R�+��<��C>DY0�
Ty=��)��R�>C�>�[�= ޽mU�>?��=�(��:��λ�&.{=��f��3/��kK��\�=W�ʻ1��>�����4�=k�)������ ��=P�#���,���A�sJ,��ՙ>�kY�>����ܼ~I>%�S���ս�k� վW�g>�f>
ƙ����l��..R>��ʽ�k�=�=����a�P��IO?��I?�C?��F?t�B?;.�CM?o(��I?o�F?VGD?h�(����SH?�{H?��>��D?�G?�A?E7F?7���"Ǿk0/?W ��ž�-,?X��� k���!?ߥ߾�����,?Ӿ �⾡�?�T?�.�>��"��N�Y�˾5n0?�?�>*��> %��P��� ��>.?�l�b�����?���� " ��L-?�H�>x?L"�n��>%~�>�g'��X ����^�??��<�ݾ��+?LD!<.V<��,������Q"?,�|� ���,?G��������?���G��W�-?
action_output_shape memory_sizeversion_numbertrainer_patch_versiontrainer_minor_versiontrainer_major_versionis_continuous_controlpolicy_1/add/ypolicy_1/add_2/ypolicy_1/Sum/reduction_indices $policy/main_graph_0/hidden_0/BiasAdd�����?vector_observation#policy/main_graph_0/hidden_0/kernel
�!policy/main_graph_0/hidden_0/bias� policy/main_graph_0/hidden_0/Mul2 �����?$policy/main_graph_0/hidden_0/BiasAddpolicy_1/dense/MatMul�����? policy/main_graph_0/hidden_0/Mulpolicy/dense/kernel�<policy_1/dense/MatMul/patch:0�policy_1/strided_slice������? action_maskspolicy_1/Softmax2�����?policy_1/dense/MatMul policy_1/addd�����?policy_1/Softmaxpolicy_1/add/y policy_1/Mulf�����? policy_1/addpolicy_1/strided_slice policy_1/Sum������? policy_1/Mulpolicy_1/Sum/reduction_indicespolicy_1/truedivg�����? policy_1/Mul policy_1/Sumpolicy_1/add_2d�����?policy_1/truedivpolicy_1/add_2/ypolicy_1/Log_12r�����?policy_1/add_2policy_1/concat_2/concat2�����?policy_1/Log_1action2�����?policy_1/concat_2/concat@@@�A���3���3�? ��>�����=;���
�>�e����U>X��=t`��_�>���>*p\>�}�=���=\�?=�f�=a�E�nڙ=E�\�!ü�1�#�n=_ ��NJ�����>Ҍ�<��=��=��'=��Ͼ�&>*��D4�>S}}>_WV>��>�jj>(�f>� >��B>��<
�&>�,>�����\(��ޤ���a��G?>C�>�e,>��C�2D)>ڦ�=�!>YI>��=Pd���F������܎>����{A>P��=����j�?>�R�n�=�Z����\��>`��)= M��[�s�'�@��ܦ�ډ��m����
˾��]��=�;�">]|�>���=��#> RT�}Q>e�O��|���|>�g�>:�>9ke�3V'>/�1�X�v��>�PDJ��>����B=�_n=bW���>��>,���#�H�
$_�:�}�NƔ>Nf�>z���am��_�>}��>�D�ƺ`>ш�=;��=1k����>��>d�þ#�
���>�
�=����[�=�D>��"�=������>� >%�2�Po��}Ȝ�Ƙ� >�8�> �Ҿ��2>���>��y�
�>J��m#����<�V�> �e��X���p_>�X/�� >��=,�b>1�=�*>� ��+����9�>�}ѽ�l>�ϲ= �R��ܥ.>��ʽۈǽ�GD�,��t��Ο�;
H/>S41����5�=������)>z���$��>�����a�=��%>@�,�3{�>�ܳ�v{½Wl:>�N=�fƽ}�ľ�V�����w���+�+<�ǹ��7�����=,��œH��a��?%���=��7?OD?�#s>F�>.k?0�>QƝ>��(����?j�վ�R�><��=�0��Pv�=�Vu��� =ũ�>�� <���F7;��ǔ>� >@ӑ=��B� `�>�x���>�GN>K��=z�X;�+<<
��=���=<���c�M���2�U ?�ر�W�9>1�?#�H>jP>8�|>��K>�?>:E>W����@ň��{��:��>���=0;�>�� ?� ���,���>�>|�e�0��?J�7?i�"?���=�#>>�?�. ?�Ծ�p&�� '?�׾�]r?z�?v!�x u?������ �~��=���B����C?�Y?'?U��>�<�>�d:>�6!?%�о�%�W�T<s�<�9�>�,?#����=��+�X��$�c?��2�7!2�_/<?/�e?���>(/9?���>�VK?�L�>{����z�=�&?*��kl�?���?��ݾ�J?1��u����H?5Ƀ�ڽ����?W��>�\.?�AC?���>J�K?��'?9f��s�����>�(7>���>��>�;�Rp?�(.>e:v<�Ҩ�����&º>W�׼ ��>���>���&�X�>����I3����=�b$�兢��nC�0�=����l�y�ԼAΠ>d�_>��Һ� �j�𾚆�>�c��i�)>�Aw> ����¿>���>vft���>�/3>�� =�g;���s�Ř>�*=��->�[�<� ���K�=��> {���½�K�:5�m����� �^��M�p�> �i>p��=}�{�\�=ut��1> ��) ���;?I��é�� @?SG?�:?Bm5?��=?�+;?Uu@?@|��I#��iC?7? �J�:?��<?����->?2
�>���>rT�iK�>�_�>��������/���] ?A�?�>�O�2�> �>n������d�c)?{ ����^�5?L1��S ���?�w��q�޾ص?������վ��?s\׾y���n%?�9Ͼ�;��f!?a��>& �>���u\�>���>���8�� � ���$?�b�> q>�Ծi}�:����(?�����q�8&? �>���>l�����9�����!?

30
Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class BouncerAgent : Agent

sensor.AddObservation(target.transform.localPosition);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
for (var i = 0; i < vectorAction.Length; i++)
var continuousActions = actionBuffers.ContinuousActions;
for (var i = 0; i < continuousActions.Length; i++)
vectorAction[i] = Mathf.Clamp(vectorAction[i], -1f, 1f);
continuousActions[i] = Mathf.Clamp(continuousActions[i], -1f, 1f);
var x = vectorAction[0];
var y = ScaleAction(vectorAction[1], 0, 1);
var z = vectorAction[2];
var x = continuousActions[0];
var y = ScaleAction(continuousActions[1], 0, 1);
var z = continuousActions[2];
vectorAction[0] * vectorAction[0] +
vectorAction[1] * vectorAction[1] +
vectorAction[2] * vectorAction[2]) / 3f);
continuousActions[0] * continuousActions[0] +
continuousActions[1] * continuousActions[1] +
continuousActions[2] * continuousActions[2]) / 3f);
m_LookDir = new Vector3(x, y, z);
}

}
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = Input.GetAxis("Horizontal");
actionsOut[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
actionsOut[2] = Input.GetAxis("Vertical");
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = Input.GetAxis("Horizontal");
continuousActionsOut[1] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
continuousActionsOut[2] = Input.GetAxis("Vertical");
}
void Update()

156
Project/Assets/ML-Agents/Examples/Bouncer/TFModels/Bouncer.nn
文件差异内容过多而无法显示
查看文件

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


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
using Random = UnityEngine.Random;

// The dictionary with all the body parts in it are in the jdController
var bpDict = m_JdController.bodyPartsDict;
var continuousActions = actionBuffers.ContinuousActions;
bpDict[leg0Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[leg1Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[leg2Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[leg3Upper].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[leg0Lower].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[leg1Lower].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[leg2Lower].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[leg3Lower].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[leg0Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg1Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg2Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg3Upper].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[leg0Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg1Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg2Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg3Lower].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[leg0Upper].SetJointStrength(vectorAction[++i]);
bpDict[leg1Upper].SetJointStrength(vectorAction[++i]);
bpDict[leg2Upper].SetJointStrength(vectorAction[++i]);
bpDict[leg3Upper].SetJointStrength(vectorAction[++i]);
bpDict[leg0Lower].SetJointStrength(vectorAction[++i]);
bpDict[leg1Lower].SetJointStrength(vectorAction[++i]);
bpDict[leg2Lower].SetJointStrength(vectorAction[++i]);
bpDict[leg3Lower].SetJointStrength(vectorAction[++i]);
bpDict[leg0Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg1Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg2Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg3Upper].SetJointStrength(continuousActions[++i]);
bpDict[leg0Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg1Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg2Lower].SetJointStrength(continuousActions[++i]);
bpDict[leg3Lower].SetJointStrength(continuousActions[++i]);
}
void FixedUpdate()

1001
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerDynamic.nn
文件差异内容过多而无法显示
查看文件

1001
Project/Assets/ML-Agents/Examples/Crawler/TFModels/CrawlerStatic.nn
文件差异内容过多而无法显示
查看文件

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


using System;
using Unity.MLAgents.Actuators;
using Random = UnityEngine.Random;
public class FoodCollectorAgent : Agent
{

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

gameObject.GetComponentInChildren<Renderer>().material = normalMaterial;
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = 0f;
actionsOut[1] = 0f;
actionsOut[2] = 0f;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
discreteActionsOut[1] = 0;
discreteActionsOut[2] = 0;
actionsOut[2] = 2f;
discreteActionsOut[2] = 2;
actionsOut[0] = 1f;
discreteActionsOut[0] = 1;
actionsOut[2] = 1f;
discreteActionsOut[2] = 1;
actionsOut[0] = 2f;
discreteActionsOut[0] = 2;
actionsOut[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
discreteActionsOut[3] = Input.GetKey(KeyCode.Space) ? 1 : 0;
}
public override void OnEpisodeBegin()

2
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs


// Send stats via SideChannel so that they'll appear in TensorBoard.
// These values get averaged every summary_frequency steps, so we don't
// need to send every Update() call.
if ((Time.frameCount % 100)== 0)
if ((Time.frameCount % 100) == 0)
{
m_Recorder.Add("TotalScore", totalScore);
}

642
Project/Assets/ML-Agents/Examples/FoodCollector/TFModels/FoodCollector.nn
文件差异内容过多而无法显示
查看文件

31
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


using UnityEngine;
using System.Linq;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using UnityEngine.Serialization;
public class GridAgent : Agent

m_ResetParams = Academy.Instance.EnvironmentParameters;
}
public override void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker)
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
// Prevents the agent from picking an action that would make it collide with a wall
// Prevents the agent from picking an action that would make it collide with a wall
var positionX = (int)transform.position.x;
var positionZ = (int)transform.position.z;
var maxPosition = (int)m_ResetParams.GetWithDefault("gridSize", 5f) - 1;

actionMasker.SetMask(0, new []{ k_Left});
actionMask.WriteMask(0, new[] { k_Left });
actionMasker.SetMask(0, new []{k_Right});
actionMask.WriteMask(0, new[] { k_Right });
actionMasker.SetMask(0, new []{k_Down});
actionMask.WriteMask(0, new[] { k_Down });
actionMasker.SetMask(0, new []{k_Up});
actionMask.WriteMask(0, new[] { k_Up });
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var action = Mathf.FloorToInt(vectorAction[0]);
var action = actionBuffers.DiscreteActions[0];
var targetPos = transform.position;
switch (action)

}
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = k_NoAction;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = k_NoAction;
actionsOut[0] = k_Right;
discreteActionsOut[0] = k_Right;
actionsOut[0] = k_Up;
discreteActionsOut[0] = k_Up;
actionsOut[0] = k_Left;
discreteActionsOut[0] = k_Left;
actionsOut[0] = k_Down;
discreteActionsOut[0] = k_Down;
}
}

1000
Project/Assets/ML-Agents/Examples/GridWorld/TFModels/GridWorld.nn
文件差异内容过多而无法显示
查看文件

23
Project/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs


using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class HallwayAgent : Agent

m_GroundRenderer.material = m_GroundMaterial;
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionSegment<int> act)
var action = Mathf.FloorToInt(act[0]);
var action = act[0];
switch (action)
{
case 1:

m_AgentRb.AddForce(dirToGo * m_HallwaySettings.agentRunSpeed, ForceMode.VelocityChange);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
}
void OnCollisionEnter(Collision col)

}
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = 0;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
actionsOut[0] = 3;
discreteActionsOut[0] = 3;
actionsOut[0] = 1;
discreteActionsOut[0] = 1;
actionsOut[0] = 4;
discreteActionsOut[0] = 4;
actionsOut[0] = 2;
discreteActionsOut[0] = 2;
}
}

992
Project/Assets/ML-Agents/Examples/Hallway/TFModels/Hallway.nn
文件差异内容过多而无法显示
查看文件

23
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs


using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
public class PushAgentBasic : Agent
{

/// <summary>
/// Moves the agent according to the selected action.
/// </summary>
public void MoveAgent(float[] act)
public void MoveAgent(ActionSegment<int> act)
var action = Mathf.FloorToInt(act[0]);
var action = act[0];
switch (action)
{

/// <summary>
/// Called every step of the engine. Here the agent takes an action.
/// </summary>
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = 0;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
actionsOut[0] = 3;
discreteActionsOut[0] = 3;
actionsOut[0] = 1;
discreteActionsOut[0] = 1;
actionsOut[0] = 4;
discreteActionsOut[0] = 4;
actionsOut[0] = 2;
discreteActionsOut[0] = 2;
}
}

1000
Project/Assets/ML-Agents/Examples/PushBlock/TFModels/PushBlock.nn
文件差异内容过多而无法显示
查看文件

23
Project/Assets/ML-Agents/Examples/Pyramids/Scripts/PyramidAgent.cs


using UnityEngine;
using Random = UnityEngine.Random;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class PyramidAgent : Agent

}
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionSegment<int> act)
var action = Mathf.FloorToInt(act[0]);
var action = act[0];
switch (action)
{
case 1:

m_AgentRb.AddForce(dirToGo * 2f, ForceMode.VelocityChange);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = 0;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
actionsOut[0] = 3;
discreteActionsOut[0] = 3;
actionsOut[0] = 1;
discreteActionsOut[0] = 1;
actionsOut[0] = 4;
discreteActionsOut[0] = 4;
actionsOut[0] = 2;
discreteActionsOut[0] = 2;
}
}

997
Project/Assets/ML-Agents/Examples/Pyramids/TFModels/Pyramids.nn
文件差异内容过多而无法显示
查看文件

12
Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class ReacherAgent : Agent

/// <summary>
/// The agent's four actions correspond to torques on each of the two joints.
/// </summary>
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var torqueX = Mathf.Clamp(vectorAction[0], -1f, 1f) * 150f;
var torqueZ = Mathf.Clamp(vectorAction[1], -1f, 1f) * 150f;
var torqueX = Mathf.Clamp(actionBuffers.ContinuousActions[0], -1f, 1f) * 150f;
var torqueZ = Mathf.Clamp(actionBuffers.ContinuousActions[1], -1f, 1f) * 150f;
torqueX = Mathf.Clamp(vectorAction[2], -1f, 1f) * 150f;
torqueZ = Mathf.Clamp(vectorAction[3], -1f, 1f) * 150f;
torqueX = Mathf.Clamp(actionBuffers.ContinuousActions[2], -1f, 1f) * 150f;
torqueZ = Mathf.Clamp(actionBuffers.ContinuousActions[3], -1f, 1f) * 150f;
m_RbB.AddTorque(new Vector3(torqueX, 0f, torqueZ));
}

549
Project/Assets/ML-Agents/Examples/Reacher/TFModels/Reacher.nn
文件差异内容过多而无法显示
查看文件

2
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/AdjustTrainingTimescale.cs


using UnityEngine;
namespace MLAgentsExamples
namespace MLAgentsExamples
{
public class AdjustTrainingTimescale : MonoBehaviour
{

4
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/DirectionIndicator.cs


using UnityEngine;
using UnityEngine;
public bool updatedByAgent; //should this be updated by the agent? If not, it will use local settings
public Transform transformToFollow; //ex: hips or body
public Transform targetToLookAt; //target in the scene the indicator will point to

14
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/JointDriveController.cs


[System.Serializable]
public class BodyPart
{
[Header("Body Part Info")][Space(10)] public ConfigurableJoint joint;
[Header("Body Part Info")] [Space(10)] public ConfigurableJoint joint;
[Header("Ground & Target Contact")][Space(10)]
[Header("Ground & Target Contact")]
[Space(10)]
public GroundContact groundContact;
public TargetContact targetContact;

[Header("Current Joint Settings")][Space(10)]
[Header("Current Joint Settings")]
[Space(10)]
public Vector3 currentEularJointRotation;
[HideInInspector] public float currentStrength;

[Header("Other Debug Info")][Space(10)]
[Header("Other Debug Info")]
[Space(10)]
public Vector3 currentJointForce;
public float currentJointForceSqrMag;

public class JointDriveController : MonoBehaviour
{
[Header("Joint Drive Settings")][Space(10)]
[Header("Joint Drive Settings")]
[Space(10)]
public float maxJointSpring;
public float jointDampen;

20
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


/// </summary>
public class ModelOverrider : MonoBehaviour
{
HashSet<string> k_SupportedExtensions = new HashSet<string>{"nn", "onnx"};
HashSet<string> k_SupportedExtensions = new HashSet<string> { "nn", "onnx" };
const string k_CommandLineModelOverrideFlag = "--mlagents-override-model";
const string k_CommandLineModelOverrideDirectoryFlag = "--mlagents-override-model-directory";
const string k_CommandLineModelOverrideExtensionFlag = "--mlagents-override-model-extension";

int TotalCompletedEpisodes
{
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
get { return m_PreviousAgentCompletedEpisodes + (m_Agent == null ? 0 : m_Agent.CompletedEpisodes); }
}
int TotalNumSteps

public bool HasOverrides
{
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
get { return m_BehaviorNameOverrides.Count > 0 || !string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory); }
}
public static string GetOverrideBehaviorName(string originalBehaviorName)

var args = commandLineArgsOverride ?? Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length; i++)
{
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length-2)
if (args[i] == k_CommandLineModelOverrideFlag && i < args.Length - 2)
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length-1)
else if (args[i] == k_CommandLineModelOverrideDirectoryFlag && i < args.Length - 1)
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length-1)
else if (args[i] == k_CommandLineModelOverrideExtensionFlag && i < args.Length - 1)
{
m_OverrideExtension = args[i + 1].Trim().ToLower();
var isKnownExtension = k_SupportedExtensions.Contains(m_OverrideExtension);

#endif
}
}
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length-1)
else if (args[i] == k_CommandLineQuitAfterEpisodesFlag && i < args.Length - 1)
{
Int32.TryParse(args[i + 1], out maxEpisodes);
}

{
assetPath = m_BehaviorNameOverrides[behaviorName];
}
else if(!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
else if (!string.IsNullOrEmpty(m_BehaviorNameOverrideDirectory))
{
assetPath = Path.Combine(m_BehaviorNameOverrideDirectory, $"{behaviorName}.{m_OverrideExtension}");
}

{
model = File.ReadAllBytes(assetPath);
}
catch(IOException)
catch (IOException)
{
Debug.Log($"Couldn't load file {assetPath} at full path {Path.GetFullPath(assetPath)}", this);
// Cache the null so we don't repeatedly try to load a missing file

if (!overrideOk && m_QuitOnLoadFailure)
{
if(!string.IsNullOrEmpty(overrideError))
if (!string.IsNullOrEmpty(overrideError))
{
Debug.LogWarning(overrideError);
}

6
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Monitor.cs


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

var displayValues = s_DisplayTransformValues[target];
var index = 0;
var orderedKeys = displayValues.Keys.OrderBy(x => - displayValues[x].time);
var orderedKeys = displayValues.Keys.OrderBy(x => -displayValues[x].time);
foreach (var key in orderedKeys)
{
s_KeyStyle.alignment = TextAnchor.MiddleRight;

s_RedStyle = s_ColorStyle[5];
}
}
}
}

2
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/OrientationCubeController.cs


using UnityEngine;
using UnityEngine;
namespace Unity.MLAgentsExamples
{

2
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs


m_OriginalMaximumDeltaTime = Time.maximumDeltaTime;
m_OriginalSolverIterations = Physics.defaultSolverIterations;
m_OriginalSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks ;
m_OriginalReuseCollisionCallbacks = Physics.reuseCollisionCallbacks;
// Override
Physics.gravity *= gravityMultiplier;

2
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/SensorBase.cs


}
/// <inheritdoc/>
public void Update() {}
public void Update() { }
/// <inheritdoc/>
public void Reset() { }

8
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/TargetController.cs


using UnityEngine;
using UnityEngine;
using Random = UnityEngine.Random;
using Unity.MLAgents;
using UnityEngine.Events;

/// </summary>
public class TargetController : MonoBehaviour
{
[Header("Target Fell Protection")]
public bool respawnIfFallsOffPlatform = true; //If the target falls off the platform, reset the position.
public float fallDistance = 5; //distance below the starting height that will trigger a respawn

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


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
public class AgentSoccer : Agent

m_ResetParams = Academy.Instance.EnvironmentParameters;
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionSegment<int> act)
{
var dirToGo = Vector3.zero;
var rotateDir = Vector3.zero;

var forwardAxis = (int)act[0];
var rightAxis = (int)act[1];
var rotateAxis = (int)act[2];
var forwardAxis = act[0];
var rightAxis = act[1];
var rotateAxis = act[2];
switch (forwardAxis)
{

ForceMode.VelocityChange);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
{
if (position == Position.Goalie)

// Existential penalty cumulant for Generic
timePenalty -= m_Existential;
}
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
Array.Clear(actionsOut, 0, actionsOut.Length);
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut.Clear();
actionsOut[0] = 1f;
discreteActionsOut[0] = 1;
actionsOut[0] = 2f;
discreteActionsOut[0] = 2;
actionsOut[2] = 1f;
discreteActionsOut[2] = 1;
actionsOut[2] = 2f;
discreteActionsOut[2] = 2;
actionsOut[1] = 1f;
discreteActionsOut[1] = 1;
actionsOut[1] = 2f;
discreteActionsOut[1] = 2;
}
}
/// <summary>

1001
Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos.nn
文件差异内容过多而无法显示
查看文件

6
Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs


// no scene environment variable is found.
var args = Environment.GetCommandLineArgs();
Console.WriteLine("Command line arguments passed: " + String.Join(" ", args));
for (int i = 0; i < args.Length; i++) {
if (args [i] == k_SceneCommandLineFlag && i < args.Length - 1) {
for (int i = 0; i < args.Length; i++)
{
if (args[i] == k_SceneCommandLineFlag && i < args.Length - 1)
{
sceneName = args[i + 1];
}
}

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


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class TemplateAgent : Agent

}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
{
}

14
Project/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs


public bool net;
public enum FloorHit
{
Service,
FloorHitUnset,
FloorAHit,
FloorBHit
}
{
Service,
FloorHitUnset,
FloorAHit,
FloorBHit
}
public FloorHit lastFloorHit;

lastFloorHit = FloorHit.Service;
net = false;
}
void AgentAWins()
{
m_AgentA.SetReward(1);

20
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs


using UnityEngine;
using UnityEngine.UI;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class TennisAgent : Agent

sensor.AddObservation(m_InvertMult * gameObject.transform.rotation.z);
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var moveX = Mathf.Clamp(vectorAction[0], -1f, 1f) * m_InvertMult;
var moveY = Mathf.Clamp(vectorAction[1], -1f, 1f);
var rotate = Mathf.Clamp(vectorAction[2], -1f, 1f) * m_InvertMult;
var continuousActions = actionBuffers.ContinuousActions;
var moveX = Mathf.Clamp(continuousActions[0], -1f, 1f) * m_InvertMult;
var moveY = Mathf.Clamp(continuousActions[1], -1f, 1f);
var rotate = Mathf.Clamp(continuousActions[2], -1f, 1f) * m_InvertMult;
if (moveY > 0.5 && transform.position.y - transform.parent.transform.position.y < -1.5f)
{

m_TextComponent.text = score.ToString();
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
actionsOut[0] = Input.GetAxis("Horizontal"); // Racket Movement
actionsOut[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f; // Racket Jumping
actionsOut[2] = Input.GetAxis("Vertical"); // Racket Rotation
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = Input.GetAxis("Horizontal"); // Racket Movement
continuousActionsOut[1] = Input.GetKey(KeyCode.Space) ? 1f : 0f; // Racket Jumping
continuousActionsOut[2] = Input.GetAxis("Vertical"); // Racket Rotation
}
public override void OnEpisodeBegin()

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


using System;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
using BodyPart = Unity.MLAgentsExamples.BodyPart;

}
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
bpDict[chest].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[spine].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
var continuousActions = actionBuffers.ContinuousActions;
bpDict[chest].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], continuousActions[++i]);
bpDict[spine].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], continuousActions[++i]);
bpDict[thighL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[thighR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[shinL].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[shinR].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[footR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[footL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], vectorAction[++i]);
bpDict[thighL].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[thighR].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[shinL].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[shinR].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[footR].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], continuousActions[++i]);
bpDict[footL].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], continuousActions[++i]);
bpDict[armL].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[armR].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[forearmL].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[forearmR].SetJointTargetRotation(vectorAction[++i], 0, 0);
bpDict[head].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[armL].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[armR].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[forearmL].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[forearmR].SetJointTargetRotation(continuousActions[++i], 0, 0);
bpDict[head].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[chest].SetJointStrength(vectorAction[++i]);
bpDict[spine].SetJointStrength(vectorAction[++i]);
bpDict[head].SetJointStrength(vectorAction[++i]);
bpDict[thighL].SetJointStrength(vectorAction[++i]);
bpDict[shinL].SetJointStrength(vectorAction[++i]);
bpDict[footL].SetJointStrength(vectorAction[++i]);
bpDict[thighR].SetJointStrength(vectorAction[++i]);
bpDict[shinR].SetJointStrength(vectorAction[++i]);
bpDict[footR].SetJointStrength(vectorAction[++i]);
bpDict[armL].SetJointStrength(vectorAction[++i]);
bpDict[forearmL].SetJointStrength(vectorAction[++i]);
bpDict[armR].SetJointStrength(vectorAction[++i]);
bpDict[forearmR].SetJointStrength(vectorAction[++i]);
bpDict[chest].SetJointStrength(continuousActions[++i]);
bpDict[spine].SetJointStrength(continuousActions[++i]);
bpDict[head].SetJointStrength(continuousActions[++i]);
bpDict[thighL].SetJointStrength(continuousActions[++i]);
bpDict[shinL].SetJointStrength(continuousActions[++i]);
bpDict[footL].SetJointStrength(continuousActions[++i]);
bpDict[thighR].SetJointStrength(continuousActions[++i]);
bpDict[shinR].SetJointStrength(continuousActions[++i]);
bpDict[footR].SetJointStrength(continuousActions[++i]);
bpDict[armL].SetJointStrength(continuousActions[++i]);
bpDict[forearmL].SetJointStrength(continuousActions[++i]);
bpDict[armR].SetJointStrength(continuousActions[++i]);
bpDict[forearmR].SetJointStrength(continuousActions[++i]);
}
//Update OrientationCube and DirectionIndicator

31
Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs


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

m_GroundRenderer.material = m_GroundMaterial;
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionSegment<int> act)
{
AddReward(-0.0005f);
var smallGrounded = DoGroundCheck(true);

var rotateDir = Vector3.zero;
var dirToGoForwardAction = (int)act[0];
var rotateDirAction = (int)act[1];
var dirToGoSideAction = (int)act[2];
var jumpAction = (int)act[3];
var dirToGoForwardAction = act[0];
var rotateDirAction = act[1];
var dirToGoSideAction = act[2];
var jumpAction = act[3];
if (dirToGoForwardAction == 1)
dirToGo = (largeGrounded ? 1f : 0.5f) * 1f * transform.forward;

jumpingTime -= Time.fixedDeltaTime;
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers.DiscreteActions);
if ((!Physics.Raycast(m_AgentRb.position, Vector3.down, 20))
|| (!Physics.Raycast(m_ShortBlockRb.position, Vector3.down, 20)))
{

}
}
public override void Heuristic(float[] actionsOut)
public override void Heuristic(in ActionBuffers actionsOut)
System.Array.Clear(actionsOut, 0, actionsOut.Length);
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut.Clear();
actionsOut[1] = 2f;
discreteActionsOut[1] = 2;
actionsOut[0] = 1f;
discreteActionsOut[0] = 1;
actionsOut[1] = 1f;
discreteActionsOut[1] = 1;
actionsOut[0] = 2f;
discreteActionsOut[0] = 2;
actionsOut[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
discreteActionsOut[3] = Input.GetKey(KeyCode.Space) ? 1 : 0;
}
// Detect when the agent hits the goal

1001
Project/Assets/ML-Agents/Examples/WallJump/TFModels/BigWallJump.nn
文件差异内容过多而无法显示
查看文件

1001
Project/Assets/ML-Agents/Examples/WallJump/TFModels/SmallWallJump.nn
文件差异内容过多而无法显示
查看文件

46
Project/Assets/ML-Agents/Examples/Worm/Prefabs/PlatformWormDynamicTarget.prefab


m_Interpolate: 0
m_Constraints: 0
m_CollisionDetection: 0
--- !u!114 &8042564747579887
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7516457449653310668}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3c8f113a8b8d94967b1b1782c549be81, type: 3}
m_Name:
m_EditorClassIdentifier:
tagToDetect: agent
spawnRadius: 40
respawnIfTouched: 1
respawnIfFallsOffPlatform: 1
fallDistance: 5
onTriggerEnterEvent:
m_PersistentCalls:
m_Calls: []
onTriggerStayEvent:
m_PersistentCalls:
m_Calls: []
onTriggerExitEvent:
m_PersistentCalls:
m_Calls: []
onCollisionEnterEvent:
m_PersistentCalls:
m_Calls: []
onCollisionStayEvent:
m_PersistentCalls:
m_Calls: []
onCollisionExitEvent:
m_PersistentCalls:
m_Calls: []
--- !u!1001 &906401165941233076
PrefabInstance:
m_ObjectHideFlags: 0

propertyPath: ground
value:
objectReference: {fileID: 7519759559437056804}
- target: {fileID: 6060305997946326746, guid: 3ebcde4cf2d5c4c029e2a5ce3d853aba,
type: 3}
propertyPath: m_TagString
value: agent
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3ebcde4cf2d5c4c029e2a5ce3d853aba, type: 3}
--- !u!1001 &7202236613889278392

--- !u!4 &7519759559437056804 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 840186797462469276, guid: d6fc96a99a9754f07b48abf1e0d55a5c,
type: 3}
m_PrefabInstance: {fileID: 7202236613889278392}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7516457449653310668 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 845742365997159796, guid: d6fc96a99a9754f07b48abf1e0d55a5c,
type: 3}
m_PrefabInstance: {fileID: 7202236613889278392}
m_PrefabAsset: {fileID: 0}

29
Project/Assets/ML-Agents/Examples/Worm/Scripts/WormAgent.cs


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

public bool respawnTargetWhenTouched;
public float targetSpawnRadius;
[Header("Body Parts")] [Space(10)]
[Header("Body Parts")]
[Space(10)]
[Header("Joint Settings")] [Space(10)]
[Header("Joint Settings")]
[Space(10)]
JointDriveController m_JdController;
Vector3 m_DirToTarget;
float m_MovingTowardsDot;

//We want to collect this info because it is the actual rotation, not the "target rotation"
public Quaternion GetJointRotation(ConfigurableJoint joint)
{
return(Quaternion.FromToRotation(joint.axis, joint.connectedBody.transform.rotation.eulerAngles));
return (Quaternion.FromToRotation(joint.axis, joint.connectedBody.transform.rotation.eulerAngles));
}
/// <summary>

float maxDist = 10;
if (Physics.Raycast(bodySegment0.position, Vector3.down, out hit, maxDist))
{
sensor.AddObservation(hit.distance/maxDist);
sensor.AddObservation(hit.distance / maxDist);
}
else
sensor.AddObservation(1);

target.position = newTargetPos + ground.position;
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
var continuousActions = actionBuffers.ContinuousActions;
bpDict[bodySegment1].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[bodySegment2].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[bodySegment3].SetJointTargetRotation(vectorAction[++i], vectorAction[++i], 0);
bpDict[bodySegment1].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[bodySegment2].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[bodySegment3].SetJointTargetRotation(continuousActions[++i], continuousActions[++i], 0);
bpDict[bodySegment1].SetJointStrength(vectorAction[++i]);
bpDict[bodySegment2].SetJointStrength(vectorAction[++i]);
bpDict[bodySegment3].SetJointStrength(vectorAction[++i]);
bpDict[bodySegment1].SetJointStrength(continuousActions[++i]);
bpDict[bodySegment2].SetJointStrength(continuousActions[++i]);
bpDict[bodySegment3].SetJointStrength(continuousActions[++i]);
if (bodySegment0.position.y < ground.position.y -2)
if (bodySegment0.position.y < ground.position.y - 2)
{
EndEpisode();
}

1001
Project/Assets/ML-Agents/Examples/Worm/TFModels/WormDynamic.nn
文件差异内容过多而无法显示
查看文件

1001
Project/Assets/ML-Agents/Examples/Worm/TFModels/WormStatic.nn
文件差异内容过多而无法显示
查看文件

5
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_5_docs/docs/)
[![docs badge](https://img.shields.io/badge/docs-reference-blue.svg)](https://github.com/Unity-Technologies/ml-agents/tree/release_6_docs/docs/)
[![license badge](https://img.shields.io/badge/license-Apache--2.0-green.svg)](LICENSE)

## Releases & Documentation
**Our latest, stable release is `Release 5`. Click
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_5_docs/docs/Readme.md)
[here](https://github.com/Unity-Technologies/ml-agents/tree/release_6_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 6** | **August 12, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_6)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_6_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_6.zip)** |
| **Release 5** | **July 31, 2020** | **[source](https://github.com/Unity-Technologies/ml-agents/tree/release_5)** | **[docs](https://github.com/Unity-Technologies/ml-agents/tree/release_5_docs/docs/Readme.md)** | **[download](https://github.com/Unity-Technologies/ml-agents/archive/release_5.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) |
| **Release 3** | June 10, 2020 | [source](https://github.com/Unity-Technologies/ml-agents/tree/release_3) | [docs](https://github.com/Unity-Technologies/ml-agents/tree/release_3_docs/docs/Readme.md) | [download](https://github.com/Unity-Technologies/ml-agents/archive/release_3.zip) |

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


}
}
}
#endif
#endif

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


}
}
}
#endif // UNITY_2020_1_OR_NEWER
#endif // UNITY_2020_1_OR_NEWER

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


}
}
#endif // UNITY_2020_1_OR_NEWER
#endif // UNITY_2020_1_OR_NEWER

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


var numJointExtractorObservations = 0;
m_JointExtractors = new List<IJointExtractor>(poseExtractor.NumEnabledPoses);
foreach(var rb in poseExtractor.GetEnabledRigidbodies())
foreach (var rb in poseExtractor.GetEnabledRigidbodies())
{
var jointExtractor = new RigidBodyJointExtractor(rb);
numJointExtractorObservations += jointExtractor.NumObservations(settings);

}
/// <inheritdoc/>
public void Reset() {}
public void Reset() { }
/// <inheritdoc/>
public SensorCompressionType GetCompressionType()

4
com.unity.ml-agents.extensions/Runtime/Sensors/PhysicsSensorSettings.cs


}
}
foreach(var vel in poseExtractor.GetEnabledModelSpaceVelocities())
foreach (var vel in poseExtractor.GetEnabledModelSpaceVelocities())
{
if (settings.UseModelSpaceLinearVelocity)
{

}
}
foreach(var vel in poseExtractor.GetEnabledLocalSpaceVelocities())
foreach (var vel in poseExtractor.GetEnabledLocalSpaceVelocities())
{
if (settings.UseLocalSpaceLinearVelocity)
{

10
com.unity.ml-agents.extensions/Runtime/Sensors/PoseExtractor.cs


var localUp = localPose[i].rotation * Vector3.up;
var localFwd = localPose[i].rotation * Vector3.forward;
var localRight = localPose[i].rotation * Vector3.right;
Debug.DrawLine(current.position+offset, current.position+offset+.1f*localUp, Color.red);
Debug.DrawLine(current.position+offset, current.position+offset+.1f*localFwd, Color.green);
Debug.DrawLine(current.position+offset, current.position+offset+.1f*localRight, Color.blue);
Debug.DrawLine(current.position + offset, current.position + offset + .1f * localUp, Color.red);
Debug.DrawLine(current.position + offset, current.position + offset + .1f * localFwd, Color.green);
Debug.DrawLine(current.position + offset, current.position + offset + .1f * localRight, Color.blue);
}
}

{
// Push to the stack in reverse order
var children = tree[current];
for (var childIdx = children.Count-1; childIdx >= 0; childIdx--)
for (var childIdx = children.Count - 1; childIdx >= 0; childIdx--)
stack.Push((children[childIdx], depth+1));
stack.Push((children[childIdx], depth + 1));
}
}

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


public static int NumObservations(Rigidbody body, Joint joint, PhysicsSensorSettings settings)
{
if(body == null || joint == null)
if (body == null || joint == null)
{
return 0;
}

4
com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodyPoseExtractor.cs


if (rootGameObject == null)
{
rbs = rootBody.GetComponentsInChildren<Rigidbody>();
joints = rootBody.GetComponentsInChildren <Joint>();
joints = rootBody.GetComponentsInChildren<Joint>();
}
else
{

for (var i = 0; i < rbs.Length; i++)
{
if(rbs[i] != null)
if (rbs[i] != null)
{
bodyToIndex[rbs[i]] = i;
}

4
com.unity.ml-agents.extensions/Runtime/Sensors/RigidBodySensorComponent.cs


/// <summary>
/// Editor component that creates a PhysicsBodySensor for the Agent.
/// </summary>
public class RigidBodySensorComponent : SensorComponent
public class RigidBodySensorComponent : SensorComponent
{
/// <summary>
/// The root Rigidbody of the system.

var numPoseObservations = poseExtractor.GetNumPoseObservations(Settings);
var numJointObservations = 0;
foreach(var rb in poseExtractor.GetEnabledRigidbodies())
foreach (var rb in poseExtractor.GetEnabledRigidbodies())
{
var joint = rb.GetComponent<Joint>();
numJointObservations += RigidBodyJointExtractor.NumObservations(rb, joint, Settings);

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


}
}
}
#endif
#endif

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


}
}
}
#endif // #if UNITY_2020_1_OR_NEWER
#endif // #if UNITY_2020_1_OR_NEWER

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


return Pose.identity;
}
protected internal override Vector3 GetLinearVelocityAt(int index)
protected internal override Vector3 GetLinearVelocityAt(int index)
{
return Vector3.zero;
}

}
// Getting a parent index should throw an index exception
Assert.Throws <NullReferenceException>(
Assert.Throws<NullReferenceException>(
() => poseExtractor.GetParentIndex(0)
);

};
}
protected internal override Vector3 GetLinearVelocityAt(int index)
protected internal override Vector3 GetLinearVelocityAt(int index)
{
return Vector3.zero;
}

{
// Degenerate case with a loop
var poseExtractor = new UselessPoseExtractor();
poseExtractor.Init(new[] {-1, 2, 1});
poseExtractor.Init(new[] { -1, 2, 1 });
poseExtractor.Init(new[] {-1, 1});
poseExtractor.Init(new[] { -1, 1 });
// This just shouldn't blow up
poseExtractor.GetDisplayNodes();

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


// body 1 has parent 0
Assert.AreEqual(0, poseExtractor.GetParentIndex(1));
var virtualRootPos = new Vector3(0,2,0);
var virtualRootPos = new Vector3(0, 2, 0);
var virtualRootRot = Quaternion.Euler(0, 42, 0);
virtualRoot.transform.position = virtualRootPos;
virtualRoot.transform.rotation = virtualRootRot;

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


namespace Unity.MLAgents.Extensions.Tests
{
internal class RuntimeExampleTest {
internal class RuntimeExampleTest
{
[Test]
public void RuntimeTestMath()

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


### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
### Minor Changes
#### com.unity.ml-agents (C#)
- Update Barracuda to 1.0.2.
- Enabled C# formatting using `dotnet-format`.
#### ml-agents / ml-agents-envs / gym-unity (Python)
### Bug Fixes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
## [1.3.0-preview] - 2020-08-12
### Major Changes
#### com.unity.ml-agents (C#)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- The minimum supported Python version for ml-agents-envs was changed to 3.6.1. (#4244)
- The interaction between EnvManager and TrainerController was changed; EnvManager.advance() was split into to stages,
and TrainerController now uses the results from the first stage to handle new behavior names. This change speeds up

7
com.unity.ml-agents/CONTRIBUTING.md


### Code style
All python code should be formatted with
[`black`](https://github.com/ambv/black). Style and formatting for C# may be
enforced later.
[`black`](https://github.com/ambv/black).
C# code is formatted using [`dotnet-format`](https://github.com/dotnet/format).
You must have [dotnet](https://dotnet.microsoft.com/download) and
`dotnet-format` installed first.
### Python type annotations

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


[unity ML-Agents Toolkit]: https://github.com/Unity-Technologies/ml-agents
[unity inference engine]: https://docs.unity3d.com/Packages/com.unity.barracuda@latest/index.html
[package manager documentation]: https://docs.unity3d.com/Manual/upm-ui-install.html
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Installation.md
[installation instructions]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_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

2
com.unity.ml-agents/Editor/DemonstrationImporter.cs


/// <summary>
/// Asset Importer used to parse demonstration files.
/// </summary>
[ScriptedImporter(1, new[] {"demo"})]
[ScriptedImporter(1, new[] { "demo" })]
internal class DemonstrationImporter : ScriptedImporter
{
const string k_IconPath = "Packages/com.unity.ml-agents/Editor/Icons/DemoIcon.png";

20
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_5_docs/docs/
* https://github.com/Unity-Technologies/ml-agents/tree/release_6_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_5_docs/" +
[HelpURL("https://github.com/Unity-Technologies/ml-agents/tree/release_6_docs/" +
"docs/Learning-Environment-Design.md")]
public class Academy : IDisposable
{

// This try-catch is because DontDestroyOnLoad cannot be used in Editor Tests
GameObject.DontDestroyOnLoad(m_StepperObject);
}
catch {}
catch { }
}
/// <summary>

void ResetActions()
{
DecideAction = () => {};
DestroyAction = () => {};
AgentPreStep = i => {};
AgentSendState = () => {};
AgentAct = () => {};
AgentForceReset = () => {};
OnEnvironmentReset = () => {};
DecideAction = () => { };
DestroyAction = () => { };
AgentPreStep = i => { };
AgentSendState = () => { };
AgentAct = () => { };
AgentForceReset = () => { };
OnEnvironmentReset = () => { };
}
static void OnQuitCommandReceived()

3
com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs


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

/// <inheritdoc cref="IEquatable{T}.Equals(T)"/>
public bool Equals(ActionSegment<T> other)
{
return Offset == other.Offset && Length == other.Length && Equals(Array, other.Array);
return Offset == other.Offset && Length == other.Length && Array.SequenceEqual(other.Array);
}
/// <inheritdoc cref="ValueType.GetHashCode"/>

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


{
NumContinuousActions = numContinuousActions;
NumDiscreteActions = numDiscreteActions;
BranchSizes = branchSizes;
BranchSizes = branchSizes;
SumOfDiscreteBranchSizes = branchSizes?.Sum() ?? 0;
}
}

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


public ActuatorDiscreteActionMask DiscreteActionMask => m_DiscreteActionMask;
/// <summary>
/// Returns the previously stored actions for the actuators in this list.
/// The currently stored <see cref="ActionBuffers"/> object for the <see cref="IActuator"/>s managed by this class.
// public float[] StoredContinuousActions { get; private set; }
/// <summary>
/// Returns the previously stored actions for the actuators in this list.
/// </summary>
// public int[] StoredDiscreteActions { get; private set; }
public ActionBuffers StoredActions { get; private set; }
/// <summary>

/// Updates the local action buffer with the action buffer passed in. If the buffer
/// passed in is null, the local action buffer will be cleared.
/// </summary>
/// <param name="continuousActionBuffer">The action buffer which contains all of the
/// continuous actions for the IActuators in this list.</param>
/// <param name="discreteActionBuffer">The action buffer which contains all of the
/// discrete actions for the IActuators in this list.</param>
/// <param name="actions">The <see cref="ActionBuffers"/> object which contains all of the
/// actions for the IActuators in this list.</param>
public void UpdateActions(ActionBuffers actions)
{
ReadyActuatorsForExecution();

/// <summary>
/// Sorts the <see cref="IActuator"/>s according to their <see cref="IActuator.GetName"/> value.
/// Sorts the <see cref="IActuator"/>s according to their <see cref="IActuator.Name"/> value.
/// </summary>
void SortActuators()
{

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


/// <see cref="ActionSegment{T}"/> initialized from a float array.</returns>
public static ActionBuffers FromDiscreteActions(float[] discreteActions)
{
return new ActionBuffers(ActionSegment<float>.Empty, discreteActions == null ? ActionSegment<int>.Empty
: new ActionSegment<int>(Array.ConvertAll(discreteActions,
x => (int)x)));
return new ActionBuffers(ActionSegment<float>.Empty, discreteActions == null ? ActionSegment<int>.Empty
: new ActionSegment<int>(Array.ConvertAll(discreteActions,
x => (int)x)));
}
public ActionBuffers(float[] continuousActions, int[] discreteActions)

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


public void WriteDiscreteActionMask(IDiscreteActionMask actionMask)
{
m_ActionReceiver.WriteDiscreteActionMask(actionMask);
m_ActionReceiver.WriteDiscreteActionMask(actionMask);
}
/// <summary>

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


/// [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_5_docs/docs/Learning-Environment-Design-Agents.md
/// [Reinforcement Learning in Unity]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Learning-Environment-Design.md
/// [Agents]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md
/// [Reinforcement Learning in Unity]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design.md
/// [Unity ML-Agents Toolkit manual]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Readme.md
/// [Unity ML-Agents Toolkit manual]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Readme.md
[HelpURL("https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/" +
[HelpURL("https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/" +
"docs/Learning-Environment-Design-Agents.md")]
[Serializable]
[RequireComponent(typeof(BehaviorParameters))]

public int maxStep;
}
[SerializeField][HideInInspector]
[SerializeField]
[HideInInspector]
[SerializeField][HideInInspector]
[SerializeField]
[HideInInspector]
internal bool hasUpgradedFromAgentParameters;
/// <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_5_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_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_5_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/ML-Agents-Overview.md#a-quick-note-on-reward-signals
/// [Agents - Rewards]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#rewards
/// [Reward Signals]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_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)

///
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// </remarks>
public virtual void Initialize() {}
public virtual void Initialize() { }
/// <summary>
/// Implement `Heuristic()` to choose an action for this agent using a custom heuristic.

/// 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_5_docs/docs/Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Demonstration Recorder]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [GameObject]: https://docs.unity3d.com/Manual/GameObjects.html
/// </remarks>
/// <example>

/// 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_5_docs/docs/Learning-Environment-Design-Agents.md#observations-and-sensors
/// [Observations and Sensors]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#observations-and-sensors
/// </remarks>
public virtual void CollectObservations(VectorSensor sensor)
{

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

///
/// For more information about implementing agent actions see [Agents - Actions].
///
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs/Learning-Environment-Design-Agents.md#actions
/// </remarks>
/// <param name="actions">
/// Struct containing the buffers of actions to be executed at this step.

/// </summary>
/// <seealso cref="Initialize"/>
/// <seealso cref="EndEpisode"/>
public virtual void OnEpisodeBegin() {}
public virtual void OnEpisodeBegin() { }
public ActionBuffers GetStoredContinuousActions()
public ActionBuffers GetStoredActionBuffers()
{
return m_ActuatorManager.StoredActions;
}

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


Array.Clear(actionsOut, 0, actionsOut.Length);
}
public virtual void OnActionReceived(float[] vectorAction) {}
public virtual void OnActionReceived(float[] vectorAction) { }
/// <summary>
/// Returns the last action that was decided on by the Agent.

/// </returns>
/// <seealso cref="OnActionReceived(float[])"/>
// [Obsolete("GetAction has been deprecated, please use GetStoredContinuousActions, Or GetStoredDiscreteActions.")]
// [Obsolete("GetAction has been deprecated, please use GetStoredActionBuffers, Or GetStoredDiscreteActions.")]
public float[] GetAction()
{
return m_Info.storedVectorActions;

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


var agentInfoProto = ai.ToAgentInfoProto();
var agentActionProto = new AgentActionProto();
if(ai.storedVectorActions != null)
if (ai.storedVectorActions != null)
{
agentActionProto.VectorActions.AddRange(ai.storedVectorActions);
}

var brainParametersProto = new BrainParametersProto
{
VectorActionSize = { bp.VectorActionSize },
VectorActionSpaceType = (SpaceTypeProto) bp.VectorActionSpaceType,
VectorActionSpaceType = (SpaceTypeProto)bp.VectorActionSpaceType,
if(bp.VectorActionDescriptions != null)
if (bp.VectorActionDescriptions != null)
{
brainParametersProto.VectorActionDescriptions.AddRange(bp.VectorActionDescriptions);
}

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


Dictionary<string, BrainParameters> m_UnsentBrainKeys = new Dictionary<string, BrainParameters>();
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
/// The Unity to External client.
UnityToExternalProto.UnityToExternalProtoClient m_Client;
#endif

UnityInputProto Initialize(UnityOutputProto unityOutput,
out UnityInputProto unityInput)
{
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
m_IsOpen = true;
var channel = new Channel(
"localhost:" + m_CommunicatorInitParameters.port,

/// </summary>
public void Dispose()
{
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
if (!m_IsOpen)
{
return;

switch (command)
{
case CommandProto.Quit:
{
QuitCommandReceived?.Invoke();
return;
}
{
QuitCommandReceived?.Invoke();
return;
}
{
foreach (var brainName in m_OrderedAgentsRequestingDecisions.Keys)
m_OrderedAgentsRequestingDecisions[brainName].Clear();
foreach (var brainName in m_OrderedAgentsRequestingDecisions.Keys)
{
m_OrderedAgentsRequestingDecisions[brainName].Clear();
}
ResetCommandReceived?.Invoke();
return;
ResetCommandReceived?.Invoke();
return;
}
{
return;
}
{
return;
}
}
}

/// <param name="sensors">Sensors that will produce the observations</param>
public void PutObservations(string behaviorName, AgentInfo info, List<ISensor> sensors)
{
# if DEBUG
#if DEBUG
if (!m_SensorShapeValidators.ContainsKey(behaviorName))
{
m_SensorShapeValidators[behaviorName] = new SensorShapeValidator();

/// <param name="unityOutput">The UnityOutput to be sent.</param>
UnityInputProto Exchange(UnityOutputProto unityOutput)
{
# if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_STANDALONE_LINUX
if (!m_IsOpen)
{
return null;

2
com.unity.ml-agents/Runtime/Communicator/UnityRLCapabilities.cs


/// A class holding the capabilities flags for Reinforcement Learning across C# and the Trainer codebase. This
/// struct will be used to inform users if and when they are using C# / Trainer features that are mismatched.
/// </summary>
public UnityRLCapabilities(bool baseRlCapabilities=true)
public UnityRLCapabilities(bool baseRlCapabilities = true)
{
m_BaseRLCapabilities = baseRlCapabilities;
}

2
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_5_docs/docs//Learning-Environment-Design-Agents.md#recording-demonstrations
/// [Imitation Learning - Recording Demonstrations]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_docs/docs//Learning-Environment-Design-Agents.md#recording-demonstrations
/// </remarks>
[RequireComponent(typeof(Agent))]
[AddComponentMenu("ML Agents/Demonstration Recorder", (int)MenuGroup.Default)]

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


///
/// See [Agents - Actions] for more information on masking actions.
///
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_5_docs/docs/Learning-Environment-Design-Agents.md#actions
/// [Agents - Actions]: https://github.com/Unity-Technologies/ml-agents/blob/release_6_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>

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


public InferenceDevice InferenceDevice
{
get { return m_InferenceDevice; }
set { m_InferenceDevice = value; UpdateAgentPolicy();}
set { m_InferenceDevice = value; UpdateAgentPolicy(); }
}
[HideInInspector, SerializeField]

case BehaviorType.HeuristicOnly:
return GenerateHeuristicPolicy(heuristic);
case BehaviorType.InferenceOnly:
{
if (m_Model == null)
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
if (m_Model == null)
{
var behaviorType = BehaviorType.InferenceOnly.ToString();
throw new UnityAgentsException(
$"Can't use Behavior Type {behaviorType} without a model. " +
"Either assign a model, or change to a different Behavior Type."
);
}
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
return new BarracudaPolicy(m_BrainParameters, m_Model, m_InferenceDevice);
}
case BehaviorType.Default:
if (Academy.Instance.IsCommunicatorOn)
{

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


/// For the discrete action space: the number of branches in the action space.
/// </value>
[FormerlySerializedAs("vectorActionSize")]
public int[] VectorActionSize = new[] {1};
public int[] VectorActionSize = new[] { 1 };
/// <summary>
/// The list of strings describing what the actions correspond to.

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


public float this[int index]
{
get { return 0.0f; }
set {}
set { }
}
}

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


using System.Collections.Generic;
using Unity.MLAgents.Inference.Utils;
using UnityEngine;
using Random=System.Random;
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 = (int)(intervals.Count / 2);
// List that will store interval lengths
float[] intervalSizes = new float[numIntervals];
// List that will store uniform distributions

for(int i = 0; i < numIntervals; i++)
for (int i = 0; i < numIntervals; i++)
{
var min = intervals[2 * i];
var max = intervals[2 * i + 1];

intervalFuncs[i] = () => min + (float)distr.NextDouble() * intervalSize;
}
// Normalize interval lengths
for(int i = 0; i < numIntervals; i++)
for (int i = 0; i < numIntervals; i++)
}
}
for(int i = 1; i < numIntervals; i++)
for (int i = 1; i < numIntervals; i++)
}
}
Multinomial intervalDistr = new Multinomial(seed + 1);
float MultiRange()
{

4
com.unity.ml-agents/Runtime/Sensors/CameraSensor.cs


/// </summary>
public SensorCompressionType CompressionType
{
get { return m_CompressionType; }
get { return m_CompressionType; }
set { m_CompressionType = value; }
}

}
/// <inheritdoc/>
public void Update() {}
public void Update() { }
/// <inheritdoc/>
public void Reset() { }

14
com.unity.ml-agents/Runtime/Sensors/CameraSensorComponent.cs


/// </summary>
public Camera Camera
{
get { return m_Camera; }
get { return m_Camera; }
set { m_Camera = value; UpdateSensor(); }
}

/// </summary>
public string SensorName
{
get { return m_SensorName; }
get { return m_SensorName; }
set { m_SensorName = value; }
}

/// </summary>
public int Width
{
get { return m_Width; }
get { return m_Width; }
set { m_Width = value; }
}

/// </summary>
public int Height
{
get { return m_Height; }
set { m_Height = value; }
get { return m_Height; }
set { m_Height = value; }
}
[HideInInspector, SerializeField, FormerlySerializedAs("grayscale")]

/// </summary>
public bool Grayscale
{
get { return m_Grayscale; }
get { return m_Grayscale; }
set { m_Grayscale = value; }
}

/// </summary>
public SensorCompressionType CompressionType
{
get { return m_Compression; }
get { return m_Compression; }
set { m_Compression = value; UpdateSensor(); }
}

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


TensorShape m_TensorShape;
internal ObservationWriter() {}
internal ObservationWriter() { }
/// <summary>
/// Set the writer to write to an IList at the given channelOffset.

4
com.unity.ml-agents/Runtime/Sensors/RayPerceptionSensor.cs


var startPositionWorld = Transform.TransformPoint(startPositionLocal);
var endPositionWorld = Transform.TransformPoint(endPositionLocal);
return (StartPositionWorld : startPositionWorld, EndPositionWorld : endPositionWorld);
return (StartPositionWorld: startPositionWorld, EndPositionWorld: endPositionWorld);
}
/// <summary>

}
/// <inheritdoc/>
public void Reset() {}
public void Reset() { }
/// <inheritdoc/>
public int[] GetObservationShape()

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


{
get { return m_RaysPerDirection; }
// Note: can't change at runtime
set { m_RaysPerDirection = value;}
set { m_RaysPerDirection = value; }
}
[HideInInspector, SerializeField, FormerlySerializedAs("maxRayDegrees")]

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


{
public BoolReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

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


{
public FloatReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

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


{
public IntReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 1)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

10
com.unity.ml-agents/Runtime/Sensors/Reflection/ObservableAttribute.cs


internal static List<ISensor> CreateObservableSensors(object o, bool excludeInherited)
{
var sensorsOut = new List<ISensor>();
foreach (var(field, attr) in GetObservableFields(o, excludeInherited))
foreach (var (field, attr) in GetObservableFields(o, excludeInherited))
{
var sensor = CreateReflectionSensor(o, field, null, attr);
if (sensor != null)

}
foreach (var(prop, attr) in GetObservableProperties(o, excludeInherited))
foreach (var (prop, attr) in GetObservableProperties(o, excludeInherited))
{
if (!prop.CanRead)
{

else
{
var (_, sensorType) = s_TypeToSensorInfo[memberType];
sensor = (ISensor) Activator.CreateInstance(sensorType, reflectionSensorInfo);
sensor = (ISensor)Activator.CreateInstance(sensorType, reflectionSensorInfo);
}
// Wrap the base sensor in a StackingSensor if we're using stacking.

internal static int GetTotalObservationSize(object o, bool excludeInherited, List<string> errorsOut)
{
int sizeOut = 0;
foreach (var(field, attr) in GetObservableFields(o, excludeInherited))
foreach (var (field, attr) in GetObservableFields(o, excludeInherited))
{
if (s_TypeToSensorInfo.ContainsKey(field.FieldType))
{

}
}
foreach (var(prop, attr) in GetObservableProperties(o, excludeInherited))
foreach (var (prop, attr) in GetObservableProperties(o, excludeInherited))
{
if (!prop.CanRead)
{

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


{
public QuaternionReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 4)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

6
com.unity.ml-agents/Runtime/Sensors/Reflection/ReflectionSensorBase.cs


m_PropertyInfo = reflectionSensorInfo.PropertyInfo;
m_ObservableAttribute = reflectionSensorInfo.ObservableAttribute;
m_SensorName = reflectionSensorInfo.SensorName;
m_Shape = new[] {size};
m_Shape = new[] { size };
}
/// <inheritdoc/>

}
/// <inheritdoc/>
public void Update() {}
public void Update() { }
public void Reset() {}
public void Reset() { }
/// <inheritdoc/>
public SensorCompressionType GetCompressionType()

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


{
public Vector2ReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 2)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

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


{
public Vector3ReflectionSensor(ReflectionSensorInfo reflectionSensorInfo)
: base(reflectionSensorInfo, 3)
{}
{ }
internal override void WriteReflectedField(ObservationWriter writer)
{

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

正在加载...
取消
保存