Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Space4.cs
Go to the documentation of this file.
1 using System;
4 using UnityEngine;
5 
6 namespace droid.Runtime.Utilities.Structs {
9  [Serializable]
10  public struct Space4 : ISpace {
14  public int DecimalGranularity {
15  get { return this._decimal_granularity; }
16  set { this._decimal_granularity = value; }
17  }
18 
22  [SerializeField]
24 
25  [SerializeField] bool normalised;
26 
28  get { return this._distribution_sampler; }
29  set { this._distribution_sampler = value; }
30  }
31 
35  public bool IsNormalised { get { return this.normalised; } set { this.normalised = value; } }
36 
40  public Vector4 _Min_Values;
41 
45  public Vector4 _Max_Values;
46 
51 
52  public Space4(int decimal_granularity = 2) : this() {
53  this._decimal_granularity = decimal_granularity;
54  this._Min_Values = Vector4.negativeInfinity;
55  this._Max_Values = Vector4.positiveInfinity;
56  this._distribution_sampler = new DistributionSampler();
57  }
58 
62  public Vector4 Span { get { return this._Max_Values - this._Min_Values; } }
63 
67  public Space1 Xspace {
68  get {
69  return new Space1(this.DecimalGranularity) {
70  _Min_Value = this._Min_Values.x,
71  _Max_Value = this._Max_Values.x
72  };
73  }
74  }
75 
79  public Space1 Yspace {
80  get {
81  return new Space1(this.DecimalGranularity) {
82  _Min_Value = this._Min_Values.y,
83  _Max_Value = this._Max_Values.y
84  };
85  }
86  }
87 
91  public Space1 Zspace {
92  get {
93  return new Space1(this.DecimalGranularity) {
94  _Min_Value = this._Min_Values.z,
95  _Max_Value = this._Max_Values.z
96  };
97  }
98  }
99 
103  public Space1 Wspace {
104  get {
105  return new Space1(this.DecimalGranularity) {
106  _Min_Value = this._Min_Values.w,
107  _Max_Value = this._Max_Values.w
108  };
109  }
110  }
111 
116  public dynamic Sample() {
117  var x = this.DistributionSampler.Range(this._Min_Values.x, this._Max_Values.x);
118  var y = this.DistributionSampler.Range(this._Min_Values.y, this._Max_Values.y);
119  var z = this.DistributionSampler.Range(this._Min_Values.z, this._Max_Values.z);
120  var w = this.DistributionSampler.Range(this._Min_Values.w, this._Max_Values.w);
121 
122  return new Vector4(x, y, z, w);
123  }
124 
129  public Quaternion RandomQuaternion() {
130  var vector = this.Sample();
131  return new Quaternion(vector.x, vector.y, vector.z, vector.w);
132  }
133 
139  public Vector4 ClipNormaliseRound(Vector4 v) {
140  if (v.x > this._Max_Values.x) {
141  v.x = this._Max_Values.x;
142  } else if (v.x < this._Min_Values.x) {
143  v = this._Min_Values;
144  }
145 
146  if (this.Span.x > 0) {
147  v.x = this.Round((v.x - this._Min_Values.x) / this.Span.x);
148  } else {
149  v.x = 0;
150  }
151 
152  if (v.y > this._Max_Values.y) {
153  v.y = this._Max_Values.y;
154  } else if (v.y < this._Min_Values.y) {
155  v = this._Min_Values;
156  }
157 
158  if (this.Span.y > 0) {
159  v.y = this.Round((v.y - this._Min_Values.y) / this.Span.y);
160  } else {
161  v.y = 0;
162  }
163 
164  if (v.z > this._Max_Values.z) {
165  v.z = this._Max_Values.z;
166  } else if (v.z < this._Min_Values.z) {
167  v = this._Min_Values;
168  }
169 
170  if (this.Span.z > 0) {
171  v.z = this.Round((v.z - this._Min_Values.z) / this.Span.z);
172  } else {
173  v.z = 0;
174  }
175 
176  if (v.w > this._Max_Values.w) {
177  v.w = this._Max_Values.w;
178  } else if (v.w < this._Min_Values.w) {
179  v = this._Min_Values;
180  }
181 
182  if (this.Span.w > 0) {
183  v.w = this.Round((v.w - this._Min_Values.w) / this.Span.w);
184  } else {
185  v.w = 0;
186  }
187 
188  return v;
189  }
190 
196  public float Round(float v) { return (float)Math.Round(v, this.DecimalGranularity); }
197 
201  public static Space4 ZeroOne {
202  get { return new Space4(1) {_Min_Values = Vector4.zero, _Max_Values = Vector4.one}; }
203  }
204 
208  public static Space4 TwentyEighty {
209  get { return new Space4(1) {_Min_Values = Vector4.one * 0.2f, _Max_Values = Vector4.one * 0.8f}; }
210  }
211 
215  public static Space4 MinusOneOne {
216  get { return new Space4(2) {_Min_Values = -Vector4.one, _Max_Values = Vector4.one}; }
217  }
218  }
219 }
Vector4 ClipNormaliseRound(Vector4 v)
Definition: Space4.cs:139
Space4(int decimal_granularity=2)
Definition: Space4.cs:52
DistributionSampler _distribution_sampler
Definition: Space4.cs:23