Esempio n. 1
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var vecObsSizeT = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex  = 0;

            foreach (var agent in agents)
            {
                var tensorOffset = 0;
                // Write each sensor consecutively to the tensor
                foreach (var sensorIndex in m_SensorIndices)
                {
                    m_WriteAdapter.SetTarget(tensorProxy, agentIndex, tensorOffset);
                    var sensor     = agent.sensors[sensorIndex];
                    var numWritten = sensor.Write(m_WriteAdapter);
                    tensorOffset += numWritten;
                }
                Debug.AssertFormat(
                    tensorOffset == vecObsSizeT,
                    "mismatch between vector observation size ({0}) and number of observations written ({1})",
                    vecObsSizeT, tensorOffset
                    );

                agentIndex++;
            }
        }
Esempio n. 2
0
        public void Generate(
            TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var memorySize = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agentInfo.Keys)
            {
                var memory = agentInfo[agent].memories;
                if (memory == null)
                {
                    agentIndex++;
                    continue;
                }
                for (var j = 0; j < Math.Min(memorySize, memory.Count); j++)
                {
                    if (j >= memory.Count)
                    {
                        break;
                    }
                    tensorProxy.data[agentIndex, j] = memory[j];
                }
                agentIndex++;
            }
        }
        public void Generate(
            TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var memorySize = (int)tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agents)
            {
                var agentInfo = agent.Info;
                var memory    = agentInfo.memories;

                var offset = memorySize * m_MemoryIndex;

                if (memory == null)
                {
                    agentIndex++;
                    continue;
                }
                for (var j = 0; j < memorySize; j++)
                {
                    if (j >= memory.Count)
                    {
                        break;
                    }
                    tensorProxy.data[agentIndex, j] = memory[j + offset];
                }
                agentIndex++;
            }
        }
Esempio n. 4
0
        public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);

            var memorySize = (int)tensorProxy.Shape[tensorProxy.Shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agentInfo.Keys)
            {
                var memory = agentInfo[agent].memories;

                int offset = memorySize * memoryIndex;

                if (memory == null)
                {
                    agentIndex++;
                    continue;
                }
                for (var j = 0; j < memorySize; j++)
                {
                    if (j >= memory.Count)
                    {
                        break;
                    }
                    tensorProxy.Data[agentIndex, j] = memory[j + offset];
                }
                agentIndex++;
            }
        }
Esempio n. 5
0
        public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            var textures = agentInfo.Keys.Select(
                agent => agentInfo[agent].visualObservations[_index]).ToList();

            TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);
            Utilities.TextureToTensorProxy(tensorProxy, textures, _grayScale, _allocator);
        }
Esempio n. 6
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var agentIndex = 0;

            foreach (var agent in agents)
            {
                m_WriteAdapter.SetTarget(tensorProxy, agentIndex, 0);
                agent.sensors[m_SensorIndex].Write(m_WriteAdapter);
                agentIndex++;
            }
        }
Esempio n. 7
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var agentIndex = 0;

            foreach (var infoSensorPair in infos)
            {
                var sensor = infoSensorPair.sensors[m_SensorIndex];
                m_WriteAdapter.SetTarget(tensorProxy, agentIndex, 0);
                sensor.Write(m_WriteAdapter);
                agentIndex++;
            }
        }
        public void Generate(
            TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var agentIndex = 0;

            foreach (var agent in agents)
            {
                // TODO direct access to sensors list here - should we do it differently?
                // TODO m_Index here is the visual observation index. Will work for now but not if we add more sensor types.
                agent.m_Sensors[m_Index].WriteToTensor(tensorProxy, agentIndex);
                agentIndex++;
            }
        }
Esempio n. 9
0
        public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);
            var vecObsSizeT = tensorProxy.Shape[tensorProxy.Shape.Length - 1];

            var agentIndex = 0;

            foreach (var agent in agentInfo.Keys)
            {
                var vectorObs = agentInfo[agent].stackedVectorObservation;
                for (var j = 0; j < vecObsSizeT; j++)
                {
                    tensorProxy.Data[agentIndex, j] = vectorObs[j];
                }
                agentIndex++;
            }
        }
Esempio n. 10
0
        public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);

            var maskSize   = tensorProxy.Shape[tensorProxy.Shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agentInfo.Keys)
            {
                var maskList = agentInfo[agent].actionMasks;
                for (var j = 0; j < maskSize; j++)
                {
                    var isUnmasked = (maskList != null && maskList[j]) ? 0.0f : 1.0f;
                    tensorProxy.Data[agentIndex, j] = isUnmasked;
                }
                agentIndex++;
            }
        }
        public void Generate(
            TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var vecObsSizeT = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex  = 0;

            foreach (var agent in agents)
            {
                var info      = agent.Info;
                var vectorObs = info.stackedVectorObservation;
                for (var j = 0; j < vecObsSizeT; j++)
                {
                    tensorProxy.data[agentIndex, j] = vectorObs[j];
                }
                agentIndex++;
            }
        }
Esempio n. 12
0
        public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);

            var actionSize = tensorProxy.Shape[tensorProxy.Shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agentInfo.Keys)
            {
                var pastAction = agentInfo[agent].storedVectorActions;
                for (var j = 0; j < actionSize; j++)
                {
                    tensorProxy.Data[agentIndex, j] = pastAction[j];
                }

                agentIndex++;
            }
        }
