Last active
November 9, 2015 14:18
-
-
Save pbowyer/2e257c7567d8ac8d0201 to your computer and use it in GitHub Desktop.
This gives different results on each platform we test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Please paste your output into a comment at | |
https://gist.github.com/pbowyer/2e257c7567d8ac8d0201 | |
""" | |
import scipy # Imported for version number only | |
from scipy.odr import Model, Data, ODR | |
from scipy.stats import linregress | |
import numpy as np | |
def orthoregress(x, y): | |
"""Perform an Orthogonal Distance Regression on the given data, | |
using the same interface as the standard scipy.stats.linregress function. | |
Arguments: | |
x: x data | |
y: y data | |
Returns: | |
[m, c, nan, nan, nan] | |
Uses standard ordinary least squares to estimate the starting parameters | |
then uses the scipy.odr interface to the ODRPACK Fortran code to do the | |
orthogonal distance calculations. | |
""" | |
linreg = linregress(x, y) | |
print(linreg) | |
mod = Model(f) | |
dat = Data(x, y) | |
od = ODR(dat, mod, beta0=linreg[0:2]) | |
out = od.run() | |
return list(out.beta) + [np.nan, np.nan, np.nan] | |
def f(p, x): | |
"""Basic linear regression 'model' for use with ODR""" | |
return (p[0] * x) + p[1] | |
###################################################### | |
# Start useful debugging code | |
###################################################### | |
import platform | |
import sys | |
def linux_distribution(): | |
try: | |
return platform.linux_distribution() | |
except: | |
return "N/A" | |
print("""Python version: %s | |
dist: %s | |
linux_distribution: %s | |
system: %s | |
machine: %s | |
platform: %s | |
uname: %s | |
version: %s | |
mac_ver: %s | |
""" % ( | |
sys.version.split('\n'), | |
str(platform.dist()), | |
linux_distribution(), | |
platform.system(), | |
platform.machine(), | |
platform.platform(), | |
platform.uname(), | |
platform.version(), | |
platform.mac_ver(), | |
)) | |
print("Numpy version: " + np.__version__) | |
print("Scipy version: " + scipy.__version__) | |
print("") | |
###################################################### | |
# End useful debugging code | |
###################################################### | |
x = np.arange(5).astype(np.float64) | |
y = np.array([3.5, 2.7, 6.8, 5.6, 9.7]).astype(np.float64) | |
res = orthoregress(x, y) | |
print(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another from the community: