浏览代码

updated sampler api doc strings

/usim-randomization
Steven Leal 4 年前
当前提交
6fc1e7cb
共有 11 个文件被更改,包括 256 次插入47 次删除
  1. 3
      com.unity.perception/Editor/Randomization/ParameterElement.cs
  2. 23
      com.unity.perception/Runtime/Randomization/Samplers/FloatRange.cs
  3. 14
      com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs
  4. 17
      com.unity.perception/Runtime/Randomization/Samplers/ISampler.cs
  5. 41
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
  6. 67
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
  7. 57
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
  8. 3
      com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
  9. 25
      com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs
  10. 28
      com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs
  11. 25
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs

3
com.unity.perception/Editor/Randomization/ParameterElement.cs


{
addFolderButton.clicked += () =>
{
var folderPath = EditorUtility.OpenFolderPanel("Add Options From Folder", Application.dataPath, "Goober");
var folderPath = EditorUtility.OpenFolderPanel(
"Add Options From Folder", Application.dataPath, string.Empty);
if (folderPath == string.Empty)
return;
var categories = LoadAssetsFromFolder(folderPath, categoricalParameter.sampleType);

23
com.unity.perception/Runtime/Randomization/Samplers/FloatRange.cs


using System;
using Unity.Assertions;
/// <summary>
/// A struct representing a continuous range of values
/// </summary>
/// <summary>
/// The smallest value contained within the range
/// </summary>
/// <summary>
/// The largest value contained within the range
/// </summary>
/// <summary>
/// Constructs a float range
/// </summary>
/// <param name="min">The smallest value contained within the range</param>
/// <param name="max">The largest value contained within the range</param>
public FloatRange(float min, float max)
{
minimum = min;

/// <summary>
/// Assert whether this range is valid
/// </summary>
/// <exception cref="ArgumentException"></exception>
if (minimum > maximum)
throw new ArgumentException("Invalid sampling range");
Assert.IsTrue(minimum > maximum);
}
}
}

14
com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs


namespace UnityEngine.Perception.Randomization.Samplers
{
/// <summary>
/// An interface describing bounded random samplers
/// </summary>
/// <summary>
/// The base seed used to initialize this sampler's state
/// </summary>
/// <summary>
/// The current random state of this sampler
/// </summary>
/// <summary>
/// A range bounding the values generated by this sampler
/// </summary>
FloatRange range { get; set; }
}
}

17
com.unity.perception/Runtime/Randomization/Samplers/ISampler.cs


/// <summary>
/// Set the base seed value of this sampler
/// </summary>
/// <param name="seed"></param>
/// <param name="seed">The seed that will replace the sampler's current seed</param>
/// <param name="batchIndex">
/// The current job index
/// <param name="offsetIndex">
/// The index used to offset the sampler's state.
/// Typically set to either the current scenario iteration or a job's batch index.
void IterateState(int batchIndex);
void IterateState(int offsetIndex);
/// Generate one sample
/// Generates one sample
/// <returns>The generated sample</returns>
/// Schedule a job to generate multiple samples
/// Schedules a job to generate an array of samples
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of generated samples</returns>
NativeArray<float> Samples(int sampleCount, out JobHandle jobHandle);
}
}

41
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs


