関数プログラマから見たPythonと機械学習

Masahiro Sakai
Masahiro SakaiSoftware Engineer at Preferred Networks, Inc.
Python
(2018-02-27)
Masahiro Sakai ( )
PYTHON
• Twitter: @masahiro_sakai
github: https://github.com/msakai/
G+: https://plus.google.com/+MasahiroSakai
• :
( )
• :
– ( Haskell)
–
–
•
• Python
• Python
•
……
• Haskell
– Haskell ( )
• Ruby
–
( Python )
– Ruby-GNOME2
• Python
– Chainer + α
– PyPI
DISCLAIMER
•
Python
–
–
–
• Python
–
•
•
•
•
関数プログラマから見たPythonと機械学習
•
– R MATLAB
•
– numpy/scipy, pandas, scikit-learn, matplotlib, Jupyter
Notebook,
–
Python
• ……
Python
• ) numpy.array ==
– numpy …
– Python
⇒
– sorted([np.zeros(2), np.zeros(2)])
• ( collections-extended
RangeMap )
: ……
• ……
•
……
• ) pandas itertuples
type(next(pd.DataFrame({"x" + str(i): [i] for i in range(253)}).itertuples()))
#=> pandas.core.frame.Pandas
type(next(pd.DataFrame({"x" + str(i): [i] for i in range(254)}).itertuples()))
#=> tuple
関数プログラマから見たPythonと機械学習
: Lisp-1
•
– Scheme, JavaScript
– Common Lisp, Ruby Lisp-2 ( )
•
Python Ruby
obj.foo(args) obj.foo(args)
( ) obj.foo() obj.foo(), obj.foo
obj.foo obj.method(:foo)
m(args) m.call(args), m[args]
: Lisp-1
• ……
→
→
• Ruby Lisp-2
•
•
Python Ruby
obj.foo(…) obj.foo(…), obj.foo …
( ) obj.foo() obj.foo(), obj.foo
obj.foo obj.method(:foo)
m(…) m.call(…), m[…]
• (PEP 484)
• mypy
def greeting(name: str) -> str:
return 'Hello ' + name
print(greeting(0))
# => error: Argument 1 to "greeting" has incompatible
type "int"; expected "str"
• Haskeller
–
–
•
– →
• Python Haskell
–
• List Tuple List
……
• (gradual typing)
– (dynamic typing) (static typing)
– Jeremy G. Siek and Walid Taha, Gradual Typing for Functional Languages, in
Proceedings of the 2006 Scheme and Functional Programming Workshop
•
– dynamic type: Any … Any
– type consistency relation: A B
• A = B Any
( : int→Any Any→str)
–
int ⊑ Any ⊑ str
•
(1)
(2)
•
– Python (mypy), TypeScript, Closure, Hack, Flow, C#?
–
• Python
–
• Python (mypy)
• ……
– (Any )
• e.g. Blame Calculus ( )
• Python (mypy)
• :
• (np.array, chainer.Variable )
⇒
• shape
– shape
•
( : forward backward )
(1)
def __call__(self, x : np.array) -> np.array:
• shape Array(m,n,o)
……
– reshape
⇒ (c.f. )
– Haskell hmatrix API †
……
•
(2)
† https://hackage.haskell.org/package/hmatrix-0.18.2.0/docs/Numeric-LinearAlgebra-Static.html
: Chainer
• Chainer
DSL
–
–
type_check.expect(in_types[0].shape == in_types[1].shape)
Expect: in_types[0].shape == in_types[1].shape
Actual: (3,) != (2,)
http://blog.unnono.net/2015/10/chainer-typecheck.html
(3)
•
•
…
•
関数プログラマから見たPythonと機械学習
• CPython
• GPU CPU
– Python
……
– NN CPU
– GPU
……
numpy
• numpy
• numpy
( numpy )
– : x[np.arange(x.shape[0])[:, None], p]
–
•
•
( 1 540 2.1GB )
parsy-1.1.0 290m7.032s
pyparsing-2.2.0 562m41.623s
funcparserlib-0.3.6 79m45.315s
megaparsec-5.3.1 (Haskell) 18m12.025s
attoparsec-0.13.1.0 (Haskell) 15m46.415s
: Python str Haskell
ByteString(bytes )
• :
–
–
……
• Cython
–
–
•
–
CPython
(Go )
• GIL (Global Interpreter Lock)
–
CPython
……
ONNX-Chainer ……
関数プログラマから見たPythonと機械学習
• Python
• Python
–
– Python
•
1 of 29

