Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Space1.cs
Go to the documentation of this file.
1 using System;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Utilities.Structs {
10  [Serializable]
11  public struct Space1 : ISpace {
16 
20  public float _Min_Value;
21 
25  public float _Max_Value;
26 
27  [SerializeField] bool normalised;
28 
32  [SerializeField]
34 
36  get { return this._distribution_sampler; }
37  set { this._distribution_sampler = value; }
38  }
39 
40  public Space1(int decimal_granularity = 2) : this() {
41  this._Decimal_Granularity = decimal_granularity;
42  this._Min_Value = -1f; //float.NegativeInfinity;
43  this._Max_Value = 1f; //float.PositiveInfinity;
44 
45  this._distribution_sampler = new DistributionSampler();
46  }
47 
52  public dynamic Sample() {
53  var x = this.DistributionSampler.Range(this._Min_Value, this._Max_Value);
54 
55  return x;
56  }
57 
61  public float Span { get { return this._Max_Value - this._Min_Value; } }
62 
63  public float ClipNormaliseRound(float v) {
64  if (v > this._Max_Value) {
65  v = this._Max_Value;
66  } else if (v < this._Min_Value) {
67  v = this._Min_Value;
68  }
69 
70  return this.Round((v - this._Min_Value) / this.Span);
71  }
72 
73  public Vector2 ToVector2() { return new Vector2(this._Min_Value, this._Max_Value); }
74 
75  public Vector3 ToVector3() {
76  return new Vector3(this._Min_Value, this._Max_Value, this._Decimal_Granularity);
77  }
78 
79  public string Vector3Description() { return "Motion Space (min, max, granularity)"; }
80 
81  public float Round(float v) { return (float)Math.Round(v, this._Decimal_Granularity); }
82 
83  public static Space1 TwentyEighty { get { return new Space1(1) {_Min_Value = 0.2f, _Max_Value = 0.8f}; } }
84 
85  public static Space1 ZeroOne { get { return new Space1(1) {_Min_Value = 0, _Max_Value = 1}; } }
86  public int DecimalGranularity { get { return this._Decimal_Granularity; } }
87 
91  public Boolean IsNormalised { get { return this.normalised; } set { this.normalised = value; } }
92 
93  public static Space1 MinusOneOne { get { return new Space1(1) {_Min_Value = -1, _Max_Value = 1}; } }
94  public static Space1 DiscreteZeroOne { get { return new Space1(0) {_Min_Value = 0, _Max_Value = 1}; } }
95  }
96 }
Space1(int decimal_granularity=2)
Definition: Space1.cs:40
DistributionSampler _distribution_sampler
Definition: Space1.cs:33