Did I find the right examples for you? yes no

All Samples(48)  |  Call(48)  |  Derive(0)  |  Import(0)
Returns the variance & standard deviation of the input.
Ignores unknown and character values, if no values found besides
unknown it will just return 'None'.  Note this uses the population
stddev, not the stddev.

Inputs:
  - a dictionary of frequency distributions.  The value associated with
    the key indicates the frequency of the key.  If the key or value
    are not ints or floats it will attempt to convert them - at a cost
    in speed.  Exceptions will be ignored.(more...)

        def get_variance_and_stddev(values, mean=None):
    """ Returns the variance & standard deviation of the input.
        Ignores unknown and character values, if no values found besides
        unknown it will just return 'None'.  Note this uses the population
        stddev, not the stddev.

        Inputs:
          - a dictionary of frequency distributions.  The value associated with
            the key indicates the frequency of the key.  If the key or value
            are not ints or floats it will attempt to convert them - at a cost
            in speed.  Exceptions will be ignored.
            ex:  {1:5, 2:6] - indicating 5 occurances of 1 and 6 of 2
          - mean - optional, can be faster to provide it, but it will
            determine the mean if it's not provided.
        Outputs:
          - variance
          - stddev
        Test Coverage:
          - complete via test harness
        Further info:
          - calculator: http://easycalculation.com/statistics/standard-deviation.php
          - it will ignore non-numeric data
    """
    count   = 0
    accum   = 0

    if mean is None:
        mean = get_mean(values)

    for key in values:
        #accum += math.pow(mean - int(value), 2)  * int(values[value])
        #count += int(values[value])

        try:
            accum += math.pow(mean - key, 2)  * values[key]
            count += values[key]
        except TypeError:
            try:
                numeric_key   = number(key)
                numeric_count = number(values[key])
                accum += math.pow(mean - numeric_key, 2)  * numeric_count
                count += numeric_count
            except ValueError:
                pass # ignore this key/val, could be rare garbage 

    try:
        variance = accum / count
        stddev   = math.sqrt(variance)
        return variance, stddev
    except ZeroDivisionError:
        return None, None
        


src/d/a/datagristle-0.56/gristle/field_determinator.py   datagristle(Download)
                self.field_median[f_no] = mather.GetDictMedian().run(self.field_freqs[f_no])
                (self.variance[f_no], self.stddev[f_no])   \
                   =  mather.get_variance_and_stddev(self.field_freqs[f_no],
                                                     self.field_mean[f_no])
            else:

src/d/a/DataGristle-HEAD/gristle/field_determinator.py   DataGristle(Download)
                self.field_median[f_no] = mather.GetDictMedian().run(self.field_freqs[f_no])
                (self.variance[f_no], self.stddev[f_no])   \
                   =  mather.get_variance_and_stddev(self.field_freqs[f_no],
                                                     self.field_mean[f_no])
            else:

src/d/a/datagristle-0.56/gristle/tests/test_field_math.py   datagristle(Download)
    def test_math_empty_list(self):
        list_1   = {}
        list_1a  = (None, None)
        assert mod.get_variance_and_stddev(list_1) == list_1a
 
    def test_math_identical_single_number_occuring_once(self):
 
        list_1   = {2:1}
        list_1a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_1, 2) == list_1a
        list_1a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_1, 2) == list_1a
        assert mod.get_variance_and_stddev(list_1)    == list_1a
 
        list_2   = {2:1, 2:1,2:1}
        list_2a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_2, 2) == list_2a
        assert mod.get_variance_and_stddev(list_2)    == list_2a

src/d/a/DataGristle-HEAD/gristle/tests/test_field_math.py   DataGristle(Download)
    def test_math_empty_list(self):
        list_1   = {}
        list_1a  = (None, None)
        assert mod.get_variance_and_stddev(list_1) == list_1a
 
    def test_math_identical_single_number_occuring_once(self):
 
        list_1   = {2:1}
        list_1a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_1, 2) == list_1a
        list_1a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_1, 2) == list_1a
        assert mod.get_variance_and_stddev(list_1)    == list_1a
 
        list_2   = {2:1, 2:1,2:1}
        list_2a  = (0.0, 0.0)
        assert mod.get_variance_and_stddev(list_2, 2) == list_2a
        assert mod.get_variance_and_stddev(list_2)    == list_2a