/// <summary>
 ///   Constructs a new Receiver Operating Characteristic point.
 /// </summary>
 internal Point(ReceiverOperatingCharacteristic curve, double cutoff,
                int truePositives, int trueNegatives, int falsePositives, int falseNegatives)
     : base(truePositives, trueNegatives, falsePositives, falseNegatives)
 {
     this.curve  = curve;
     this.cutoff = cutoff;
 }
        /// <summary>
        ///   Compares two ROC curves.
        /// </summary>
        /// <param name="curve">The ROC curve to compare this to.</param>
        /// <param name="r">The amount of correlation between the two curves.</param>
        /// <returns></returns>
        public double Compare(ReceiverOperatingCharacteristic curve, double r)
        {
            // Areas
            double AUC1 = this.Area;
            double AUC2 = curve.Area;

            // Errors
            double se1 = this.Error;
            double se2 = curve.Error;

            // Standard error
            return((AUC1 - AUC2) / System.Math.Sqrt(se1 * se1 + se2 * se2 - 2 * r * se1 * se2));
        }
        public static void Test()
        {
            var realData = Util.ArrayInit(20, d => Bernoulli.Sample(0.5) ? 1.0 : 0.0);
            var testData = Util.ArrayInit(20, d => Beta.Sample(1, 1));

            // Creates the Receiver Operating Curve of the given source
            var rocCurve = new ReceiverOperatingCharacteristic(realData, realData);

            // Compute the ROC curve with 20 points
            rocCurve.Compute(20);

            for (int i = 0; i < rocCurve.Points.Count; i++)
            {
                Console.WriteLine("ROC curve at point {0}: false positive rate {1:0.000}, true positive rate {2:0.000}, accuracy {3:0.000}", i, 1 - rocCurve.Points[i].Specificity, rocCurve.Points[i].Specificity, rocCurve.Points[i].Accuracy);
            }

            Console.WriteLine("Area under the ROC curve: {0:0.000}", rocCurve.Area);
        }