Unity 机器学习代理工具包 (ML-Agents) 是一个开源项目,它使游戏和模拟能够作为训练智能代理的环境。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

75 行
1.5 KiB

using System.Collections.Generic;
using System.Collections.ObjectModel;
using Unity.MLAgents.Sensors;
using UnityEngine;
public class GoalSensorComponent : SensorComponent
{
public int observationSize;
public GoalSensor goalSensor;
/// <summary>
/// Creates a GoalSensor.
/// </summary>
/// <returns></returns>
public override ISensor CreateSensor()
{
goalSensor = new GoalSensor(observationSize);
return goalSensor;
}
/// <inheritdoc/>
public override int[] GetObservationShape()
{
return new[] { observationSize };
}
public void AddGoal(IEnumerable<float> goal)
{
if (goalSensor != null)
{
goalSensor.AddObservation(goal);
}
}
public void AddGoal(float goal)
{
if (goalSensor != null)
{
goalSensor.AddObservation(goal);
}
}
public void AddOneHotGoal(int goal, int range)
{
if (goalSensor != null)
{
goalSensor.AddOneHotObservation(goal, range);
}
}
public void AddGoal(Vector3 goal)
{
if (goalSensor != null)
{
goalSensor.AddObservation(goal);
}
}
}
public class GoalSensor : VectorSensor
{
public GoalSensor(int observationSize, string name = null) : base(observationSize)
{
if (name == null)
{
name = $"GoalSensor_size{observationSize}";
}
}
public override ObservationType GetObservationType()
{
return ObservationType.Goal;
}
}