Skip to content

Instantly share code, notes, and snippets.

View JadenTravnik's full-sized avatar

JadenTravnik

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
h = np.zeros(n)
z = np.zeros(n)
w = np.random.random(n)
beta = np.random.random(n)
alpha = np.exp(beta)
theta = np.random.random()
def autostep_tidbd_step(n, representation, S_t, S_tp1, C, gamma, w, h, z, alpha, tau, lmbda, zeta, rho, omega):
def loading_bar(i_step, _max, div=100, character='\u25A1'):
if not i_step % (_max // div):
print(character, end='' if i_step < ((_max // div) * div) else '\n', flush=True)
for i in range(200):
loading_bar(i, 200)
@JadenTravnik
JadenTravnik / calc_true_return.py
Created November 12, 2018 20:20
Calculate true return from any signal
import numpy as np
def calculate_discounted_return_backwards(value, gamma, normalize=True):
ret = np.zeros(value.shape[0]) # initialize the array we hold our values in
i = value.shape[0]-1 # starting at the end, heading backwards
while i >= 0: # until we reach the start of the array
ret[i] += value[i] # add the
try: # we surround in a try catch in case we are at the start
ret[i] += (ret[i+1] * gamma) # we add the previous return with a decay
except: # if there was no ret[i+1]
@JadenTravnik
JadenTravnik / confusion_matrix.py
Last active June 29, 2018 15:36
One-liner Confusion Matrix
def confusion_matrix(yt, yp, nc):
"""
Returns a confusion matrix in the same format as sklearn.metrics.confustion_matrix
:param yt: list of true labels
:param yp: list of predictions
:param nc: number of classes
"""
return [[sum(v == (j, i) for v in zip(yp, yt)) for j in range(nc)] for i in range(nc)]
@JadenTravnik
JadenTravnik / EmailLogger.py
Last active June 28, 2018 19:02
Simple email logger for long python processes and commandline interface
from email.mime.text import MIMEText
from getpass import getpass
import smtplib
import argparse
class EmailLogger:
def __init__(self, subject, sender, receivers):
"""
Creates an EmailLogger object which can email messages from the sender to the reciever using gmail
@JadenTravnik
JadenTravnik / pretty_list.bash
Created April 11, 2018 13:24
print latest git branches color coded
git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
@JadenTravnik
JadenTravnik / get_n_colors.py
Last active December 16, 2019 23:24
python n random hex colors
import random
get_colors = lambda n: list(map(lambda i: "#" + "%06x" % random.randint(0, 0xFFFFFF),range(n)))
winter = lambda n: [f'#00{"%02x"%(255-i)}{"%02x"%i}' for i in np.arange(1,255, 255/n, int)]
#import numpy as np
#get_colors = lambda n: list(map(lambda i: "#" + "%06x" % np.random.randint(0, 0xFFFFFF),range(n)))
class Viking(object):
def __init__(self, arg):
if arg == 'add':
def dynamo(self, arg):
""" dynamo's a dynamic method!
"""
self.weight += 1
return arg + self.weight
self.weight = 50
@JadenTravnik
JadenTravnik / device_to_port.bash
Created March 2, 2018 16:33
This utility script prints out a list associating what devices are on what ports.
!#/bin/bash
# This utility script prints out a list associating what devices are on what ports.
for sysdevpath in $(find /sys/bus/usb/devices/usb*/ -name dev); do
(
syspath="${sysdevpath%/dev}"
devname="$(udevadm info -q name -p $syspath)"
[[ "$devname" == "bus/"* ]] && continue
eval "$(udevadm info -q property --export -p $syspath)"
[[ -z "$ID_SERIAL" ]] && continue
echo "/dev/$devname - $ID_SERIAL"