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 | |
| from scipy.stats import norm | |
| # particle filter for localization using echolocation | |
| # given: measurements, accelerometer readings, heading | |
| # user's state: [x, y, theta] | |
| # control: d(theta), d(position) |
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
| # code to draw a DNA sequence logo... | |
| import matplotlib.pyplot as plt | |
| from matplotlib import transforms | |
| import matplotlib.patheffects | |
| import numpy as np | |
| def entropy(row): | |
| return -sum(x*np.log2(x+0.0000001) for x in row) |
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
| # Online k-means algorithm | |
| # see http://www.cs.princeton.edu/courses/archive/fall08/cos436/Duda/C/sk_means.htm | |
| import numpy as np | |
| def k_means(data, k, threshhold=2): | |
| """ | |
| Does k-means clustering of the data. | |
| Args: |
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
| #!/bin/bash | |
| for var in "$@"; do | |
| filename=${var%.*} | |
| #echo $filename | |
| #echo $@ | |
| echo "writing to $filename.html" | |
| pandoc $var --self-contained --toc -c /home/yjzhang/Dropbox/Notes/buttondown.css -s --mathml -o $filename.html | |
| done |
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
| cimport cython | |
| import numpy as np | |
| cimport numpy as np | |
| from libc.math cimport log2 | |
| ctypedef fused int2: | |
| short | |
| int |
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 password_gen(num_chars, chars): | |
| """ | |
| This is a generator | |
| that outputs all passwords of lowercase letters of length | |
| num_chars. | |
| Inputs: | |
| num_chars- the length of the password | |
| chars- a list of the characters that can be part of the password | |
| """ |
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
| # Plotting clusterings with matplotlib | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| def plot_clusterings(data, clusterings, k): | |
| """ | |
| Args: | |
| data - n x d numpy array | |
| clusterings - 1 x n numpy array, values from 0 to k-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
| from random import randint | |
| def random_string(n): | |
| return ''.join(chr(randint(0, 25) + ord('a')) for i in range(n)) |
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 os | |
| import binascii | |
| print binascii.hexlify(os.urandom(10)) | |
NewerOlder