Ejemplo n.º 1
0
        public DecisionTreeClassifyer getBestDecisionTreeClassifyer(float[] w)
        {
            //最小誤り率を無限大に初期化
            float errMin = 10000;

            for (int r = 0; r < data[0].GetLength(0); r++)
            {
                for (int op = 0; op <= 1; op++)
                {
                    for (float v = this.min[r] - this.step[r]; v < this.min[r] + ((float)k + 1.0f) * this.step[r]; v += this.step[r])
                    {
                        float werr = 0.0f;
                        DecisionTreeClassifyer dtcf = new DecisionTreeClassifyer(v, r, op);
                        for (int j = 0; j < data.GetLength(0); j++)
                        {
                            werr += w[j] * (dtcf.classify(data[j]) == classElement[j] ? 0.0f : 1.0f);
                        }

                        if (errMin > werr)
                        {
                            best   = dtcf;
                            errMin = werr;
                        }
                    }
                }
            }

            return(best);
        }
Ejemplo n.º 2
0
 public DecisionTreeClassifyer[] boosting()
 {
     DecisionTreeClassifyer[] dtcf = new DecisionTreeClassifyer[k];
     for (int i = 0; i < k; i++)
     {
         SelectBestDecisitonTree sbdt = new SelectBestDecisitonTree(data, classElemnt, p);
         dtcf[i] = sbdt.getBestDecisionTreeClassifyer(w[i]);
         //Miの誤り率の計算
         errorM[i] = 0;
         for (int j = 0; j < data.GetLength(0); j++)
         {
             errorM[i] += w[i][j] * (dtcf[i].classify(data[j]) == classElemnt[j]? 0.0f:1.0f);
         }
         dtcf[i].error = errorM[i];
         if (i < k - 1)
         {
             for (int j = 0; j < data.GetLength(0); j++)
             {
                 if (dtcf[i].classify(data[j]) == classElemnt[j])
                 {
                     w[i + 1][j] = w[i][j] * (errorM[i] / (1.0f - errorM[i]));
                 }
             }
             float wsum = 0;
             for (int j = 0; j < data.GetLength(0); j++)
             {
                 wsum += w[i + 1][j];
             }
             for (int j = 0; j < data.GetLength(0); j++)
             {
                 w[i + 1][j] = w[i + 1][j] / wsum;
             }
         }
     }
     return(dtcf);
 }