Ejemplo n.º 1
0
        public void GenerateVectorObservation()
        {
            var inputTensor = new TensorProxy
            {
                shape = new long[] { 2, 3 }
            };
            const int batchSize  = 4;
            var       agentInfos = GetFakeAgents();
            var       alloc      = new TensorCachingAllocator();
            var       generator  = new VectorObservationGenerator(alloc);

            generator.AddSensorIndex(0);
            generator.AddSensorIndex(1);
            generator.AddSensorIndex(2);
            var agent0 = agentInfos[0];
            var agent1 = agentInfos[1];
            var inputs = new List <AgentInfoSensorsPair>
            {
                new AgentInfoSensorsPair {
                    agentInfo = agent0._Info, sensors = agent0.sensors
                },
                new AgentInfoSensorsPair {
                    agentInfo = agent1._Info, sensors = agent1.sensors
                },
            };

            generator.Generate(inputTensor, batchSize, inputs);
            Assert.IsNotNull(inputTensor.data);
            Assert.AreEqual(inputTensor.data[0, 0], 1);
            Assert.AreEqual(inputTensor.data[0, 2], 3);
            Assert.AreEqual(inputTensor.data[1, 0], 4);
            Assert.AreEqual(inputTensor.data[1, 2], 6);
            alloc.Dispose();
        }
Ejemplo n.º 2
0
        public void GenerateVectorObservation()
        {
            var inputTensor = new TensorProxy
            {
                shape = new long[] { 2, 4 }
            };
            const int batchSize  = 4;
            var       agentInfos = GetFakeAgents(ObservableAttributeOptions.ExamineAll);
            var       alloc      = new TensorCachingAllocator();
            var       generator  = new VectorObservationGenerator(alloc);

            generator.AddSensorIndex(0); // ObservableAttribute (size 1)
            generator.AddSensorIndex(1); // TestSensor (size 0)
            generator.AddSensorIndex(2); // TestSensor (size 0)
            generator.AddSensorIndex(3); // VectorSensor (size 3)
            var agent0 = agentInfos[0];
            var agent1 = agentInfos[1];
            var inputs = new List <AgentInfoSensorsPair>
            {
                new AgentInfoSensorsPair {
                    agentInfo = agent0._Info, sensors = agent0.sensors
                },
                new AgentInfoSensorsPair {
                    agentInfo = agent1._Info, sensors = agent1.sensors
                },
            };

            generator.Generate(inputTensor, batchSize, inputs);
            Assert.IsNotNull(inputTensor.data);
            Assert.AreEqual(inputTensor.data[0, 1], 1);
            Assert.AreEqual(inputTensor.data[0, 3], 3);
            Assert.AreEqual(inputTensor.data[1, 1], 4);
            Assert.AreEqual(inputTensor.data[1, 3], 6);
            alloc.Dispose();
        }
        public void GenerateVectorObservation()
        {
            var inputTensor = new TensorProxy
            {
                shape = new long[] { 2, 3 }
            };
            const int batchSize  = 4;
            var       agentInfos = GetFakeAgents();
            var       alloc      = new TensorCachingAllocator();
            var       generator  = new VectorObservationGenerator(alloc);

            generator.AddSensorIndex(0);
            generator.AddSensorIndex(1);
            generator.AddSensorIndex(2);
            generator.Generate(inputTensor, batchSize, agentInfos);
            Assert.IsNotNull(inputTensor.data);
            Assert.AreEqual(inputTensor.data[0, 0], 1);
            Assert.AreEqual(inputTensor.data[0, 2], 3);
            Assert.AreEqual(inputTensor.data[1, 0], 4);
            Assert.AreEqual(inputTensor.data[1, 2], 6);
            alloc.Dispose();
        }