public void AdaBoost_Test() { Logger.Info("AdaBoost_Test"); int hit = 0; double correctRatio; ClassificationProblem problem = ProblemFactory.CreateClassificationProblem(ClassificationProblemType.ChessBoard); AdaBoost classifier; ExampleSet t_set = problem.TrainingSet; ExampleSet v_set = problem.ValidationSet; classifier = new AdaBoost(t_set, 1000, problem.Dimension); classifier.Train(); foreach (Example e in v_set.Examples) { int iResult = classifier.Predict(e.X); if (e.Label.Id == iResult) { hit++; } } correctRatio = 1.0*hit / v_set.Count; Logger.Info("CorrectRatio: {0}", correctRatio); Assert.IsTrue(correctRatio > 0.900, string.Format("AdaBoost (2-class) Correct Ratio, expected: greater than 0.900, actual: {0}.", correctRatio)); }
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; }
/// <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; } }
/// <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.Examples[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); } }
/// <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; } }
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; }