Skip to content

Instantly share code, notes, and snippets.

View spaghetti-source's full-sized avatar

Takanori MAEHARA spaghetti-source

View GitHub Profile
@spaghetti-source
spaghetti-source / LUdecomposition.cc
Created April 29, 2013 15:38
Simple Sparse Linear Solver
//
// Sparse LU Decomposition (Gilbert-Peierls)
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
@spaghetti-source
spaghetti-source / 2layerNN.cc
Last active December 17, 2015 11:59
Two-layer Neural Network
// Two-layer Neural Network
//
// USAGE:
// ./a.out in.txt out.txt
// gnuplot -e "plot 'in.txt', 'out.txt'; pause 2"
//
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cstdlib>
% Radial Basis Function expansion
%
% f(x) = sum k(x, yi) wi
% -> w = k(X,Y) \ f(X)
% here k(x,y) := rho(|x-y|), e.g., exp(-|x-y2|^2)
% input data
N = 100;
X = rand(N,1);
fX = abs( cos( 2 * 3.14 * (X .* X) ) );
@spaghetti-source
spaghetti-source / readmnist.cc
Created May 21, 2013 14:35
Read MNIST Database (handwritten digits)
// Read MNIST Database (handwritten digits)
//
// Usage:
// 1. download
// train-images-idx3-ubyte.gz
// train-labels-idx2-ubyte.gz
// from
// http://yann.lecun.com/exdb/mnist/
// and extract them.
//
@spaghetti-source
spaghetti-source / kNNmnist.cc
Last active December 17, 2015 14:19
k-NN classification for MNIST dataset
//
// Nearlest Neighbour Classification for MNIST dataset
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
@spaghetti-source
spaghetti-source / svm-logsumexp.cc
Created May 26, 2013 03:51
Support Vector Machine (gradient descent with log-sum-exp approximation)
//
// Support Vector Machine
// (gradient descent with log-sum-exp approximation)
//
// original:
// G(w) := min_{+,-} { <w, x_+> - <w,x_-> } --> maximize
// approx:
// G'(w) := -log sum_{+,-} exp (-<w, x_+> - <w,x_->) --> maximize
// <=>
// L(w) := sum_{+,-} exp -<w, x_+ - x_-> --> minimize
@spaghetti-source
spaghetti-source / hybridBFD.cc
Created June 3, 2013 16:27
Hybrid Bellman-Ford / Dijkstra
// Bellman-Ford / DIjkstra hybrid for shortest path
//
// D. Yefem and I. Rotem (2010):
// Hybrid Bellman-Ford-Dijkstra Algorithm,
// TechnicalReport, Ben-Gurion University of the Negev.
//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
# coding: utf-8
#
# easy_install tweepy
# easy_install python-dateutil
#
from tweepy import OAuthHandler, Stream
from tweepy.streaming import StreamListener
import tweepy, sys, json
from time import strptime
import datetime, calendar, dateutil.parser
// Bigram graph G = (V,E)
// V: set of words
// E: u->v iff "u v" occurs in the document
//
// Usage: ./a.out < pg11.txt
// ( http://www.gutenberg.org/cache/epub/11/pg11.txt )
//
// the 0.0514497
// and 0.0313457
// to 0.0241298