Ignore:
Timestamp:
08/18/15 22:09:24 (9 years ago)
Author:
tim
Message:

major code refactoring, better organizing location of library functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/nanownlib/stats.py

    r16 r20  
    77import gzip
    88import random
    9 import numpy
     9try:
     10    import numpy
     11except:
     12    sys.stderr.write('ERROR: Could not import numpy module.  Ensure it is installed.\n')
     13    sys.stderr.write('       Under Debian, the package name is "python3-numpy"\n.')
     14    sys.exit(1)
    1015
    1116# Don't trust numpy's seeding
     
    3136
    3237    return statistics.mean(products)
     38
     39   
     40def OLSRegression(x,y):
     41    #print(x,y)
     42    x = numpy.array(x)
     43    y = numpy.array(y)
     44    #A = numpy.vstack([x, numpy.ones(len(x))]).T
     45    #m, c = numpy.linalg.lstsq(A, y)[0] # broken
     46    #c,m = numpy.polynomial.polynomial.polyfit(x, y, 1) # less accurate
     47    c,m = numpy.polynomial.Polynomial.fit(x,y,1).convert().coef
     48
     49    #print(m,c)
     50
     51    #import matplotlib.pyplot as plt
     52    #plt.clf()
     53    #plt.scatter(x, y)
     54    #plt.plot(x, m*x + c, 'r', label='Fitted line')
     55    #plt.show()
     56   
     57    return (m,c)
    3358
    3459
Note: See TracChangeset for help on using the changeset viewer.