d7054053ae
The word "Copyright" alone is sufficient to claim copyright, the (c) symbol need not be present.[1] As per PEP 263, a Python file with non-ASCII characters must have a line with "coding: <some-encoding>". Python files containing only 7-bit ASCII characters need no such line.[2] This commit removes unnecessary Unicode copyright symbols and unnecessary encoding lines. [1]: http://www.copyright.gov/circs/circ03.pdf [2]: http://legacy.python.org/dev/peps/pep-0263/ Closes-Bug: #1324686 Change-Id: Id381ea1f029a0cfddd3773c6d9f16c47842d9c33
67 lines
1.7 KiB
Python
67 lines
1.7 KiB
Python
#
|
|
# Copyright 2014 Red Hat, Inc
|
|
#
|
|
# Author: Eoghan Glynn <eglynn@redhat.com>
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
import math
|
|
|
|
|
|
def mean(s, key=lambda x: x):
|
|
"""Calculate the mean of a numeric list.
|
|
"""
|
|
count = float(len(s))
|
|
if count:
|
|
return math.fsum(map(key, s)) / count
|
|
return 0.0
|
|
|
|
|
|
def deltas(s, key, m=None):
|
|
"""Calculate the squared distances from mean for a numeric list.
|
|
"""
|
|
m = m or mean(s, key)
|
|
return [(key(i) - m) ** 2 for i in s]
|
|
|
|
|
|
def variance(s, key, m=None):
|
|
"""Calculate the variance of a numeric list.
|
|
"""
|
|
return mean(deltas(s, key, m))
|
|
|
|
|
|
def stddev(s, key, m=None):
|
|
"""Calculate the standard deviation of a numeric list.
|
|
"""
|
|
return math.sqrt(variance(s, key, m))
|
|
|
|
|
|
def outside(s, key, lower=0.0, upper=0.0):
|
|
"""Determine if value falls outside upper and lower bounds.
|
|
"""
|
|
v = key(s)
|
|
return v < lower or v > upper
|
|
|
|
|
|
def anomalies(s, key, lower=0.0, upper=0.0):
|
|
"""Separate anomalous data points from the in-liers.
|
|
"""
|
|
inliers = []
|
|
outliers = []
|
|
for i in s:
|
|
if outside(i, key, lower, upper):
|
|
outliers.append(i)
|
|
else:
|
|
inliers.append(i)
|
|
return inliers, outliers
|