Exemplo n.º 1
0
        /// <summary>
        ///   Computes a ROC curve with 1/increment points
        /// </summary>
        /// <param name="increment">The increment over the previous point for each point in the curve.</param>
        /// <param name="forceOrigin">True to force the inclusion of the (0,0) point, false otherwise. Default is false.</param>
        public void Compute(double increment, bool forceOrigin)
        {
            var    points = new List <ReceiverOperatingCharacteristicPoint>();
            double cutoff;

            // Create the curve, computing a point for each cutoff value
            for (cutoff = dfalse; cutoff <= dtrue; cutoff += increment)
            {
                points.Add(ComputePoint(cutoff));
            }


            // Sort the curve by descending specificity
            points.Sort(new Comparison <ReceiverOperatingCharacteristicPoint>(
                            delegate(ReceiverOperatingCharacteristicPoint a, ReceiverOperatingCharacteristicPoint b)
            {
                // First order by descending specifity
                int c = a.Specificity.CompareTo(b.Specificity);

                if (c == 0)     // then order by ascending sensitivity
                {
                    return(a.Sensitivity.CompareTo(b.Sensitivity));
                }
                else
                {
                    return(c);
                }
            }
                            ));

            if (forceOrigin)
            {
                var last = points[points.Count - 1];
                if (last.FalsePositiveRate != 0.0 || last.Sensitivity != 0.0)
                {
                    points.Add(ComputePoint(Double.PositiveInfinity));
                }
            }


            // Create the point collection
            this.collection = new ReceiverOperatingCharacteristicPointCollection(points.ToArray());

            // Calculate area and error associated with this curve
            this.area  = calculateAreaUnderCurve();
            this.error = calculateStandardError();
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Computes a ROC curve with the given increment points
        /// </summary>
        public void Compute(params double[] cutpoints)
        {
            List <ReceiverOperatingCharacteristicPoint> points = new List <ReceiverOperatingCharacteristicPoint>();

            // Create the curve, computing a point for each cutpoint
            for (int i = 0; i < cutpoints.Length; i++)
            {
                points.Add(ComputePoint(cutpoints[i]));
            }


            // Sort the curve by descending specificity
            points.Sort(new Comparison <ReceiverOperatingCharacteristicPoint>(
                            delegate(ReceiverOperatingCharacteristicPoint a, ReceiverOperatingCharacteristicPoint b)
            {
                // First order by descending specifity
                int c = a.Specificity.CompareTo(b.Specificity);

                if (c == 0)     // then order by ascending sensitivity
                {
                    return(a.Sensitivity.CompareTo(b.Sensitivity));
                }
                else
                {
                    return(c);
                }
            }
                            ));


            // Create the point collection
            this.collection = new ReceiverOperatingCharacteristicPointCollection(points.ToArray());

            // Calculate area and error associated with this curve
            this.area  = calculateAreaUnderCurve();
            this.error = calculateStandardError();
        }