Created
August 11, 2015 10:13
-
-
Save pkaf/042fa5b9707ea2f51090 to your computer and use it in GitHub Desktop.
Returns a normal pdf at grid x that can be used as an error distribution. Here, grid x is linearly spaced between -cutoff to +cutoff sigma of the loc.
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
import scipy.stats as st | |
import numpy as np | |
def err_pdf( loc, scale, size=15, cutoff=5): | |
""" | |
PURPOSE | |
-------- | |
Returns gaussian pdf at grid x that can be used as an error distribution. | |
Here, grid x is linearly spaced between -cutoff to +cutoff sigma of the loc. | |
INPUT | |
------ | |
loc = scalar or a vector | |
scale = scalar or a vector | |
size = 15 #refinement of the grid. For small cutoff use larze size and viceversa. | |
cutoff = 3 #Grid is created between +-5*sigma (here, scale) on either side of loc | |
OUTPUT | |
------- | |
Gaussian(x) at corresponding x | |
""" | |
#Converting to an array, just in case | |
loc = np.array( loc, copy=False, ndmin=1) | |
scale = np.array( scale, copy=False, ndmin=1) | |
if cutoff<3: | |
print 'Are you sure you just want to use <+-3sigma value on either side?' | |
grid = loc + scale*np.linspace(-cutoff, cutoff, size)[:,None].repeat(loc.shape[0],axis=1) | |
err_pdf = st.norm.pdf( grid, loc=loc, scale=scale) | |
return err_pdf, grid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment