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
| import chainer | |
| import torch | |
| import lm_train | |
| import lm_train_th | |
| def transfer_lstm(ch_lstm, th_lstm): | |
| th_lstm.weight_ih.data = torch.from_numpy(ch_lstm.upward.W.data) | |
| th_lstm.bias_ih.data = torch.from_numpy(ch_lstm.upward.b.data) | |
| th_lstm.weight_hh.data = torch.from_numpy(ch_lstm.lateral.W.data) |
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
| import numpy | |
| import torch | |
| import torch.nn.functional as F | |
| from torch.autograd import Variable | |
| tiny = float(numpy.finfo(numpy.float32).tiny) | |
| def safe_cumprod(x, dim): | |
| return x.clamp(tiny, 1.0).log().cumsum(dim=dim).exp(); |
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
| @import url(http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono|Droid+Serif); | |
| @media all | |
| { | |
| html { | |
| margin: 0; | |
| font: .9em/1.6em "Droid Serif", Cambria, Georgia, "DejaVu Serif", serif; | |
| background-attachment: fixed; | |
| background-position: right bottom; | |
| background-repeat: no-repeat; |
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
| #include <iostream> | |
| #include <thrust/device_vector.h> | |
| #include <cooperative_groups.h> | |
| namespace cg = cooperative_groups; | |
| // using DataType = float; | |
| // using DataType4 = float4; | |
| using DataType = int; | |
| using DataType4 = int4; |
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
| (setq org-latex-classes '(("ltjsarticle" | |
| "\\documentclass{ltjsarticle} | |
| \\usepackage{url} | |
| \\usepackage{amsmath} | |
| \\usepackage{newtxtext,newtxmath} | |
| \\usepackage{graphicx} | |
| \\usepackage{luatexja} | |
| \\usepackage{hyperref} | |
| [NO-DEFAULT-PACKAGES] | |
| [PACKAGES] |
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
| %matplotlib notebook | |
| from matplotlib import pyplot | |
| import torch | |
| import math | |
| import numpy | |
| from torch.nn import Parameter, Module | |
| def dirichlet_log_pdf(pi, alpha): | |
| numel = torch.lgamma(alpha.sum(0)) + torch.sum(torch.log(pi) * (alpha - 1.0)) |
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
| #include <algorithm> | |
| #include <functional> | |
| #include <iostream> | |
| #include <fstream> | |
| #include <unordered_map> | |
| #include <vector> | |
| // byte array | |
| using Memory = std::vector<unsigned char>; | |
| using Pointer = Memory::iterator; |
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
| (setq org-latex-classes '(("ltjsarticle" | |
| "\\documentclass{ltjsarticle} | |
| \\usepackage{url} | |
| \\usepackage{amsmath} | |
| \\usepackage{newtxtext,newtxmath} | |
| \\usepackage{graphicx} | |
| \\usepackage{luatexja} | |
| \\usepackage{hyperref} | |
| [NO-DEFAULT-PACKAGES] | |
| [PACKAGES] |
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
| /++ | |
| This is a submodule of numir to provide formatting for ndslices. | |
| Note: This relies on the formatting functionality from Phobos, the D standard | |
| library. As of this writing, parts of it rely on the Garbage Collector and | |
| potentially other non-Better C functionality in D. | |
| +/ | |
| module numir.format; | |
| import mir.ndslice : SliceKind, Slice; | |
| import std.traits : isSomeChar, isSomeString; |
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
| /* library code */ | |
| /++ | |
| Referrence: | |
| - https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#Using_a_priority_queue | |
| - http://shifth.hatenablog.com/entry/2015/05/31/104829 | |
| +/ | |
| auto dijkstra(alias distfun, E, V)(E[V[2]] tree, V start) { | |
| import std.container : Array, PriorityQueue = BinaryHeap; |