Ejemplo n.º 1
0
        public override Curve CreateCurve(double[][] values)
        {
            Curve curve = new Curve();

            CurveBuilder.Sort(values);
            double threshold = values[0][0];
            int    pTotal    = CurveBuilder.GetClassCount(values, 1);

            int tpCounter  = 0;
            int fpCounter  = 0;
            int previousTp = 0;
            int previousFp = 0;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i][0] != threshold && (tpCounter + fpCounter) != 0)
                {
                    double precision =
                        tpCounter / (double)(tpCounter + fpCounter);
                    double recall = tpCounter / (double)pTotal;

                    if (!curve.IsEmpty)
                    {
                        // interpolating precision-recall points
                        interpolate(tpCounter, fpCounter, previousTp,
                                    previousFp, pTotal, curve);
                    }

                    Normalize(curve, precision, recall);
                    previousTp = tpCounter;
                    previousFp = fpCounter;

                    threshold = values[i][0];
                }

                if (values[i][1] == 1)
                {
                    tpCounter++;
                }
                else
                {
                    fpCounter++;
                }
            }

            // add the last point to the curve

            interpolate(tpCounter, fpCounter, previousTp, previousFp, pTotal,
                        curve);

            double p = tpCounter / (double)(tpCounter + fpCounter);
            double r = tpCounter / (double)pTotal;

            Normalize(curve, p, r);

            return(curve);
        }
Ejemplo n.º 2
0
        public override Curve CreateCurve(double[][] values)
        {
            Curve curve = new Curve();

            CurveBuilder.Sort(values);
            double threshold = values[0][0];
            double pTotal    = CurveBuilder.GetClassCount(values, 1);
            double nTotal    = CurveBuilder.GetClassCount(values, 0);

            int tpCounter = 0;
            int fpCounter = 0;

            double x = -1;
            double y = -1;

            for (int i = 0; i < values.Length; i++)
            {
                if (values[i][0] != threshold && (tpCounter + fpCounter) != 0)
                {
                    if (curve.IsEmpty)
                    {
                        curve.Add(0.0, 0.0);
                    }

                    x = (fpCounter == 0 ? 0.0 : fpCounter / nTotal);
                    y = (tpCounter == 0 ? 0.0 : tpCounter / pTotal);
                    curve.Add(x, y);
                    threshold = values[i][0];
                }

                if (values[i][1] == 1)
                {
                    tpCounter++;
                }
                else
                {
                    fpCounter++;
                }
            }

            // adds the last point to the curve

            x = (fpCounter == 0 ? 0.0 : fpCounter / nTotal);
            y = (tpCounter == 0 ? 0.0 : tpCounter / pTotal);
            curve.Add(x, y);
            curve.Add(1.0, 1.0);

            return(curve);
        }
Ejemplo n.º 3
0
        public Curve CreateCurve(double[][] values, double[] thresholds)
        {
            Curve curve = new Curve();

            CurveBuilder.Sort(values);
            Array.Sort(thresholds);

            int pTotal = CurveBuilder.GetClassCount(values, 1);

            int tpCounter  = 0;
            int fpCounter  = 0;
            int previousTp = 0;
            int previousFp = 0;
            int index      = 0;

            for (int i = (thresholds.Length - 1); i >= 0; i--)
            {
                while ((index < values.Length) &&
                       (values[index][0] >= thresholds[i]))
                {
                    if (values[index][1] == 1)
                    {
                        tpCounter++;
                    }
                    else
                    {
                        fpCounter++;
                    }

                    index++;
                }

                if ((previousTp != tpCounter) || (previousFp != fpCounter))
                {
                    double precision =
                        tpCounter / (double)(tpCounter + fpCounter);
                    double recall = tpCounter / (double)pTotal;

                    if (curve.IsEmpty)
                    {
                        curve.Add(0.0, precision);
                    }
                    else
                    {
                        // interpolating precision-recall points
                        interpolate(tpCounter, fpCounter, previousTp,
                                    previousFp, pTotal, curve);
                    }

                    Normalize(curve, precision, recall);
                    previousTp = tpCounter;
                    previousFp = fpCounter;
                }
            }

            // add the last point to the curve

            interpolate(tpCounter, fpCounter, previousTp, previousFp, pTotal,
                        curve);

            double p = tpCounter / (double)(tpCounter + fpCounter);
            double r = tpCounter / (double)pTotal;

            Normalize(curve, p, r);

            return(curve);
        }