Skip to content

Instantly share code, notes, and snippets.

View rayheberer's full-sized avatar
🏠
Working from home

Ray Heberer rayheberer

🏠
Working from home
View GitHub Profile
@rayheberer
rayheberer / continued_fraction.R
Created June 3, 2017 16:48
function that takes an arbitrary amount of numerics and returns a continued fraction (a + 1/(b+1/(c+...))) with a, b, c... being the order in which the arguments are passed into the function
# Use Reduce() to write a function for generating continued fractions. For example continued_fraction(4, 2, 6, 7) should return 4.462366.
continued_fraction = function(...) {
input.vector = as.numeric(c(...)) #since Reduce() acts on vectors, the arguments are first joined as a vector
return(Reduce(function(a,b) b + 1/a, rev(input.vector))) #rev() to reverse the order of the vector, so that the binary operation will work as intended
}
@rayheberer
rayheberer / precession.R
Last active June 8, 2017 15:31
calculate precession from a dataframe containing relevant info
precession_newt = function() {
celestial_bodies = rbind(planets, dwarfplanets, asteroids)
celestial_bodies = celestial_bodies[order(celestial_bodies$distance), ]
celestial_bodies = celestial_bodies[complete.cases(celestial_bodies), ]
precession = c(rep(0, nrow(celestial_bodies)))
mass_sun = 1.989 * 10**30
@rayheberer
rayheberer / sticky_sidebar.js
Last active June 9, 2017 18:36
implements sticky sidebars on crestonlibrary.com, which uses a child theme of theme.co's X
jQuery(function($){
var leftposition = $('.x-sidebar').position().left;
$(window).scroll(function(){
if( $(this).scrollTop() >= ( $('.x-main').offset().top - $('.x-navbar-wrap').height() - 10 )
&& ( $(this).scrollTop() < ( $('.x-main').height() + $('.x-main').offset().top - $('.widget_nav_menu').height() - $('.x-navbar-wrap').height() ) ) ) {
$('.x-sidebar').css({position:'fixed', top:( $('.x-navbar-wrap').height() + 10 ),
left: leftposition });
}
else if ( $(this).scrollTop() >= ( $('.x-main').height() + $('.x-main').offset().top - $('.widget_nav_menu').height() - $('.x-navbar-wrap').height() ) ) {
from utils import *
import ast
row_units = [cross(r, cols) for r in rows]
column_units = [cross(rows, c) for c in cols]
square_units = [cross(rs, cs) for rs in ('ABC','DEF','GHI') for cs in ('123','456','789')]
# TODO: Update the unit list to add the new diagonal units
left_diag_units = [[r+c for (r, c) in zip(rows, cols)]]
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV, RandomizedSearchCV
X, y = load_iris(return_X_y=True)
np.random.seed(41)
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import load_iris
data = load_iris()
fig, axes = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(hspace=0.5)
fig.suptitle('Distributions of Iris Features')
for ax, feature, name in zip(axes.flatten(), data.data.T, data.feature_names):
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from sklearn.datasets import load_iris
data = load_iris()
fig, axes = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(hspace=0.5)
fig.suptitle('Distributions of Iris Features')
class DQNMoveOnly(base_agent.BaseAgent):
# ...
# ...
# ...
# ...
def _update_target_network(self):
online_vars = tf.get_collection(
tf.GraphKeys.TRAINABLE_VARIABLES, 'DQN')
target_vars = tf.get_collection(
tf.GraphKeys.TRAINABLE_VARIABLES, 'DQNTarget')
class AtariNet(object):
# ...
# ...
# ...
def _build(self):
# ...
# ...
self.screen_features = tf.placeholder(
tf.int32,
[None, len(SCREEN_FEATURES), *self.screen_dimensions],
def preprocess_spatial_features(features, screen=True):
"""Embed categorical spatial features, log transform numeric features."""
# ...
# ...
preprocess_ops = []
for index, (feature_type, scale) in enumerate(feature_specs):
layer = transposed[:, :, :, index]
if feature_type == sc2_features.FeatureType.CATEGORICAL:
# one-hot encode in channel dimension -> 1x1 convolution