MNISTデータセットは0~9の数字を手書きした画像のデータセットであり,以下からダウンロードできる:
This file contains hidden or 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
| // | |
| // 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., |
This file contains hidden or 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
| 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; |
This file contains hidden or 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
| % | |
| % 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); |
This file contains hidden or 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
| // 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> |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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
| // 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 |
This file contains hidden or 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
| # 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 |
This file contains hidden or 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
| // 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> |
This file contains hidden or 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
| // | |
| // 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 |