Skip to content

Instantly share code, notes, and snippets.

View wassname's full-sized avatar
🙃

Michael J Clark wassname

🙃
View GitHub Profile
@the-winter
the-winter / Array-1 CodingBat JavaScript.ipynb
Created August 4, 2016 07:54
CodingBat/NodingBat JavaScript answers
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import praw
import time
seen = []
def main():
user_agent = ("User stalker 1.0")
r = praw.Reddit(user_agent=user_agent)
r.login('username', 'password')
@wassname
wassname / find_best_dummy_classification.py
Last active August 27, 2017 05:56
Try all dummy models in sklearn
# from https://gist.github.com/wassname/00b94dc7eb7220c136685fce782be3a4
from io import StringIO
import pandas as pd
import numpy as np
from sklearn import metrics
import sklearn
def parse_classification_report(classification_report):
"""Parse a sklearn classification report to a dict."""
return pd.read_fwf(
@wassname
wassname / 1README.md
Last active March 13, 2018 12:35
3Dflex.py

3Dflex.py

A script for calculating 3D flexure in python. Converted from GARRY QUINLAN's fortran program 3dflex.f.

This programme calculates the flexure for 3D elastic sheet where the sheet can have one of its 4 edges as a free edge. It uses a finite difference approach to the 3D flexure problem and lets Te, restoring force and ;loading vary in a random fashion. There are many comments written in the program to guide the user through.

INPUT:

@wassname
wassname / torch_isfinite.py
Last active August 22, 2018 05:53
pytorch isfinite: like numpy.isfinite but for torch tensors
def isfinite(x):
"""
Quick pytorch test that there are no nan's or infs.
note: torch now has torch.isnan
url: https://gist.github.com/wassname/df8bc03e60f81ff081e1895aabe1f519
"""
not_inf = ((x + 1) != x)
not_nan = (x == x)
return not_inf & not_nan
@asross
asross / figure_grid.py
Last active September 7, 2018 14:44
A helper to plot grids of graphs in matplotlib.pyplot
"""
Examples:
with figure_grid(5, 3) as grid:
grid.next()
# plot something
grid.next()
# plot something
# ...etc
@Kaixhin
Kaixhin / prob-notation.md
Last active November 15, 2018 11:25
Probability notation

Probability notation

Note: Great refresher/glossary on probability/statistics and related topics here

Notation Definition
X Random variable
P(X) Probability distribution over random variable X
X ~ P(X) Random variable X follows (~) the probability distribution P(X) *
@wassname
wassname / AdamStepLR.py
Created February 26, 2018 08:38
Combing pytorches adam and scheduled learning rate into one (for when the model doesn't have a callback for the scheduler)
class AdamStepLR(torch.optim.Adam):
"""Combine Adam and lr_scheduler.StepLR so we can use it as a normal optimiser"""
def __init__(self, params, lr=0.001, betas=(0.9, 0.999), eps=1e-08, weight_decay=0, step_size=50000, gamma=0.5):
super().__init__(params, lr, betas, eps, weight_decay)
self.scheduler = torch.optim.lr_scheduler.StepLR(self, step_size, gamma)
def step(self):
self.scheduler.step()
return super().step()
@wassname
wassname / numpy_dataset.py
Created May 8, 2018 07:02
NumpyDataset for pytorch (like tensordataset)
import torch.utils.data
class NumpyDataset(torch.utils.data.Dataset):
"""Dataset wrapping arrays.
Each sample will be retrieved by indexing array along the first dimension.
Arguments:
*arrays (numpy.array): arrays that have the same size of the first dimension.
@fvisin
fvisin / running_stats.py
Last active May 31, 2019 04:06
Running stats
class RunningStats:
"""Computes running mean and standard deviation
Adapted from:
*
<http://stackoverflow.com/questions/1174984/how-to-efficiently-\
calculate-a-running-standard-deviation>
* <http://mathcentral.uregina.ca/QQ/database/QQ.09.02/carlos1.html>
"""
def __init__(self):