Skip to content

Instantly share code, notes, and snippets.

@pkaf
Created August 11, 2015 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkaf/042fa5b9707ea2f51090 to your computer and use it in GitHub Desktop.
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.
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