浏览代码
Integrate IActuators into ML-Agents core code. (#4315)
Integrate IActuators into ML-Agents core code. (#4315)
Co-authored-by: Chris Elion <chris.elion@unity3d.com>/MLA-1734-demo-provider
GitHub
4 年前
当前提交
3a7572b4
共有 24 个文件被更改,包括 426 次插入 和 418 次删除
-
33com.unity.ml-agents/Runtime/Actuators/ActionSegment.cs
-
2com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs
-
51com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
-
72com.unity.ml-agents/Runtime/Actuators/IActionReceiver.cs
-
2com.unity.ml-agents/Runtime/Actuators/IActuator.cs
-
2com.unity.ml-agents/Runtime/Actuators/IDiscreteActionMask.cs
-
2com.unity.ml-agents/Runtime/Actuators/VectorActuator.cs
-
201com.unity.ml-agents/Runtime/Agent.cs
-
14com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs
-
2com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
-
6com.unity.ml-agents/Runtime/DecisionRequester.cs
-
118com.unity.ml-agents/Runtime/DiscreteActionMasker.cs
-
17com.unity.ml-agents/Runtime/Policies/BarracudaPolicy.cs
-
37com.unity.ml-agents/Runtime/Policies/BehaviorParameters.cs
-
20com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs
-
3com.unity.ml-agents/Runtime/Policies/IPolicy.cs
-
15com.unity.ml-agents/Runtime/Policies/RemotePolicy.cs
-
46com.unity.ml-agents/Tests/Editor/Actuators/ActuatorManagerTests.cs
-
3com.unity.ml-agents/Tests/Editor/BehaviorParameterTests.cs
-
4com.unity.ml-agents/Tests/Editor/MLAgentsEditModeTest.cs
-
38com.unity.ml-agents/Runtime/Agent.deprecated.cs
-
3com.unity.ml-agents/Runtime/Agent.deprecated.cs.meta
-
11com.unity.ml-agents/Tests/Editor/EditModeTestActionMasker.cs.meta
-
142com.unity.ml-agents/Tests/Editor/EditModeTestActionMasker.cs
|
|||
using System; |
|||
using UnityEngine; |
|||
|
|||
namespace Unity.MLAgents |
|||
{ |
|||
public partial class Agent |
|||
{ |
|||
public virtual void CollectDiscreteActionMasks(DiscreteActionMasker actionMasker) |
|||
{ |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// This method passes in a float array that is to be populated with actions. The actions
|
|||
/// </summary>
|
|||
/// <param name="actionsOut"></param>
|
|||
public virtual void Heuristic(float[] actionsOut) |
|||
{ |
|||
Debug.LogWarning("Heuristic method called but not implemented. Returning placeholder actions."); |
|||
Array.Clear(actionsOut, 0, actionsOut.Length); |
|||
} |
|||
|
|||
public virtual void OnActionReceived(float[] vectorAction) {} |
|||
|
|||
/// <summary>
|
|||
/// Returns the last action that was decided on by the Agent.
|
|||
/// </summary>
|
|||
/// <returns>
|
|||
/// The last action that was decided by the Agent (or null if no decision has been made).
|
|||
/// </returns>
|
|||
/// <seealso cref="OnActionReceived(float[])"/>
|
|||
// [Obsolete("GetAction has been deprecated, please use GetStoredContinuousActions, Or GetStoredDiscreteActions.")]
|
|||
public float[] GetAction() |
|||
{ |
|||
return m_Info.storedVectorActions; |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9650a482703b47db8cd7fb2df8caa1bf |
|||
timeCreated: 1595613441 |
|
|||
fileFormatVersion: 2 |
|||
guid: 2e2810ee6c8c64fb39abdf04b5d17f50 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using NUnit.Framework; |
|||
using Unity.MLAgents.Policies; |
|||
|
|||
namespace Unity.MLAgents.Tests |
|||
{ |
|||
public class EditModeTestActionMasker |
|||
{ |
|||
[Test] |
|||
public void Contruction() |
|||
{ |
|||
var bp = new BrainParameters(); |
|||
var masker = new DiscreteActionMasker(bp); |
|||
Assert.IsNotNull(masker); |
|||
} |
|||
|
|||
[Test] |
|||
public void FailsWithContinuous() |
|||
{ |
|||
var bp = new BrainParameters(); |
|||
bp.VectorActionSpaceType = SpaceType.Continuous; |
|||
bp.VectorActionSize = new[] {4}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
masker.SetMask(0, new[] {0}); |
|||
Assert.Catch<UnityAgentsException>(() => masker.GetMask()); |
|||
} |
|||
|
|||
[Test] |
|||
public void NullMask() |
|||
{ |
|||
var bp = new BrainParameters(); |
|||
bp.VectorActionSpaceType = SpaceType.Discrete; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
var mask = masker.GetMask(); |
|||
Assert.IsNull(mask); |
|||
} |
|||
|
|||
[Test] |
|||
public void FirstBranchMask() |
|||
{ |
|||
var bp = new BrainParameters(); |
|||
bp.VectorActionSpaceType = SpaceType.Discrete; |
|||
bp.VectorActionSize = new[] {4, 5, 6}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
var mask = masker.GetMask(); |
|||
Assert.IsNull(mask); |
|||
masker.SetMask(0, new[] {1, 2, 3}); |
|||
mask = masker.GetMask(); |
|||
Assert.IsFalse(mask[0]); |
|||
Assert.IsTrue(mask[1]); |
|||
Assert.IsTrue(mask[2]); |
|||
Assert.IsTrue(mask[3]); |
|||
Assert.IsFalse(mask[4]); |
|||
Assert.AreEqual(mask.Length, 15); |
|||
} |
|||
|
|||
[Test] |
|||
public void SecondBranchMask() |
|||
{ |
|||
var bp = new BrainParameters |
|||
{ |
|||
VectorActionSpaceType = SpaceType.Discrete, |
|||
VectorActionSize = new[] { 4, 5, 6 } |
|||
}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
masker.SetMask(1, new[] {1, 2, 3}); |
|||
var mask = masker.GetMask(); |
|||
Assert.IsFalse(mask[0]); |
|||
Assert.IsFalse(mask[4]); |
|||
Assert.IsTrue(mask[5]); |
|||
Assert.IsTrue(mask[6]); |
|||
Assert.IsTrue(mask[7]); |
|||
Assert.IsFalse(mask[8]); |
|||
Assert.IsFalse(mask[9]); |
|||
} |
|||
|
|||
[Test] |
|||
public void MaskReset() |
|||
{ |
|||
var bp = new BrainParameters |
|||
{ |
|||
VectorActionSpaceType = SpaceType.Discrete, |
|||
VectorActionSize = new[] { 4, 5, 6 } |
|||
}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
masker.SetMask(1, new[] {1, 2, 3}); |
|||
masker.ResetMask(); |
|||
var mask = masker.GetMask(); |
|||
for (var i = 0; i < 15; i++) |
|||
{ |
|||
Assert.IsFalse(mask[i]); |
|||
} |
|||
} |
|||
|
|||
[Test] |
|||
public void ThrowsError() |
|||
{ |
|||
var bp = new BrainParameters |
|||
{ |
|||
VectorActionSpaceType = SpaceType.Discrete, |
|||
VectorActionSize = new[] { 4, 5, 6 } |
|||
}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
|
|||
Assert.Catch<UnityAgentsException>( |
|||
() => masker.SetMask(0, new[] {5})); |
|||
Assert.Catch<UnityAgentsException>( |
|||
() => masker.SetMask(1, new[] {5})); |
|||
masker.SetMask(2, new[] {5}); |
|||
Assert.Catch<UnityAgentsException>( |
|||
() => masker.SetMask(3, new[] {1})); |
|||
masker.GetMask(); |
|||
masker.ResetMask(); |
|||
masker.SetMask(0, new[] {0, 1, 2, 3}); |
|||
Assert.Catch<UnityAgentsException>( |
|||
() => masker.GetMask()); |
|||
} |
|||
|
|||
[Test] |
|||
public void MultipleMaskEdit() |
|||
{ |
|||
var bp = new BrainParameters(); |
|||
bp.VectorActionSpaceType = SpaceType.Discrete; |
|||
bp.VectorActionSize = new[] {4, 5, 6}; |
|||
var masker = new DiscreteActionMasker(bp); |
|||
masker.SetMask(0, new[] {0, 1}); |
|||
masker.SetMask(0, new[] {3}); |
|||
masker.SetMask(2, new[] {1}); |
|||
var mask = masker.GetMask(); |
|||
for (var i = 0; i < 15; i++) |
|||
{ |
|||
if ((i == 0) || (i == 1) || (i == 3) || (i == 10)) |
|||
{ |
|||
Assert.IsTrue(mask[i]); |
|||
} |
|||
else |
|||
{ |
|||
Assert.IsFalse(mask[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue