Skip to content

Instantly share code, notes, and snippets.

@karpathy
karpathy / pg-pong.py
Created May 30, 2016 22:50
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@Dante83
Dante83 / face_completion.py
Last active March 9, 2018 06:52
A modification of the facial completion code on Scikit learn, that attempts to implement the algorithm on an imported face titled me.jpg in the same folder. It was a great opportunity to learn about this part of scikit learn, which is a really great library. Note that ridge and linear regression both failed for me, so that I just commented them …
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import fetch_olivetti_faces
from sklearn.utils.validation import check_random_state
from scipy.ndimage import imread
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.neighbors import KNeighborsRegressor
from sklearn.linear_model import LinearRegression
#!/usr/bin/python
# Copyright (C) 2010 Michael Ligh
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@jorng
jorng / downloadWithProgress.py
Last active April 15, 2017 00:07
Function to download a file from a specified URL while outputting a progress bar to stdout.
#! /usr/bin/python
def downloadFileWithProgress(url, downloadFolder='./', sha1=None, chunk_size=8192):
import requests, sys
"""
Function to download a file from the specified URL.
Outputs a basic progress bar and download stats to the CLI.
Optionally downloads to a specified download folder, and checks the SHA1 checksum of the file.
Chunk size can also be specified, to control the download.
@stober
stober / softmax.py
Created March 1, 2012 03:05
Softmax in Python
#! /usr/bin/env python
"""
Author: Jeremy M. Stober
Program: SOFTMAX.PY
Date: Wednesday, February 29 2012
Description: Simple softmax function.
"""
import numpy as np
npa = np.array
@jtriley
jtriley / terminalsize.py
Created July 26, 2011 21:58
Get current terminal size on Linux, Mac, and Windows
#!/usr/bin/env python
import os
import shlex
import struct
import platform
import subprocess
def get_terminal_size():
""" getTerminalSize()