예제 #1
0
        }//Init

        public void FindBMU()
        {
            //Useful locals
            int alen = m_Height * m_Width;

            //Compute the distances from pattern to code vectors
            FPA a    = PA.AddDimension(m_CurrentPatternGPU, 1);
            FPA x    = PA.Stretch(a, 1, alen);
            FPA pol  = PA.Subtract(m_Weights, x);
            FPA pol2 = PA.Multiply(pol, pol);
            FPA pol3 = PA.Sum(pol2, 0);

            m_Distances = PA.Sqrt(pol3);

            //Find the minimal distance
            FPA dist2  = PA.AddDimension(m_Distances, 1);
            FPA minval = PA.MinVal(dist2, 0);

            FPA xxx = PA.Stretch(minval, alen);

            //Prepare trigger array
            BPA trigger = PA.CompareEqual(xxx, m_Distances);

            //BMU Coord ZEROS
            BPA trigger2 = PA.AddDimension(trigger, 0);
            BPA trigger3 = PA.Stretch(trigger2, 2, 1);

            //Extract BMU Coord
            FPA lol = PA.Cond(trigger3, m_Shape, zeros);

            m_BMUCoord = PA.Sum(lol, 1);
            //m_BMUCoord = PA.Evaluate(m_BMUCoord);

            //BMU Code Vector ZEROS
            BPA triggercv2 = PA.AddDimension(trigger, 0);
            BPA triggercv3 = PA.Stretch(triggercv2, m_PatternLength, 1);

            //Extract BMU code vector
            FPA mdr = PA.Cond(triggercv3, m_Weights, zeroscv);

            m_BMUCodeVector = PA.Sum(mdr, 1);
            //m_BMUCodeVector = PA.Evaluate(m_BMUCodeVector);


            //Begin computation ! ^^ AND OUTPUT
            PA.Evaluate(m_BMUCodeVector);
            PA.Evaluate(m_BMUCoord);
        }
예제 #2
0
        public void DoEpoch(int nb)
        {
            int alen = m_Width * m_Height;

            for (int i = 0; i < nb; ++i)
            {
                //Neighborhood Function
                FPA sbmuc = PA.AddDimension(m_BMUCoord, 1);
                sbmuc = PA.Stretch(sbmuc, 1, alen);
                sbmuc = sbmuc - m_Shape;
                sbmuc = PA.Pow2(sbmuc);
                FPA sqdist = PA.Sum(sbmuc, 0);
                sqdist = PA.AddDimension(sqdist, 0);
                sqdist = PA.Stretch(sqdist, m_PatternLength, 1);
                //PA.Evaluate(sqdist);
                //

                //Learning Rate
                FPA lrate = new FPA((float)_CPU_LearningRate(m_time_val), m_PatternLength, alen);

                /*FPA sLearningRate = PA.AddDimension(LearningRate(m_Time), 1);
                 * sLearningRate = PA.Stretch(sLearningRate, m_PatternLength, alen);*/

                //Difference between units and current pattern
                FPA a   = PA.AddDimension(m_CurrentPatternGPU, 1);
                FPA x   = PA.Stretch(a, 1, alen);
                FPA pol = x - m_Weights;

                //Calcul des deltas
                FPA deltaW = lrate * pol;

                //Mise à jour des poids
                m_Weights = m_Weights + deltaW;

                //Incrémente le compteur de temps
                //m_Time = PA.Add(m_Time, 1.0f);
                m_time_val += 1;
            }
        }