[SamplerDisplayName("Constant")]
public struct ConstantSampler : ISampler
{
/// <summary>
/// The value from which samples will be generated
/// </summary>
/// <summary>
/// Constructs a new ConstantSampler
/// </summary>
/// <param name="value">The value from which samples will be generated</param>
/// <summary>
/// Resets a sampler's state to its base random seed.
/// Note that there is no state to reset for ConstantSamplers.
/// </summary>
/// <summary>
/// Resets a sampler's state to its base random seed and then offsets said seed using an index value.
/// Note that ConstantSamplers do not have random states.
/// </summary>
/// <param name="index">Often a the active scenario's currentIteration</param>
/// <summary>
/// Set the base seed value of this sampler.
/// Note that ConstantSamplers do not have base seeds.
/// </summary>
/// <param name="seed">The seed that will replace the sampler's current seed</param>
public void IterateState(int batchIndex) { }
/// <summary>
/// Deterministically offsets a sampler's state when generating values within a batched job.
/// Note that ConstantSamplers do not have a state to iterate.
/// </summary>
/// <param name="offsetIndex">
/// The index used to offset the sampler's state.
/// Typically set to either the current scenario iteration or a job's batch index.
/// </param>
public void IterateState(int offsetIndex) { }
/// <summary>
/// Generates one sample
/// </summary>
/// <returns>The generated sample</returns>
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of generated samples</returns>
public NativeArray<float> Samples(int sampleCount, out JobHandle jobHandle)
{
return SamplerUtility.GenerateSamples(this, sampleCount, out jobHandle);

67
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs


{
Unity.Mathematics.Random m_Random;
/// <summary>
/// The mean of the normal distribution to sample from
/// </summary>
/// <summary>
/// The standard deviation of the normal distribution to sample from
/// </summary>
/// <summary>
/// The base seed used to initialize this sampler's state
/// </summary>
[field: SerializeField]
public FloatRange range { get; set; }
/// <summary>
/// The current random state of this sampler
/// </summary>
public uint state
{
get => m_Random.state;

public NormalSampler(float min, float max, float mean, float standardDeviation, uint seed=SamplerUtility.largePrime)
/// <summary>
/// A range bounding the values generated by this sampler
/// </summary>
[field: SerializeField]
public FloatRange range { get; set; }
/// <summary>
/// Constructs a normal distribution sampler
/// </summary>
/// <param name="min">The smallest value contained within the range</param>
/// <param name="max">The largest value contained within the range</param>
/// <param name="mean">The mean of the normal distribution to sample from</param>
/// <param name="standardDeviation">The standard deviation of the normal distribution to sample from</param>
/// <param name="baseSeed">The base random seed to use for this sampler</param>
public NormalSampler(
float min, float max, float mean, float standardDeviation, uint baseSeed=SamplerUtility.largePrime)
baseSeed = seed;
this.baseSeed = baseSeed;
/// <summary>
/// Resets a sampler's state to its base random seed
/// </summary>
/// <summary>
/// Resets a sampler's state to its base random seed and then offsets said seed using an index value
/// </summary>
/// <param name="index">Often a the active scenario's currentIteration</param>
public void ResetState(int index)
{
ResetState();

/// <summary>
/// Set the base seed value of this sampler
/// </summary>
/// <param name="seed">The seed that will replace the sampler's current seed</param>
public void IterateState(int batchIndex)
/// <summary>
/// Deterministically offsets a sampler's state when generating values within a batched job
/// </summary>
/// <param name="offsetIndex">
/// The index used to offset the sampler's state.
/// Typically set to either the current scenario iteration or a job's batch index.
/// </param>
public void IterateState(int offsetIndex)
state = SamplerUtility.IterateSeed((uint)batchIndex, state);
state = SamplerUtility.IterateSeed((uint)offsetIndex, state);
/// <summary>
/// Generates one sample
/// </summary>
/// <returns>The generated sample</returns>
public float Sample()
{
return SamplerUtility.TruncatedNormalSample(

/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of generated samples</returns>
public NativeArray<float> Samples(int sampleCount, out JobHandle jobHandle)
{
var samples = SamplerUtility.GenerateSamples(this, sampleCount, out jobHandle);

57
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs


{
Unity.Mathematics.Random m_Random;
[field: SerializeField]
public FloatRange range { get; set; }
/// <summary>
/// The base seed used to initialize this sampler's state
/// </summary>
/// <summary>
/// The current random state of this sampler
/// </summary>
public uint state
{
get => m_Random.state;

public UniformSampler(float min, float max, uint seed=SamplerUtility.largePrime)
/// <summary>
/// A range bounding the values generated by this sampler
/// </summary>
[field: SerializeField]
public FloatRange range { get; set; }
/// <summary>
/// Constructs a new uniform distribution sampler
/// </summary>
/// <param name="min">The smallest value contained within the range</param>
/// <param name="max">The largest value contained within the range</param>
/// <param name="baseSeed">The base random seed to use for this sampler</param>
public UniformSampler(float min, float max, uint baseSeed=SamplerUtility.largePrime)
baseSeed = seed;
this.baseSeed = baseSeed;
/// <summary>
/// Resets a sampler's state to its base random seed
/// </summary>
/// <summary>
/// Resets a sampler's state to its base random seed and then offsets said seed using an index value
/// </summary>
/// <param name="index">Often a the active scenario's currentIteration</param>
public void ResetState(int index)
{
ResetState();

/// <summary>
/// Set the base seed value of this sampler
/// </summary>
/// <param name="seed">The seed that will replace the sampler's current seed</param>
public void IterateState(int batchIndex)
/// <summary>
/// Deterministically offsets a sampler's state when generating values within a batched job
/// </summary>
/// <param name="offsetIndex">
/// The index used to offset the sampler's state.
/// Typically set to either the current scenario iteration or a job's batch index.
/// </param>
public void IterateState(int offsetIndex)
state = SamplerUtility.IterateSeed((uint)batchIndex, state);
state = SamplerUtility.IterateSeed((uint)offsetIndex, state);
/// <summary>
/// Generates one sample
/// </summary>
/// <returns>The generated sample</returns>
/// <summary>
/// Schedules a job to generate an array of samples
/// </summary>
/// <param name="sampleCount">The number of samples to generate</param>
/// <param name="jobHandle">The handle of the scheduled job</param>
/// <returns>A NativeArray of generated samples</returns>
public NativeArray<float> Samples(int sampleCount, out JobHandle jobHandle)
{
var samples = SamplerUtility.GenerateSamples(this, sampleCount, out jobHandle);

3
com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs


namespace UnityEngine.Perception.Randomization.Samplers
{
/// <summary>
/// A set of utility functions for defining sampler interfaces
/// </summary>
public static class SamplerUtility
{
internal const uint largePrime = 0x202A96CF;

25
com.unity.perception/Runtime/Randomization/Scenarios/FixedLengthScenario.cs


namespace UnityEngine.Perception.Randomization.Scenarios
{
/// <summary>
/// An example scenario where each scenario iteration runs for exactly one frame
/// A scenario that runs for a fixed number of frames during each iteration
/// <summary>
/// Constants describing the execution of this scenario
/// </summary>
/// <summary>
/// The number of frames to generate per iteration
/// </summary>
/// <summary>
/// The iteration index begin the simulation on
/// </summary>
/// <summary>
/// The total number of iterations to complete before the simulation terminates
/// </summary>
/// <summary>
/// Returns whether the current scenario iteration has completed
/// </summary>
/// <summary>
/// Returns whether the scenario has completed
/// </summary>
/// <summary>
/// Called before the scenario begins iterating
/// </summary>
public override void OnInitialize()
{
currentIteration = constants.startingIteration;

28
com.unity.perception/Runtime/Randomization/Scenarios/Scenario.cs


namespace UnityEngine.Perception.Randomization.Scenarios
{
/// <summary>
/// The base class of scenarios with serializable constants
/// </summary>
/// <typeparam name="T">The type of constants to serialize</typeparam>
/// <summary>
/// A construct containing serializable constants that control the execution of this scenario
/// </summary>
public override string OnSerialize()
{
return JsonUtility.ToJson(constants, true);
}
public override void OnDeserialize(string json)
{
constants = JsonUtility.FromJson<T>(json);
}
/// <summary>
/// Serializes this scenario's constants to a json file in the Unity StreamingAssets folder
/// </summary>
writer.Write(OnSerialize());
writer.Write(JsonUtility.ToJson(constants, true));
/// <summary>
/// Deserializes this scenario's constants from a json file in the Unity StreamingAssets folder
/// </summary>
/// <exception cref="ScenarioException"></exception>
OnDeserialize(jsonText);
constants = JsonUtility.FromJson<T>(jsonText);
}
}
}

25
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


namespace UnityEngine.Perception.Randomization.Scenarios
{
/// <summary>
/// The base class of all scenario classes
/// </summary>
/// <summary>
/// If true, this scenario will quit the Unity application when it's finished executing
/// </summary>
/// <summary>
/// When true, this scenario will deserializes constants from a Json file before it begins executing
/// </summary>
/// <summary>
/// The name of the Json file this scenario's constants are serialized to/from.
/// </summary>
[HideInInspector] public string serializedConstantsFileName = "constants";
/// <summary>

/// Called when the scenario has finished iterating
/// </summary>
public virtual void OnComplete() { }
/// <summary>
/// To be overriden in derived Scenario classes
/// </summary>
public abstract string OnSerialize();
/// <summary>
/// To be overriden in derived Scenario classes
/// </summary>
public abstract void OnDeserialize(string json);
/// <summary>
/// Serializes the scenario's constants to a JSON file located at serializedConstantsFilePath

正在加载...
取消
保存