Skip to content

Instantly share code, notes, and snippets.

View ktnyt's full-sized avatar
🐱

ktnyt ktnyt

🐱
View GitHub Profile
@ktnyt
ktnyt / conv_dae.py
Last active August 29, 2015 14:24
FunctionSet model for Chainer based Convolutional Denoising Autoencoder
class ConvolutionalAutoencoder(FunctionSet):
def __init__(self, n_in, n_out, ksize, stride=1, pad=0, wscale=1, bias=0, nobias=False):
super(ConvolutionalAutoencoder, self).__init__(
encode=F.Convolution2D(n_in, n_out, ksize, stride=stride, pad=pad, wscale=wscale, bias=bias, nobias=nobias),
decode=F.Convolution2D(n_out, n_in, ksize, stride=stride, pad=pad, wscale=wscale, bias=bias, nobias=nobias)
)
def forward(self, x_data, train=True):
x = Variable(x_data)
t = Variable(x_data)
@ktnyt
ktnyt / brica_svm.py
Created July 3, 2015 09:59
Linear SVM Component Implementation with BriCA
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import brica1
# SVM Component Definition
@ktnyt
ktnyt / brica_chainer_sda.py
Created August 17, 2015 05:53
BriCA + Chainer based simple SDA implementation
import numpy as np
from chainer import Variable, FunctionSet, optimizers
import chainer.functions as F
import data
import brica1
class SLP(FunctionSet):
def __init__(self, n_input, n_output):
super(SLP, self).__init__(
@ktnyt
ktnyt / brica_chainer_sda.py
Last active October 3, 2015 11:20
Implementation of stacked denoising autoencoder using BriCA1 and Chainer.
import argparse
import numpy as np
from sklearn.datasets import fetch_mldata
from chainer import Variable, FunctionSet, optimizers, cuda
import chainer.functions as F
import brica1
class Perceptron():
def __init__(self, n_in, n_out, use_cuda=False):
self.model = FunctionSet(
@ktnyt
ktnyt / treasure_hunt_generator.sh
Last active October 14, 2015 05:23
Self explanatory
#!/bin/sh
if [ -d treasure_hunt ]
then
rm -r treasure_hunt
fi
mkdir treasure_hunt
echo 'Aye aye mate! Welcome to the treasure hunt!' >> treasure_hunt/README
@ktnyt
ktnyt / gist:5928759
Created July 4, 2013 15:50
An example of access log parsing
#!/usr/bin/env perl
use strict;
use warnings;
my %rank_hour; # Access per hour
my %rank_file; # Access per file
open LOG, "<", "access_log"; # Open log file
open CSV, ">", "access_log.csv"; # Open CSV output file
@ktnyt
ktnyt / ecell4.rb
Last active December 22, 2015 13:59
A brew formula for installing E-Cell version 4. Put the formula in /usr/local/Library/formula, run "brew install ecell4", and add /usr/local/lib/python2.7/site-packages to the $PYTHONPATH variable. Uncomment the lines in the "targets" array to install the module of choice. Note that some of these modules depend on other Python modules (e.g. SciPy)
require 'formula'
# Contact celery [at] g-language.org for questions
# Or should I call this formula plain ecell...?
class Ecell4 < Formula
homepage 'http://www.e-cell.org/'
url 'https://github.com/ecell/ecell4/tarball/master'
sha1 '2b1bdf70b0bdfd09e091943eb110b1aab03db6c6'
version '4'
@ktnyt
ktnyt / shor.py
Created December 25, 2015 04:53
Simulation of Shor's Algorithm
import numpy as np
import matplotlib.pyplot as plt
def Hadamard(n):
def Hn(H=np.array([[1, 1], [1, -1]], dtype=np.complex64), n=n):
if n > 1:
return Hn(H=np.kron(np.array([[1, 1], [1, -1]], dtype=np.complex64), H), n=n-1)
return H
return Hn(n=n)
@ktnyt
ktnyt / bustimer.rb
Created December 26, 2013 08:35
Parsing bus api output with ruby
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
url = 'http://hack.sfc.keioac.jp/sfcbusapi/index.php'
uri = URI.parse( url )
res = Net::HTTP.get( uri )
m = /^callback\((.+)\);$/.match( res )
@ktnyt
ktnyt / needle.c
Last active January 1, 2016 19:49
A simple implementation of the Needleman-Wunsch Algorithm in C.
#include <stdio.h>
#include <stdlib.h>
void reverse(char** Pstring);
int match(char a, char b);
int main(int argc, char* argv[]) {
if(argc < 2) {
fprintf(stderr, "Usage: needle <sequence 1> <sequence 2>");
}