ラベル

AI Forecast 8306MUFG (215) Social (75) life (70) Financial (62) IT (57) Proposal (56) idea (50) Fund Management (48) Trading (43) economics (42) Covid-19 (40) AI (38) Hedge Fund (36) Risk (36) Culture (31) BOJ (29) Science (26) hobby (24) accounting (17) Apps (16) career (11) job (7) Travel (6) Hiking (5) emotion (5) music (3) Statarb (2) piano (2)

2019年11月13日水曜日

プログラミングと数学(小さな発見) Programming and Mathematics(One Tiny Finding)

プログラミングと数学(小さな発見) Programming and Mathematics(One Tiny Finding)



CartPoleという棒立ての問題をQテーブルを用いて離散的に強化学習するPythonのステップを読んだ。4要素の連続値ベクタを5ステップに離散化したのち、スカラーに次元圧縮するロジックを見つけて感動した。I read Python code for reinforced learning using Q table for CartPole problem to let pole keep standing on the cart.  Very impressed to find out one logic to perform dimension reduction from 4 dimension to scalar on 4 element continuous number vector with 5 step discretization.

最初、下記の赤の部分が何をしているのか不明だった。いろいろ見ていくうちに、離散化ステップをNとしたN進法で次元圧縮しているのだということが分かり、「アッタマいい!」と納得した。プログラムは単なるコーディングでなく、いろいろな知恵の集合体であることを再認識した。Initially no idea what below red part is doing.  While reading further, I realized that it is a N base dimension reduction taking number of discritization steps as N. Very smart way to do all at once.  At the same time I realized again that programming is not just a coding but including lots of wisdom.

def digitize_state(observation):
    cart_pos, cart_v, pole_angle, pole_v = observation
    digitized = [
        np.digitize(cart_pos, bins=bins(-2.4, 2.4, num_dizitized)),
        np.digitize(cart_v, bins=bins(-3.0, 3.0, num_dizitized)),
        np.digitize(pole_angle, bins=bins(-0.5, 0.5, num_dizitized)),
        np.digitize(pole_v, bins=bins(-2.0, 2.0, num_dizitized))
    ]
    return sum([x * (num_dizitized**i) for i, x in enumerate(digitized)])