Ejemplo n.º 1
0
        public double GetTotalHappines()
        {
            Preferences data       = Preferences.GetInstance();
            int         Preference = 0;

            // Calculate matrix neurons weight
            for (int y = 0; y < m_height; y++)
            {
                for (int x = 0; x < m_width; x++)
                {
                    Neuron N = m_neurons[y, x];
                    if (0 < N.Value)
                    {
                        Preference += data.GetPreferenceByMen(y, x + 1) - 1;
                    }
                }
            }

            return((100.0 * (90.0 - Preference)) / 90.0);
        }
Ejemplo n.º 2
0
Archivo: Neuron.cs Proyecto: dovh/openu
        public virtual bool Calculate(bool verbose)
        {
            Preferences Data      = Preferences.GetInstance();
            double      A         = 1;
            double      B         = 1;
            double      C         = 1;
            double      D         = 1;
            double      prevValue = m_Value;

            int selfPreference = Data.GetPreferenceByMen(Y, X + 1);

            double newValue = 0;
            double Sum      = 0;

            foreach (Neuron Ni in m_Inputs)
            {
                if (0 < Ni.Value)
                {
                    if (Ni.Y == Y)
                    {
                        newValue -= A * Ni.Value;

                        Debug.Assert(selfPreference != Data.GetPreferenceByMen(Ni.Y, Ni.X + 1));
                        if (selfPreference > Data.GetPreferenceByMen(Ni.Y, Ni.X + 1))
                        {
                            newValue -= D * Ni.Value;
                        }
                        else
                        {
                            newValue += D * Ni.Value;
                        }
                    }

                    if (Ni.X == X)
                    {
                        newValue -= B * Ni.Value;

                        if ((selfPreference == Data.GetPreferenceByMen(Ni.Y, Ni.X + 1) && Value < Ni.Value) ||
                            selfPreference > Data.GetPreferenceByMen(Ni.Y, Ni.X + 1))
                        {
                            newValue -= D * Ni.Value;
                        }
                        else
                        {
                            newValue += D * Ni.Value;
                        }
                    }

                    Sum += Ni.Value;
                }
            }

            newValue -= C * (Sum - 10);
            newValue  = Math.Tanh(newValue);

            //m_Value = newValue;
            m_Value = 0.8 * prevValue + 0.2 * newValue;

            double Change = Math.Abs(m_Value / prevValue - 1);
            bool   Stable = Change < 0.0005;

            return(Stable);
        }