http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95120
Revision: 95120
Author: giovanni
Date: 2011-08-21 04:03:24 +0000 (Sun, 21 Aug 2011)
Log Message:
-----------
added find_peak function to lifecycle.cvsmooth
Modified Paths:
--------------
trunk/tools/wsor/editor_lifecycle/lifecycle/cvsmooth.py
Modified: trunk/tools/wsor/editor_lifecycle/lifecycle/cvsmooth.py
===================================================================
--- trunk/tools/wsor/editor_lifecycle/lifecycle/cvsmooth.py 2011-08-21
04:03:20 UTC (rev 95119)
+++ trunk/tools/wsor/editor_lifecycle/lifecycle/cvsmooth.py 2011-08-21
04:03:24 UTC (rev 95120)
@@ -1,5 +1,6 @@
import numpy as np
-from scipy.interpolate import splrep, splev
+from scipy.interpolate import splrep, splev, UnivariateSpline
+from scipy.optimize import fmin
def spsmooth(x, y, ye, **kwargs):
'''
@@ -42,4 +43,17 @@
return np.mean(best)
-
+def find_peak(x,y,ye,k=3):
+ '''
+ Finds maximum in time series (x_i, y_i) using smoothing splines
+
+ Parameters
+ ----------
+ x,y - data
+ ye - standard errors estimates
+ k - spline degree (must be <= 5)
+ '''
+ s = spsmooth(x, y, ye, k=k)
+ spl = UnivariateSpline(x, y, ye ** -1, k=k, s=s)
+ xp = fmin(lambda k : -spl(k), x.mean())
+ return xp, spl
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs