浏览代码

comments

/gridworld-custom-obs
Chris Elion 5 年前
当前提交
1a485482
共有 4 个文件被更改,包括 45 次插入16 次删除
  1. 51
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridSensorComponent.cs
  2. 1
      com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs
  3. 4
      com.unity.ml-agents/Runtime/SideChannels/SideChannelsManager.cs
  4. 5
      com.unity.ml-agents/Tests/Editor/SamplerTests.cs

51
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridSensorComponent.cs


// TODO use grid size from env parameters
int gridSize = 5;
/// <summary>
/// Creates a BasicSensor.
/// </summary>
/// <returns></returns>
public override ISensor CreateSensor()
{
return new GridSensor(gridArea, gridSize, pixelsPerCell);

public class GridSensor : ISensor
{
GridArea m_GridArea;
int m_PixlesPerCell;
int m_PixelsPerCell;
int m_GridSize;
int[] m_Shape;
const int k_NumChannels = 4;

m_GridArea = gridArea;
m_GridSize = gridSize;
m_PixlesPerCell = pixelsPerCell;
m_PixelsPerCell = pixelsPerCell;
m_Shape = new []{ gridSize * pixelsPerCell, gridSize * pixelsPerCell, k_NumChannels };
}

return m_Shape;
}
/// <inheritdoc/>
/// <summary>
/// Writes a one-hot encoding of the area state for the observations.
/// As a 3x3 example, for this area state:
///
/// A..
/// ..P
/// G..
///
/// The corresponding channels would be
/// channel 0 (empty)
/// 011
/// 110
/// 011
///
/// channel 1 (goal)
/// 000
/// 000
/// 100
///
/// channel 2 (pit)
/// 000
/// 001
/// 000
///
/// channel 3 (agent)
/// 100
/// 000
/// 000
///
/// </summary>
/// <param name="writer"></param>
/// <returns></returns>
// There is a minimum size to visual observations (see MIN_RESOLUTION_FOR_ENCODER in the python code)
// So repeat each cell m_PixelsPerCell times/
var height = m_GridSize * m_PixlesPerCell;
var width = m_GridSize * m_PixlesPerCell;
var height = m_GridSize * m_PixelsPerCell;
var width = m_GridSize * m_PixelsPerCell;
var i = h / m_PixlesPerCell;
var i = h / m_PixelsPerCell;
var j = w / m_PixlesPerCell;
var j = w / m_PixelsPerCell;
var cellVal = board[i, j];
for (var c = 0; c < k_NumChannels; c++)
{

1
com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs


{
return false;
}
}
else if (unityVersion.Major != pythonVersion.Major)
{

4
com.unity.ml-agents/Runtime/SideChannels/SideChannelsManager.cs


/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
internal static T GetSideChannel<T>() where T: SideChannel
internal static T GetSideChannel<T>() where T : SideChannel
return (T) sc;
return (T)sc;
}
}
return null;

5
com.unity.ml-agents/Tests/Editor/SamplerTests.cs


const int k_Seed = 1337;
const double k_Epsilon = 0.0001;
EnvironmentParametersChannel m_Channel;
public SamplerTests()
{
m_Channel = SideChannelsManager.GetSideChannel<EnvironmentParametersChannel>();

SideChannelsManager.RegisterSideChannel(m_Channel);
}
}
[Test]
public void UniformSamplerTest()
{

binaryWriter.Write(message.Length);
binaryWriter.Write(message);
}
return memStream.ToArray();
return memStream.ToArray();
}
}
}
正在加载...
取消
保存