# HG changeset patch # User Nicolas Saunier # Date 1475012276 14400 # Node ID 2277ab1a81412bcbf9dc0098b6f4e950931a0c47 # Parent 33d296984dd8172ec935501b1a912cb4dc70f181 added utility for lognorm estimation diff -r 33d296984dd8 -r 2277ab1a8141 python/utils.py --- 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.