0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

geometry > 連番から分岐経路番号を取得する実装 (上部:4分岐, 最下部のみ:3分岐)> v0.1, v0.2

Last updated at Posted at 2017-10-14
動作環境
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 16.04 LTS desktop amd64
TensorFlow v1.2.1
cuDNN v5.1 for Linux
CUDA v8.0
Python 3.5.2
IPython 6.0.0 -- An enhanced Interactive Python.
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)

やろうとしていること

geometry > sub-triangles > Triangular van der Corput列 > v0.1 > for文のネスト
の方法を使う場合、連番から分岐経路番号(d値)を取得する必要がある。

T(d1, d2) = (T(d1))(d2)
T(d1, d2, d3) = ((T(d1))(d2))(d3)

のような感じ。

ただし、d1,..d{n_1}は{0..3}の値を取り、最後のdn(例: d3)だけ{1..3}の値を持つとする。
(d値が0となる点は若い連番ですでに取得しているという理由から)

code v0.1

idxToDary_171014.py
import numpy as np
import math

# on Python 3.5.2

# v0.1 Oct. 14, 2017
#  - add show_darrays()
#  - add get_depth()


def get_depth(idx):
    if idx == 0:
        return 1
    depth = int(math.log(idx, 4))+1
    return depth


def show_darrays(idx):
    depth = get_depth(idx)
    print(idx, depth, end=': ')

    # MSB
    d1 = 0
    if depth == 1:
        d1 = idx % 4
    else:
        d1 = (idx - 4**(depth-1)) // 4**(depth-2) // (4-1)
    print(d1, end=' ')

    # inbetween
    for mi in range(depth-1, 1, -1):
        dm = (idx - 4**(depth-1)) // (4**(mi-2)) // (4-1) % 4
        print(dm, end=' ')

    # LSB
    last = (idx - 4**(depth-1)) % (4-1) + 1
    if depth > 1:
        print("", last, end='')
    print()


# test
for idx in range(18):
    show_darrays(idx)

show_darrays(63)
show_darrays(64)

show_darrays(255)
show_darrays(256)

show_darrays(1023)
show_darrays(1024)

結果[連番、深さ: d値(d1, d2, ...)]の表示順番

run
0 1: 0 
1 1: 1 
2 1: 2 
3 1: 3 
4 2: 0  1
5 2: 0  2
6 2: 0  3
7 2: 1  1
8 2: 1  2
9 2: 1  3
10 2: 2  1
11 2: 2  2
12 2: 2  3
13 2: 3  1
14 2: 3  2
15 2: 3  3
16 3: 0 0  1
17 3: 0 0  2
63 3: 3 3  3
64 4: 0 0 0  1
255 4: 3 3 3  3
256 5: 0 0 0 0  1
1023 5: 3 3 3 3  3
1024 6: 0 0 0 0 0  1

TODO

きちんとしたテスト関数を作り、本当に正しいか確認する。

code v0.2

refactoringした。

idxToDary_171014.py
import numpy as np
import math

# on Python 3.5.2

# v0.2 Oct. 14, 2017
#  - refactor
# v0.1 Oct. 14, 2017
#  - add show_darrays()
#  - add get_depth()


def get_depth(idx):
    if idx == 0:
        return 1
    depth = int(math.log(idx, 4))+1
    return depth


def show_darrays(idx):
    depth = get_depth(idx)
    print(idx, depth, end=': ')

    # MSB
    if depth == 1:
        d1 = idx % 4
        print(d1)
        return d1
    remnant = (idx - 4**(depth-1))
    d1 = remnant // 4**(depth-2) // (4-1)
    print(d1, end=' ')

    # inbetween
    for mi in range(depth-1, 1, -1):
        dm = remnant // (4**(mi-2)) // (4-1) % 4
        print(dm, end=' ')

    # LSB
    last = remnant % (4-1) + 1
    print("", last)


# test
for idx in range(18):
    show_darrays(idx)

show_darrays(63)
show_darrays(64)

show_darrays(255)
show_darrays(256)

show_darrays(1023)
show_darrays(1024)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?