|
|
|
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using Unity.MLAgents; |
|
|
|
using UnityEngine; |
|
|
|
|
|
|
|
namespace Unity.MLAgents |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
public Func<float> CreateUniformSampler(float min, float max, int seed) |
|
|
|
{ |
|
|
|
System.Random distr = new System.Random(seed); |
|
|
|
Random distr = new Random(seed); |
|
|
|
return () => min + (float)distr.NextDouble() * (max - min); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public Func<float> CreateMultiRangeUniformSampler(IList<float> intervals, int seed) |
|
|
|
{ |
|
|
|
//RNG
|
|
|
|
System.Random distr = new System.Random(seed); |
|
|
|
Random distr = new Random(seed); |
|
|
|
int numIntervals = (int)(intervals.Count()/2); |
|
|
|
int numIntervals = (int)(intervals.Count/2); |
|
|
|
// List that will store interval lengths
|
|
|
|
float[] intervalSizes = new float[numIntervals]; |
|
|
|
// List that will store uniform distributions
|
|
|
|
|
|
|
for(int i = 0; i < numIntervals; i++) |
|
|
|
{ |
|
|
|
var min = intervals.ElementAt(2 * i); |
|
|
|
var max = intervals.ElementAt(2 * i + 1); |
|
|
|
var min = intervals[2 * i]; |
|
|
|
var max = intervals[2 * i + 1]; |
|
|
|
var intervalSize = max - min; |
|
|
|
sumIntervalSizes += intervalSize; |
|
|
|
intervalSizes[i] = intervalSize; |
|
|
|