This file contains 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
"""Local regression""" | |
# Author: Mathieu Blondel <mathieu@mblondel.org> | |
# License: BSD 3 clause | |
import numpy as np | |
from sklearn.base import BaseEstimator, RegressorMixin | |
from sklearn.metrics.pairwise import pairwise_kernels | |
from sklearn.linear_model import Ridge |
This file contains 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
# adapted from http://roscidus.com/desktop/node/413 | |
import socket | |
import gobject | |
def server(host, port): | |
'''Initialize server and start listening.''' | |
sock = socket.socket() | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
sock.bind((host, port)) |
This file contains 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 recv_count(): | |
try: | |
while True: | |
n = (yield) | |
print "T-minus", n | |
except GeneratorExit: | |
print "Kaboom!" | |
def ex1(): | |
r = recv_count() |
This file contains 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 | |
""" | |
Find the operations needed to sum up to TARGET by using all 4 numbers in NUMBERS. | |
""" | |
from itertools import permutations, product | |
NUMBERS = ["3","4","7","8"] | |
TARGET = 10.0 |
This file contains 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 random | |
""" | |
Find pi by the Monte-Carlo method. | |
area of a circle = pi r^2 | |
area of a square = (2r)^2 = 4 r^2 | |
Perform random uniform sampling between -1 and 1. | |
The proportion of points in the unit circle is: |
This file contains 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
# (C) 2011 Mathieu Blondel | |
# License: BSD 3 clause | |
import numpy as np | |
import numpy.linalg as linalg | |
import pylab as pl | |
from cvxopt import matrix, solvers | |
np.random.seed(0) |
This file contains 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 online_mean_variance(iterable): | |
mN = 0 | |
mM = 0.0 | |
mS = 0.0 | |
for x in iterable: | |
mN += 1 | |
nextM = mM + (x - mM) / mN | |
mS += (x - mM) * (x - nextM) |
This file contains 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
# (C) Mathieu Blondel 2012 | |
# License: BSD 3 clause | |
import numpy as np | |
from scipy.optimize import fmin_l_bfgs_b | |
from sklearn.base import BaseEstimator, RegressorMixin | |
from sklearn.utils.extmath import safe_sparse_dot |
This file contains 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
""" | |
Exercises for the Markov Chain Monte-Carlo (MCMC) course available at | |
http://users.aims.ac.za/~ioana/ | |
""" | |
import numpy as np | |
import numpy.linalg as la | |
import pylab | |
from scipy import stats |
This file contains 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
"""Variable-length curve averaging""" | |
# Author: Mathieu Blondel <mathieu@mblondel.org> | |
# License: BSD 3 clause | |
import numpy as np | |
from scipy.interpolate import interp1d | |
def curves_mean_std(X, Y, kind="linear"): |
OlderNewer