This file contains hidden or 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
# Source: @kastnerkyle | |
import numpy as np | |
import torch | |
import random | |
import os | |
default_seed=4142 | |
print("Setting all possible default seeds based on {}".format(default_seed)) | |
# try to get deterministic runs |
This file contains hidden or 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
function make_clicks() { | |
var x = document.evaluate( | |
"//div[@role='button' and contains(@id,'SmartShape_') and @class='cp-frameset']", | |
document, | |
null, | |
XPathResult.FIRST_ORDERED_NODE_TYPE, | |
null | |
).singleNodeValue; | |
if (x) { | |
x.click(); |
This file contains hidden or 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
import numpy as np | |
import scipy as sp | |
import scipy.optimize as opt | |
# Generate linear regression | |
a = 3 | |
b = 2 | |
n = 1000 | |
np.random.seed(42) | |
X = np.random.normal(loc=0, scale=4, size=(n,1)) |
This file contains hidden or 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
def sliding_window(a, win_size): | |
'''Slding window view of a 2D array a using numpy stride tricks. | |
For a given input array `a` and the output array `b`, we will have | |
`b[i] = a[i:i+w]` | |
Args: | |
a: numpy array of shape (N,M) | |
Returns: | |
numpy array of shape (K,w,M) where K=N-w+1 | |
''' |
This file contains hidden or 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
# typed from video: youtu.be/npw4s1QTmPg | |
# Raymond Gettinger, Modern Python Dictionaries: A confluence of a dozen great idea, PyCon 2017 | |
from __future__ import division, print_function | |
import array | |
import collections | |
import itertools | |
# Placeholder constants | |
FREE = -1 |
This file contains hidden or 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
def weighted_percentile(a, q, weights=None, interpolation='step'): | |
""" | |
Compute the qth percentile of the data a, optionally weight can be provided. | |
Returns the qth percentile(s) of the array elements. | |
Methodology | |
----------- | |
If weights are not provided, we set all `a` of equal weight of 1. Then we | |
normalize the weight by equal factor so that their sum is 1. Then, in sorted | |
ascending order of `a`, we plot the values as a curve from 0 to 1 and lookup |
This file contains hidden or 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
import socket | |
import socketserver | |
import threading | |
def sender(hostname, port, content): | |
"""Connect to a TCP port and send content, then wait for reply | |
""" | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: | |
sock.connect((hostname, port)) | |
sock.sendall(content) |
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
"""Provide class of a generic ANN for classification (using binary cross entropy) | |
""" | |
import numpy as np | |
# define activation functions g(Z), and their first derivative, using numpy | |
# hold all activation function pairs in a global dict |
This file contains hidden or 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
import argparse | |
from math import sin, cos, radians, gcd | |
from typing import Tuple, List | |
import numpy as np | |
from PIL import Image, ImageDraw | |
RADIANS = np.pi / 180 | |
DIMENSION = (500, 500) # coordinate origin at centre |
This file contains hidden or 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
"""Selecton rank algorithm | |
""" | |
import random | |
def selrank(array, start, stop, k): | |
"""return the k-th largest element (0-th = max) in sliced list | |
`array[start:stop]` using the selection rank algorithm | |
This move the larger elements of array to lower indices such that at the end |