public override void FindBMU() { //Normalize the weight vector FloatParallelArray transpose = ParallelArrays.Transpose(m_GPUWeight, 1, 0); FloatParallelArray weightsq = ParallelArrays.InnerProduct(m_GPUWeight, ParallelArrays.Transpose(m_GPUWeight, 1, 0)); FloatParallelArray weightsum = ParallelArrays.Sum(weightsq, 0); FloatParallelArray weightlength = ParallelArrays.Sqrt(weightsum); weightlength = ParallelArrays.Stretch(ParallelArrays.AddDimension(weightlength, 1), 1, m_Parent.DataSource.PatternLength); FloatParallelArray weightnorm = ParallelArrays.Divide(m_GPUWeight, weightlength); weightnorm = ParallelArrays.Transpose(weightnorm, 1, 0); //Normalize the input vector FloatParallelArray inputsq = ParallelArrays.InnerProduct(m_GPUInput, ParallelArrays.Transpose(m_GPUInput, 1, 0)); FloatParallelArray inputsum = ParallelArrays.Sum(inputsq, 0); FloatParallelArray inputlength = ParallelArrays.Sqrt(inputsum); inputlength = ParallelArrays.Stretch(ParallelArrays.AddDimension(inputlength, 1), 1, m_Parent.DataSource.PatternLength); FloatParallelArray inputnorm = ParallelArrays.Divide(m_GPUInput, inputlength); FloatParallelArray pacc = ParallelArrays.InnerProduct(inputnorm, weightnorm); //Replication bug here... FloatParallelArray bmxval = ParallelArrays.MaxVal(pacc, 1); //MSR Vivian Swelson workaround DisposableFloatParallelArray bmxvalEvaluated = ParallelArrays.Evaluate(bmxval); bmxval = ParallelArrays.AddDimension(bmxvalEvaluated, 1); bmxval = ParallelArrays.Stretch(bmxval, 1, m_Parent.NeuronMap.GetLength(0)); //Winner matrix (0 = winner) FloatParallelArray pwinner = ParallelArrays.Subtract(pacc, bmxval); //Convert to 1 = winner, 0 otherwise FloatParallelArray zero = new FloatParallelArray(0.0f, pwinner.Shape); FloatParallelArray one = new FloatParallelArray(1.0f, pwinner.Shape); BoolParallelArray bmask = ParallelArrays.CompareEqual(pwinner, zero); m_PWinner = ParallelArrays.Cond(bmask, one, zero); }