Mercurial Hosting > traffic-intelligence
diff python/utils.py @ 855:2277ab1a8141
added utility for lognorm estimation
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 27 Sep 2016 17:37:56 -0400 |
parents | 33d296984dd8 |
children | e310577cc0b8 |
line wrap: on
line diff
--- a/python/utils.py Thu Sep 22 17:50:35 2016 -0400 +++ b/python/utils.py Tue Sep 27 17:37:56 2016 -0400 @@ -5,10 +5,10 @@ import matplotlib.pyplot as plt from datetime import time, datetime from math import sqrt, ceil, floor -from scipy.stats import kruskal, shapiro +from scipy.stats import kruskal, shapiro, lognorm from scipy.spatial import distance from scipy.sparse import dok_matrix -from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf, savez, load as npload +from numpy import zeros, array, exp, sum as npsum, int as npint, arange, cumsum, median, isnan, ones, convolve, dtype, isnan, NaN, mean, ma, isinf, savez, load as npload, log datetimeFormat = "%Y-%m-%d %H:%M:%S" @@ -46,6 +46,11 @@ var = (exp(scale**2)-1)*exp(2*loc+scale**2) return mean, var +def fitLogNormal(x): + 'returns the fitted location and scale of the lognormal (general definition)' + shape, loc, scale = lognorm.fit(x, floc=0.) + return log(scale), shape + def sampleSize(stdev, tolerance, percentConfidence, printLatex = False): from scipy.stats.distributions import norm k = round(norm.ppf(0.5+percentConfidence/200., 0, 1)*100)/100. # 1.-(100-percentConfidence)/200.