public override void DeleteTermsOperation() { foreach (var item in Terms) { if (item != null) { Terms.Variable x = item as Terms.Variable; x.Clean(); } } Terms.Clear(); }
public virtual unsafe Term GetTerm(Index time) { if (time.N != OuterShape.N) { throw new Exception(""); } int index = 0; int mult = 1; for (int i = time.N - 1; i >= 0; i--) { index += time[i] * mult; mult *= OuterShape[i]; if (time[i] < 0 || time[i] >= OuterShape[i]) { if (EmptyVariable == null) { EmptyVariable = new Terms.Variable(InnerShape.Clone()) { Trainable = false }; EmptyVariable.Weights.SetFloat(0); } else if (!EmptyVariable.Shape.EqualShape(InnerShape)) { EmptyVariable.Clean(); EmptyVariable = new Terms.Variable(InnerShape.Clone()) { Trainable = false }; EmptyVariable.Weights.SetFloat(0); } return(EmptyVariable); } } while (Terms.Count <= index) { Terms.Add(null); } if (Terms[index] == null) { return(Terms[index] = CreateTerm(time)); } return(Terms[index]); }
public Variable(Dimension[] OuterDimensions, Terms.Variable w, bool setzero = false, bool randomize = true, string RandMethod = "") { this.W = w; if (setzero) { W.Weights.SetFloat(0); } else if (randomize) { Randomiz.Randomize((float *)W.Weights.Array, W.Shape.TotalSize); } this.InnerShape = w.Shape.Clone(); this.InnerDimensions = new Dimension[w.Shape.N]; for (int i = 0; i < w.Shape.N; i++) { this.InnerDimensions[i] = w.Shape[i]; } this.OuterDimensions = OuterDimensions; }
public Variable(Dimension[] OuterDimensions, Shape s, bool setzero = false, bool randomize = true, string RandMethod = "") //add initializers etc { W = new Terms.Variable(s.Clone()); if (setzero) { W.Weights.SetFloat(0); } else if (randomize) { Randomiz.Randomize((float *)W.Weights.Array, s.TotalSize); } this.InnerShape = s; this.InnerDimensions = new Dimension[s.N]; for (int i = 0; i < s.N; i++) { this.InnerDimensions[i] = s[i]; } this.OuterDimensions = OuterDimensions; }