public void ApplyDiscreteActionOutput() { var inputTensor = new TensorProxy() { shape = new long[] { 2, 5 }, data = new Tensor( 2, 5, new[] { 0.5f, 22.5f, 0.1f, 5f, 1f, 4f, 5f, 6f, 7f, 8f }) }; var alloc = new TensorCachingAllocator(); var applier = new DiscreteActionOutputApplier(new[] { 2, 3 }, 0, alloc); var agentIds = new List<int>() { 0, 1 }; // Dictionary from AgentId to Action var actionDict = new Dictionary<int, float[]>() { { 0, null }, { 1, null } }; applier.Apply(inputTensor, agentIds, actionDict); Assert.AreEqual(actionDict[0][0], 1); Assert.AreEqual(actionDict[0][1], 1); Assert.AreEqual(actionDict[1][0], 1); Assert.AreEqual(actionDict[1][1], 2); alloc.Dispose(); }
public void ApplyDiscreteActionOutput() { var actionSpec = ActionSpec.MakeDiscrete(2, 3); var inputTensor = new TensorProxy() { shape = new long[] { 2, 2 }, data = new Tensor( 2, 2, new[] { 1f, 1f, 1f, 2f }), }; var alloc = new TensorCachingAllocator(); var applier = new DiscreteActionOutputApplier(actionSpec, 0, alloc); var agentIds = new List <int>() { 0, 1 }; // Dictionary from AgentId to Action var actionDict = new Dictionary <int, ActionBuffers>() { { 0, ActionBuffers.Empty }, { 1, ActionBuffers.Empty } }; applier.Apply(inputTensor, agentIds, actionDict); Assert.AreEqual(actionDict[0].DiscreteActions[0], 1); Assert.AreEqual(actionDict[0].DiscreteActions[1], 1); Assert.AreEqual(actionDict[1].DiscreteActions[0], 1); Assert.AreEqual(actionDict[1].DiscreteActions[1], 2); alloc.Dispose(); }
public void ApplyDiscreteActionOutput() { var inputTensor = new TensorProxy() { shape = new long[] { 2, 5 }, data = new Tensor( 2, 5, new[] { 0.5f, 22.5f, 0.1f, 5f, 1f, 4f, 5f, 6f, 7f, 8f }) }; var agentInfos = GetFakeAgentInfos(); var alloc = new TensorCachingAllocator(); var applier = new DiscreteActionOutputApplier(new[] { 2, 3 }, 0, alloc); applier.Apply(inputTensor, agentInfos); var agents = agentInfos; var agent = agents[0] as TestAgent; Assert.NotNull(agent); var action = agent.GetAction(); Assert.AreEqual(action.vectorActions[0], 1); Assert.AreEqual(action.vectorActions[1], 1); agent = agents[1] as TestAgent; Assert.NotNull(agent); action = agent.GetAction(); Assert.AreEqual(action.vectorActions[0], 1); Assert.AreEqual(action.vectorActions[1], 2); alloc.Dispose(); }
public void ApplyDiscreteActionOutput() { var inputTensor = new TensorProxy() { shape = new long[] { 2, 5 }, data = new Tensor( 2, 5, new[] { 0.5f, 22.5f, 0.1f, 5f, 1f, 4f, 5f, 6f, 7f, 8f }) }; var alloc = new TensorCachingAllocator(); var applier = new DiscreteActionOutputApplier(new[] { 2, 3 }, 0, alloc); var action0 = new AgentAction(); var action1 = new AgentAction(); var callbacks = new List <AgentIdActionPair>() { new AgentIdActionPair { agentId = 0, action = (a) => action0 = a }, new AgentIdActionPair { agentId = 1, action = (a) => action1 = a } }; applier.Apply(inputTensor, callbacks); Assert.AreEqual(action0.vectorActions[0], 1); Assert.AreEqual(action0.vectorActions[1], 1); Assert.AreEqual(action1.vectorActions[0], 1); Assert.AreEqual(action1.vectorActions[1], 2); alloc.Dispose(); }
public void ApplyDiscreteActionOutput() { var inputTensor = new Tensor() { Shape = new long[] { 2, 5 }, Data = new float[, ] { { 0.5f, 22.5f, 0.1f, 5f, 1f }, { 4f, 5f, 6f, 7f, 8f } } }; var agentInfos = GetFakeAgentInfos(); var applier = new DiscreteActionOutputApplier(new int[] { 2, 3 }, 0); applier.Apply(inputTensor, agentInfos); var agents = agentInfos.Keys.ToList(); var agent = agents[0] as TestAgent; var action = agent.GetAction(); Assert.AreEqual(action.vectorActions[0], 1); Assert.AreEqual(action.vectorActions[1], 1); agent = agents[1] as TestAgent; action = agent.GetAction(); Assert.AreEqual(action.vectorActions[0], 1); Assert.AreEqual(action.vectorActions[1], 2); }
public void ApplyHybridActionOutput() { var actionSpec = new ActionSpec(3, new[] { 2, 3 }); var continuousInputTensor = new TensorProxy() { shape = new long[] { 2, 3 }, data = new Tensor(2, 3, new float[] { 1, 2, 3, 4, 5, 6 }) }; var discreteInputTensor = new TensorProxy() { shape = new long[] { 2, 2 }, data = new Tensor( 2, 2, new[] { 1f, 1f, 1f, 2f }), }; var continuousApplier = new ContinuousActionOutputApplier(actionSpec); var alloc = new TensorCachingAllocator(); var discreteApplier = new DiscreteActionOutputApplier(actionSpec, 0, alloc); var agentIds = new List <int>() { 0, 1 }; // Dictionary from AgentId to Action var actionDict = new Dictionary <int, ActionBuffers>() { { 0, ActionBuffers.Empty }, { 1, ActionBuffers.Empty } }; continuousApplier.Apply(continuousInputTensor, agentIds, actionDict); discreteApplier.Apply(discreteInputTensor, agentIds, actionDict); Assert.AreEqual(actionDict[0].ContinuousActions[0], 1); Assert.AreEqual(actionDict[0].ContinuousActions[1], 2); Assert.AreEqual(actionDict[0].ContinuousActions[2], 3); Assert.AreEqual(actionDict[0].DiscreteActions[0], 1); Assert.AreEqual(actionDict[0].DiscreteActions[1], 1); Assert.AreEqual(actionDict[1].ContinuousActions[0], 4); Assert.AreEqual(actionDict[1].ContinuousActions[1], 5); Assert.AreEqual(actionDict[1].ContinuousActions[2], 6); Assert.AreEqual(actionDict[1].DiscreteActions[0], 1); Assert.AreEqual(actionDict[1].DiscreteActions[1], 2); alloc.Dispose(); }
public void TestDiscreteApply() { var actionSpec = ActionSpec.MakeDiscrete(3, 2); const float smallLogProb = -1000.0f; const float largeLogProb = -1.0f; var logProbs = new TensorProxy { data = new Tensor( 2, 5, new[] { smallLogProb, smallLogProb, largeLogProb, // Agent 0, branch 0 smallLogProb, largeLogProb, // Agent 0, branch 1 largeLogProb, smallLogProb, smallLogProb, // Agent 1, branch 0 largeLogProb, smallLogProb, // Agent 1, branch 1 }), valueType = TensorProxy.TensorType.FloatingPoint }; var applier = new DiscreteActionOutputApplier(actionSpec, 2020, null); var agentIds = new List <int> { 42, 1337 }; var actionBuffers = new Dictionary <int, ActionBuffers>(); actionBuffers[42] = new ActionBuffers(actionSpec); actionBuffers[1337] = new ActionBuffers(actionSpec); applier.Apply(logProbs, agentIds, actionBuffers); Assert.AreEqual(2, actionBuffers[42].DiscreteActions[0]); Assert.AreEqual(1, actionBuffers[42].DiscreteActions[1]); Assert.AreEqual(0, actionBuffers[1337].DiscreteActions[0]); Assert.AreEqual(0, actionBuffers[1337].DiscreteActions[1]); }
public void TestDiscreteApply() { var actionSpec = ActionSpec.MakeDiscrete(3, 2); var applier = new DiscreteActionOutputApplier(actionSpec, 2020, null); var agentIds = new List <int> { 42, 1337 }; var actionBuffers = new Dictionary <int, ActionBuffers>(); actionBuffers[42] = new ActionBuffers(actionSpec); actionBuffers[1337] = new ActionBuffers(actionSpec); var actionTensor = new TensorProxy { data = new Tensor( 2, 2, new[] { 2.0f, // Agent 0, branch 0 1.0f, // Agent 0, branch 1 0.0f, // Agent 1, branch 0 0.0f // Agent 1, branch 1 }), shape = new long[] { 2, 2 }, valueType = TensorProxy.TensorType.FloatingPoint }; applier.Apply(actionTensor, agentIds, actionBuffers); Assert.AreEqual(2, actionBuffers[42].DiscreteActions[0]); Assert.AreEqual(1, actionBuffers[42].DiscreteActions[1]); Assert.AreEqual(0, actionBuffers[1337].DiscreteActions[0]); Assert.AreEqual(0, actionBuffers[1337].DiscreteActions[1]); }