Exemplo n.º 1
0
        public void TestAddObservationOneHot()
        {
            var sensor = new VectorSensor(4);

            sensor.AddOneHotObservation(2, 4);
            SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 0f });
        }
Exemplo n.º 2
0
        public void TestAddObservationBool()
        {
            var sensor = new VectorSensor(1);

            sensor.AddObservation(true);
            SensorTestHelper.CompareObservation(sensor, new[] { 1f });
        }
Exemplo n.º 3
0
        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 });
        }
Exemplo n.º 4
0
        public void TestWriteTooMany()
        {
            var sensor = new VectorSensor(2);

            sensor.AddObservation(new[] { 1f, 2f, 3f, 4f });

            SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f });
        }
Exemplo n.º 5
0
        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 });
        }
Exemplo n.º 6
0
        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 });
        }
Exemplo n.º 7
0
        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 }));
        }