Skip to content

Instantly share code, notes, and snippets.

View sergeant-wizard's full-sized avatar
😵

Ryo Miyajima sergeant-wizard

😵
  • Preferred Networks
  • Tokyo
View GitHub Profile
#include <iostream>
#include <stdint.h>
class Area;
class Quest;
template <typename T, typename Meaning>
struct Explicit
{
Explicit() {}
@sergeant-wizard
sergeant-wizard / rgb2hex.rb
Created September 8, 2015 08:08
rgb to hex
[254, 253, 3].map { |v| v.to_s(16).rjust(2, '0') }.join
@sergeant-wizard
sergeant-wizard / nested_loop.ex
Created October 30, 2015 05:03
nested loop in elixir
defmodule Loop do
def each([head|tail], fun) do
[fun.(head)|each(tail, fun)]
end
def each([], _) do
[]
end
end
Loop.each [1, 2], fn element ->
@sergeant-wizard
sergeant-wizard / input.csv
Created November 25, 2015 10:34
NPB input.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 34 columns, instead of 1 in line 4.
0.02620087336,0,0,0,0,1,0,0,0,0,0,0,0,0.237037037,0.5070422535,0.6,0.6923076923,0,0.1212121212,0.5,0.6367980884,0.5735080058,0.6797752809,0.6111111111,0.7682926829,0.2727272727,0.479638009,0.7974683544,0.7183098592,0.4277777778,0.2958823529,0,0.2083333333,1
0.2358078603,0,0,1,0,0,0,0,0,0,0,0,0,0.6790123457,0.01408450704,0,0.07692307692,0,0,0,0.05256869773,0.03881610869,0.1011235955,0.05555555556,0.0487804878,0,0.01357466063,0.1392405063,0.1549295775,0.6777777778,0.3594117647,0.2173913043,0.5416666667,1
0.2139737991,0,0,0,1,0,0,0,0,0,0,0,0,0.1265432099,1,0.3333333333,0.1538461538,0,1,0.714,0.3261648746,0.3352741388,0.2921348315,0.1111111111,0.2682926829,0.09090909091,0.2805429864,0.2151898734,0.2253521127,0.2916666667,0.2111764706,0,0.375,1
0.05021834061,0,0,0,0,1,0,0,0,0,0,0,0,0.3067901235,0.3943661972,0.06666666667,0.2307692308,0,0.3333333333,0.25,0.146953405,0.1358563804,0.1853932584,0.2222222222,0.1341463415,0,0.09502262443,0.2025316456,0.2253521127,0.4222222222,0.3223529412,0.1739130435,0.4166666667,1
0.0
library(dplyr)
library(ggplot2)
extract_input <- function(data) {
return(data %>% select(c(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)))
}
extract_labels <- function(data) {
return(data %$% Species %>% factor)
}
library(plyr)
num_data <- 100
true_lambda <- 1
sample_from_distribution <- function(candidates, distribution, threshold) {
while (TRUE) {
x <- sample(candidates, size = 1)
dice <- runif(n = 1, min = 0, max = 1)
if (dice < distribution(x) / threshold) {
library(magrittr)
F <- function(y, theta) {
dnorm(y, mean = theta, sd = 1)
}
G0 <- function(theta) {
dnorm(theta, mean = 0, sd = 1)
}
def show_mat(mat):
fig = plt.figure()
ax = fig.add_subplot(111)
cax = ax.matshow(mat)
fig.colorbar(cax)
@sergeant-wizard
sergeant-wizard / lin_eq_benchmark.py
Created March 2, 2017 08:46
linear equation performance
import scipy.linalg
import numpy as np
import sys
num_samples = 500000
n = 7
def inv(Q, x, num_eqs):
@sergeant-wizard
sergeant-wizard / np_print.py
Created March 23, 2017 02:15
numpy print format
np.set_printoptions(formatter={'float': lambda x: '%+1.1f' % x}, linewidth=50)