Recommended

プログラムを高速化する話 by
プログラムを高速化する話プログラムを高速化する話
プログラムを高速化する話京大 マイコンクラブ
242.3K views120 slides
暗号技術の実装と数学 by
暗号技術の実装と数学暗号技術の実装と数学
暗号技術の実装と数学MITSUNARI Shigeo
9.6K views35 slides
いまさら聞けない!CUDA高速化入門 by
いまさら聞けない!CUDA高速化入門いまさら聞けない!CUDA高速化入門
いまさら聞けない!CUDA高速化入門Fixstars Corporation
5.3K views90 slides
オンラインゲームの仕組みと工夫 by
オンラインゲームの仕組みと工夫オンラインゲームの仕組みと工夫
オンラインゲームの仕組みと工夫Yuta Imai
869.7K views56 slides
何となく勉強した気分になれるパーサ入門 by
何となく勉強した気分になれるパーサ入門何となく勉強した気分になれるパーサ入門
何となく勉強した気分になれるパーサ入門masayoshi takahashi
35.8K views43 slides
Tensor コアを使った PyTorch の高速化 by
Tensor コアを使った PyTorch の高速化Tensor コアを使った PyTorch の高速化
Tensor コアを使った PyTorch の高速化Yusuke Fujimoto
7.8K views14 slides

More Related Content

What's hot

【Unity】 Behavior TreeでAIを作る by
 【Unity】 Behavior TreeでAIを作る 【Unity】 Behavior TreeでAIを作る
【Unity】 Behavior TreeでAIを作るtorisoup
19.8K views49 slides
1076: CUDAデバッグ・プロファイリング入門 by
1076: CUDAデバッグ・プロファイリング入門1076: CUDAデバッグ・プロファイリング入門
1076: CUDAデバッグ・プロファイリング入門NVIDIA Japan
21K views51 slides
中3女子でもわかる constexpr by
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexprGenya Murakami
49K views100 slides
C/C++プログラマのための開発ツール by
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツールMITSUNARI Shigeo
13.8K views30 slides
Gpu vs fpga by
Gpu vs fpgaGpu vs fpga
Gpu vs fpgaYukitaka Takemura
18.7K views28 slides
TVM の紹介 by
TVM の紹介TVM の紹介
TVM の紹介Masahiro Masuda
5.5K views68 slides

What's hot(20)

【Unity】 Behavior TreeでAIを作る by torisoup
 【Unity】 Behavior TreeでAIを作る 【Unity】 Behavior TreeでAIを作る
