This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, " ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = '') |