# HG changeset patch # User Jeff Hammel # Date 1513547735 28800 # Node ID 0f3af15bb29ac368253c4759ac9621e8a96b6288 # Parent 1b61ce99ee82df430410d1e5b4c85077ffcd34fd add noise introduction function diff -r 1b61ce99ee82 -r 0f3af15bb29a tvii/noise.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tvii/noise.py Sun Dec 17 13:55:35 2017 -0800 @@ -0,0 +1,20 @@ +""" +functions for noise addition +""" + +import random + +def add_noise(points, noise=None, fraction=0.01): + """ + add `noise` to `points` vector + + noise -- absolute magnitude of noise to add + fraction -- fraction of range of points to add, if `noise` not given + """ + + if noise is None: + span = max(points) - min(points) + noise = fraction*span + + return [x+noise*random.random() + for x in points]