浏览代码

merged sampler interfaces

/main
Steven Leal 4 年前
当前提交
baff24ea
共有 12 个文件被更改,包括 45 次插入50 次删除
  1. 14
      com.unity.perception/Editor/Randomization/SamplerElement.cs
  2. 3
      com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
  3. 9
      com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
  4. 19
      com.unity.perception/Runtime/Randomization/Samplers/ISampler.cs
  5. 18
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
  6. 2
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
  7. 2
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
  8. 2
      com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs
  9. 23
      com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs
  10. 3
      com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs.meta
  11. 0
      /com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs.meta
  12. 0
      /com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs

14
com.unity.perception/Editor/Randomization/SamplerElement.cs


void CreateSampler(Type samplerType)
{
var newSampler = (ISampler)Activator.CreateInstance(samplerType);
if (newSampler is IRandomRangedSampler rangedSampler)
{
rangedSampler.baseSeed = SamplerUtility.GenerateRandomSeed();
newSampler.baseSeed = SamplerUtility.GenerateRandomSeed();
if (m_RangeProperty != null)
rangedSampler.range = new FloatRange(
m_RangeProperty.FindPropertyRelative("minimum").floatValue,
m_RangeProperty.FindPropertyRelative("maximum").floatValue);
}
if (m_RangeProperty != null)
newSampler.range = new FloatRange(
m_RangeProperty.FindPropertyRelative("minimum").floatValue,
m_RangeProperty.FindPropertyRelative("maximum").floatValue);
m_Sampler = newSampler;
m_Property.managedReferenceValue = newSampler;

3
com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs


{
base.Validate();
foreach (var sampler in samplers)
if (sampler is IRandomRangedSampler rangedSampler)
rangedSampler.range.Validate();
sampler.range.Validate();
}
}
}

9
com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs


var i = 0;
foreach (var sampler in samplers)
{
sampler.Rebase(SamplerUtility.IterateSeed((uint)i++, SamplerUtility.largePrime));
sampler.IterateState(i++);
sampler.ResetState();
}
}

foreach (var sampler in samplers)
{
sampler.Rebase(SamplerUtility.GenerateRandomSeed());
sampler.baseSeed = SamplerUtility.GenerateRandomSeed();
sampler.ResetState();
}
}

public void ResetState(int scenarioIteration)
{
foreach (var sampler in samplers)
sampler.ResetState(scenarioIteration);
{
sampler.ResetState();
sampler.IterateState(scenarioIteration);
}
}
/// <summary>

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


public interface ISampler
{
/// <summary>
/// Resets a sampler's state to its base random seed
/// The base seed used to initialize this sampler's state
void ResetState();
uint baseSeed { get; set; }
/// Resets a sampler's state to its base random seed and then offsets said seed using an index value
/// The current random state of this sampler
/// </summary>
uint state { get; set; }
/// <summary>
/// A range bounding the values generated by this sampler
/// <param name="index">Often a the active scenario's currentIteration</param>
void ResetState(int index);
FloatRange range { get; set; }
/// Set the base seed value of this sampler
/// Resets a sampler's state to its base random seed
/// <param name="seed">The seed that will replace the sampler's current seed</param>
void Rebase(uint seed);
void ResetState();
/// <summary>
/// Deterministically offsets a sampler's state when generating values within a batched job

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


/// </summary>
public float value;
public uint baseSeed
{
get => SamplerUtility.largePrime;
set { }
}
public uint state
{
get => SamplerUtility.largePrime;
set { }
}
public FloatRange range
{
get => new FloatRange(value, value);
set { }
}
/// <summary>
/// Constructs a new ConstantSampler
/// </summary>

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


/// https://en.wikipedia.org/wiki/Truncated_normal_distribution
/// </summary>
[Serializable]
public struct NormalSampler : ISampler, IRandomRangedSampler
public struct NormalSampler : ISampler
{
Unity.Mathematics.Random m_Random;

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


/// Returns uniformly distributed random values within a designated range.
/// </summary>
[Serializable]
public struct UniformSampler : ISampler, IRandomRangedSampler
public struct UniformSampler : ISampler
{
Unity.Mathematics.Random m_Random;

2
com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs


namespace RandomizationTests.SamplerTests
{
public abstract class RangedSamplerTests<T> where T : struct, ISampler, IRandomRangedSampler
public abstract class RangedSamplerTests<T> where T : struct, ISampler
{
const int k_TestSampleCount = 30;
protected T m_BaseSampler;

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


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

3
com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs.meta


fileFormatVersion: 2
guid: 0f406605b3cb4d55b84b5955196c4911
timeCreated: 1597419465

/com.unity.perception/Tests/Runtime/Randomization/SamplerTests/RangedSamplerTests.cs.meta → /com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs.meta

/com.unity.perception/Tests/Runtime/Randomization/SamplerTests/RangedSamplerTests.cs → /com.unity.perception/Tests/Runtime/Randomization/SamplerTests/SamplerTestsBase.cs

正在加载...
取消
保存