Esempio n. 13
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var maskSize   = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var infoSensorPair in infos)
            {
                var agentInfo = infoSensorPair.agentInfo;
                var maskList  = agentInfo.actionMasks;
                for (var j = 0; j < maskSize; j++)
                {
                    var isUnmasked = (maskList != null && maskList[j]) ? 0.0f : 1.0f;
                    tensorProxy.data[agentIndex, j] = isUnmasked;
                }
                agentIndex++;
            }
        }
Esempio n. 14
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var actionSize = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var infoSensorPair in infos)
            {
                var info       = infoSensorPair.agentInfo;
                var pastAction = info.storedVectorActions;
                for (var j = 0; j < actionSize; j++)
                {
                    tensorProxy.data[agentIndex, j] = pastAction[j];
                }

                agentIndex++;
            }
        }
Esempio n. 15
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var agentIndex = 0;

            foreach (var infoSensorPair in infos)
            {
                var sensor = infoSensorPair.sensors[m_SensorIndex];
                if (infoSensorPair.agentInfo.done)
                {
                    // If the agent is done, we might have a stale reference to the sensors
                    // e.g. a dependent object might have been disposed.
                    // To avoid this, just fill observation with zeroes instead of calling sensor.Write.
                    TensorUtils.FillTensorBatch(tensorProxy, agentIndex, 0.0f);
                }
                else
                {
                    m_WriteAdapter.SetTarget(tensorProxy, agentIndex, 0);
                    sensor.Write(m_WriteAdapter);
                }
                agentIndex++;
            }
        }
Esempio n. 16
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var memorySize = (int)tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var infoSensorPair in infos)
            {
                var          info   = infoSensorPair.agentInfo;
                var          offset = memorySize * m_MemoryIndex;
                List <float> memory;
                if (info.done)
                {
                    m_Memories.Remove(info.episodeId);
                }
                if (!m_Memories.TryGetValue(info.episodeId, out memory))
                {
                    for (var j = 0; j < memorySize; j++)
                    {
                        tensorProxy.data[agentIndex, j] = 0;
                    }
                    agentIndex++;
                    continue;
                }
                for (var j = 0; j < memorySize; j++)
                {
                    if (j >= memory.Count)
                    {
                        break;
                    }

                    tensorProxy.data[agentIndex, j] = memory[j + offset];
                }
                agentIndex++;
            }
        }
Esempio n. 17
0
        public void Generate(
            TensorProxy tensorProxy, int batchSize, IEnumerable <Agent> agents)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);

            var memorySize = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex = 0;

            foreach (var agent in agents)
            {
                var          info = agent.Info;
                List <float> memory;

                if (agent.Info.done)
                {
                    m_Memories.Remove(agent.Info.id);
                }
                if (!m_Memories.TryGetValue(agent.Info.id, out memory))
                {
                    for (var j = 0; j < memorySize; j++)
                    {
                        tensorProxy.data[agentIndex, j] = 0;
                    }
                    agentIndex++;
                    continue;
                }
                for (var j = 0; j < Math.Min(memorySize, memory.Count); j++)
                {
                    if (j >= memory.Count)
                    {
                        break;
                    }
                    tensorProxy.data[agentIndex, j] = memory[j];
                }
                agentIndex++;
            }
        }
Esempio n. 18
0
        public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
        {
            TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
            var vecObsSizeT = tensorProxy.shape[tensorProxy.shape.Length - 1];
            var agentIndex  = 0;

            foreach (var info in infos)
            {
                if (info.agentInfo.done)
                {
                    // If the agent is done, we might have a stale reference to the sensors
                    // e.g. a dependent object might have been disposed.
                    // To avoid this, just fill observation with zeroes instead of calling sensor.Write.
                    TensorUtils.FillTensorBatch(tensorProxy, agentIndex, 0.0f);
                }
                else
                {
                    var tensorOffset = 0;
                    // Write each sensor consecutively to the tensor
                    foreach (var sensorIndex in m_SensorIndices)
                    {
                        var sensor = info.sensors[sensorIndex];
                        m_WriteAdapter.SetTarget(tensorProxy, agentIndex, tensorOffset);
                        var numWritten = sensor.Write(m_WriteAdapter);
                        tensorOffset += numWritten;
                    }
                    Debug.AssertFormat(
                        tensorOffset == vecObsSizeT,
                        "mismatch between vector observation size ({0}) and number of observations written ({1})",
                        vecObsSizeT, tensorOffset
                        );
                }

                agentIndex++;
            }
        }
Esempio n. 19
0
 public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
 {
     TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
     TensorUtils.FillTensorWithRandomNormal(tensorProxy, m_RandomNormal);
 }
Esempio n. 20
0
 public void Generate(TensorProxy tensorProxy, int batchSize, IEnumerable <AgentInfoSensorsPair> infos)
 {
     TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
 }
Esempio n. 21
0
 public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
 {
     TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
 }
Esempio n. 22
0
 public void Generate(TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
 {
     TensorUtils.ResizeTensor(tensorProxy, batchSize, _allocator);
     _randomNormal.FillTensor(tensorProxy);
 }
Esempio n. 23
0
 public void Generate(
     TensorProxy tensorProxy, int batchSize, Dictionary <Agent, AgentInfo> agentInfo)
 {
     TensorUtils.ResizeTensor(tensorProxy, batchSize, m_Allocator);
     TensorUtils.FillTensorWithRandomNormal(tensorProxy, m_RandomNormal);
 }