Skip to content

Instantly share code, notes, and snippets.

@gibrown
Created March 13, 2017 22:55
Show Gist options
  • Save gibrown/5ded937f53bf00605b0b98ba13df1b1d to your computer and use it in GitHub Desktop.
Save gibrown/5ded937f53bf00605b0b98ba13df1b1d to your computer and use it in GitHub Desktop.
Simple graphing of Elasticsearch scoring functions.
from __future__ import division
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from pylab import *
import math
from scipy.stats import beta, norm, uniform
from scipy.special import betaln
from random import random, normalvariate
import numpy as np
from datetime import *
import os
import time
def graph(x, y, title):
plt.plot(x, y)
plt.suptitle( title )
plt.show()
def gauss( origin, offset, scale, decay, abs_max, x_range, title ):
sigma = - scale**2 / ( 2 * math.log( decay ) )
x = np.array(x_range)
y = np.exp(-(np.maximum(0, np.absolute(x-origin) - offset)**2)/2/sigma)
if ( abs_max > 0 ):
y = np.minimum( abs_max, y )
graph( x, y, title )
return y
def exp( origin, offset, scale, decay, abs_max, x_range, title ):
l = math.log( decay ) / scale
x = np.array(x_range)
y = np.exp(l * np.maximum(0, np.absolute(x-origin) - offset))
if ( abs_max > 0 ):
y = np.minimum( abs_max, y )
graph( x, y, title )
return y
def log2p( mult, abs_max, x_range, title ):
x = np.array(x_range)
y = mult * np.log( x + 2 )
if ( abs_max > 0 ):
y = np.minimum( abs_max, y )
graph( x, y, title )
return y
def sqrt( mult, abs_max, x_range, title ):
x = np.array(x_range)
y = mult * np.sqrt( x )
if ( abs_max > 0 ):
y = np.minimum( abs_max, y )
graph( x, y, title )
return y
#################################
# Equations
sqrt( 0.1, 0, np.arange( 0, 1000000, 10 ), 'sqrt(active_installs) ' )
x = np.arange( 0, 1000000, 10 )
y1 = log2p( 0.375, 0, x, 'log2p(active_installs)' )
y2 = exp( 1000000, 0, 900000, 0.75, 0, x, 'exp(active_installs)' )
graph( x, y1 * y2, 'combined log2p(active_installs) * exp(active_installs)' )
log2p( 0.25, 0, x, 'active installs' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment