忍者ブログ

揺動経路の記録

   

[PR]

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

t-SNE

t-SNE(t-distributed stochastic neighbor embedding)は次元圧縮アルゴリズム


import numpy as np
from sklearn import datasets
from sklearn import manifold

import matplotlib.pylab as plt

def main():
    boston = datasets.load_boston()
    """
    boston = datasets.load_boston()
    ・概要
        米国ボストン市郊外における地域別の住宅価格のデータセット。

    ・データセットの詳細
        レコード数     506
        カラム数     14
        主な用途     回帰 (Regression)
        データセットの詳細     UCI Machine Learning Repository: Housing Data Set

    ・各カラムの構成
        CRIM     人口 1 人当たりの犯罪発生数
        ZN     25,000 平方フィート以上の住居区画の占める割合
        INDUS     小売業以外の商業が占める面積の割合
        CHAS     チャールズ川によるダミー変数 (1: 川の周辺, 0: それ以外)
        NOX     NOx の濃度
        RM     住居の平均部屋数
        AGE     1940 年より前に建てられた物件の割合
        DIS     5 つのボストン市の雇用施設からの距離 (重み付け済)
        RAD     環状高速道路へのアクセスしやすさ
        TAX     $10,000 ドルあたりの不動産税率の総計
        PTRATIO     町毎の児童と教師の比率
        B     町毎の黒人 (Bk) の比率を次の式で表したもの。 1000(Bk – 0.63)^2
        LSTAT     給与の低い職業に従事する人口の割合 (%)
    """

    perp_list = range(5,60,5)
    for i, val in enumerate(perp_list):
        print "({0}), perplexity = {1}".format(i, val)
        model = manifold.TSNE(perplexity = val, init = "pca")
        tsne_result = model.fit_transform(boston.data)
        plt.subplot(3, 4, i + 1)
        plt.title("Perplexity = {0}".format(val))
        plt.plot(tsne_result[:,0], tsne_result[:,1], ".")
        plt.grid()

    plt.show()


if __name__ == '__main__':
    main()

GRU in tensorflow

GRUの中身をいろいろ見たい場合、定義したグラフからスコープ変数を元に全Variableは取ってくることはできる。
しかし、update, resetはGatesにまとめられていたり、隠れ状態がCandidateにまとめられていたり、それぞれの重み、バイアスパラメータがあったり、よくわからないので中身を見る必要がある。。。
どうやら、行列演算をまとめている。

そうすると、_linear関数の中身も見る必要がある。

http://stackoverflow.com/questions/38692531/explanation-of-gru-cell-in-tensorflow



------------------------------------------------------------------------------------------------------

    """Gated recurrent unit (GRU) with nunits cells."""
with vs.variable_scope(scope or type(self).__name__): # "GRUCell"
with vs.variable_scope("Gates"): # Reset gate and update gate.
# We start with bias of 1.0 to not reset and not update.
r, u = array_ops.split(1, 2, _linear([inputs, state],
2 * self._num_units, True, 1.0))
r, u = sigmoid(r), sigmoid(u)
with vs.variable_scope("Candidate"):
c = self._activation(_linear([inputs, r * state],
self._num_units, True))
new_h = u * state + (1 - u) * c



def _linear(args, output_size, bias, bias_start=0.0, scope=None):
"""Linear map: sum_i(args[i] * W[i]), where W[i] is a variable.

Args:
args: a 2D Tensor or a list of 2D, batch x n, Tensors.
output_size: int, second dimension of W[i].
bias: boolean, whether to add a bias term or not.
bias_start: starting value to initialize the bias; 0 by default.
scope: VariableScope for the created subgraph; defaults to "Linear".

Returns:
A 2D Tensor with shape [batch x output_size] equal to
sum_i(args[i] * W[i]), where W[i]s are newly created matrices.

Raises:
ValueError: if some of the arguments has unspecified or wrong shape.
"""
if args is None or (nest.is_sequence(args) and not args):
raise ValueError("`args` must be specified")
if not nest.is_sequence(args):
args = [args]

# Calculate the total size of arguments on dimension 1.
total_arg_size = 0
shapes = [a.get_shape().as_list() for a in args]
for shape in shapes:
if len(shape) != 2:
raise ValueError("Linear is expecting 2D arguments: %s" % str(shapes))
if not shape[1]:
raise ValueError("Linear expects shape[1] of arguments: %s" % str(shapes))
else:
total_arg_size += shape[1]

# Now the computation.
with vs.variable_scope(scope or "Linear"):
matrix = vs.get_variable("Matrix", [total_arg_size, output_size])
# <<<
if len(args) == 1:
res = math_ops.matmul(args[0], matrix)
else:
res = math_ops.matmul(array_ops.concat(1, args), matrix)# <<<
if not bias:
return res
bias_term = vs.get_variable(
"Bias", [output_size],
initializer=init_ops.constant_initializer(bias_start))
return res + bias_term

RNNとDropoutとバッチ正則化と

2015-2016年あたりに色々論文が出ているらしいのでサーベイしなければならない

  • RNNとDropout
時間軸方向にDropoutを行うとよくない。
http://arxiv.org/pdf/1409.2329v5.pdf
http://neuralnet.hatenablog.jp/

但し、ベイズ的な解釈を行うことで時間軸方向のドロップアウトもできて
精度も上がるケースがあるらしい
http://qiita.com/yoh_okuno/items/4bcfbc10dd4d03e19690

A Theoretically Grounded Application of Dropout in Recurrent Neural Networks
https://arxiv.org/abs/1512.05287


  • RNNとバッチ正則化
バッチ正則化はRNNには有効ではないという話題にも触れており、他の提案手法の文献も
ある
http://isw3.naist.jp/~neubig/student/2015/seitaro-s/161025neuralnet_study_LSTM.pdf

プロフィール

HN:
stochaotic
性別:
非公開

最新記事

(06/17)
(05/31)
(11/09)
(03/23)
(02/11)

P R

Copyright ©  -- 揺動経路の記録 --  All Rights Reserved
Design by CriCri / Photo by Geralt / powered by NINJA TOOLS / 忍者ブログ / [PR]