Skip to content

Instantly share code, notes, and snippets.

@jammycakes
Created May 27, 2012 21:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jammycakes/2815988 to your computer and use it in GitHub Desktop.
Save jammycakes/2815988 to your computer and use it in GitHub Desktop.
A script to attempt to predict how Git's popularity will increase over the next few years.
import math
import scipy.optimize
'''
This script attempts to predict how Git's popularity will increase
over the next few years by extrapolating the results of the annual
Eclipse Community Survey.
The forecast assumes that Git adoption is following an S-curve
(http://en.wikipedia.org/wiki/Sigmoid_function) up to an asymptotic
maximum value. Git's popularity would then be as follows:
p(t) = pmax / (1 + exp k(t0 - t))
where:
* p(t) is Git's popularity at time t
* pmax is the asymptotic maximum adoption which Git will attain
* t0 is the time at which Git adoption reaches 50% of pmax
* k is a constant scaling factor for time.
The forecast performs a least-squares fit to the data.
'''
points = (
(2009, 2.4),
(2010, 6.8),
(2011, 12.8),
(2012, 27.6)
)
def p(t, t0, pmax, k):
return pmax / (1 + math.exp(k * (t0 - t)))
def error(arg):
(t0, pmax, k) = arg
sqerr = 0
for point in points:
(t, pt) = point
e = p(t, t0, pmax, k) - pt
sqerr += (e*e)
return sqerr
initial_guess = [2013, 70, 1]
min = scipy.optimize.fmin(error, initial_guess, disp=False)
(t0, pmax, k) = min
print ('t0=' + str(t0) +', pmax=' + str(pmax) + ', k=' + str(k))
for year in range(2009, 2020):
print (str(year) + ': ' + str(p(year, t0, pmax, k)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment