public override void DoEpoch(float t, float round_t) { float[,] test2d; float[] test; this.FindBMU(); //Slice the pwinner row by row and do some great stuff m_PWinner = ParallelArrays.Evaluate(m_PWinner); Slice[] slices = new Slice[2]; for (int i = 0; i < m_Parent.DataSource.PatternCount; ++i) { slices[1] = new Slice(0, m_Parent.NeuronMap.GetLength(0)); slices[0] = new Slice(i, 1); FloatParallelArray s = ParallelArrays.Section(m_PWinner, slices); s = ParallelArrays.Evaluate(s); FloatParallelArray bmuw = ParallelArrays.DropDimension(ParallelArrays.InnerProduct(s, m_GPUWeight), 0); FloatParallelArray bmuc = ParallelArrays.InnerProduct(s, m_GPUCoord); //Compute distances to bmu DisposableFloatParallelArray bmucEvaluated = ParallelArrays.Evaluate(bmuc); //Workaround bmuc = ParallelArrays.Stretch(bmucEvaluated, m_Parent.NeuronMap.GetLength(0), 1); FloatParallelArray diff = ParallelArrays.Subtract(m_GPUCoord, bmuc); FloatParallelArray dist = ParallelArrays.Multiply(diff, diff); dist = ParallelArrays.Sum(dist, 1); dist = ParallelArrays.Multiply(-1.0f, dist); //Apply update formula FloatParallelArray constE = new FloatParallelArray((float)(Math.E), m_Parent.NeuronMap.GetLength(0)); FloatParallelArray sigma = new FloatParallelArray((float)(Math.Pow(Neighborhood(t, round_t) * 0.85, 2)), m_Parent.NeuronMap.GetLength(0)); FloatParallelArray lrate = new FloatParallelArray((float)LearningRate(t, round_t), m_Parent.NeuronMap.GetLength(0), m_Parent.DataSource.PatternLength); FloatParallelArray omeg = ParallelArrays.Divide(dist, sigma); //FloatParallelArray momeg = ParallelArrays.Pow(constE, omeg); FloatParallelArray momeg = ParallelArrays.Pow2(ParallelArrays.Log2(constE) * omeg); DisposableFloatParallelArray domeg = ParallelArrays.Evaluate(momeg); //Workaround omeg = ParallelArrays.AddDimension(domeg, 1); omeg = ParallelArrays.Stretch(omeg, 1, m_Parent.DataSource.PatternLength); FloatParallelArray sbmuw = ParallelArrays.AddDimension(bmuw, 0); sbmuw = ParallelArrays.Stretch(sbmuw, m_Parent.NeuronMap.GetLength(0), 1); m_GPUWeight = ((m_GPUWeight + ((sbmuw - m_GPUWeight) * omeg * lrate))); } m_GPUWeight = ParallelArrays.Evaluate(m_GPUWeight); }
public FloatParallelArray Pop() { if (IsEmpty) { throw new UnexpectedOperation(); } if (m_ContArray.Shape[0] - 1 == 0) { IsEmpty = true; return(m_ContArray); } Slice slc = new Slice(0, m_ContArray.Shape[0] - 1); FloatParallelArray popelem = ParallelArrays.Section(m_ContArray, slc); m_ContArray = ParallelArrays.Replicate(m_ContArray, m_ContArray.Shape[0] - 1); return(popelem); }