Reinforcement Learning
ml-agents
TensorBoard
ONNX
Pyramids
deep-reinforcement-learning
ML-Agents-Pyramids
Instructions to use AnnaMats/ppo-Pyramids-Training with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ml-agents
How to use AnnaMats/ppo-Pyramids-Training with ml-agents:
mlagents-load-from-hf --repo-id="AnnaMats/ppo-Pyramids-Training" --local-dir="./download: string[]s"
- Notebooks
- Google Colab
- Kaggle
| using System; | |
| using System.Collections.Generic; | |
| using Unity.MLAgents.Inference.Utils; | |
| using Random = System.Random; | |
| namespace Unity.MLAgents | |
| { | |
| /// <summary> | |
| /// Takes a list of floats that encode a sampling distribution and returns the sampling function. | |
| /// </summary> | |
| internal static class SamplerFactory | |
| { | |
| public static Func<float> CreateUniformSampler(float min, float max, int seed) | |
| { | |
| Random distr = new Random(seed); | |
| return () => min + (float)distr.NextDouble() * (max - min); | |
| } | |
| public static Func<float> CreateGaussianSampler(float mean, float stddev, int seed) | |
| { | |
| RandomNormal distr = new RandomNormal(seed, mean, stddev); | |
| return () => (float)distr.NextDouble(); | |
| } | |
| public static Func<float> CreateMultiRangeUniformSampler(IList<float> intervals, int seed) | |
| { | |
| //RNG | |
| Random distr = new Random(seed); | |
| // Will be used to normalize intervalFuncs | |
| float sumIntervalSizes = 0; | |
| //The number of intervals | |
| int numIntervals = (intervals.Count / 2); | |
| // List that will store interval lengths | |
| float[] intervalSizes = new float[numIntervals]; | |
| // List that will store uniform distributions | |
| IList<Func<float>> intervalFuncs = new Func<float>[numIntervals]; | |
| // Collect all intervals and store as uniform distrus | |
| // Collect all interval sizes | |
| for (int i = 0; i < numIntervals; i++) | |
| { | |
| var min = intervals[2 * i]; | |
| var max = intervals[2 * i + 1]; | |
| var intervalSize = max - min; | |
| sumIntervalSizes += intervalSize; | |
| intervalSizes[i] = intervalSize; | |
| intervalFuncs[i] = () => min + (float)distr.NextDouble() * intervalSize; | |
| } | |
| // Normalize interval lengths | |
| for (int i = 0; i < numIntervals; i++) | |
| { | |
| intervalSizes[i] = intervalSizes[i] / sumIntervalSizes; | |
| } | |
| // Build cmf for intervals | |
| for (int i = 1; i < numIntervals; i++) | |
| { | |
| intervalSizes[i] += intervalSizes[i - 1]; | |
| } | |
| Multinomial intervalDistr = new Multinomial(seed + 1); | |
| float MultiRange() | |
| { | |
| int sampledInterval = intervalDistr.Sample(intervalSizes); | |
| return intervalFuncs[sampledInterval].Invoke(); | |
| } | |
| return MultiRange; | |
| } | |
| } | |
| } | |