Ejemplo n.º 1
0
        /// <summary>
        /// Estimates the unbiased population covariance from the provided samples.
        /// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
        /// Returns NaN if data has less than two entries or if any entry is NaN.
        /// </summary>
        /// <param name="samples1">A subset of samples, sampled from the full population.</param>
        /// <param name="samples2">A subset of samples, sampled from the full population.</param>
        public static double Covariance(this IEnumerable <double> samples1, IEnumerable <double> samples2)
        {
            var array1 = samples1 as double[];
            var array2 = samples2 as double[];

            return(array1 != null && array2 != null
                ? ArrayStatistics.Covariance(array1, array2)
                : StreamingStatistics.Covariance(samples1, samples2));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Estimates the unbiased population covariance from the provided samples.
 /// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
 /// Returns NaN if data has less than two entries or if any entry is NaN.
 /// Null-entries are ignored.
 /// </summary>
 /// <param name="samples1">A subset of samples, sampled from the full population.</param>
 /// <param name="samples2">A subset of samples, sampled from the full population.</param>
 public static double Covariance(this IEnumerable <double?> samples1, IEnumerable <double?> samples2)
 {
     if (samples1 == null)
     {
         throw new ArgumentNullException("samples1");
     }
     if (samples2 == null)
     {
         throw new ArgumentNullException("samples2");
     }
     return(StreamingStatistics.Covariance(samples1.Where(d => d.HasValue).Select(d => d.Value), samples2.Where(d => d.HasValue).Select(d => d.Value)));
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Estimates the unbiased population covariance from the provided samples.
 /// On a dataset of size N will use an N-1 normalizer (Bessel's correction).
 /// Returns NaN if data has less than two entries or if any entry is NaN.
 /// Null-entries are ignored.
 /// </summary>
 /// <param name="samples1">A subset of samples, sampled from the full population.</param>
 /// <param name="samples2">A subset of samples, sampled from the full population.</param>
 public static double Covariance(this IEnumerable <double?> samples1, IEnumerable <double?> samples2)
 {
     return(StreamingStatistics.Covariance(samples1.Where(d => d.HasValue).Select(d => d.Value), samples2.Where(d => d.HasValue).Select(d => d.Value)));
 }