Skip to content

Instantly share code, notes, and snippets.

Mathieu Blondel mblondel

Block or report user

Report or block mblondel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mblondel
mblondel / logsum.py
Created Apr 13, 2010
Logarithm of a sum without underflow
View logsum.py
import numpy as np
def _logsum(logx, logy):
"""
Return log(x+y), avoiding arithmetic underflow/overflow.
logx: log(x)
logy: log(y)
Rationale:
@mblondel
mblondel / echo_server.py
Created Jun 20, 2010
TCP/IP server using a main loop
View echo_server.py
# 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))
@mblondel
mblondel / coroutines.py
Created Jul 4, 2010
Python corountine examples
View coroutines.py
def recv_count():
try:
while True:
n = (yield)
print "T-minus", n
except GeneratorExit:
print "Kaboom!"
def ex1():
r = recv_count()
@mblondel
mblondel / hmm.tex
Created Jul 12, 2010
Good-looking HMM and Lattice diagrams using TikZ
View hmm.tex
% (C) Mathieu Blondel, July 2010
\documentclass[a4paper,10pt]{article}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{amsmath}
@mblondel
mblondel / second_order_ode.py
Created Jul 23, 2010
Solve second order differential equation using the Euler and the Runge-Kutta methods
View second_order_ode.py
#!/usr/bin/env python
"""
Find the solution for the second order differential equation
u'' = -u
with u(0) = 10 and u'(0) = -5
using the Euler and the Runge-Kutta methods.
@mblondel
mblondel / number_plate_solver.py
Created Jul 23, 2010
Solve Number plate game by generating and interpreting Forth programs
View number_plate_solver.py
#!/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
@mblondel
mblondel / mc_pi.py
Created Jul 25, 2010
Compute pi by MCMC
View mc_pi.py
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:
View mcmc_exercices.py
"""
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
@mblondel
mblondel / lda_gibbs.py
Last active Jun 19, 2019
Latent Dirichlet Allocation with Gibbs sampler
View lda_gibbs.py
"""
(C) Mathieu Blondel - 2010
License: BSD 3 clause
Implementation of the collapsed Gibbs sampler for
Latent Dirichlet Allocation, as described in
Finding scientifc topics (Griffiths and Steyvers)
"""
@mblondel
mblondel / svm.py
Last active Jun 19, 2019
Support Vector Machines
View svm.py
# Mathieu Blondel, September 2010
# License: BSD 3 clause
import numpy as np
from numpy import linalg
import cvxopt
import cvxopt.solvers
def linear_kernel(x1, x2):
return np.dot(x1, x2)
You can’t perform that action at this time.