Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
Space3.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 Space3 : ISpace {
15  [SerializeField]
17 
22  get { return this._distribution_sampler; }
23  set { this._distribution_sampler = value; }
24  }
25 
26  public Int32 DecimalGranularity {
27  get { return this._decimal_granularity; }
28  set { this._decimal_granularity = value; }
29  }
30 
32  public bool normalised;
33  public Boolean IsNormalised { get { return this.normalised; } set { this.normalised = value; } }
34 
35  public Vector3 _Min_Values;
36  public Vector3 _Max_Values;
37 
38  public Space3(DistributionSampler ds, int decimal_granularity = 1) : this() {
39  this._decimal_granularity = decimal_granularity;
40  this._Min_Values = Vector3.one * -100f;
41  this._Max_Values = Vector3.one * 100f; //Vector3.positiveInfinity;
42  this._distribution_sampler = new DistributionSampler();
43  }
44 
45  public Vector3 Span { get { return this._Max_Values - this._Min_Values; } }
46 
47  public dynamic Sample() {
48  var x = this.DistributionSampler.Range(this._Min_Values.x, this._Max_Values.x);
49  var y = this.DistributionSampler.Range(this._Min_Values.y, this._Max_Values.y);
50  var z = this.DistributionSampler.Range(this._Min_Values.z, this._Max_Values.z);
51 
52  return new Vector3(x, y, z);
53  }
54 
55  public Vector3 ClipNormaliseRound(Vector3 v) {
56  if (v.x > this._Max_Values.x) {
57  v.x = this._Max_Values.x;
58  } else if (v.x < this._Min_Values.x) {
59  v.x = this._Min_Values.x;
60  }
61 
62  if (this.Span.x > 0) {
63  v.x = this.Round((v.x - this._Min_Values.x) / this.Span.x);
64  } else {
65  v.x = 0;
66  }
67 
68  if (v.y > this._Max_Values.y) {
69  v.y = this._Max_Values.y;
70  } else if (v.y < this._Min_Values.y) {
71  v.y = this._Min_Values.y;
72  }
73 
74  if (this.Span.y > 0) {
75  v.y = this.Round((v.y - this._Min_Values.y) / this.Span.y);
76  } else {
77  v.y = 0;
78  }
79 
80  if (v.z > this._Max_Values.z) {
81  v.z = this._Max_Values.z;
82  } else if (v.z < this._Min_Values.z) {
83  v.z = this._Min_Values.z;
84  }
85 
86  if (this.Span.z > 0) {
87  v.z = this.Round((v.z - this._Min_Values.z) / this.Span.z);
88  } else {
89  v.z = 0;
90  }
91 
92  return v;
93  }
94 
100  public float Round(float v) { return (float)Math.Round(v, this.DecimalGranularity); }
101 
102  public Space1 Xspace {
103  get {
104  return new Space1(this.DecimalGranularity) {
105  _Min_Value = this._Min_Values.x,
106  _Max_Value = this._Max_Values.x
107  };
108  }
109  }
110 
111  public Space1 Yspace {
112  get {
113  return new Space1(this.DecimalGranularity) {
114  _Min_Value = this._Min_Values.y,
115  _Max_Value = this._Max_Values.y
116  };
117  }
118  }
119 
120  public Space1 Zspace {
121  get {
122  return new Space1(this.DecimalGranularity) {
123  _Min_Value = this._Min_Values.z,
124  _Max_Value = this._Max_Values.z
125  };
126  }
127  }
128 
135  public static Space3 operator+(Space3 b, Vector3 c) {
136  b._Min_Values += c;
137  b._Max_Values += c;
138  return b;
139  }
140 
147  public static Space3 operator-(Space3 b, Vector3 c) {
148  b._Min_Values -= c;
149  b._Max_Values -= c;
150  return b;
151  }
152 
159  public static Space3 operator-(Vector3 c, Space3 b) {
160  b._Min_Values -= c;
161  b._Max_Values -= c;
162  return b;
163  }
164 
171  public static Space3 operator+(Vector3 c, Space3 b) {
172  b._Min_Values += c;
173  b._Max_Values += c;
174  return b;
175  }
176 
181  public static Space3 ZeroOne {
182  get {
183  return new Space3(new DistributionSampler()) {_Min_Values = Vector3.zero, _Max_Values = Vector3.one};
184  }
185  }
186 
187  public static Space3 TwentyEighty {
188  get {
189  return new Space3(new DistributionSampler()) {
190  _Min_Values = Vector3.one * 0.2f,
191  _Max_Values = Vector3.one * 0.8f
192  };
193  }
194  }
195 
196  public static Space3 MinusOneOne {
197  get {
198  return new Space3(new DistributionSampler()) {_Min_Values = -Vector3.one, _Max_Values = Vector3.one};
199  }
200  }
201  }
202 }
static Space3 operator-(Space3 b, Vector3 c)
Definition: Space3.cs:147
Space3(DistributionSampler ds, int decimal_granularity=1)
Definition: Space3.cs:38
static Space3 operator+(Vector3 c, Space3 b)
Definition: Space3.cs:171
static Space3 operator+(Space3 b, Vector3 c)
Definition: Space3.cs:135
Vector3 ClipNormaliseRound(Vector3 v)
Definition: Space3.cs:55
DistributionSampler _distribution_sampler
Definition: Space3.cs:16
static Space3 operator-(Vector3 c, Space3 b)
Definition: Space3.cs:159