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 / newtonkrylov.cc
Last active December 19, 2015 13:59
Newton-Krylov method for function minimization.
//
// Newton-Krylov method
//
// The Newton method is:
// Step 1. solve H(x) u = g(x), where H is a Hessian and g is a gradient.
// Step 2. update x = x - u.
// This is a second order method, which requires a Hessian information.
// On the Newton-Krylov method, Step 1 is implemented as
// (a) solve this equation by iterative (Krylov subspace) method.
// (b) use numerical difference to LHS evaluation, i.e.,
n = 400;
A = diag( log( [2:n+1] ) ) + randn(n) / n;
b = randn(n,1);
y = A \ b;
EPS = 1e-8;
% GCR
disp(' '); disp('GRR');
tic;
%
% Modified (numerical stable) version of Walker and Zhou's Simpler GMRES.
%
% Homer F. Walker and Lu Zhou (1994): A simpler GMRES.
% Numerical Linear Algebra and Applications, Vol.1, No.6, 571-581.
% ( http://users.wpi.edu/~walker/Papers/gmres-simpler,NLAA_1,1994,571-581.pdf )
%
n = 100;
A = diag( log( [2:n+1] ) ) + randn(n);

MNISTデータセットで遊ぼう

概要

MNISTデータセットは0~9の数字を手書きした画像のデータセットであり,以下からダウンロードできる:

http://yann.lecun.com/exdb/mnist/

// n-grams graph G = (V,E)
// V: set of n-grams (i.e., n-tuple of words for n = 1 .. N )
// E: u->v iff v is a next n-gram of v in the document
//
// Usage: ./a.out < pg11.txt
// ( http://www.gutenberg.org/cache/epub/11/pg11.txt )
//
#include <iostream>
#include <vector>
#include <cstdio>
// n-gram graph G = (V,E)
// V: set of n-grams (i.e., n-tuple of words)
// E: u->v iff v is a next n-gram of v in the document
//
// Usage: ./a.out < pg11.txt
// ( http://www.gutenberg.org/cache/epub/11/pg11.txt )
//
// the_march_hare 0.224377
// march_hare_said 0.04768
// march_hare_interrupted 0.02384
// 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
# 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
@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>
@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