Skip to content

Instantly share code, notes, and snippets.

@yosemitebandit
yosemitebandit / logistic_donut.py
Last active January 22, 2016 06:28
addressing the donut problem in logistic regression
import numpy as np
import matplotlib.pyplot as plt
N = 1000
H = N/2
D = 2
R_inner = 5
R_outer = 10
@yosemitebandit
yosemitebandit / cross_entropy.py
Last active January 22, 2016 06:28
looking at gradient descent with logistic regression
import numpy as np
N = 100
H = N/2
D = 2
# Generate a random point cloud.
X = np.random.randn(N, D)
# Create two classes with this data, centering the first class at (2, 2) and
@yosemitebandit
yosemitebandit / crop_to_path.py
Created November 18, 2015 04:51
cut an image out based on a path in python with Pillow, Numpy and Shapely
"""Crop a polygonal selection from an image."""
import numpy as np
from PIL import Image
from shapely.geometry import Point
from shapely.geometry import Polygon
im = Image.open('bird.jpg').convert('RGBA')
pixels = np.array(im)
im_copy = np.array(im)
@yosemitebandit
yosemitebandit / image_histogram.py
Created October 7, 2015 18:13
histogram of an image
import matplotlib.pyplot as plt
import numpy as np
from skimage import io
raw_image = io.imread('test.jpg')
figure_grid = gridspec.GridSpec(1, 1)
ax0 = plt.subplot(figure_grid[0, 0])
hist, bin_edges = np.histogram(raw_image, bins=np.arange(0, 256))
ax0.bar(bin_edges[:-1], hist, width=1)
plt.show()
@yosemitebandit
yosemitebandit / corners.py
Created September 29, 2015 06:49
trying to find "corners" of puzzle pieces
import numpy as np
import matplotlib.pyplot as plt
from skimage import feature
from skimage import filters
from skimage import io
from skimage import measure
# Load the image.
@yosemitebandit
yosemitebandit / serial_test.py
Created September 12, 2015 00:11
testing fona modules with serial commands on the beaglebone black
import Adafruit_BBIO.UART as UART
import serial
UART.setup("UART1")
ser = serial.Serial(port="/dev/ttyO1", baudrate=9600, timeout=1)
ser.close()
ser.open()
@yosemitebandit
yosemitebandit / core.clj
Last active September 2, 2015 18:39
pingping -- start of a pong game with quil
(ns pingping.core
(:import [java.awt.event KeyEvent])
(:require [quil.core :as q]))
(defn draw-rect [r]
(q/rect (:x r) (:y r) (:w r) (:h r)))
;; define left- and right-side rackets, as well as a ball and ball velocity
@yosemitebandit
yosemitebandit / Procfile
Created September 1, 2015 01:17
a clojure webapp with ring for deploying on heroku
web: java $JVM_OPTS -cp target/webdev.jar clojure.main -m webdev.core $PORT
@yosemitebandit
yosemitebandit / binary_search_tree.py
Created August 13, 2015 08:22
binary trees in python
class Node(object):
"""A node referencing other nodes, forming a subtree."""
def __init__(self, data):
self.left = None
self.right = None
self.data = data
def __repr__(self):
"""A (not-so-good) display."""
@yosemitebandit
yosemitebandit / queue.py
Created August 13, 2015 00:46
python FIFO queue
class Node(object):
def __init__(self, value):
self.value = value
self.next = None
def __repr__(self):
return 'Node %s' % self.value
class Queue(object):