from scipy import *
from scipy import stats
import pylab
import sys
sys.path.append("/home/ludger/lib/python2.6/site-packages/")
import statistics

####################################################

def gammaPDF(x, alpha, beta):
    return stats.gamma(alpha).pdf(x*beta)*beta

####################################################

def gammaSample(n, alpha, beta):
    return stats.gamma(alpha).rvs(n)/beta

####################################################

def kde(x, t, weights):
    weights = weights / sum(weights) * len(weights)
    return statistics.pdf(x, t, weights)

####################################################

n=100              
normal_sample = stats.norm().rvs(n)                # Generate sample from N(0,1)
weights = ones(n)
t = linspace(-3, 3, 100)                           # Grid at which density will be evaluated
density_estimate=kde(normal_sample, t, weights)    # Compute density estimate
pylab.figure()
pylab.plot(t, density_estimate)                    # Plot density estimate
pylab.show()

