Algorithm questions: Sample variance, sample standard deviation, variance, standard variance and weighted average

Source: Internet
Author: User
Tags arithmetic square root

Sample variance and sample standard deviation

1. Definition: The average of the difference between the data in the sample and the average of the sample is called the sample variance, and the arithmetic square root of the sample variance is called the sample standard deviation.

Note: Both the sample variance and the sample standard deviation measure the amount of a sample's fluctuation, the larger the sample variance or sample standard deviation, the greater the fluctuation of the sample data.

Standard deviation and standard variance

1. Definition: Variance is the average of the square sum of the difference between the data and the average. In probability and mathematical statistics, variance is used to measure the degree of deviation between the random variable and its mathematical expectation (i.e. mean value). Standard deviation is most commonly used as a measure of statistical distribution in probability statistics. The standard deviation is defined as the arithmetic square root of variance, which reflects the degree of dispersion among the individuals in the group.

Weighted average

1, definition: The weighted average number (weighted average) is the average of different gravity data, that is, the original data according to a reasonable proportion of the calculation.

The algorithm code is as follows:

public static double Standarddeviation (this ilist<double> source) {if (Source = null)
            {throw new ArgumentNullException ("source"); } if source. Count = = 0) {return double.
            NaN; Double variance = source.
    
            Variance ();
        return math.sqrt (variance); public static double Samplestandarddeviation (this ilist<double> source) {if (sou
            RCE = = null) {throw new ArgumentNullException ("source"); } if source. Count = 0 | | Source. Count = = 1) {return double.
            NaN; Double variance = source.
    
            Samplevariance ();
        return math.sqrt (variance);
         public static double variance (this ilist<double> source) {if (Source = null)   {throw new ArgumentNullException ("source"); } if source. Count = = 0) {return double.
            NaN; int count = source.
            Count ();
    
            Double deviation = calculatedeviation (source, count);
        return deviation/count; public static double Samplevariance (this ilist<double> source) {if (Source = = Nu
            LL) {throw new ArgumentNullException ("source");; } if source. Count = 0 | | Source. Count = = 1) {return double.
            NaN; int count = source.
            Count ();
    
            Double deviation = calculatedeviation (source, count);
        Return deviation/(count-1);
        public static double Weightedaverage (this ilist<double> source, ilist<double> factors) {if (Source = =NULL) {throw new ArgumentNullException ("source"); } if source. Count!= factors.
            Count) {throw new ArgumentException ("Source count isn't equal to factors count."); } if source. Count = = 0) {return double.
            NaN; Double sum = factors.
    
            Sum (); if (sum = = 0) {return double.
            NaN;
    
            Double weight = 0; for (int index = 0; index < factors. Count;
            index++) {weight + = Source[index] * (Factors[index]/sum);
        return weight; private static double calculatedeviation (ilist<double> source, int count) {Doubl e avg = source.
            Average ();
    
            Double deviation = 0;
     for (int index = 0; index < count; index++)       {deviation + = (Source[index]-avg) * (Source[index]-avg);
        return deviation; }

The above is used more in the financial aspect ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.