Skip to content

Instantly share code, notes, and snippets.

@liangfu
liangfu / min-char-rnn.py
Created March 28, 2016 01:31 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@liangfu
liangfu / gist:eebbdb27c6a1fd616751
Created March 27, 2016 16:35 — forked from karpathy/gist:587454dc0146a6ae21fc
An efficient, batched LSTM.
"""
This is a batched LSTM forward and backward pass
"""
import numpy as np
import code
class LSTM:
@staticmethod
def init(input_size, hidden_size, fancy_forget_bias_init = 3):
@liangfu
liangfu / cvquantile.cpp
Last active April 27, 2016 09:19
Compute quantile of input matrix for given value range from 0.0 to 1.0
/**
* compute quantile of input matrix for given value range from 0.0 to 1.0
*/
float cvQuantile(CvMat * src, float p)
{
p=MIN(1,MAX(0,p)); // eliminate overflow
int nr = src->rows, nc = src->cols;
CvMat * converted = cvCreateMat(nr,nc,CV_32F);
CvMat * reshaped = cvCreateMat(1,nr*nc,CV_32F);
CvMat * sorted = cvCreateMat(1,nr*nc,CV_32F);
#include <cstring>
#include <numeric>
#include <functional>
/**
* Hackers Delight: http://www.hackersdelight.org/HDcode/nlz.c.txt
*/
int pop(unsigned x) {
x = x - ((x >> 1) & 0x55555555);
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
@liangfu
liangfu / QSound2.h
Created July 13, 2012 02:23
QSound interface with SDL_mixer implementation
/**
* @file QSound2.h
* @author Liangfu Chen <[email protected]>
* @date Tue Jul 10 14:39:25 2012
*
* @brief QSound interface with SDL_mixer implementation
*
* Phonon is not the default option while compile Qt4.
* This class is designed to enable brief sound playback in
* the Linux environment.
@liangfu
liangfu / sorting.py
Created January 28, 2012 05:37
general sorting algorithms in python
#!/usr/bin/env python
from math import sqrt
import random
def bubble_sort(a):
"""
basic sorting method -- bubble sort
"""
s = len(a)