Skip to content

Instantly share code, notes, and snippets.

View koreyou's full-sized avatar

Yuta Koreeda koreyou

View GitHub Profile
# Written by Yuta Koreeda
# CC-BY
import numpy as np
class ExtremeLearningMachine(object):
def __init__(self, n_unit, activation=None):
self._activation = self._sig if activation is None else activation
self._n_unit = n_unit
###### Editor debris ########
*.org
*~
¥#*
# spyder
.spyderproject/
# pycharm
@koreyou
koreyou / chainer_reporting_demo.ipynb
Created June 26, 2017 14:29
Demostration of how we can use chainer's reporing mechanism to monitor variables' metrics
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import chainer
import chainer.functions as F
import chainer.links as L
from chainer import training
from chainer.training import extensions
# Network definition
class MLP(chainer.Chain):
def __init__(self, n_out):
super(MLP, self).__init__()
@koreyou
koreyou / lock_decorator.py
Last active September 9, 2017 05:09
lock decorator
def lock(f):
""" decorator which locks class method
You need property _lock defined as in the following.
self._lock = threading.Lock()
"""
def body(self, *args, **kwargs):
with self._lock:
return f(self, *args, **kwargs)
return body
@koreyou
koreyou / safe_mkdir.py
Created September 12, 2017 16:00
Safer directory creation
@contextlib.contextmanager
def safe_mkdir(path, dir=None):
""" Create a directory in safe(r) way. Specified directory is created only when
whole operations in `with` scoped is completed successfully. All the files
that are created within the temporaly generated dir will be kept within.
This may not work in some OS.
"""
if dir is None:
dir = os.path.dirname(path)
@koreyou
koreyou / sequence_mask.py
Created August 26, 2017 09:48
[Chainer] Mask sequence with length
def sequence_mask(x, length, value=0.):
xp = cuda.get_array_module(length.data)
# create permutation on (length.ndim + 1) dimension and expand dims until it has shame rank as x
perms = xp.arange(x.shape[length.ndim]).reshape(
[1] * length.ndim + [-1] + [1] * (x.ndim - length.ndim -1))
length = length.reshape([1] * (length.ndim - 1) + [-1] + [1] * (x.ndim - length.ndim))
pad = xp.ones_like(x) * value
mask = xp.broadcast_to(perms, x.shape) < length
return F.where(mask, x, pad)
@koreyou
koreyou / optimizer_comparison.ipynb
Created October 27, 2017 11:12
Comparison of the behaviours of the SGD optimizers
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@koreyou
koreyou / split.html
Created October 28, 2017 02:35
Vertically split colors within one <div> element
<div style="background-image: linear-gradient(bottom, #FFD51A 50%, #FAC815 50%);
background-image: -o-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -moz-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -webkit-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
background-image: -ms-linear-gradient(bottom, #33D51A 50%, #FAC815 50%);
display: inline-block;">aaaa</div>
@koreyou
koreyou / early_stopping_chainer.ipynb
Created October 29, 2017 13:35
Implementation of early stopping for Chainer
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.