LoginSignup
1
1

More than 5 years have passed since last update.

spherepts > Delaunay > ScipyのDelaunayに置き換えても同じ結果になる (適用する問題によるのだろう)

Last updated at Posted at 2017-11-19
動作環境
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)
scipy v0.19.1
geopandas v0.3.0
MATLAB R2017b (Home Edition)

概要

Scipy > API > Delaunay試してみた > QhullオプションがMATLABとは異なる

上記で気になっていたのがMATLABのdelaunay()とScipyのDelaunay()の結果の違い。
QhullのオプションをQzなしで実行しようとしても、扱っている問題がcosphericalなポイントセットであるため、QzなしではScipyでエラーがでる。
また、Qz以外の理由によっても両者に違いが出ていると推測される。

I have a hunch that...
Scipyの結果をMATLABに読込ませて最終結果に違いがあるか確認することにした。

処理手順

  1. MATLABの処理において delaunay(x)のxをファイル出力する
    • 出力ファイル: delaunay_input_171118.txt
  2. Scipyでファイルを読込みDelaunay()の結果をファイル出力する
    • 出力ファイル: out_delaunay_171119.txt
  3. MATLABの処理において、手順2のファイルを読込み、続きの処理を行う

手順1ではsave()を使う。手順3でload()を使う。

手順2のコードは下記。

delaunay_save_171119.py
import numpy as np
from scipy.spatial import Delaunay

'''
v0.2 Nov. 19, 2017
  - add convert_to_matlab_index()
v0.1 Nov. 19, 2017
  - add delaunay_save()
'''


def convert_to_matlab_index(dln):
    return (dln + 1)


def delaunay_save(xyz):
    dln = Delaunay(xyz).simplices
    dln = convert_to_matlab(dln)
    np.savetxt('out_delaunay_171119.txt', dln, fmt='%.0f')
    return dln


if __name__ == '__main__':
    IN_FILE = 'delaunay_input_171118.txt'
    xyz = np.genfromtxt(IN_FILE, delimiter='  ')
    print("---xyz---")
    print(xyz)

    print("---dln---")
    dln = delaunay_save(xyz)

    print(dln)

実行

@ozwk さんに教えていただいたisequal()を使いました。

情報感謝です。

>> [x0,tri0] = getIcosNodes(4,0);
>> [x1,tri1] = getIcosNodes_load(4,0);
>> isequal(x0,x1)

ans =

  logical

   1

同じになっている。
両者を図で目視しても違和感は感じない。

qiita.png

qiita.png

MATLABとScipyのDelaunay()の違いについては、僕が対象としている問題では最終結果に影響しないように思われる。

他の問題によっては最終結果に影響するかもしれない

補足資料

delaunay_input_171118.txt
   0.0000000e+00   8.5065081e-01   5.2573111e-01
   0.0000000e+00  -8.5065081e-01   5.2573111e-01
   0.0000000e+00   8.5065081e-01  -5.2573111e-01
   0.0000000e+00  -8.5065081e-01  -5.2573111e-01
   5.2573111e-01   0.0000000e+00   8.5065081e-01
  -5.2573111e-01   0.0000000e+00   8.5065081e-01
   5.2573111e-01   0.0000000e+00  -8.5065081e-01
  -5.2573111e-01   0.0000000e+00  -8.5065081e-01
   8.5065081e-01   5.2573111e-01   0.0000000e+00
  -8.5065081e-01   5.2573111e-01   0.0000000e+00
   8.5065081e-01  -5.2573111e-01   0.0000000e+00
  -8.5065081e-01  -5.2573111e-01   0.0000000e+00
out_delaunay_171119.txt
8 12 6 2
8 11 4 2
8 1 6 5
8 3 7 9
8 11 5 2
8 6 5 2
8 1 6 10
8 12 4 2
8 11 4 7
8 12 6 10
8 1 3 9
8 11 5 9
8 11 7 9
8 1 3 10
8 1 5 9
1
1
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
1
1