ノート
時系列データなどから、ノイズにロバストにアトラクタを復元できる.
Takens' theorem - Wikipedia
埋め込み定理により、時系列データから数理モデルを構築.
周期倍分岐 e.g.乱流の発生
google-cloud-datastore<=0.20からgoogle-cloud-datastore>=0.21へアップデートするときの応急処置
google-cloud-datastore>=0.21にアップデートするとdatastoreのQuery.fetch().next_page()がプライベートメソッドになっている.
そのため,以下のように書き換えることで,アップデートに対応できる.
lst, has_next, cursor = query.fetch(start_cursor=cursor).next_page()
から
itr = query.fetch(start_cursor=cursor) lst, has_next, cursor = list(next(itr.pages)), itr.next_page_token != cursor, itr.next_page_token
とすることで,応急処置できる.
google-cloud-python=0.19.0から^0.20.0にアップグレードできない問題の解決法
問題
pip3 install --upgrade google-cloud
google-cloud==0.19.0の環境から^0.20.0へアップグレードしようとすると
ImportError: cannot import name 'datastore'
のようにImportErrorが発生するようになる.
解決法
pip3 uninstall -y google-cloud-bigquery google-cloud-bigtable google-cloud-core google-cloud-datastore google-cloud-dns google-cloud-error-reporting google-cloud-language google-cloud-logging google-cloud-monitoring google-cloud-pubsub google-cloud-resource-manager google-cloud-storage google-cloud-translate google-cloud-vision google-gax protobuf pip3 install google-cloud --upgrade python -c "from google.cloud import datastore"
依存関係に問題があったらしい
協調フィルタリングを使ってアニメ推薦サイトを作った
こちらがそのサイトhttp://allanime.reviews
まだ、レビュー数が少ないので推薦精度は良くないけど、レビューを集めて、推薦手法を組み合わせたりして、精度を上げていきたい😀
numpy.linalg.normの入力のndarrayの要素の型がなぜかnumpy.float64ではなく,floatになってしまった時の対処法
スパース学習をしようとgroup lassoを実装した時に踏んだバグ?
group lassoのプロキシマルオペレータは次のようになる.
import numpy as np def _prox_w21_norm(W,param): task_weight = np.linalg.norm(W, axis=1) zero_idx = task_weight != 0 radial_mat = np.zeros(W.shape) radial_mat[zero_idx] = W[zero_idx]/task_weight[zero_idx,np.newaxis] updated_mat = W - param*radial_mat idx = W*updated_mat <= 0 updated_mat[idx] = 0 return updated_mat
この際最適化をForward backward splitting(ダッチさん2009)でといていると反復の途中で
<class 'numpy.float64'> # W の要素 <class 'float'> # W の要素 --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-131-6d534db85f86> in <module>() 1 A = martins() ----> 2 B = martins_smooth() 3 pl.loglog(MARTINS_OBJ, label='MARTINS') 4 pl.loglog(MARTINS_SMOOTH_OBJ,label='MARTINS SMOOTH') 5 pl.legend() <ipython-input-129-d92ef3b97804> in martins_smooth() 5 MARTINS_SMOOTH_STEP.clear() 6 for t in range(LOOP): ----> 7 obj = objective(W) 8 MARTINS_SMOOTH_OBJ.append(obj) 9 gamma, W = linesearch(W, gamma) <ipython-input-126-e6b93142ddc4> in objective(W) 1 def objective(W): ----> 2 return l2_loss(W)+W21_PARAM*w21_norm(W)+W12_PARAM*w21_norm(W.T) <ipython-input-125-a9ca0e6faaa4> in w21_norm(W) 1 def w21_norm(W): ----> 2 return np.sum(np.linalg.norm(W, axis=1)) /usr/local/lib/python3.5/dist-packages/numpy/linalg/linalg.py in norm(x, ord, axis, keepdims) 2158 # special case for speedup 2159 s = (x.conj() * x).real -> 2160 return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) 2161 else: 2162 try: AttributeError: 'float' object has no attribute 'sqrt'
となり,エラーを吐かれてしまうという謎の現象に直面した.
反復回数が数千回目で発生するので実装に間違いはなさそう.
暗黙の型変換が起きてこのようなエラーが吐かれてしまうと考え,numpyの実装からnumpy.linalg.normの自分が使うところのみを修正,改善して対応した.
from numpy.core import add def norm(x, axis=None): tmp = add.reduce((x.conj() * x).real, axis=axis) if type(tmp) == float: return math.sqrt(tmp) else: return np.sqrt(tmp.astype(np.float64))
追記
array.astype(np.float32)
とやればエラーに直面しない
ipython3 parallel でsshを使ったクラスタを作成
準備
クラスタを作成
ipython clusterのプロファイルを作成
ipython profile create --parallel --profile=ssh
作成したプロファイルまで移動
cd IPYTHON_DIR/profile_ssh/ e.g. cd ~/.config/ipython/profile_ssh/
ipcluster_config.pyを編集
c = get_config() c.IPClusterEngines.engine_launcher_class = 'SSH' c.LocalControllerLauncher.controller_args = ["--ip='*'"] c.SSHEngineSetLauncher.engines = { "host1":4, "host2":4, "host3":4, "host4":4, } c.SSHEngineSetLauncher.engine_cmd = ['ipengine3'] # ipython3でクラスタを作成せるときマニュアルが2を対象としたものが多いため、ここを忘れがち
scpで他のホストの同じディレクトリにprofile_sshを手動でコピーする。
これにより、ipython3でクラスタを作成することができました。
あとは動作を確認してみます
ipcluster3 start --profile=ssh 2015-12-15 23:02:55.661 [IPClusterStart] Starting ipcluster with [daemon=False] ...... 2015-12-15 23:03:29.019 [IPClusterStart] Engines appear to have started successfully
感想
ipython2のマニュアルを見ていたためc.SSHEngineSetLauncher.engine_cmd = ['ipengine3']
を設定するということに気づくのが遅れてたいへん手間取ってしまったのがとてもつらかった。