浏览代码

Merge pull request #442 from Unity-Technologies/dev-api-doc-decision

Fixes to Decision.cs
/develop-generalizationTraining-TrainerController
GitHub 6 年前
当前提交
9b2c759e
共有 5 个文件被更改,包括 107 次插入65 次删除
  1. 29
      unity-environment/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DDecision.cs
  2. 22
      unity-environment/Assets/ML-Agents/Examples/Basic/Scripts/BasicDecision.cs
  3. 31
      unity-environment/Assets/ML-Agents/Examples/SharedAssets/Scripts/RandomDecision.cs
  4. 19
      unity-environment/Assets/ML-Agents/Examples/Template/Scripts/TemplateDecision.cs
  5. 71
      unity-environment/Assets/ML-Agents/Scripts/Decision.cs

29
unity-environment/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DDecision.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
public class Ball3DDecision : MonoBehaviour, Decision

public float[] Decide(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public float[] Decide(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
if (gameObject.GetComponent<Brain>().brainParameters.vectorActionSpaceType == SpaceType.continuous)
if (gameObject.GetComponent<Brain>().brainParameters.vectorActionSpaceType
== SpaceType.continuous)
{
List<float> act = new List<float>();

act.Add(state[5] * rotationSpeed);
act.Add(vectorObs[5] * rotationSpeed);
act.Add(-state[7] * rotationSpeed);
act.Add(-vectorObs[7] * rotationSpeed);
else
{
return new float[1]{ 1f };
}
return new float[1] { 1f };
public List<float> MakeMemory(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public List<float> MakeMemory(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
{
return new List<float>();
}

22
unity-environment/Assets/ML-Agents/Examples/Basic/Scripts/BasicDecision.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
public float[] Decide(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public float[] Decide(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
return new float[1]{ 1f };
return new float[1] { 1f };
public List<float> MakeMemory(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public List<float> MakeMemory(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
}
}

31
unity-environment/Assets/ML-Agents/Examples/SharedAssets/Scripts/RandomDecision.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
public class RandomDecision : MonoBehaviour, Decision

public void Awake()
{
brainParameters =
brainParameters =
public float[] Decide(List<float> state, List<Texture2D> observation,
float reward, bool done, List<float> memory)
public float[] Decide(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
if (actionSpaceType == SpaceType.continuous)
{
List<float> act = new List<float>();

act.Add(2*Random.value-1);
act.Add(2 * Random.value - 1);
else
{
return new float[1] { Random.Range(0,actionSpaceSize) };
}
return new float[1] { Random.Range(0, actionSpaceSize) };
public List<float> MakeMemory(List<float> state,
List<Texture2D> observation, float reward,
bool done, List<float> memory)
public List<float> MakeMemory(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
{
return new List<float>();
}

19
unity-environment/Assets/ML-Agents/Examples/Template/Scripts/TemplateDecision.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
public float[] Decide(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public float[] Decide(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
public List<float> MakeMemory(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory)
public List<float> MakeMemory(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory)
}
}

71
unity-environment/Assets/ML-Agents/Scripts/Decision.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
/// Generic functions for Decision Interface
/// <summary>
/// Interface for implementing the behavior of an Agent that uses a Heuristic
/// Brain. The behavior of an Agent in this case is fully decided using the
/// implementation of these methods and no training or inference takes place.
/// Currently, the Heuristic Brain does not support text observations and actions.
/// </summary>
/// \brief Implement this method to define the logic of decision making
/// for the CoreBrainHeuristic
/** Given the information about the agent, return a vector of actions.
* @param state The state of the agent
* @param observation The cameras the agent uses
* @param reward The reward the agent had at the previous step
* @param done Whether or not the agent is done
* @param memory The memories stored from the previous step with MakeMemory()
* @return The vector of actions the agent will take at the next step
*/
float[] Decide(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory);
/// <summary>
/// Defines the decision-making logic of the agent. Given the information
/// about the agent, returns a vector of actions.
/// </summary>
/// <returns>Vector action vector.</returns>
/// <param name="vectorObs">The vector observations of the agent.</param>
/// <param name="visualObs">The cameras the agent uses for visual observations.</param>
/// <param name="reward">The reward the agent received at the previous step.</param>
/// <param name="done">Whether or not the agent is done.</param>
/// <param name="memory">
/// The memories stored from the previous step with
/// <see cref="MakeMemory(List{float}, List{Texture2D}, float, bool, List{float})"/>
/// </param>
float[] Decide(
List<float>
vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory);
/// \brief Implement this method to define the logic of memory making for
/// the CoreBrainHeuristic
/** Given the information about the agent, return the new memory vector for the agent.
* @param state The state of the agent
* @param observation The cameras the agent uses
* @param reward The reward the agent had at the previous step
* @param done Weather or not the agent is done
* @param memory The memories stored from the previous step with MakeMemory()
* @return The vector of memories the agent will use at the next step
*/
List<float> MakeMemory(List<float> state, List<Texture2D> observation, float reward, bool done, List<float> memory);
}
/// <summary>
/// Defines the logic for creating the memory vector for the Agent.
/// </summary>
/// <returns>The vector of memories the agent will use at the next step.</returns>
/// <param name="vectorObs">The vector observations of the agent.</param>
/// <param name="visualObs">The cameras the agent uses for visual observations.</param>
/// <param name="reward">The reward the agent received at the previous step.</param>
/// <param name="done">Whether or not the agent is done.</param>
/// <param name="memory">
/// The memories stored from the previous call to this method.
/// </param>
List<float> MakeMemory(
List<float> vectorObs,
List<Texture2D> visualObs,
float reward,
bool done,
List<float> memory);
}
正在加载...
取消
保存