Back to index

python-biopython  1.60
test_lowess.py
Go to the documentation of this file.
00001 # This code is part of the Biopython distribution and governed by its
00002 # license.  Please see the LICENSE file that should have been included
00003 # as part of this package.
00004 
00005 try:
00006     from numpy import array, median
00007 except ImportError:
00008     from Bio import MissingExternalDependencyError
00009     raise MissingExternalDependencyError(
00010         "Install NumPy if you want to use Bio.Statistics.lowess.")
00011 
00012 from Bio.Statistics.lowess import lowess
00013 import unittest
00014 
00015 class test_lowess(unittest.TestCase):
00016 
00017     def test_Precomputed(self):
00018         x = array([0.0, 1.0, 2.0, 3.0, 5.0, 9.0, 11.0])
00019         y = x**2
00020         # Precalculated smooth output
00021         ys = array([-2.96219015, 1.72680044, 6.58686813,
00022                     11.62986671, 28.18598762, 86.85271581, 116.83893423 ])
00023         # Smooth output calculated by the lowess function
00024         output = lowess(x, y, f=2./3., iter = 3)
00025         for precomputed, calculated in zip(ys, output):
00026             self.assertAlmostEqual(precomputed, calculated, places=4)
00027 
00028 if __name__ == "__main__":
00029     runner = unittest.TextTestRunner(verbosity = 2)
00030     unittest.main(testRunner=runner)