【Unity】 Behavior TreeでAIを作る
torisoup19.8K views
1076: CUDAデバッグ・プロファイリング入門 by NVIDIA Japan
1076: CUDAデバッグ・プロファイリング入門1076: CUDAデバッグ・プロファイリング入門
1076: CUDAデバッグ・プロファイリング入門
NVIDIA Japan21K views
中3女子でもわかる constexpr by Genya Murakami
中3女子でもわかる constexpr中3女子でもわかる constexpr
中3女子でもわかる constexpr
Genya Murakami49K views
C/C++プログラマのための開発ツール by MITSUNARI Shigeo
C/C++プログラマのための開発ツールC/C++プログラマのための開発ツール
C/C++プログラマのための開発ツール
MITSUNARI Shigeo13.8K views
20230105_TITECH_lecture_ishizaki_public.pdf by Kazuaki Ishizaki
20230105_TITECH_lecture_ishizaki_public.pdf20230105_TITECH_lecture_ishizaki_public.pdf
20230105_TITECH_lecture_ishizaki_public.pdf
Kazuaki Ishizaki414 views
計算機アーキテクチャを考慮した高能率画像処理プログラミング by Norishige Fukushima
計算機アーキテクチャを考慮した高能率画像処理プログラミング計算機アーキテクチャを考慮した高能率画像処理プログラミング
計算機アーキテクチャを考慮した高能率画像処理プログラミング
Norishige Fukushima8.8K views
Python 3.9からの新定番zoneinfoを使いこなそう by Ryuji Tsutsui
Python 3.9からの新定番zoneinfoを使いこなそうPython 3.9からの新定番zoneinfoを使いこなそう
Python 3.9からの新定番zoneinfoを使いこなそう
Ryuji Tsutsui6.9K views
Swin Transformer (ICCV'21 Best Paper) を完璧に理解する資料 by Yusuke Uchida
Swin Transformer (ICCV'21 Best Paper) を完璧に理解する資料Swin Transformer (ICCV'21 Best Paper) を完璧に理解する資料
Swin Transformer (ICCV'21 Best Paper) を完璧に理解する資料
Yusuke Uchida16K views
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム by Takuya Azumi
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォームAutoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Autoware: ROSを用いた一般道自動運転向けソフトウェアプラットフォーム
Takuya Azumi25.1K views
第1回ROS勉強会発表資料 ROS+Gazeboではじめるロボットシミュレーション by akio19937
第1回ROS勉強会発表資料 ROS+Gazeboではじめるロボットシミュレーション第1回ROS勉強会発表資料 ROS+Gazeboではじめるロボットシミュレーション
第1回ROS勉強会発表資料 ROS+Gazeboではじめるロボットシミュレーション
akio1993735.9K views
ソーシャルゲームのためのデータベース設計 by Yoshinori Matsunobu
ソーシャルゲームのためのデータベース設計ソーシャルゲームのためのデータベース設計
ソーシャルゲームのためのデータベース設計
Yoshinori Matsunobu124.3K views
20160724_cv_sfm_revisited by Kyohei Unno
20160724_cv_sfm_revisited20160724_cv_sfm_revisited
20160724_cv_sfm_revisited
Kyohei Unno4.3K views
負荷試験ツールlocustを使おう by iRidge, Inc.
負荷試験ツールlocustを使おう負荷試験ツールlocustを使おう
負荷試験ツールlocustを使おう
iRidge, Inc.1.1K views
組み込み関数(intrinsic)によるSIMD入門 by Norishige Fukushima
組み込み関数(intrinsic)によるSIMD入門組み込み関数(intrinsic)によるSIMD入門
組み込み関数(intrinsic)によるSIMD入門
Norishige Fukushima47.5K views

Similar to 関数プログラマから見たPythonと機械学習

SociaLite: High-level Query Language for Big Data Analysis by
SociaLite: High-level Query Language for Big Data AnalysisSociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data AnalysisDataWorks Summit
2.4K views52 slides
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵 by
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵Wanbok Choi
697 views51 slides
Migrating from matlab to python by
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to pythonActiveState
1.2K views57 slides
Hadoop london by
Hadoop londonHadoop london
Hadoop londonYahoo Developer Network
319 views149 slides
Swift for tensorflow by
Swift for tensorflowSwift for tensorflow
Swift for tensorflow규영 허
311 views31 slides
Real Time Big Data Management by
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data ManagementAlbert Bifet
1.3K views67 slides

Similar to 関数プログラマから見たPythonと機械学習(20)

SociaLite: High-level Query Language for Big Data Analysis by DataWorks Summit
SociaLite: High-level Query Language for Big Data AnalysisSociaLite: High-level Query Language for Big Data Analysis
SociaLite: High-level Query Language for Big Data Analysis
DataWorks Summit2.4K views
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵 by Wanbok Choi
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
[Let'Swift 2019] 실용적인 함수형 프로그래밍 워크샵
Wanbok Choi697 views
Migrating from matlab to python by ActiveState
Migrating from matlab to pythonMigrating from matlab to python
Migrating from matlab to python
ActiveState1.2K views
Swift for tensorflow by 규영 허
Swift for tensorflowSwift for tensorflow
Swift for tensorflow
규영 허311 views
Real Time Big Data Management by Albert Bifet
Real Time Big Data ManagementReal Time Big Data Management
Real Time Big Data Management
Albert Bifet1.3K views
Introduction to Haskell: 2011-04-13 by Jay Coskey
Introduction to Haskell: 2011-04-13Introduction to Haskell: 2011-04-13
Introduction to Haskell: 2011-04-13
Jay Coskey841 views
Numba: Array-oriented Python Compiler for NumPy by Travis Oliphant
Numba: Array-oriented Python Compiler for NumPyNumba: Array-oriented Python Compiler for NumPy
Numba: Array-oriented Python Compiler for NumPy
Travis Oliphant15.5K views
Python高级编程(二) by Qiangning Hong
Python高级编程(二)Python高级编程(二)
Python高级编程(二)
Qiangning Hong9.7K views
Learning notes of r for python programmer (Temp1) by Chia-Chi Chang
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
Chia-Chi Chang1.8K views
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi by Databricks
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiNatural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
Databricks2K views
チームメイトのためにdocstringを書こう! pyconjp2019 by cocodrips
チームメイトのためにdocstringを書こう! pyconjp2019チームメイトのためにdocstringを書こう! pyconjp2019
チームメイトのためにdocstringを書こう! pyconjp2019
cocodrips10.4K views
Foilsを使ってみた。 by Keisuke OTAKI
Foilsを使ってみた。Foilsを使ってみた。
Foilsを使ってみた。
Keisuke OTAKI568 views

More from Masahiro Sakai

DeepXplore: Automated Whitebox Testing of Deep Learning by
DeepXplore: Automated Whitebox Testing of Deep LearningDeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep LearningMasahiro Sakai
1.6K views25 slides
Towards formal verification of neural networks by
Towards formal verification of neural networksTowards formal verification of neural networks
Towards formal verification of neural networksMasahiro Sakai
660 views32 slides
Writing a SAT solver as a hobby project by
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby projectMasahiro Sakai
2K views31 slides
RClassify: Classifying Race Conditions in Web Applications via Deterministic ... by
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...Masahiro Sakai
794 views5 slides
ゼロピッチ: MOOC by
ゼロピッチ: MOOCゼロピッチ: MOOC
ゼロピッチ: MOOCMasahiro Sakai
1.1K views8 slides
SAT/SMT solving in Haskell by
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in HaskellMasahiro Sakai
3.4K views32 slides

More from Masahiro Sakai(20)

DeepXplore: Automated Whitebox Testing of Deep Learning by Masahiro Sakai
DeepXplore: Automated Whitebox Testing of Deep LearningDeepXplore: Automated Whitebox Testing of Deep Learning
DeepXplore: Automated Whitebox Testing of Deep Learning
Masahiro Sakai1.6K views
Towards formal verification of neural networks by Masahiro Sakai
Towards formal verification of neural networksTowards formal verification of neural networks
Towards formal verification of neural networks
Masahiro Sakai660 views
Writing a SAT solver as a hobby project by Masahiro Sakai
Writing a SAT solver as a hobby projectWriting a SAT solver as a hobby project
Writing a SAT solver as a hobby project
Masahiro Sakai2K views
RClassify: Classifying Race Conditions in Web Applications via Deterministic ... by Masahiro Sakai
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
RClassify: Classifying Race Conditions in Web Applications via Deterministic ...
Masahiro Sakai794 views
SAT/SMT solving in Haskell by Masahiro Sakai
SAT/SMT solving in HaskellSAT/SMT solving in Haskell
SAT/SMT solving in Haskell
Masahiro Sakai3.4K views
SAT/SMTソルバの仕組み by Masahiro Sakai
SAT/SMTソルバの仕組みSAT/SMTソルバの仕組み
SAT/SMTソルバの仕組み
Masahiro Sakai36.6K views
Introduction to Max-SAT and Max-SAT Evaluation by Masahiro Sakai
Introduction to Max-SAT and Max-SAT EvaluationIntroduction to Max-SAT and Max-SAT Evaluation
Introduction to Max-SAT and Max-SAT Evaluation
Masahiro Sakai5.4K views
Aluminum: Principled Scenario Exploration through Minimality by Masahiro Sakai
Aluminum: Principled Scenario Exploration through MinimalityAluminum: Principled Scenario Exploration through Minimality
Aluminum: Principled Scenario Exploration through Minimality
Masahiro Sakai1.2K views
代数的実数とCADの実装紹介 by Masahiro Sakai
代数的実数とCADの実装紹介代数的実数とCADの実装紹介
代数的実数とCADの実装紹介
Masahiro Sakai3.8K views
How a CDCL SAT solver works by Masahiro Sakai
How a CDCL SAT solver worksHow a CDCL SAT solver works
How a CDCL SAT solver works
Masahiro Sakai25.2K views
萩野服部研究室 スキー合宿 2012 自己紹介(酒井) by Masahiro Sakai
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
萩野服部研究室 スキー合宿 2012 自己紹介(酒井)
Masahiro Sakai1K views
自動定理証明の紹介 by Masahiro Sakai
自動定理証明の紹介自動定理証明の紹介
自動定理証明の紹介
Masahiro Sakai8.3K views
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P... by Masahiro Sakai
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
“Adoption and Focus: Practical Linear Types for Imperative Programming”他の紹介@P...
Masahiro Sakai839 views
“Design and Implementation of Generics for the .NET Common Language Runtime”他... by Masahiro Sakai
“Design and Implementation of Generics for the .NET Common Language Runtime”他...“Design and Implementation of Generics for the .NET Common Language Runtime”他...
“Design and Implementation of Generics for the .NET Common Language Runtime”他...
Masahiro Sakai907 views
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg... by Masahiro Sakai
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
“Symbolic bounds analysis of pointers, array indices, and accessed memory reg...
Masahiro Sakai1.3K views
自然言語をラムダ式で解釈する体系PTQのHaskell実装 by Masahiro Sakai
自然言語をラムダ式で解釈する体系PTQのHaskell実装自然言語をラムダ式で解釈する体系PTQのHaskell実装
自然言語をラムダ式で解釈する体系PTQのHaskell実装
Masahiro Sakai2.4K views
Whole Program Paths 等の紹介@PLDIr#3 by Masahiro Sakai
Whole Program Paths 等の紹介@PLDIr#3Whole Program Paths 等の紹介@PLDIr#3
Whole Program Paths 等の紹介@PLDIr#3
Masahiro Sakai1.4K views

Recently uploaded

Investor Presentation by
Investor PresentationInvestor Presentation
Investor Presentationeser sevinç
23 views26 slides
SUMIT SQL PROJECT SUPERSTORE 1.pptx by
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptxSumit Jadhav
11 views26 slides
Stone Masonry and Brick Masonry.pdf by
Stone Masonry and Brick Masonry.pdfStone Masonry and Brick Masonry.pdf
Stone Masonry and Brick Masonry.pdfMohammed Abdullah Laskar
20 views6 slides
MK__Cert.pdf by
MK__Cert.pdfMK__Cert.pdf
MK__Cert.pdfHassan Khan
10 views1 slide
Design and analysis of a new undergraduate Computer Engineering degree – a me... by
Design and analysis of a new undergraduate Computer Engineering degree – a me...Design and analysis of a new undergraduate Computer Engineering degree – a me...
Design and analysis of a new undergraduate Computer Engineering degree – a me...WaelBadawy6
56 views4 slides
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... by
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...AakashShakya12
63 views115 slides

Recently uploaded(20)

SUMIT SQL PROJECT SUPERSTORE 1.pptx by Sumit Jadhav
SUMIT SQL PROJECT SUPERSTORE 1.pptxSUMIT SQL PROJECT SUPERSTORE 1.pptx
SUMIT SQL PROJECT SUPERSTORE 1.pptx
Sumit Jadhav 11 views
Design and analysis of a new undergraduate Computer Engineering degree – a me... by WaelBadawy6
Design and analysis of a new undergraduate Computer Engineering degree – a me...Design and analysis of a new undergraduate Computer Engineering degree – a me...
Design and analysis of a new undergraduate Computer Engineering degree – a me...
WaelBadawy656 views
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,... by AakashShakya12
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
Literature review and Case study on Commercial Complex in Nepal, Durbar mall,...
AakashShakya1263 views
Multi-objective distributed generation integration in radial distribution sy... by IJECEIAES
Multi-objective distributed generation integration in radial  distribution sy...Multi-objective distributed generation integration in radial  distribution sy...
Multi-objective distributed generation integration in radial distribution sy...
IJECEIAES15 views
NEW SUPPLIERS SUPPLIES (copie).pdf by georgesradjou
NEW SUPPLIERS SUPPLIES (copie).pdfNEW SUPPLIERS SUPPLIES (copie).pdf
NEW SUPPLIERS SUPPLIES (copie).pdf
georgesradjou14 views
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th... by ahmedmesaiaoun
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
Performance of Back-to-Back Mechanically Stabilized Earth Walls Supporting th...
ahmedmesaiaoun12 views
fakenews_DBDA_Mar23.pptx by deepmitra8
fakenews_DBDA_Mar23.pptxfakenews_DBDA_Mar23.pptx
fakenews_DBDA_Mar23.pptx
deepmitra812 views
Informed search algorithms.pptx by Dr.Shweta
Informed search algorithms.pptxInformed search algorithms.pptx
Informed search algorithms.pptx
Dr.Shweta16 views

関数プログラマから見たPythonと機械学習