Skip to content

Instantly share code, notes, and snippets.

@ansjsun
ansjsun / l-bfgs.py
Created January 15, 2014 13:22 — forked from yuyay/l-bfgs.py
import numpy as np
from scipy.optimize import fmin_bfgs
def rosen(x):
return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:1])**2.0)
def rosen_der(x):
xm = x[1:-1]
xm_m1 = x[:-2]
xm_p1 = x[2:]
@ansjsun
ansjsun / crf.py
Created November 8, 2013 03:56 — forked from neubig/crf.py
#!/usr/bin/python
# crf.py (by Graham Neubig)
# This script trains conditional random fields (CRFs)
# stdin: A corpus of WORD_POS WORD_POS WORD_POS sentences
# stdout: Feature vectors for emission and transition properties
from collections import defaultdict
from math import log, exp
import sys