Пример #1
0
 public WeakLearnPara(List <WeakLearn> pool, int start, int count, AdaBoost ada, ManualResetEvent doneEvent)
 {
     m_pool      = pool;
     m_start     = start;
     m_count     = count;
     m_ada       = ada;
     m_doneEvent = doneEvent;
 }
Пример #2
0
        /// <summary>
        /// foamliu, 2009/02/24, 初始化权重.
        ///
        /// </summary>
        private static void InitializeWeights(AdaBoost ada, ref double[] dist)
        {
            double vote = 1.0 / ada.m_m;

            for (int i = 0; i < ada.m_m; i++)
            {
                dist[i] = vote;
            }
        }
Пример #3
0
        /// <summary>
        /// foamliu, 2009/02/24, 更新权重分布.
        ///
        /// </summary>
        /// <param name="at"></param>
        /// <param name="ht"></param>
        private static void UpdateDistribution(AdaBoost ada, ref double[] dist, double at, WeakLearn ht)
        {
            for (int i = 0; i < ada.m_m; i++)
            {
                Example example = ada.m_t_set[i];

                int iResult = ht.Predict(example.X);

                // foamliu, 2009/03/04, 更新权重, example.Label.Id 和 iResult 可能的取值均为 -1和+1,
                // 当它们相同, 乘积为1, 整个项 > 0, 乘子 > 1, 权重提升;
                // 当它们不同, 乘积为-1, 整个项 < 0, 乘子 < 1, 权重下降.
                dist[i] = dist[i] * Math.Exp(-at * example.Label.Id * iResult);
            }
        }
Пример #4
0
        /// <summary>
        /// foamliu, 2009/02/24, 归一化权重分布.
        ///
        /// </summary>
        /// <param name="t"></param>
        private static void NormalizeDistribution(AdaBoost ada, ref double[] dist)
        {
            double sum = 0.0;

            for (int i = 0; i < ada.m_m; i++)
            {
                sum += dist[i];
            }

            double reciprocal = 1.0 / sum;

            for (int i = 0; i < ada.m_m; i++)
            {
                // foamliu, 2009/02/04, 优化.
                dist[i] *= reciprocal;
            }
        }