summaryrefslogtreecommitdiff
path: root/monkey/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'monkey/util.py')
-rw-r--r--monkey/util.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/monkey/util.py b/monkey/util.py
index 6d57d29..9648926 100644
--- a/monkey/util.py
+++ b/monkey/util.py
@@ -2,6 +2,7 @@
from heapq import heappush, heappop
import itertools
+import math
# A simple priority queue based on the heapq class.
class PQueue(object):
@@ -52,3 +53,11 @@ def get_line(text, n):
# Indent each line in [text] by [indent] spaces.
def indent(text, indent=2):
return '\n'.join([' '*indent+line for line in text.split('\n')])
+
+# Average in a list.
+def avg(l):
+ return sum(l)/len(l)
+
+# Logistic function.
+def logistic(x, L=1, k=1, x_0=0):
+ return L/(1+math.exp(-k*(x-x_0)))