Skip to content

Instantly share code, notes, and snippets.

View samuel-bohman's full-sized avatar

Samuel samuel-bohman

  • Stockholm, Sweden
View GitHub Profile
# Takes an ordered vector of numeric values and returns a small bar chart made
# out of Unicode block elements. Works well inside dplyr mutate() or summarise()
# calls on grouped data frames.
sparkbar <- function(values) {
span <- max(values) - min(values)
if(span > 0 & !is.na(span)) {
steps <- round(values / (span / 7))
blocks <- c('', '', '', '', '', '', '', '')
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '')
# Inspired by https://medium.com/@tuzzer/cart-pole-balancing-with-q-learning-b54c6068d947
import gym
import numpy as np
import math
from collections import deque
class QCartPoleSolver():
def __init__(self, buckets=(1, 1, 6, 12,), n_episodes=1000, n_win_ticks=195, min_alpha=0.1, min_epsilon=0.1, gamma=1.0, ada_divisor=25, max_env_steps=None, quiet=False, monitor=False):
self.buckets = buckets # down-scaling feature space to discrete range
# Day 0: Mean, Median, and Mode
# Selecting standard input
con <- file('stdin', open='r')
# We don't need the first input
data_line <- readLines(con)[[2]]
# splitting the data into individual string
split_data <- strsplit(data_line, " ")