Skip to content

Instantly share code, notes, and snippets.

@teebu
Created November 13, 2020 02:08
Show Gist options
  • Save teebu/3b40e72e43e9e9fe15d232ed241cafea to your computer and use it in GitHub Desktop.
Save teebu/3b40e72e43e9e9fe15d232ed241cafea to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
from math import exp, log
def getGaussDecayValue(value,origin,scale,decay,offset=0):
# does this work?
z = -1*(scale**2)/(2*log(decay))
a = (-1* (max(0, abs(value - origin) - offset)**2))
value = exp(a/2*z)
return value
def getExpDecayValue(value, origin, scale, decay, offset=0):
z = log(decay) / scale
value = exp(z * max(0, abs(value - origin) - offset))
return value
def getDecayValue(type, value, origin, scale, decay, offset=0):
if type == 'exp':
return getExpDecayValue(value, origin, scale, decay, offset)
else:
return getGaussDecayValue(value, origin, scale, decay, offset)
def getApproachValue(type, value, bar, scale, decay, offset=0):
v = getDecayValue(type, value, 0, scale, decay, offset)
return (bar - (bar * v)) / bar
plt.axis([0, 100, 0, 1])
x = []
y = []
for score in range(0, 100, 5):
# what does bar do?
val = getApproachValue('exp', score, 10, 40, 0.20, 0)
print(score, '\t', val)
x.append(score)
y.append(val)
plt.plot(x, y)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment