complex small world

どうしようもない日々の追想

株価の予測

株価の変動予測もまた時系列予測として大変面白い対象であり、実利に直結する(上手くいけば・・)。 近年ではPythonなどのScrapingツールにより、一般市民が株価変動を解析することが可能になりつつある。 その中身は、また次回にして結局株価変動の定性的傾向と知見は何だろうと解析を行っている。 Pythonで過去2年間の株価を取得して、それぞれの銘柄変動がどのような傾向があるか調べた結果、 結局のところ、市場変動の隣接要素には負の相関があるようだ。

まさに以下のリンクで述べられているような傾向。 負の相関があればそのような単純戦略で確かに利益を上げられそうだが、確かにそうかも。

stockedge.hatenablog.com

Unityでアセット画面が表示されない

ブラウザからアセットをインストールしようとして、[Unityで開く]ボタンをクリックしても、UnityのAsset Store画面には何も表示されない。 f:id:wataridori2010:20161214224641p:plain

つまり、こういう症状が発生した。 f:id:wataridori2010:20161214224646p:plain 結果的に、このAsset StoreウインドウをUnityから独立させ(ドラッグして)、もう一度ブラウザ側の[Unityで開く]ボタンをクリックすると、無事表示できた。Unityのバグなんですかね?

いまさらiOSでTensorflow

RNNに続いて今更ながらTensorflowのiOSデモをテストしました。ここで提供されているモデルは、GoogleがInceptionと読んでいる、ネットワーク構造をグジャグジャに短絡とかしているあのモデルのデモです。正直、僕はVGGの方が好きです。 ちなみに自分の環境はOS X El Capitan 10.11.6 / Xcode 8 / Python 2.7です。

shu223さん等のネット情報を参考にすれば、なんとも簡単に出来そうです。 qiita.com

でも、簡単にはできませんでした。。こういうのが嫌なんすよね。その忘備録もかねてメモなのです。tensorflowはtensorflow-0.10.0でございます。なぜか最新バージョンではないが、、気にしない気にしない。

Releases · tensorflow/tensorflow · GitHub

さて障壁の数々をメモっていきます。

まずビルドが最後まで通らない

以下の最後のステップを実行すると、ビルドできません。

tensorflow/contrib/makefile/compile_ios_tensorflow.sh

Xcode 7.3.0より新しいバージョンのXcodeでビルドして下さい と怒られます。

ハ?、実行環境はXcode8.0なんすけど。。

これはcompile_ios_tensorflow.shが、そもそも間違って?ます。エディタで開いて7.3.0となっている部分を7.3にすると、ビルドが無事に進行しました。しかしビルド時間の長いこと長いこと。

iOSのプロジェクトで謎のリンクエラー

f:id:wataridori2010:20161129002659p:plain

_deflate ,_inflate、 一体なんのこっちゃ? グーグル先生によると、どうやらzlibのリンクが上手くいってないようです。先人の知恵 breakpoints not working in tf_ios_makefile_example · Issue #4098 · tensorflow/tensorflow · GitHub を基に、Xcodeの[Build Phrases] - [Link Binary with Libraries] にlibz.1.2.8.tbd辺りを追加します。さあてこれで上手くいった、と思いきや、

iOSのカメラが起動しない・・

どうやらiOS10から、info.plistにカメラの使用目的を記載する項目を追記しないとカメラ使えないんですね、知らなかった。 qiita.com

はい、Iron !!

f:id:wataridori2010:20161129003740j:plain でもやはり、処理速度はとても遅いですね。

RNN 調査 ver1.2

各ステップの解説

load_dataメソッド

  • 文字のスクリプトデータを読み込む
  • スクリプトデータを文字やスペースなどの1文字単位で切り出す words=list(words)
  • 文字数分の多次元配列の入れ物datasetを確保
  • datasetには単語を出現順番idに変換して登録
  • そこでvocabには新しい単語を登録
  • つまり学習で用いるvocab.binは、学習データ内に出現した文字のリスト
  • また学習するデータセットのdatasetは、文字リストのid番号に変換された文書

なるほど、そういや言語認識って古くからそんな感じだったっけ・・ 実際にシェイクスピアのvocab.binのサイズは65、全データサイズ(コーパスサイズ)は1115394。それならRNNのユニット数でデフォルトで128ですが、65とかでもいいのでは?


そういうことでUnit数は65でやってみた。

Stopely of with the vowers not of than as was
Petian from cause, here I his seathes?

Firsgow:
And ads fondation.

LEFDIS:
Hath was I'll we funshand, many all for acwall.
No, sir, sister
Hath himself sables are of preasome?

MERCUTIO:
You injure's mend the
ridsber it denief comins us.
Your pleasures, since the peacures I softime;
The mose.

ANTIGONUS:
Mercy the matter that was back wonst be froward;
To corrember to devon;
And so well, well by dished? is Warwick.

VINCEG OF MARGA:
Well,
Heighmons kill Claudon come cover thou beseep,
I do forth, that the heast is weep; I much, and paren
Battering.

LEONTES:
Could Hangly he with hill shall law to be the
threp, and impost unkind laws for pubned.

FLOROZES:
A, residented best thou tongue, and he then make again;
I'll virth, attembless and defending thee.

QUEEN ELIZABETH:
Your friar, and treasunement malens as you time thou doward.

WARWICK:
Sir! Thou afthallower on will:
With city, one unoss, Jumietiondel, come of you.

First Henry:
Your son, it will lights accounts Possity.
The house, this us is outhing his imp'd just
spirate on storce proftiended to masters, us for cust,
Do Lucenter's roege, I may reignish some striins of her;
I must be the big out shall concommand;
Ere thou till so to you, my lord, good much.'

LADY CARSET:
Who you to must with his pain rick in:
He is did that abolable to burrage
But bares, be proud him. Think's think.

Praver:
And thou, peryingfo, 'tis Caduuties all;
This curish me on King contrament of thy pray
Me honest what onledeng: fair the falful his stot hillown
A knenches: what throve an quock on your latume
As these prove you hath the viol what you call
A grash motherward sir.

BRADECURT:
I' what now us inknrectes me air modest, touch hef,
To that in't: so maid it show my franter is
Coudgeth brash-now 'tis the speeton:
Pove King my child you, he stay here's work;
'Tis on propernen out.

ROREA:
Rome?' Go, is it donate! and, you palse, marshal wind
I so dreawauge diverite you, not you hold, 

確かにあまり変わらないような。ただモデルのサイズが6.3MBだったのが1.7MBになりました。学習も速くなってます。 以下はSeq_lengthが50であるところを5にして実験。うーん対して変わらないような。これは一体どういうことだ?

wink by the seasten vant to your councation.

QUEEN MARGARET:
Nast sail years and flair of.
But new as thou will of cight of, and than from the maid.
Was save wast him, mow.

CAMILLO:
Tind the roinners Passon upon fred fle.

LUCIO:
This?

Fill our life thee thile to the indrothifity again me?
Have instruct the wound or bring
Furderer untuppartious be so speak.

POMPEY:
O, 'twis!
In ours the other they have flain to dever;
Sypeties brother inot to falsird's charks proce! lives your word!

FLORIZEL:
He fard,
And be angranten improotuaate him: afterns
and year otch on behold;
Thou shall with disca,
Wherein naiton's
behase to thy mogest'd
From the burious brother,
Big the moother'd strong must be
Faither canwer, infordet; so, fond the power'd take him made's through
The Padest gave to confess widow Tybalt; and
lie.

DUKE OF AUMERLE:
I beting my bedown,
Nor heart friends, his my past to she gree.
,he turn.
Nay, in theik night her have live stank to years
Reweforen
For me it to breep and in onotsed
for me?

First Sneribuestenat, thou fault,s,
Or seen, his, mistile-kight at sea with silst the strick.

BINCIO:
With the send natly,
Jeuced go rash monaled iningiin remains sin
From him you! I be thee! He vastague friend,
And brother wishers need seasuath over;
Oning ho! you not indort me a matter; a wread, nature
Could I, I fielding my fall, but they
Cractize my soe.
He come not?

GLOUCESTER:
What, but the lord. The shipt, give ear have the goldeds in tidy more floweral newbers:
North will pity: the chaughthing but 'tis death!
Then reside asleed enemy of him fool.

:han:
We--
The sworns, ballentis the mornaced in viction
To liven, he have deputy branablount frish,
And lights whime joyful stillanched war
Or danger,
A should beauty when Rome. Wouls stone; that that worst take, thou livather's fitch
we stay bloptible; Noth's eye
Which tell him boy common in the earth.
Was, gainsio with exur's first and bellinge?

KING EDWARD IV:
It should course for they stite
Brance than you he

RNN調査 ver1

今更感がかなりあるものの、、RNN: Recurrent Neural Networkって面白そうだなと思い、CharRNNのソースに触れてみた。 オリジナルはこちら。chainerバージョンです(chainer-char-rnn)。有り難く使わせて頂きました。 github.com

いきなりですが調査結果

  • 正直CPUでもGPUでもスピードにそんなに違いはない。やはりそこがRNNの課題点?
  • CharRNNはpython2で組まれてるので注意。
  • 実行環境はwindows/x64/GPU/Python3.5(3.5用に少し改変)

テスト実行にあたってのログ

Train:(CPU)

$python train.py

Train:(GPU)

$python train.py --gpu 0

  • 学習ではCVフォルダが生成され、その中にチェックポイントでのモデルファイルがセーブされていく

Test:(CPU):

  • vocalファイルと、モデル、最初の一字を少なくとも指定する(word-seqモデルなので最初の1字だけ指定すればいい) $python sample.py --vocabulary data/tinyshakespeare/vocab.bin --model cv/charrnn_epoch_0.04.chainermodel --primetext hello

すると最初に生成されたモデルはこんな感じ

helloa  oaeTa
nehnreyttffpmywa e  pree
n nlg
ds e. 
qocs,oo  eaAoaopdmrh toslpyiootta aoeRler eaGehoate Cfass dmome et, oo
iDN eoMPzdlnhtokTrn nor Mo:huramth  dsdlannhoroh Rhourk,lsrteeos hnhioWo aediciunsordGhosadrh
n,e
 e. nD I;s
oer s hlr Topi
P:sfTem, nyetbcki 
rJ e s  p eiefto pilishrab.ybnAegtI.vspiyir .eoo od en'oNo
ifN reeki?aRaleeehe LLny  e l,a;e s troeotd  uo oaSo uh ,nh  gdha nhdirC;
 e n mn ' lra

rre;cew tek
 b, OD
,
es  etgspnee. iMSCcsslnag iiaM
:dL, kttw ae Zrdih rcyar n hswEM FDgbnh emsl
:eNo.';Ced
j:odnqs  t h
iEaraetoyd ffaehpiokot
hs,tfe ciuf.oith

eCUobuS?EANLSINrmgeonesfndoiiaa;lnpn esdtnbit IWtTho'ledc tn egna Ga sNbci h.:e ssght duhtT oobdo
hsig
ee,ehnmr:
 bM
s  
em
IX y?Te,ilruq
 pcdtlwratiohmsda ! r
u eolu  fhw
pholNIm e d usho,ewoOhotl dL  ..n tUlLwsrCgbkte  a
esoee eoimRo Dnyan br
  mertm- aryev Ifed  tg
h
dcEu i ne,hrgfoec.a-ymradsmwso: iew  uuas
ohSenudoettrrmerl  tbsa'dk dan.yvh
f
iontsniEeereii ,nityyueeheyoerslnqe e ciuee:n
e

dh owif e, 
i d   grnrotp aei r
 d
ie
csaethrWa:iedkwen.ern&etrt odr' tfd d lArtaFmeur rte
Iahr Do,irsiR K, xlttaror Nfo ns
rrarf to ntssrouhgtsnkhoteaeioaat eese
uoe'oj.avD y'ihrYpti,tLsknlhmna r ie
iiasr
hH sr si tie, ayi;tae.G .oTyc y mTi;e
g, smuke

eehh.AkehTIEra  ku Btilafreetttos I hoeos
H
CE.Lki'GANj$nopt
 AnrilAbren.  utput ahg ote ehhas I:difarseI i,molt iolwradt,le o!yhhgh     'grrmo nrTthgaroskdItnosaoeehe!Rrlarg,,vv Lrlnm uhrSmwaent
