public void TestStacking() { VectorSensor wrapped = new VectorSensor(2); ISensor sensor = new StackingSensor(wrapped, 3); wrapped.AddObservation(new[] { 1f, 2f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 1f, 2f }); sensor.Update(); wrapped.AddObservation(new[] { 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 2f, 3f, 4f }); sensor.Update(); wrapped.AddObservation(new[] { 5f, 6f }); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f, 5f, 6f }); sensor.Update(); wrapped.AddObservation(new[] { 7f, 8f }); SensorTestHelper.CompareObservation(sensor, new[] { 3f, 4f, 5f, 6f, 7f, 8f }); sensor.Update(); wrapped.AddObservation(new[] { 9f, 10f }); SensorTestHelper.CompareObservation(sensor, new[] { 5f, 6f, 7f, 8f, 9f, 10f }); // Check that if we don't call Update(), the same observations are produced SensorTestHelper.CompareObservation(sensor, new[] { 5f, 6f, 7f, 8f, 9f, 10f }); }
public void TestAddObservationFloat() { var sensor = new VectorSensor(1); sensor.AddObservation(1.2f); SensorTestHelper.CompareObservation(sensor, new[] { 1.2f }); }
public void TestAddObservationQuaternion() { var sensor = new VectorSensor(4); sensor.AddObservation(Quaternion.identity); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 1f }); }
public void TestAddObservationInt() { var sensor = new VectorSensor(1); sensor.AddObservation(42); SensorTestHelper.CompareObservation(sensor, new[] { 42f }); }
public void TestAddObservationOneHot() { var sensor = new VectorSensor(4); sensor.AddOneHotObservation(2, 4); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 0f }); }
public void TestAddObservationBool() { var sensor = new VectorSensor(1); sensor.AddObservation(true); SensorTestHelper.CompareObservation(sensor, new[] { 1f }); }
public void AssertStackingReset() { var agentGo1 = new GameObject("TestAgent"); var bp1 = agentGo1.AddComponent <BehaviorParameters>(); bp1.BrainParameters.NumStackedVectorObservations = 3; bp1.BrainParameters.ActionSpec = ActionSpec.MakeContinuous(1); var aca = Academy.Instance; var agent1 = agentGo1.AddComponent <TestAgent>(); var policy = new TestPolicy(); agent1.SetPolicy(policy); StackingSensor sensor = null; foreach (ISensor s in agent1.sensors) { if (s is StackingSensor) { sensor = s as StackingSensor; } } Assert.NotNull(sensor); for (int i = 0; i < 20; i++) { agent1.RequestDecision(); aca.EnvironmentStep(); } policy.OnRequestDecision = () => SensorTestHelper.CompareObservation(sensor, new[] { 18f, 19f, 21f }); agent1.EndEpisode(); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f }); }
public void TestWriteEnumerable() { var sensor = new VectorSensor(4); sensor.AddObservation(new[] { 1f, 2f, 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f }); }
public void TestWriteTooMany() { var sensor = new VectorSensor(2); sensor.AddObservation(new[] { 1f, 2f, 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f }); }
public void TestWriteNotEnough() { var sensor = new VectorSensor(4); sensor.AddObservation(new[] { 1f, 2f }); // Make sure extra zeros are added SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 0f, 0f }); }
public void TestAddObservationVec() { var sensor = new VectorSensor(3); sensor.AddObservation(new Vector3(1, 2, 3)); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f }); sensor = new VectorSensor(2); sensor.AddObservation(new Vector2(4, 5)); SensorTestHelper.CompareObservation(sensor, new[] { 4f, 5f }); }
public void TestStackingReset() { VectorSensor wrapped = new VectorSensor(2); ISensor sensor = new StackingSensor(wrapped, 3); wrapped.AddObservation(new[] { 1f, 2f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 1f, 2f }); sensor.Update(); wrapped.AddObservation(new[] { 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 2f, 3f, 4f }); sensor.Reset(); wrapped.AddObservation(new[] { 5f, 6f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 5f, 6f }); }
public void TestWrite() { var sensor = new VectorSensor(4); sensor.AddObservation(1f); sensor.AddObservation(2f); sensor.AddObservation(3f); sensor.AddObservation(4f); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f }); // Check that if we don't call Update(), the same observations are produced SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f }); // Check that Update() clears the data sensor.Update(); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f }); }
public void Test3DStacking() { var wrapped = new Dummy3DSensor(); wrapped.ObservationSpec = ObservationSpec.Visual(2, 1, 2); var sensor = new StackingSensor(wrapped, 2); // Check the stacking is on the last dimension wrapped.CurrentObservation = new[, , ] { { { 1f, 2f } }, { { 3f, 4f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 0f, 0f, 1f, 2f } }, { { 0f, 0f, 3f, 4f } } }); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 5f, 6f } }, { { 7f, 8f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 1f, 2f, 5f, 6f } }, { { 3f, 4f, 7f, 8f } } }); sensor.Update(); wrapped.CurrentObservation = new[, , ] { { { 9f, 10f } }, { { 11f, 12f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 5f, 6f, 9f, 10f } }, { { 7f, 8f, 11f, 12f } } }); // Check that if we don't call Update(), the same observations are produced SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 5f, 6f, 9f, 10f } }, { { 7f, 8f, 11f, 12f } } }); // Test reset sensor.Reset(); wrapped.CurrentObservation = new[, , ] { { { 13f, 14f } }, { { 15f, 16f } } }; SensorTestHelper.CompareObservation(sensor, new[, , ] { { { 0f, 0f, 13f, 14f } }, { { 0f, 0f, 15f, 16f } } }); }
public void TestVectorStacking() { VectorSensor wrapped = new VectorSensor(2); StackingSensor sensor = new StackingSensor(wrapped, 3); wrapped.AddObservation(new[] { 1f, 2f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 0f, 1f, 2f }); var data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 0f, 0f, 0f, 0f, 1f, 2f })); sensor.Update(); wrapped.AddObservation(new[] { 3f, 4f }); SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 2f, 3f, 4f }); data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 0f, 0f, 1f, 2f, 3f, 4f })); sensor.Update(); wrapped.AddObservation(new[] { 5f, 6f }); SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f, 5f, 6f }); data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 1f, 2f, 3f, 4f, 5f, 6f })); sensor.Update(); wrapped.AddObservation(new[] { 7f, 8f }); SensorTestHelper.CompareObservation(sensor, new[] { 3f, 4f, 5f, 6f, 7f, 8f }); data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 3f, 4f, 5f, 6f, 7f, 8f })); sensor.Update(); wrapped.AddObservation(new[] { 9f, 10f }); SensorTestHelper.CompareObservation(sensor, new[] { 5f, 6f, 7f, 8f, 9f, 10f }); data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 5f, 6f, 7f, 8f, 9f, 10f })); // Check that if we don't call Update(), the same observations are produced SensorTestHelper.CompareObservation(sensor, new[] { 5f, 6f, 7f, 8f, 9f, 10f }); data = sensor.GetStackedObservations(); Assert.IsTrue(data.ToArray().SequenceEqual(new[] { 5f, 6f, 7f, 8f, 9f, 10f })); }