Skip to content

Instantly share code, notes, and snippets.

View caffeine-potent's full-sized avatar

Otto Wagner caffeine-potent

View GitHub Profile
@caffeine-potent
caffeine-potent / map.geojson
Last active December 23, 2018 06:59
Extent collections of terminal for image recognition project.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@caffeine-potent
caffeine-potent / data.py
Last active February 14, 2017 15:29
Dynamic Allocation
class B:
def __init__(self):
self.data = []
def update(self, row):
for r in row:
self.data.append(r)
def finalize(self):
return np.reshape(self.data, newshape=(len(self.data)/5, 5))
ax = B()
@caffeine-potent
caffeine-potent / EpsilonGreedy.py
Created February 10, 2017 20:03
Epsilon Greedy from "Bandit Algorithms"
import numpy as np
class EpsGreedy()
def __init__(self, number_of_bandits, epsilon, start_greedy= True):
self.count = np.zeros(number_of_bandits)
self.scores = np.array([int(!start_greedy)] * number of bandits)
self.epsilon = epsilon
self.bandit_count = number_of_bandits
def select_arm():
choice = np.random.binomial(1,self.epsilon):
if choice = 1: #EXPLORE
import math
import random
def categorical_draw(probs):
'''
if
P(A) = .5
P(B) = .2
P(C) = .3
import math
import random
def categorical_draw(probs):
'''
if
P(A) = .5
P(B) = .2
P(C) = .3
@caffeine-potent
caffeine-potent / numdict.py
Last active February 23, 2017 18:40
select numerical keys in dictionary
my_dict = dict({
1 : "",
2 : "",
3 : "oyy",
"oyy" : "",
1990 : 's kid',
2000 : "a",
2014 : "b",
2015 : "c",
"foo" : "bar",
@caffeine-potent
caffeine-potent / extending_dict_some_more.py
Created February 23, 2017 19:12
Extending Dict to Ask for user input.
class info(dict):
def add_item(self, item_name, question, type = None):
answer = raw_input(question)
if type is not None:
answer = type(answer)
self[item_name] = answer
a = info()
a.add_item("name", "What is your name? ")
a.add_item("quest", "What is your quest? ")
@caffeine-potent
caffeine-potent / stretch.py
Created July 13, 2017 18:54
Scraping for performance improvements without the use of C or CYTHON. Stretching an array for an image resolution matching issue.
def discrete_stretch(array, size):
""" Expands 2d array by some factor.
For example the following array is expanded by a factor of 3
[ 1 2 ]
[ 3 4 ]
[ 1 1 1 2 2 2]
[ 1 1 1 2 2 2]
[ 1 1 1 2 2 2]
@caffeine-potent
caffeine-potent / geom_mediod.py
Last active July 30, 2021 02:40
Geometric Median in one line of native python.
from scipy.spatial.distance import euclidean
points = [
[1,3],
[2,4],
[3,3],
[4,5],
[3,7],
[5,1],
[5,3],
@caffeine-potent
caffeine-potent / list_comp.py
Last active January 28, 2018 21:12
List comprehension with depth = 2
#
# Solution to a question posed in https://www.reddit.com/r/learnpython/comments/72ll3i/list_comprehension_help/
#
# def gen_function_that_can_be_one_lined(my_list):
# for i, x in enumerate(my_list):
# for y in x:
# yield ( i, y)
#
#List