Пример #1
0
 protected override int Test(FeatureVector vector, out double[] details)
 {
     // classify(v) = argmax(P(c)P(v|c)) = argmax_c(prob_c * prob_v_c)
     double[] v_logProb_c = new double[NoOfClasses];
     for (int c_i = 0; c_i < NoOfClasses; c_i++)
     {
         v_logProb_c[c_i] = CalculateLogProb_v_c(vector, c_i);
     }
     // Convert back from log to decimal format.
     NormalizationHelper.NormalizeLogs(v_logProb_c, 10);
     details = v_logProb_c;
     return(StatisticsHelper.ArgMax(details));
 }
        protected override int Test(FeatureVector vector, out double[] details)
        {
            double[] distribution = new double[NoOfClasses];

            // Do two things:
            // 1) Calculate the probability of a document belonging to class c_i, given document <c>vector</c>, and
            // 2) Calculate Z, which will be used to normalize the distribution shortly.
            for (int c_i = 0; c_i < NoOfClasses; c_i++)
            {
                double logProb = _lambda_c[c_i];
                for (int u_i = 0; u_i < vector.UsedFeatures.Length; u_i++)
                {
                    int f_i = vector.UsedFeatures[u_i];
                    logProb += CalculateLogProb_c_f(c_i, f_i);
                }
                distribution[c_i] = logProb;
            }
            NormalizationHelper.NormalizeLogs(distribution, Math.E);
            details = distribution;
            return(StatisticsHelper.ArgMax(details));
        }