Пример #1
0
        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 });
        }
Пример #2
0
        public void TestAddObservationQuaternion()
        {
            var sensor = new VectorSensor(4);

            sensor.AddObservation(Quaternion.identity);
            SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 0f, 1f });
        }
Пример #3
0
        public void TestAddObservationInt()
        {
            var sensor = new VectorSensor(1);

            sensor.AddObservation(42);
            SensorTestHelper.CompareObservation(sensor, new[] { 42f });
        }
Пример #4
0
        public void TestAddObservationOneHot()
        {
            var sensor = new VectorSensor(4);

            sensor.AddOneHotObservation(2, 4);
            SensorTestHelper.CompareObservation(sensor, new[] { 0f, 0f, 1f, 0f });
        }
Пример #5
0
        public void TestAddObservationFloat()
        {
            var sensor = new VectorSensor(1);

            sensor.AddObservation(1.2f);
            SensorTestHelper.CompareObservation(sensor, new[] { 1.2f });
        }
Пример #6
0
        public void TestAddObservationBool()
        {
            var sensor = new VectorSensor(1);

            sensor.AddObservation(true);
            SensorTestHelper.CompareObservation(sensor, new[] { 1f });
        }
Пример #7
0
        public void TestWriteTooMany()
        {
            var sensor = new VectorSensor(2);

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

            SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f });
        }
Пример #8
0
        public void TestWriteEnumerable()
        {
            var sensor = new VectorSensor(4);

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

            SensorTestHelper.CompareObservation(sensor, new[] { 1f, 2f, 3f, 4f });
        }
Пример #9
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 });
        }
Пример #10
0
        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 });
        }
Пример #11
0
        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 });
        }
Пример #12
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 });
        }
Пример #13
0
        public void AssertStackingReset()
        {
            var agentGo1 = new GameObject("TestAgent");

            agentGo1.AddComponent <TestAgent>();
            var behaviorParameters = agentGo1.GetComponent <BehaviorParameters>();

            behaviorParameters.brainParameters.numStackedVectorObservations = 3;
            var agent1 = agentGo1.GetComponent <TestAgent>();
            var aca    = Academy.Instance;

            agent1.LazyInitialize();
            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 });
        }