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 | |
from math import sqrt | |
import random | |
def bubble_sort(a): | |
""" | |
basic sorting method -- bubble sort | |
""" | |
s = len(a) |
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
/** | |
* @file QSound2.h | |
* @author Liangfu Chen <chenclf@gmail.com> | |
* @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. |
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
#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); |
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
/** | |
* 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); |
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
""" | |
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): |
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
""" | |
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) |
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
function MLPdemo() | |
net.alpha=0.002; | |
net.maxiter=200; | |
% hyperbolic - input layer | |
net.layer{1}.forward = @tanh_forward; | |
net.layer{1}.backward = @tanh_backward; | |
net.layer{1}.alpha=net.alpha; |
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
char num2char(size_t num){ | |
char res = 0; int val = num%62; | |
if (val<10){ res = val+48; | |
}else if (val>=10&&val<36){ res = val+65-10; | |
}else if (val>=36&&val<62){ res = val+97-36; | |
}return res; | |
} | |
void swap(char & a, char & b){char t=b;b=a;a=t;} | |
void hash(char * src, char * dst, int sz){ | |
memcpy(dst,src,32); |
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
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """ | |
import numpy as np | |
import cPickle as pickle | |
import gym | |
# hyperparameters | |
H = 200 # number of hidden layer neurons | |
batch_size = 10 # every how many episodes to do a param update? | |
learning_rate = 1e-4 | |
gamma = 0.99 # discount factor for reward |
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
#include <string> | |
#include <ctime> | |
#if defined WIN32 | |
#include <windows.h> | |
#include <stdint.h> | |
static int gettimeofday(struct timeval * tp, struct timezone * tzp) | |
{ | |
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's | |
static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); | |
SYSTEMTIME system_time; |
OlderNewer