private static void WeakLearnThread(object o) { WeakLearnPara para = (WeakLearnPara)o; for (int i = para.Start; i < para.Start + para.Count; i++) { WeakLearn learn = para.Pool[i]; learn.Distribution = para.AdaBoost.m_dist; learn.Train(); learn.CalcR(); } // foamliu, 2009/03/09, 完成, 通知主训练线程. para.DoneEvent.Set(); }
/// <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); } }