,ot,yihk
ermie S:RsRudef nhpalr yedly'tuairifheitI .eo
te$o:o oys  u'episedctsLe
sNhonr kpttewofkkmae grwm Tl  lstotooo ,b k ehtresrot yrP oh   eyatnauctk eomda etyNhsanr3yp.ea
tod
tram'eImne ri  ytaynsyYehurrd,vto  yenm f,so,ulia oheamNo e. lrOsSooH!maatnesiiyn
 ost,iv 'r oLs,pcDeeop artiuNht d e f. odi o, l,ehm ssAfaeh,lcl. w cl
.iMHnkYt: heF  rf  Lesflht  M tnwtisdt d.be uaOsltuG hh vr  r h 
tww rap:lTubttZeoNcly.
HtY a,ynLtu atrhhth ooSoA
h hI:aoivheref ,  tyoa el lbi
dieiwn ho 'OtTwl rieinudyog lTinawEacLIW
.PedYul t:awwr
 yowo re o   te,ms w va srteutil  fe ah,haty ys

半分ぐらい学習が終わったモデルでは以下のような感じ。(ちなみに全部まで学習をやろうとしたがPCのメモリが他のアプリのせいで足らず、強制終了になってた。でも全部やってもlossが0.1~0.2ポイント減る程度なので、そんなに変わらない気も。) $python sample.py --vocabulary data/tinyshakespeare/vocab.bin --model cv/charrnn_epoch_27.66.chainermodel --primetext h

hello, though
you speak ofe, your heart too' are like a loanch,
When I have I mine eye of virtuo.
And we do seem his tacked blessed you.

GONZALO:
How hence, for I cause:
Ratclipp'd it from mine eye into this;
Weaking mortal obey'd on the grounds,
Sinking without think to fasting drat.

Gurkenman:
Ammatity is earth, peace, indeed,
if I may go but to full.

CAMILLO:
Since handly I have hath his bones the behind,
Come with a bush! Whose women will be drink.

First Senator:
No queen it, it is agais;
He speak only kneel befork the king.
And many heaving those words, I see
Would have many sound from you again,
Since, that ban me presence, God blessed withal
home before warice of mockets?

CAMILLO:
Sight, grabow, let's ere I had, soon again.

TRANIO:
Sir, Richard, I for Rome? woll, sir!
I do more the city Clifford with them
One I be deep! I am a recestive
Who bach as dinens and matter's house:
But I will before my loves on others
Finger and no more liberty, my lord,
Which we may not nature propire their dinner:
Nor my dears God to him that fly thither
to chance! Is right that he is deposes are thee:

CLIFFORD:
It were at one of old, any you shall,
Hither, you in rignion; tells trumpets!
O bleed'st unhailing, thou dest young El'res:
One import seeming here please yeavenl'd,
And neither was his trancals to my father.

WARWICK:
Yet, if that avour'd to thy sake, O my son?
He comes him. How, go, brother; but the lord. The suit
To say the king thee.
Since it is vile of King Romeo.

Tailor:
Dearly with the command vice but Mercutio
The frozen to e'ed wonder?

MOPSA:
I must no more Gyazen: hath have lengt to
the same as your own curses: 'enceal he.

ROMEO:
They'll so sister within mine. They pass, ne'er not
wantedience.

DUKE VINCENTIO:
It awaid's meetner traitors, more, Camior
will't make thy king for his deer,
What, the bound I mean, before my life;
There's cipusion and man not
Did it do morely.

Apotich:
If I'f angry, I have adon and draughtered
often: no very true great manly at t

すごい。文章っぽくなってる。意味は不明なものが多いですが。

XcodeでOpenCV処理する際の動画読み込みエラー

エラーその2

動画が読み込めない・・

(環境移行は中々大変・Windows懐かしや・・)

自分のテスト環境は以下

ヘッダーファイルのパスも通してます。 ライブラリも加えてます。 ( videoio.3.1.0, imageproc.3.1.0, highgui.3.1.0, core.3.1.0)

ビルドも成功したが、動画が読めん、というエラー。

原因は、相対パスではなく、絶対パスにしなきゃならない、というオチでした。

/Users/...からちゃんと書きましょう。。