gnu: Add python-pynndescent.
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
CommitLineData
741115b6 1;;; GNU Guix --- Functional package management for GNU
0877b74f 2;;; Copyright © 2015, 2016, 2017, 2018, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
d56d3ae7 3;;; Copyright © 2016, 2020 Efraim Flashner <efraim@flashner.co.il>
382550f0 4;;; Copyright © 2016, 2017, 2020 Marius Bakke <mbakke@fastmail.com>
be6eb2f1 5;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
d2a7cb46 6;;; Copyright © 2018, 2019, 2020 Tobias Geerinckx-Rice <me@tobias.gr>
3a354e10 7;;; Copyright © 2018 Kei Kebreau <kkebreau@posteo.net>
a9b34762
MM
8;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
9;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
2dab4188 10;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
564cf93f 11;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
df4c8434 12;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
d60b064d 13;;; Copyright © 2019 Nicolas Goaziou <mail@nicolasgoaziou.fr>
5dc04da4 14;;; Copyright © 2019, 2020 Guillaume Le Vaillant <glv@posteo.net>
5e42d197 15;;; Copyright © 2019 Brett Gilio <brettg@gnu.org>
d9e9a261 16;;; Copyright © 2020 Konrad Hinsen <konrad.hinsen@fastmail.net>
bcbd6340 17;;; Copyright © 2020 Edouard Klein <edk@beaver-labs.com>
b6540374 18;;; Copyright © 2020 Vinicius Monego <monego@posteo.net>
5f37d7e3 19;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
741115b6
RW
20;;;
21;;; This file is part of GNU Guix.
22;;;
23;;; GNU Guix is free software; you can redistribute it and/or modify it
24;;; under the terms of the GNU General Public License as published by
25;;; the Free Software Foundation; either version 3 of the License, or (at
26;;; your option) any later version.
27;;;
28;;; GNU Guix is distributed in the hope that it will be useful, but
29;;; WITHOUT ANY WARRANTY; without even the implied warranty of
30;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31;;; GNU General Public License for more details.
32;;;
33;;; You should have received a copy of the GNU General Public License
34;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
35
36(define-module (gnu packages machine-learning)
37 #:use-module ((guix licenses) #:prefix license:)
38 #:use-module (guix packages)
39 #:use-module (guix utils)
40 #:use-module (guix download)
23aab4ab 41 #:use-module (guix svn-download)
c1670a81 42 #:use-module (guix build-system cmake)
741115b6 43 #:use-module (guix build-system gnu)
0a3063d6 44 #:use-module (guix build-system ocaml)
be6eb2f1 45 #:use-module (guix build-system python)
8406138b 46 #:use-module (guix build-system r)
a9b34762 47 #:use-module (guix git-download)
71f80f54 48 #:use-module (gnu packages)
0dfeb285 49 #:use-module (gnu packages adns)
5a14e81e 50 #:use-module (gnu packages algebra)
b9445d0b 51 #:use-module (gnu packages audio)
23aab4ab 52 #:use-module (gnu packages autotools)
b9445d0b 53 #:use-module (gnu packages base)
99260014 54 #:use-module (gnu packages bash)
0931c609 55 #:use-module (gnu packages boost)
be6eb2f1 56 #:use-module (gnu packages check)
0931c609 57 #:use-module (gnu packages compression)
b6540374 58 #:use-module (gnu packages cmake)
9e37e537 59 #:use-module (gnu packages cran)
4fa16c9a 60 #:use-module (gnu packages databases)
23aab4ab 61 #:use-module (gnu packages dejagnu)
0931c609 62 #:use-module (gnu packages gcc)
b9445d0b 63 #:use-module (gnu packages glib)
f1765b57 64 #:use-module (gnu packages graphviz)
b9445d0b 65 #:use-module (gnu packages gstreamer)
5f0ff6a9 66 #:use-module (gnu packages image)
b9445d0b 67 #:use-module (gnu packages linux)
8cd10a76 68 #:use-module (gnu packages llvm)
0931c609 69 #:use-module (gnu packages maths)
112c2c01 70 #:use-module (gnu packages mpi)
0a3063d6 71 #:use-module (gnu packages ocaml)
3929f46c 72 #:use-module (gnu packages onc-rpc)
791c11d6 73 #:use-module (gnu packages perl)
c1670a81 74 #:use-module (gnu packages pkg-config)
0dfeb285 75 #:use-module (gnu packages protobuf)
0931c609 76 #:use-module (gnu packages python)
b6540374 77 #:use-module (gnu packages python-check)
ec1224a7 78 #:use-module (gnu packages python-science)
10451f6b 79 #:use-module (gnu packages python-web)
44d10b1f 80 #:use-module (gnu packages python-xyz)
c61557b1 81 #:use-module (gnu packages rpc)
4fa16c9a 82 #:use-module (gnu packages serialization)
f1765b57 83 #:use-module (gnu packages sphinx)
c1670a81 84 #:use-module (gnu packages statistics)
4fa16c9a 85 #:use-module (gnu packages sqlite)
c1670a81 86 #:use-module (gnu packages swig)
99260014 87 #:use-module (gnu packages web)
5f0ff6a9 88 #:use-module (gnu packages xml)
39bb4937
RW
89 #:use-module (gnu packages xorg)
90 #:use-module (ice-9 match))
741115b6 91
a9b34762
MM
92(define-public fann
93 ;; The last release is >100 commits behind, so we package from git.
94 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
95 (package
96 (name "fann")
97 (version (string-append "2.2.0-1." (string-take commit 8)))
98 (source (origin
99 (method git-fetch)
100 (uri (git-reference
b0e7b699 101 (url "https://github.com/libfann/fann")
a9b34762
MM
102 (commit commit)))
103 (file-name (string-append name "-" version "-checkout"))
104 (sha256
105 (base32
106 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
107 (build-system cmake-build-system)
108 (arguments
109 `(#:phases
110 (modify-phases %standard-phases
111 (replace 'check
112 (lambda* (#:key outputs #:allow-other-keys)
113 (let* ((out (assoc-ref outputs "out")))
114 (with-directory-excursion (string-append (getcwd) "/tests")
115 (invoke "./fann_tests"))))))))
116 (home-page "http://leenissen.dk/fann/wp/")
117 (synopsis "Fast Artificial Neural Network")
118 (description
bd2bd80d
MB
119 "FANN is a neural network library, which implements multilayer
120artificial neural networks in C with support for both fully connected and
121sparsely connected networks.")
a9b34762
MM
122 (license license:lgpl2.1))))
123
741115b6
RW
124(define-public libsvm
125 (package
126 (name "libsvm")
2cffa2f2 127 (version "3.23")
741115b6
RW
128 (source
129 (origin
130 (method url-fetch)
d1308c5e
TGR
131 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
132 name "-" version ".tar.gz"))
741115b6 133 (sha256
2cffa2f2 134 (base32 "0jpaq0rr92x38p4nk3gjan79ip67m6p80anb28z1d8601miysyi5"))))
741115b6
RW
135 (build-system gnu-build-system)
136 (arguments
2cffa2f2 137 `(#:tests? #f ; no "check" target
741115b6
RW
138 #:phases (modify-phases %standard-phases
139 (delete 'configure)
140 (replace
d1308c5e 141 'install ; no ‘install’ target
741115b6
RW
142 (lambda* (#:key outputs #:allow-other-keys)
143 (let* ((out (assoc-ref outputs "out"))
144 (bin (string-append out "/bin/")))
145 (mkdir-p bin)
146 (for-each (lambda (file)
147 (copy-file file (string-append bin file)))
148 '("svm-train"
149 "svm-predict"
150 "svm-scale")))
151 #t)))))
62290cd4 152 (home-page "https://www.csie.ntu.edu.tw/~cjlin/libsvm/")
741115b6
RW
153 (synopsis "Library for Support Vector Machines")
154 (description
155 "LIBSVM is a machine learning library for support vector
156classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
157distribution estimation (one-class SVM). It supports multi-class
158classification.")
159 (license license:bsd-3)))
71f80f54
RW
160
161(define-public python-libsvm
162 (package (inherit libsvm)
163 (name "python-libsvm")
164 (build-system gnu-build-system)
165 (arguments
2cffa2f2 166 `(#:tests? #f ; no "check" target
71f80f54
RW
167 #:make-flags '("-C" "python")
168 #:phases
169 (modify-phases %standard-phases
170 (delete 'configure)
171 (replace
d1308c5e 172 'install ; no ‘install’ target
71f80f54
RW
173 (lambda* (#:key inputs outputs #:allow-other-keys)
174 (let ((site (string-append (assoc-ref outputs "out")
175 "/lib/python"
176 (string-take
177 (string-take-right
178 (assoc-ref inputs "python") 5) 3)
179 "/site-packages/")))
180 (substitute* "python/svm.py"
181 (("../libsvm.so.2") "libsvm.so.2"))
182 (mkdir-p site)
183 (for-each (lambda (file)
184 (copy-file file (string-append site (basename file))))
185 (find-files "python" "\\.py"))
186 (copy-file "libsvm.so.2"
187 (string-append site "libsvm.so.2")))
188 #t)))))
189 (inputs
190 `(("python" ,python)))
191 (synopsis "Python bindings of libSVM")))
0931c609 192
23aab4ab
RW
193(define-public ghmm
194 ;; The latest release candidate is several years and a couple of fixes have
195 ;; been published since. This is why we download the sources from the SVN
196 ;; repository.
197 (let ((svn-revision 2341))
198 (package
199 (name "ghmm")
200 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
201 (source (origin
202 (method svn-fetch)
203 (uri (svn-reference
204 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
205 (revision svn-revision)))
e3a69938 206 (file-name (string-append name "-" version "-checkout"))
23aab4ab
RW
207 (sha256
208 (base32
209 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
210 (build-system gnu-build-system)
211 (arguments
ced12a7b
RW
212 `(#:imported-modules (,@%gnu-build-system-modules
213 (guix build python-build-system))
3cb8cb66
MB
214 #:modules ((guix build python-build-system)
215 ,@%gnu-build-system-modules)
ced12a7b 216 #:phases
23aab4ab
RW
217 (modify-phases %standard-phases
218 (add-after 'unpack 'enter-dir
219 (lambda _ (chdir "ghmm") #t))
ced12a7b
RW
220 (delete 'check)
221 (add-after 'install 'check
222 (assoc-ref %standard-phases 'check))
223 (add-before 'check 'fix-PYTHONPATH
224 (lambda* (#:key inputs outputs #:allow-other-keys)
9c2563a8 225 (let ((python-version (python-version
ced12a7b
RW
226 (assoc-ref inputs "python"))))
227 (setenv "PYTHONPATH"
228 (string-append (getenv "PYTHONPATH")
229 ":" (assoc-ref outputs "out")
230 "/lib/python" python-version
231 "/site-packages")))
23aab4ab
RW
232 #t))
233 (add-after 'enter-dir 'fix-runpath
234 (lambda* (#:key outputs #:allow-other-keys)
235 (substitute* "ghmmwrapper/setup.py"
236 (("^(.*)extra_compile_args = \\[" line indent)
237 (string-append indent
238 "extra_link_args = [\"-Wl,-rpath="
239 (assoc-ref outputs "out") "/lib\"],\n"
240 line
241 "\"-Wl,-rpath="
242 (assoc-ref outputs "out")
243 "/lib\", ")))
244 #t))
245 (add-after 'enter-dir 'disable-broken-tests
246 (lambda _
247 (substitute* "tests/Makefile.am"
248 ;; GHMM_SILENT_TESTS is assumed to be a command.
249 (("TESTS_ENVIRONMENT.*") "")
250 ;; Do not build broken tests.
251 (("chmm .*") "")
252 (("read_fa .*") "")
253 (("mcmc .*") "")
254 (("label_higher_order_test.*$")
255 "label_higher_order_test\n"))
256
257 ;; These Python unittests are broken as there is no gato.
258 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
259 (substitute* "ghmmwrapper/ghmmunittests.py"
260 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
261 line indent)
262 (string-append indent
263 "@unittest.skip(\"Disabled by Guix\")\n"
264 line)))
a491856f 265 #t)))))
23aab4ab
RW
266 (inputs
267 `(("python" ,python-2) ; only Python 2 is supported
268 ("libxml2" ,libxml2)))
269 (native-inputs
270 `(("pkg-config" ,pkg-config)
271 ("dejagnu" ,dejagnu)
272 ("swig" ,swig)
273 ("autoconf" ,autoconf)
274 ("automake" ,automake)
275 ("libtool" ,libtool)))
276 (home-page "http://ghmm.org")
277 (synopsis "Hidden Markov Model library")
278 (description
279 "The General Hidden Markov Model library (GHMM) is a C library with
280additional Python bindings implementing a wide range of types of @dfn{Hidden
d1e4ad1b 281Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
23aab4ab
RW
282training, HMM clustering, HMM mixtures.")
283 (license license:lgpl2.0+))))
284
791c11d6
BW
285(define-public mcl
286 (package
287 (name "mcl")
288 (version "14.137")
289 (source (origin
290 (method url-fetch)
291 (uri (string-append
292 "http://micans.org/mcl/src/mcl-"
293 (string-replace-substring version "." "-")
294 ".tar.gz"))
295 (sha256
296 (base32
297 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
298 (build-system gnu-build-system)
299 (arguments
300 `(#:configure-flags (list "--enable-blast")))
301 (inputs
302 `(("perl" ,perl)))
303 (home-page "http://micans.org/mcl/")
304 (synopsis "Clustering algorithm for graphs")
305 (description
306 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
307fast and scalable unsupervised cluster algorithm for graphs (also known as
308networks) based on simulation of (stochastic) flow in graphs.")
309 ;; In the LICENCE file and web page it says "The software is licensed
310 ;; under the GNU General Public License, version 3.", but in several of
311 ;; the source code files it suggests GPL3 or later.
312 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
313 (license license:gpl3)))
314
0a3063d6
BW
315(define-public ocaml-mcl
316 (package
317 (name "ocaml-mcl")
318 (version "12-068oasis4")
319 (source
320 (origin
fb168a31
RW
321 (method git-fetch)
322 (uri (git-reference
b0e7b699 323 (url "https://github.com/fhcrc/mcl")
fb168a31
RW
324 (commit version)))
325 (file-name (git-file-name name version))
0a3063d6
BW
326 (sha256
327 (base32
fb168a31 328 "0009dc3h2jp3qg5val452wngpqnbfyhbcxylghq0mrjqxx0jdq5p"))))
0a3063d6
BW
329 (build-system ocaml-build-system)
330 (arguments
b24aaeec 331 `(#:phases
0a3063d6
BW
332 (modify-phases %standard-phases
333 (add-before 'configure 'patch-paths
334 (lambda _
0a3063d6
BW
335 (substitute* "setup.ml"
336 (("LDFLAGS=-fPIC")
b24aaeec
RW
337 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh")))
338 (("-std=c89") "-std=gnu99")
339
340 ;; This is a mutable string, which is no longer supported. Use
341 ;; a byte buffer instead.
342 (("String.make \\(String.length s\\)")
343 "Bytes.make (String.length s)")
344
345 ;; These two belong together.
346 (("OASISString.replace_chars")
347 "Bytes.to_string (OASISString.replace_chars")
348 ((" s;")
349 " s);"))
350 (substitute* "myocamlbuild.ml"
351 (("std=c89") "std=gnu99"))
352 ;; Since we build with a more recent OCaml, we have to use C99 or
353 ;; later. This causes problems with the old C code.
354 (substitute* "src/impala/matrix.c"
355 (("restrict") "restrict_"))
0a3063d6 356 #t)))))
b24aaeec
RW
357 (native-inputs
358 `(("ocamlbuild" ,ocamlbuild)))
0a3063d6
BW
359 (home-page "https://github.com/fhcrc/mcl")
360 (synopsis "OCaml wrappers around MCL")
361 (description
362 "This package provides OCaml bindings for the MCL graph clustering
363algorithm.")
364 (license license:gpl3)))
365
0931c609
RW
366(define-public randomjungle
367 (package
368 (name "randomjungle")
369 (version "2.1.0")
370 (source
371 (origin
372 (method url-fetch)
373 (uri (string-append
df4c8434
BH
374 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
375 "/randomjungle/randomjungle-" version ".tar_.gz"))
1e92d311 376 (patches (search-patches "randomjungle-disable-static-build.patch"))
0931c609
RW
377 (sha256
378 (base32
379 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
380 (build-system gnu-build-system)
381 (arguments
382 `(#:configure-flags
1e92d311
MB
383 (list "--disable-static"
384 (string-append "--with-boost="
0931c609
RW
385 (assoc-ref %build-inputs "boost")))
386 #:phases
387 (modify-phases %standard-phases
388 (add-before
389 'configure 'set-CXXFLAGS
390 (lambda _
391 (setenv "CXXFLAGS" "-fpermissive ")
392 #t)))))
393 (inputs
394 `(("boost" ,boost)
395 ("gsl" ,gsl)
396 ("libxml2" ,libxml2)
397 ("zlib" ,zlib)))
398 (native-inputs
25e0037a
EF
399 `(("gfortran" ,gfortran)
400 ("gfortran:lib" ,gfortran "lib")))
47818201
RW
401 ;; Non-portable assembly instructions are used so building fails on
402 ;; platforms other than x86_64 or i686.
403 (supported-systems '("x86_64-linux" "i686-linux"))
df4c8434 404 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
0931c609
RW
405 (synopsis "Implementation of the Random Forests machine learning method")
406 (description
407 "Random Jungle is an implementation of Random Forests. It is supposed to
408analyse high dimensional data. In genetics, it can be used for analysing big
409Genome Wide Association (GWA) data. Random Forests is a powerful machine
410learning method. Most interesting features are variable selection, missing
411value imputation, classifier creation, generalization error estimation and
412sample proximities between pairs of cases.")
413 (license license:gpl3+)))
c1670a81 414
7d4cab74
RW
415(define-public openfst
416 (package
417 (name "openfst")
e4d51494 418 (version "1.7.9")
7d4cab74
RW
419 (source (origin
420 (method url-fetch)
421 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
422 "FstDownload/openfst-" version ".tar.gz"))
423 (sha256
424 (base32
e4d51494 425 "1pmx1yhn2gknj0an0zwqmzgwjaycapi896244np50a8y3nrsw6ck"))))
7d4cab74
RW
426 (build-system gnu-build-system)
427 (home-page "http://www.openfst.org")
428 (synopsis "Library for weighted finite-state transducers")
429 (description "OpenFst is a library for constructing, combining,
430optimizing, and searching weighted finite-state transducers (FSTs).")
431 (license license:asl2.0)))
432
c1670a81
RW
433(define-public shogun
434 (package
435 (name "shogun")
5a14e81e 436 (version "6.1.3")
c1670a81
RW
437 (source
438 (origin
439 (method url-fetch)
440 (uri (string-append
441 "ftp://shogun-toolbox.org/shogun/releases/"
442 (version-major+minor version)
443 "/sources/shogun-" version ".tar.bz2"))
444 (sha256
445 (base32
5a14e81e 446 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
c1670a81
RW
447 (modules '((guix build utils)
448 (ice-9 rdelim)))
449 (snippet
450 '(begin
451 ;; Remove non-free sources and files referencing them
452 (for-each delete-file
453 (find-files "src/shogun/classifier/svm/"
454 "SVMLight\\.(cpp|h)"))
455 (for-each delete-file
456 (find-files "examples/undocumented/libshogun/"
457 (string-append
458 "(classifier_.*svmlight.*|"
459 "evaluation_cross_validation_locked_comparison).cpp")))
460 ;; Remove non-free functions.
461 (define (delete-ifdefs file)
462 (with-atomic-file-replacement file
463 (lambda (in out)
464 (let loop ((line (read-line in 'concat))
465 (skipping? #f))
466 (if (eof-object? line)
467 #t
468 (let ((skip-next?
469 (or (and skipping?
470 (not (string-prefix?
471 "#endif //USE_SVMLIGHT" line)))
472 (string-prefix?
473 "#ifdef USE_SVMLIGHT" line))))
474 (when (or (not skipping?)
475 (and skipping? (not skip-next?)))
476 (display line out))
477 (loop (read-line in 'concat) skip-next?)))))))
5a14e81e
KK
478 (for-each delete-ifdefs
479 (append
480 (find-files "src/shogun/classifier/mkl"
481 "^MKLClassification\\.cpp")
482 (find-files "src/shogun/classifier/svm"
483 "^SVMLightOneClass\\.(cpp|h)")
484 (find-files "src/shogun/multiclass"
485 "^ScatterSVM\\.(cpp|h)")
486 (find-files "src/shogun/kernel/"
487 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
488 (find-files "src/shogun/regression/svr"
489 "^(MKLRegression|SVRLight)\\.(cpp|h)")
490 (find-files "src/shogun/transfer/domain_adaptation"
c0d7c124 491 "^DomainAdaptationSVM\\.(cpp|h)")))
6cbee49d 492 #t))))
c1670a81
RW
493 (build-system cmake-build-system)
494 (arguments
495 '(#:tests? #f ;no check target
496 #:phases
dc1d3cde
KK
497 (modify-phases %standard-phases
498 (add-after 'unpack 'delete-broken-symlinks
499 (lambda _
500 (for-each delete-file '("applications/arts/data"
501 "applications/asp/data"
502 "applications/easysvm/data"
503 "applications/msplicer/data"
504 "applications/ocr/data"
5a14e81e
KK
505 "examples/meta/data"
506 "examples/undocumented/data"))
dc1d3cde
KK
507 #t))
508 (add-after 'unpack 'change-R-target-path
509 (lambda* (#:key outputs #:allow-other-keys)
5a14e81e
KK
510 (substitute* '("src/interfaces/r/CMakeLists.txt"
511 "examples/meta/r/CMakeLists.txt")
dc1d3cde
KK
512 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
513 (string-append (assoc-ref outputs "out")
514 "/lib/R/library/")))
515 #t))
516 (add-after 'unpack 'fix-octave-modules
517 (lambda* (#:key outputs #:allow-other-keys)
5a14e81e 518 (substitute* "src/interfaces/octave/CMakeLists.txt"
dc1d3cde 519 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
5a14e81e
KK
520 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
521 ;; change target directory
dc1d3cde
KK
522 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
523 (string-append (assoc-ref outputs "out")
524 "/share/octave/packages")))
5a14e81e
KK
525 (substitute* '("src/interfaces/octave/swig_typemaps.i"
526 "src/interfaces/octave/sg_print_functions.cpp")
527 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
528 (("octave/config\\.h") "octave/octave-config.h")
529 (("octave/oct-obj.h") "octave/ovl.h"))
dc1d3cde 530 #t))
5a14e81e
KK
531 (add-after 'unpack 'move-rxcpp
532 (lambda* (#:key inputs #:allow-other-keys)
533 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
534 (mkdir-p rxcpp-dir)
535 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
536 #t)))
dc1d3cde 537 (add-before 'build 'set-HOME
c1670a81 538 ;; $HOME needs to be set at some point during the build phase
dc1d3cde 539 (lambda _ (setenv "HOME" "/tmp") #t)))
c1670a81
RW
540 #:configure-flags
541 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
542 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
5a14e81e
KK
543 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
544 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
545 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
546 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
547 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
548 "-DINTERFACE_OCTAVE=ON"
549 "-DINTERFACE_PYTHON=ON"
550 "-DINTERFACE_R=ON")))
c1670a81
RW
551 (inputs
552 `(("python" ,python)
553 ("numpy" ,python-numpy)
2d7c4ae3 554 ("r-minimal" ,r-minimal)
5537603f 555 ("octave" ,octave-cli)
c1670a81 556 ("swig" ,swig)
5a14e81e 557 ("eigen" ,eigen)
c1670a81
RW
558 ("hdf5" ,hdf5)
559 ("atlas" ,atlas)
560 ("arpack" ,arpack-ng)
561 ("lapack" ,lapack)
562 ("glpk" ,glpk)
563 ("libxml2" ,libxml2)
564 ("lzo" ,lzo)
565 ("zlib" ,zlib)))
566 (native-inputs
5a14e81e
KK
567 `(("pkg-config" ,pkg-config)
568 ("rxcpp" ,rxcpp)))
6b5b656f
RW
569 ;; Non-portable SSE instructions are used so building fails on platforms
570 ;; other than x86_64.
571 (supported-systems '("x86_64-linux"))
df10a64e 572 (home-page "https://shogun-toolbox.org/")
c1670a81
RW
573 (synopsis "Machine learning toolbox")
574 (description
575 "The Shogun Machine learning toolbox provides a wide range of unified and
cc24c4cb
VC
576efficient Machine Learning (ML) methods. The toolbox seamlessly
577combines multiple data representations, algorithm classes, and general purpose
c1670a81
RW
578tools. This enables both rapid prototyping of data pipelines and extensibility
579in terms of new algorithms.")
580 (license license:gpl3+)))
8406138b 581
b6540374
VM
582(define-public python-onnx
583 (package
584 (name "python-onnx")
585 (version "1.7.0")
586 (source
587 (origin
588 (method url-fetch)
589 (uri (pypi-uri "onnx" version))
590 ;; ONNX will build googletest from a git checkout. Patch CMake
591 ;; to use googletest from Guix and enable tests by default.
592 (patches (search-patches "python-onnx-use-system-googletest.patch"))
593 (sha256
594 (base32 "0j6rgfbhsw3a8id8pyg18y93k68lbjbj1kq6qia36h69f6pvlyjy"))))
595 (build-system python-build-system)
596 (native-inputs
597 `(("cmake" ,cmake)
598 ("googletest" ,googletest)
599 ("pybind11" ,pybind11)
600 ("python-coverage" ,python-coverage)
601 ("python-nbval" ,python-nbval)
602 ("python-pytest" ,python-pytest)
603 ("python-pytest-runner" ,python-pytest-runner)))
604 (inputs
605 `(("protobuf" ,protobuf)))
606 (propagated-inputs
607 `(("python-numpy" ,python-numpy)
608 ("python-protobuf" ,python-protobuf)
609 ("python-six" ,python-six)
610 ("python-tabulate" ,python-tabulate)
611 ("python-typing-extensions"
612 ,python-typing-extensions)))
613 (home-page "https://onnx.ai/")
614 (synopsis "Open Neural Network Exchange")
615 (description
616 "Open Neural Network Exchange (ONNX) provides an open source format for
617AI models, both deep learning and traditional ML. It defines an extensible
618computation graph model, as well as definitions of built-in operators and
619standard data types.")
620 (license license:expat)))
621
3a354e10
KK
622(define-public rxcpp
623 (package
624 (name "rxcpp")
e91a0bff 625 (version "4.1.0")
3a354e10
KK
626 (source
627 (origin
5daafe0b
TGR
628 (method git-fetch)
629 (uri (git-reference
b0e7b699 630 (url "https://github.com/ReactiveX/RxCpp")
5daafe0b 631 (commit (string-append "v" version))))
3a354e10 632 (sha256
5daafe0b
TGR
633 (base32 "1rdpa3jlc181jd08nk437aar085h28i45s6nzrv65apb3xyyz0ij"))
634 (file-name (git-file-name name version))))
3a354e10
KK
635 (build-system cmake-build-system)
636 (arguments
637 `(#:phases
638 (modify-phases %standard-phases
639 (add-after 'unpack 'remove-werror
640 (lambda _
641 (substitute* (find-files ".")
642 (("-Werror") ""))
643 #t))
644 (replace 'check
645 (lambda _
646 (invoke "ctest"))))))
647 (native-inputs
648 `(("catch" ,catch-framework)))
649 (home-page "http://reactivex.io/")
650 (synopsis "Reactive Extensions for C++")
651 (description
652 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
653values-distributed-in-time. ReactiveX is a library for composing asynchronous
654and event-based programs by using observable sequences.
655
656It extends the observer pattern to support sequences of data and/or events and
657adds operators that allow you to compose sequences together declaratively while
658abstracting away concerns about things like low-level threading,
659synchronization, thread-safety, concurrent data structures, and non-blocking
660I/O.")
661 (license license:asl2.0)))
662
39bb4937
RW
663(define-public gemmlowp-for-tensorflow
664 ;; The commit hash is taken from "tensorflow/workspace.bzl".
665 (let ((commit "38ebac7b059e84692f53e5938f97a9943c120d98")
666 (revision "2"))
667 (package
668 (name "gemmlowp")
669 (version (git-version "0" revision commit))
670 (source (origin
671 (method url-fetch)
672 (uri (string-append "https://mirror.bazel.build/"
673 "github.com/google/gemmlowp/archive/"
674 commit ".zip"))
675 (file-name (string-append "gemmlowp-" version ".zip"))
676 (sha256
677 (base32
678 "0n56s2g8hrssm4w8qj1v58gfm56a04n9v992ixkmvk6zjiralzxq"))))
679 (build-system cmake-build-system)
680 (arguments
681 `(#:configure-flags
682 (list ,@(match (%current-system)
683 ((or "x86_64-linux" "i686-linux")
a32e3b90 684 '("-DCMAKE_CXX_FLAGS=-msse2"))
39bb4937
RW
685 (_ '())))
686 #:phases
687 (modify-phases %standard-phases
688 ;; This directory contains the CMakeLists.txt.
689 (add-after 'unpack 'chdir
690 (lambda _ (chdir "contrib") #t))
691 ;; There is no install target
692 (replace 'install
693 (lambda* (#:key outputs #:allow-other-keys)
694 (let* ((out (assoc-ref outputs "out"))
695 (lib (string-append out "/lib/"))
696 (inc (string-append out "/include/")))
697 (install-file "../build/libeight_bit_int_gemm.so" lib)
698 (for-each (lambda (dir)
699 (let ((target (string-append inc "/" dir)))
700 (mkdir-p target)
701 (for-each (lambda (h)
702 (install-file h target))
703 (find-files (string-append "../" dir)
704 "\\.h$"))))
705 '("meta" "profiling" "public" "fixedpoint"
706 "eight_bit_int_gemm" "internal"))
707 #t))))))
708 (native-inputs
709 `(("unzip" ,unzip)))
710 (home-page "https://github.com/google/gemmlowp")
711 (synopsis "Small self-contained low-precision GEMM library")
712 (description
713 "This is a small self-contained low-precision @dfn{general matrix
714multiplication} (GEMM) library. It is not a full linear algebra library.
715Low-precision means that the input and output matrix entries are integers on
716at most 8 bits. To avoid overflow, results are internally accumulated on more
717than 8 bits, and at the end only some significant 8 bits are kept.")
718 (license license:asl2.0))))
f05c7eb4 719
5f0ff6a9
MB
720(define-public dlib
721 (package
722 (name "dlib")
d2a7cb46 723 (version "19.20")
5f0ff6a9
MB
724 (source (origin
725 (method url-fetch)
726 (uri (string-append
727 "http://dlib.net/files/dlib-" version ".tar.bz2"))
728 (sha256
729 (base32
d2a7cb46 730 "139jyi19qz37wwmmy48gil9d1kkh2r3w3bwdzabha6ayxmba96nz"))
5f0ff6a9
MB
731 (modules '((guix build utils)))
732 (snippet
733 '(begin
734 ;; Delete ~13MB of bundled dependencies.
735 (delete-file-recursively "dlib/external")
0ef7ea66
MB
736 (delete-file-recursively "docs/dlib/external")
737 #t))))
5f0ff6a9
MB
738 (build-system cmake-build-system)
739 (arguments
f90b2691
EF
740 `(#:configure-flags '("-DBUILD_SHARED_LIBS=ON")
741 #:phases
5f0ff6a9
MB
742 (modify-phases %standard-phases
743 (add-after 'unpack 'disable-asserts
744 (lambda _
745 ;; config.h recommends explicitly enabling or disabling asserts
746 ;; when building as a shared library. By default neither is set.
747 (substitute* "dlib/config.h"
748 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
749 #t))
4fba38db
MB
750 (add-after 'disable-asserts 'disable-failing-tests
751 (lambda _
752 ;; One test times out on MIPS, so we need to disable it.
0ef7ea66 753 ;; Others are flaky on some platforms.
4fba38db
MB
754 (let* ((system ,(or (%current-target-system)
755 (%current-system)))
756 (disabled-tests (cond
757 ((string-prefix? "mips64" system)
758 '("object_detector" ; timeout
759 "data_io"))
760 ((string-prefix? "armhf" system)
a343c461 761 '("learning_to_track"))
4fba38db 762 ((string-prefix? "i686" system)
0ef7ea66 763 '("optimization"))
4fba38db 764 (else '()))))
4fba38db
MB
765 (for-each
766 (lambda (test)
767 (substitute* "dlib/test/makefile"
0ef7ea66
MB
768 (((string-append "SRC \\+= " test "\\.cpp")) "")))
769 disabled-tests)
770 #t)))
5f0ff6a9
MB
771 (replace 'check
772 (lambda _
773 ;; No test target, so we build and run the unit tests here.
8eaf53e3 774 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
5f0ff6a9 775 (with-directory-excursion test-dir
8448e6bf
TGR
776 (invoke "make" "-j" (number->string (parallel-job-count)))
777 (invoke "./dtest" "--runall"))
f90b2691 778 #t))))))
5f0ff6a9 779 (native-inputs
3929f46c
TGR
780 `(("pkg-config" ,pkg-config)
781 ;; For tests.
782 ("libnsl" ,libnsl)))
5f0ff6a9 783 (inputs
f40841e9 784 `(("giflib" ,giflib)
4fba38db 785 ("lapack" ,lapack)
4bd428a7 786 ("libjpeg" ,libjpeg-turbo)
5f0ff6a9
MB
787 ("libpng" ,libpng)
788 ("libx11" ,libx11)
789 ("openblas" ,openblas)
790 ("zlib" ,zlib)))
791 (synopsis
792 "Toolkit for making machine learning and data analysis applications in C++")
793 (description
794 "Dlib is a modern C++ toolkit containing machine learning algorithms and
795tools. It is used in both industry and academia in a wide range of domains
796including robotics, embedded devices, mobile phones, and large high performance
797computing environments.")
798 (home-page "http://dlib.net")
799 (license license:boost1.0)))
be6eb2f1
RW
800
801(define-public python-scikit-learn
802 (package
803 (name "python-scikit-learn")
83a483aa 804 (version "0.22.1")
be6eb2f1
RW
805 (source
806 (origin
4a89bdd1
RW
807 (method git-fetch)
808 (uri (git-reference
b0e7b699 809 (url "https://github.com/scikit-learn/scikit-learn")
4a89bdd1
RW
810 (commit version)))
811 (file-name (git-file-name name version))
be6eb2f1
RW
812 (sha256
813 (base32
83a483aa 814 "1xqxv210gsmjw094vc5ghq2y9lmm74qkk22pq6flcjzj51b86jxf"))))
be6eb2f1
RW
815 (build-system python-build-system)
816 (arguments
817 `(#:phases
818 (modify-phases %standard-phases
4a89bdd1
RW
819 (add-after 'build 'build-ext
820 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
821 (replace 'check
822 (lambda _
823 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
824 (setenv "OPENBLAS_NUM_THREADS" "1")
7ff3f3d2
MB
825
826 ;; Some tests require write access to $HOME.
827 (setenv "HOME" "/tmp")
828
829 (invoke "pytest" "sklearn" "-m" "not network")))
71804546
BL
830 (add-before 'reset-gzip-timestamps 'make-files-writable
831 (lambda* (#:key outputs #:allow-other-keys)
832 ;; Make sure .gz files are writable so that the
833 ;; 'reset-gzip-timestamps' phase can do its work.
834 (let ((out (assoc-ref outputs "out")))
835 (for-each make-file-writable
836 (find-files out "\\.gz$"))
837 #t))))))
be6eb2f1
RW
838 (inputs
839 `(("openblas" ,openblas)))
840 (native-inputs
d9e9a261 841 `(("python-pytest" ,python-pytest)
4a89bdd1 842 ("python-pandas" ,python-pandas) ;for tests
be6eb2f1
RW
843 ("python-cython" ,python-cython)))
844 (propagated-inputs
845 `(("python-numpy" ,python-numpy)
d9e9a261
KH
846 ("python-scipy" ,python-scipy)
847 ("python-joblib" ,python-joblib)))
e51b34bb 848 (home-page "https://scikit-learn.org/")
be6eb2f1
RW
849 (synopsis "Machine Learning in Python")
850 (description
4a89bdd1
RW
851 "Scikit-learn provides simple and efficient tools for data mining and
852data analysis.")
382550f0 853 (properties `((python2-variant . ,(delay python2-scikit-learn))))
be6eb2f1
RW
854 (license license:bsd-3)))
855
382550f0
MB
856;; scikit-learn 0.22 and later only supports Python 3, so we stick with
857;; an older version here.
be6eb2f1 858(define-public python2-scikit-learn
382550f0
MB
859 (let ((base (package-with-python2 (strip-python2-variant python-scikit-learn))))
860 (package
861 (inherit base)
862 (version "0.20.4")
863 (source (origin
864 (method git-fetch)
865 (uri (git-reference
b0e7b699 866 (url "https://github.com/scikit-learn/scikit-learn")
382550f0
MB
867 (commit version)))
868 (file-name (git-file-name "python-scikit-learn" version))
869 (sha256
870 (base32
871 "08zbzi8yx5wdlxfx9jap61vg1malc9ajf576w7a0liv6jvvrxlpj")))))))
2dab4188 872
8cd10a76
VM
873(define-public python-pynndescent
874 (package
875 (name "python-pynndescent")
876 (version "0.4.8")
877 (source
878 (origin
879 (method url-fetch)
880 (uri (pypi-uri "pynndescent" version))
881 (sha256
882 (base32 "0li1fclif50v6xrq7wh3lif9vv5jpj7xhrb0z6g89wwjnp9b9833"))))
883 (build-system python-build-system)
884 (native-inputs
885 `(("python-nose" ,python-nose)))
886 (propagated-inputs
887 `(("python-joblib" ,python-joblib)
888 ("python-llvmlite" ,python-llvmlite)
889 ("python-numba" ,python-numba)
890 ("python-scikit-learn" ,python-scikit-learn)
891 ("python-scipy" ,python-scipy)))
892 (home-page "https://github.com/lmcinnes/pynndescent")
893 (synopsis "Nearest neighbor descent for approximate nearest neighbors")
894 (description
895 "PyNNDescent provides a Python implementation of Nearest Neighbor Descent
896for k-neighbor-graph construction and approximate nearest neighbor search.")
897 (license license:bsd-2)))
898
639ae3f2
RJ
899(define-public python-scikit-rebate
900 (package
901 (name "python-scikit-rebate")
902 (version "0.6")
903 (source (origin
904 (method url-fetch)
905 (uri (pypi-uri "skrebate" version))
906 (sha256
907 (base32
908 "1h7qs9gjxpzqabzhb8rmpv3jpmi5iq41kqdibg48299h94iikiw7"))))
909 (build-system python-build-system)
910 ;; Pandas is only needed to run the tests.
911 (native-inputs
912 `(("python-pandas" ,python-pandas)))
913 (propagated-inputs
914 `(("python-numpy" ,python-numpy)
915 ("python-scipy" ,python-scipy)
916 ("python-scikit-learn" ,python-scikit-learn)
917 ("python-joblib" ,python-joblib)))
918 (home-page "https://epistasislab.github.io/scikit-rebate/")
919 (synopsis "Relief-based feature selection algorithms for Python")
920 (description "Scikit-rebate is a scikit-learn-compatible Python
921implementation of ReBATE, a suite of Relief-based feature selection algorithms
922for Machine Learning. These algorithms excel at identifying features that are
923predictive of the outcome in supervised learning problems, and are especially
924good at identifying feature interactions that are normally overlooked by
925standard feature selection algorithms.")
926 (license license:expat)))
927
2dab4188
FT
928(define-public python-autograd
929 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
930 (revision "0")
931 (version (git-version "0.0.0" revision commit)))
932 (package
933 (name "python-autograd")
934 (home-page "https://github.com/HIPS/autograd")
935 (source (origin
936 (method git-fetch)
937 (uri (git-reference
938 (url home-page)
939 (commit commit)))
940 (sha256
941 (base32
942 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
943 (file-name (git-file-name name version))))
944 (version version)
945 (build-system python-build-system)
946 (native-inputs
947 `(("python-nose" ,python-nose)
948 ("python-pytest" ,python-pytest)))
949 (propagated-inputs
950 `(("python-future" ,python-future)
951 ("python-numpy" ,python-numpy)))
952 (arguments
953 `(#:phases (modify-phases %standard-phases
954 (replace 'check
955 (lambda _
956 (invoke "py.test" "-v"))))))
957 (synopsis "Efficiently computes derivatives of NumPy code")
958 (description "Autograd can automatically differentiate native Python and
959NumPy code. It can handle a large subset of Python's features, including loops,
960ifs, recursion and closures, and it can even take derivatives of derivatives
961of derivatives. It supports reverse-mode differentiation
962(a.k.a. backpropagation), which means it can efficiently take gradients of
963scalar-valued functions with respect to array-valued arguments, as well as
964forward-mode differentiation, and the two can be composed arbitrarily. The
965main intended application of Autograd is gradient-based optimization.")
966 (license license:expat))))
967
968(define-public python2-autograd
969 (package-with-python2 python-autograd))
112c2c01
FT
970
971(define-public lightgbm
972 (package
973 (name "lightgbm")
974 (version "2.0.12")
975 (source (origin
a2a7cc9b
EF
976 (method git-fetch)
977 (uri (git-reference
978 (url "https://github.com/Microsoft/LightGBM")
979 (commit (string-append "v" version))))
112c2c01
FT
980 (sha256
981 (base32
a2a7cc9b
EF
982 "0jlvyn7k81dzrh9ij3zw576wbgiwmmr26rzpdxjn1dbpc3njpvzi"))
983 (file-name (git-file-name name version))))
112c2c01
FT
984 (native-inputs
985 `(("python-pytest" ,python-pytest)
986 ("python-nose" ,python-nose)))
987 (inputs
988 `(("openmpi" ,openmpi)))
989 (propagated-inputs
990 `(("python-numpy" ,python-numpy)
991 ("python-scipy" ,python-scipy)))
992 (arguments
993 `(#:configure-flags
994 '("-DUSE_MPI=ON")
995 #:phases
996 (modify-phases %standard-phases
997 (replace 'check
a2a7cc9b
EF
998 (lambda _
999 (with-directory-excursion "../source"
112c2c01
FT
1000 (invoke "pytest" "tests/c_api_test/test_.py")))))))
1001 (build-system cmake-build-system)
1002 (home-page "https://github.com/Microsoft/LightGBM")
1003 (synopsis "Gradient boosting framework based on decision tree algorithms")
1004 (description "LightGBM is a gradient boosting framework that uses tree
1005based learning algorithms. It is designed to be distributed and efficient with
1006the following advantages:
1007
1008@itemize
1009@item Faster training speed and higher efficiency
1010@item Lower memory usage
1011@item Better accuracy
1012@item Parallel and GPU learning supported (not enabled in this package)
1013@item Capable of handling large-scale data
1014@end itemize\n")
1015 (license license:expat)))
a8fb82a8
FT
1016
1017(define-public vowpal-wabbit
1018 ;; Language bindings not included.
1019 (package
1020 (name "vowpal-wabbit")
1021 (version "8.5.0")
1022 (source (origin
4eb40497
EF
1023 (method git-fetch)
1024 (uri (git-reference
1025 (url "https://github.com/JohnLangford/vowpal_wabbit")
1026 (commit version)))
a8fb82a8
FT
1027 (sha256
1028 (base32
4eb40497
EF
1029 "04bwzk6ifgnz3fmzid8b7avxf9n5pnx9xcjm61nkjng1vv0bpj8x"))
1030 (file-name (git-file-name name version))))
a8fb82a8
FT
1031 (inputs
1032 `(("boost" ,boost)
1033 ("zlib" ,zlib)))
1034 (arguments
1035 `(#:configure-flags
1036 (list (string-append "--with-boost="
4eb40497
EF
1037 (assoc-ref %build-inputs "boost")))
1038 #:phases
1039 (modify-phases %standard-phases
1040 (add-after 'unpack 'make-files-writable
1041 (lambda _
d9bba529
EF
1042 (for-each make-file-writable (find-files "." ".*")) #t))
1043 (add-after 'install 'install-more-headers
1044 (lambda* (#:key outputs #:allow-other-keys)
1045 (for-each
1046 (lambda (file)
1047 (install-file file (string-append
1048 (assoc-ref outputs "out")
1049 "/include/vowpalwabbit")))
1050 (find-files "vowpalwabbit" "\\.h$"))
1051 #t)))))
a8fb82a8
FT
1052 (build-system gnu-build-system)
1053 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
1054 (synopsis "Fast machine learning library for online learning")
1055 (description "Vowpal Wabbit is a machine learning system with techniques
1056such as online, hashing, allreduce, reductions, learning2search, active, and
1057interactive learning.")
1058 (license license:bsd-3)))
915c6bf6
LC
1059
1060(define-public python2-fastlmm
1061 (package
1062 (name "python2-fastlmm")
1063 (version "0.2.21")
1064 (source
1065 (origin
1066 (method url-fetch)
1067 (uri (pypi-uri "fastlmm" version ".zip"))
1068 (sha256
1069 (base32
1070 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
1071 (build-system python-build-system)
1072 (arguments
237ee6f2
RW
1073 `(#:tests? #f ; some test files are missing
1074 #:python ,python-2)) ; only Python 2.7 is supported
915c6bf6
LC
1075 (propagated-inputs
1076 `(("python2-numpy" ,python2-numpy)
1077 ("python2-scipy" ,python2-scipy)
1078 ("python2-matplotlib" ,python2-matplotlib)
1079 ("python2-pandas" ,python2-pandas)
1080 ("python2-scikit-learn" ,python2-scikit-learn)
1081 ("python2-pysnptools" ,python2-pysnptools)))
1082 (native-inputs
1083 `(("unzip" ,unzip)
1084 ("python2-cython" ,python2-cython)
1085 ("python2-mock" ,python2-mock)
1086 ("python2-nose" ,python2-nose)))
1087 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
1088 (synopsis "Perform genome-wide association studies on large data sets")
1089 (description
1090 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
1091Models, is a program for performing both single-SNP and SNP-set genome-wide
1092association studies (GWAS) on extremely large data sets.")
1093 (license license:asl2.0)))
b9445d0b
RW
1094
1095;; There have been no proper releases yet.
1096(define-public kaldi
0877b74f
RW
1097 (let ((commit "d4791c0f3fc1a09c042dac365e120899ee2ad21e")
1098 (revision "2"))
b9445d0b
RW
1099 (package
1100 (name "kaldi")
1101 (version (git-version "0" revision commit))
1102 (source (origin
1103 (method git-fetch)
1104 (uri (git-reference
b0e7b699 1105 (url "https://github.com/kaldi-asr/kaldi")
b9445d0b
RW
1106 (commit commit)))
1107 (file-name (git-file-name name version))
1108 (sha256
1109 (base32
0877b74f 1110 "07k80my6f19mhrkwbzhjsnpf9871wmrwkl0ym468i830w67qyjrz"))))
b9445d0b
RW
1111 (build-system gnu-build-system)
1112 (arguments
1113 `(#:test-target "test"
1114 #:phases
1115 (modify-phases %standard-phases
1116 (add-after 'unpack 'chdir
1117 (lambda _ (chdir "src") #t))
1118 (replace 'configure
1119 (lambda* (#:key build system inputs outputs #:allow-other-keys)
1120 (when (not (or (string-prefix? "x86_64" system)
1121 (string-prefix? "i686" system)))
1122 (substitute* "makefiles/linux_openblas.mk"
1123 (("-msse -msse2") "")))
1124 (substitute* "makefiles/default_rules.mk"
1125 (("/bin/bash") (which "bash")))
1126 (substitute* "Makefile"
1127 (("ext_depend: check_portaudio")
1128 "ext_depend:"))
1129 (substitute* '("online/Makefile"
1130 "onlinebin/Makefile"
1131 "gst-plugin/Makefile")
1132 (("../../tools/portaudio/install")
1133 (assoc-ref inputs "portaudio")))
1134
1135 ;; This `configure' script doesn't support variables passed as
1136 ;; arguments, nor does it support "prefix".
1137 (let ((out (assoc-ref outputs "out"))
1138 (openblas (assoc-ref inputs "openblas"))
1139 (openfst (assoc-ref inputs "openfst")))
1140 (substitute* "configure"
1141 (("check_for_slow_expf;") "")
1142 ;; This affects the RPATH and also serves as the installation
1143 ;; directory.
1144 (("KALDILIBDIR=`pwd`/lib")
1145 (string-append "KALDILIBDIR=" out "/lib")))
1146 (mkdir-p out) ; must exist
1147 (setenv "CONFIG_SHELL" (which "bash"))
1148 (setenv "OPENFST_VER" ,(package-version openfst))
1149 (invoke "./configure"
1150 "--use-cuda=no"
1151 "--shared"
1152 (string-append "--openblas-root=" openblas)
1153 (string-append "--fst-root=" openfst)))))
1154 (add-after 'build 'build-ext-and-gstreamer-plugin
1155 (lambda _
1156 (invoke "make" "-C" "online" "depend")
1157 (invoke "make" "-C" "online")
1158 (invoke "make" "-C" "onlinebin" "depend")
1159 (invoke "make" "-C" "onlinebin")
1160 (invoke "make" "-C" "gst-plugin" "depend")
1161 (invoke "make" "-C" "gst-plugin")
1162 #t))
1163 ;; TODO: also install the executables.
1164 (replace 'install
1165 (lambda* (#:key outputs #:allow-other-keys)
1166 (let* ((out (assoc-ref outputs "out"))
1fdd20c7 1167 (inc (string-append out "/include"))
b9445d0b
RW
1168 (lib (string-append out "/lib")))
1169 (mkdir-p lib)
1fdd20c7
RW
1170 ;; The build phase installed symlinks to the actual
1171 ;; libraries. Install the actual targets.
1172 (for-each (lambda (file)
1173 (let ((target (readlink file)))
1174 (delete-file file)
1175 (install-file target lib)))
1176 (find-files lib "\\.so"))
1177 ;; Install headers
1178 (for-each (lambda (file)
1179 (let ((target-dir (string-append inc "/" (dirname file))))
1180 (install-file file target-dir)))
1181 (find-files "." "\\.h"))
1182 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1183 (string-append lib "/gstreamer-1.0"))
b9445d0b
RW
1184 #t))))))
1185 (inputs
1186 `(("alsa-lib" ,alsa-lib)
1187 ("gfortran" ,gfortran "lib")
1188 ("glib" ,glib)
1189 ("gstreamer" ,gstreamer)
1190 ("jack" ,jack-1)
1191 ("openblas" ,openblas)
1192 ("openfst" ,openfst)
1193 ("portaudio" ,portaudio)
1194 ("python" ,python)))
1195 (native-inputs
1196 `(("glib" ,glib "bin") ; glib-genmarshal
1197 ("grep" ,grep)
1198 ("sed" ,sed)
1199 ("pkg-config" ,pkg-config)
1200 ("which" ,which)))
1201 (home-page "https://kaldi-asr.org/")
1202 (synopsis "Speech recognition toolkit")
1203 (description "Kaldi is an extensible toolkit for speech recognition
1204written in C++.")
1205 (license license:asl2.0))))
99260014
RW
1206
1207(define-public gst-kaldi-nnet2-online
b3cf5f86
RW
1208 (let ((commit "cb227ef43b66a9835c14eb0ad39e08ee03c210ad")
1209 (revision "2"))
99260014
RW
1210 (package
1211 (name "gst-kaldi-nnet2-online")
1212 (version (git-version "0" revision commit))
1213 (source (origin
1214 (method git-fetch)
1215 (uri (git-reference
b0e7b699 1216 (url "https://github.com/alumae/gst-kaldi-nnet2-online")
99260014
RW
1217 (commit commit)))
1218 (file-name (git-file-name name version))
1219 (sha256
1220 (base32
b3cf5f86 1221 "1i6ffwiavxx07ri0lxix6s8q0r31x7i4xxvhys5jxkixf5q34w8g"))))
99260014
RW
1222 (build-system gnu-build-system)
1223 (arguments
1224 `(#:tests? #f ; there are none
1225 #:make-flags
1226 (list (string-append "SHELL="
1227 (assoc-ref %build-inputs "bash") "/bin/bash")
1228 (string-append "KALDI_ROOT="
1229 (assoc-ref %build-inputs "kaldi-src"))
1230 (string-append "KALDILIBDIR="
1231 (assoc-ref %build-inputs "kaldi") "/lib")
1232 "KALDI_FLAVOR=dynamic")
1233 #:phases
1234 (modify-phases %standard-phases
1235 (add-after 'unpack 'chdir
1236 (lambda _ (chdir "src") #t))
1237 (replace 'configure
1238 (lambda* (#:key inputs #:allow-other-keys)
1239 (let ((glib (assoc-ref inputs "glib")))
ad60a348 1240 (setenv "CXXFLAGS" "-fPIC")
99260014
RW
1241 (setenv "CPLUS_INCLUDE_PATH"
1242 (string-append glib "/include/glib-2.0:"
1243 glib "/lib/glib-2.0/include:"
1244 (assoc-ref inputs "gstreamer")
ad60a348 1245 "/include/gstreamer-1.0")))
99260014
RW
1246 (substitute* "Makefile"
1247 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
ad60a348
MB
1248 (("\\$\\(error Cannot find") "#"))
1249 #t))
99260014
RW
1250 (add-before 'build 'build-depend
1251 (lambda* (#:key make-flags #:allow-other-keys)
1252 (apply invoke "make" "depend" make-flags)))
1253 (replace 'install
1254 (lambda* (#:key outputs #:allow-other-keys)
1255 (let* ((out (assoc-ref outputs "out"))
1256 (lib (string-append out "/lib/gstreamer-1.0")))
1257 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1258 #t))))))
1259 (inputs
1260 `(("glib" ,glib)
1261 ("gstreamer" ,gstreamer)
1262 ("jansson" ,jansson)
1263 ("openfst" ,openfst)
1264 ("kaldi" ,kaldi)))
1265 (native-inputs
1266 `(("bash" ,bash)
1267 ("glib:bin" ,glib "bin") ; glib-genmarshal
1268 ("kaldi-src" ,(package-source kaldi))
1269 ("pkg-config" ,pkg-config)))
1270 (home-page "https://kaldi-asr.org/")
1271 (synopsis "Gstreamer plugin for decoding speech")
1272 (description "This package provides a GStreamer plugin that wraps
1273Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1274acoustic models. The iVectors are adapted to the current audio stream
1275automatically.")
1276 (license license:asl2.0))))
10451f6b
RW
1277
1278(define-public kaldi-gstreamer-server
1228c2ab
RW
1279 ;; This is the tip of the py3 branch
1280 (let ((commit "f68cab490be7eb0da2af1475fbc16655f50a60cb")
1281 (revision "2"))
10451f6b
RW
1282 (package
1283 (name "kaldi-gstreamer-server")
1284 (version (git-version "0" revision commit))
1285 (source (origin
1286 (method git-fetch)
1287 (uri (git-reference
b0e7b699 1288 (url "https://github.com/alumae/kaldi-gstreamer-server")
10451f6b
RW
1289 (commit commit)))
1290 (file-name (git-file-name name version))
1291 (sha256
1292 (base32
1228c2ab 1293 "17lh1368vkg8ngrcbn2phvigzlmalrqg6djx2gg61qq1a0nj87dm"))))
10451f6b
RW
1294 (build-system gnu-build-system)
1295 (arguments
1296 `(#:tests? #f ; there are no tests that can be run automatically
1297 #:modules ((guix build utils)
1298 (guix build gnu-build-system)
1299 (srfi srfi-26))
1300 #:phases
1301 (modify-phases %standard-phases
1302 (delete 'configure)
1303 (replace 'build
1304 (lambda* (#:key outputs #:allow-other-keys)
1305 ;; Disable hash randomization to ensure the generated .pycs
1306 ;; are reproducible.
1307 (setenv "PYTHONHASHSEED" "0")
1308 (with-directory-excursion "kaldigstserver"
46d07f84
RW
1309 ;; See https://github.com/alumae/kaldi-gstreamer-server/issues/232
1310 (substitute* "master_server.py"
1311 (("\\.replace\\('\\\\.*") ")"))
1312
1228c2ab
RW
1313 ;; This is a Python 2 file
1314 (delete-file "decoder_test.py")
1315 (delete-file "test-buffer.py")
1316
10451f6b
RW
1317 (for-each (lambda (file)
1318 (apply invoke
1319 `("python"
1320 "-m" "compileall"
1321 "-f" ; force rebuild
1322 ,file)))
1323 (find-files "." "\\.py$")))
1324 #t))
1325 (replace 'install
1326 (lambda* (#:key inputs outputs #:allow-other-keys)
1327 (let* ((out (assoc-ref outputs "out"))
1328 (bin (string-append out "/bin"))
1329 (share (string-append out "/share/kaldi-gstreamer-server/")))
1330 ;; Install Python files
1331 (with-directory-excursion "kaldigstserver"
1332 (for-each (cut install-file <> share)
1333 (find-files "." ".*")))
1334
1335 ;; Install sample configuration files
1336 (for-each (cut install-file <> share)
1337 (find-files "." "\\.yaml"))
1338
1339 ;; Install executables
1340 (mkdir-p bin)
1341 (let* ((server (string-append bin "/kaldi-gst-server"))
1342 (client (string-append bin "/kaldi-gst-client"))
1343 (worker (string-append bin "/kaldi-gst-worker"))
1344 (PYTHONPATH (getenv "PYTHONPATH"))
1345 (GST_PLUGIN_PATH (string-append
1346 (assoc-ref inputs "gst-kaldi-nnet2-online")
1347 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1348 (wrap (lambda (wrapper what)
1349 (with-output-to-file wrapper
1350 (lambda _
1351 (format #t
1352 "#!~a
1353export PYTHONPATH=~a
1354export GST_PLUGIN_PATH=~a
1355exec ~a ~a/~a \"$@\"~%"
1356 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1357 (which "python") share what)))
1358 (chmod wrapper #o555))))
1359 (for-each wrap
1360 (list server client worker)
1361 (list "master_server.py"
1362 "client.py"
1363 "worker.py")))
1364 #t))))))
1365 (inputs
1366 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1228c2ab
RW
1367 ("python" ,python-wrapper)
1368 ("python-pygobject" ,python-pygobject)
1369 ("python-pyyaml" ,python-pyyaml)
cb44af24 1370 ("python-tornado" ,python-tornado-6)))
10451f6b
RW
1371 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1372 (synopsis "Real-time full-duplex speech recognition server")
1373 (description "This is a real-time full-duplex speech recognition server,
1374based on the Kaldi toolkit and the GStreamer framework and implemented in
1375Python.")
1376 (license license:bsd-2))))
0dfeb285 1377
4fa16c9a
RW
1378;; Note that Tensorflow includes a "third_party" directory, which seems to not
1379;; only contain modified subsets of upstream library source code, but also
1380;; adapter headers provided by Google (such as the fft.h header, which is not
1381;; part of the upstream project code). The Tensorflow code includes headers
1382;; from the "third_party" directory. It does not look like we can replace
1383;; these headers with unmodified upstream files, so we keep them.
1384(define-public tensorflow
1385 (package
1386 (name "tensorflow")
1387 (version "1.9.0")
1388 (source
1389 (origin
1390 (method git-fetch)
1391 (uri (git-reference
b0e7b699 1392 (url "https://github.com/tensorflow/tensorflow")
4fa16c9a
RW
1393 (commit (string-append "v" version))))
1394 (file-name (string-append "tensorflow-" version "-checkout"))
1395 (sha256
1396 (base32
1397 "0a9kwha395g3wgxfwln5j8vn9nkspmd75xldrlqdq540w996g8xa"))))
1398 (build-system cmake-build-system)
1399 (arguments
1400 `(#:tests? #f ; no "check" target
1401 #:build-type "Release"
1402 #:configure-flags
1403 (let ((protobuf (assoc-ref %build-inputs "protobuf"))
1404 (protobuf:native (assoc-ref %build-inputs "protobuf:native"))
1405 (jsoncpp (assoc-ref %build-inputs "jsoncpp"))
1406 (snappy (assoc-ref %build-inputs "snappy"))
1407 (sqlite (assoc-ref %build-inputs "sqlite")))
1408 (list
1409 ;; Use protobuf from Guix
1410 (string-append "-Dprotobuf_STATIC_LIBRARIES="
1411 protobuf "/lib/libprotobuf.so")
1412 (string-append "-DPROTOBUF_PROTOC_EXECUTABLE="
1413 protobuf:native "/bin/protoc")
1414
1415 ;; Use snappy from Guix
1416 (string-append "-Dsnappy_STATIC_LIBRARIES="
1417 snappy "/lib/libsnappy.so")
1418 ;; Yes, this is not actually the include directory but a prefix...
1419 (string-append "-Dsnappy_INCLUDE_DIR=" snappy)
1420
1421 ;; Use jsoncpp from Guix
1422 (string-append "-Djsoncpp_STATIC_LIBRARIES="
1423 jsoncpp "/lib/libjsoncpp.so")
1424 ;; Yes, this is not actually the include directory but a prefix...
1425 (string-append "-Djsoncpp_INCLUDE_DIR=" jsoncpp)
1426
1427 ;; Use sqlite from Guix
1428 (string-append "-Dsqlite_STATIC_LIBRARIES="
1429 sqlite "/lib/libsqlite.a")
1430
1431 ;; Use system libraries wherever possible. Currently, this
1432 ;; only affects zlib.
1433 "-Dsystemlib_ALL=ON"
1434 "-Dtensorflow_ENABLE_POSITION_INDEPENDENT_CODE=ON"
1435 "-Dtensorflow_BUILD_SHARED_LIB=ON"
1436 "-Dtensorflow_OPTIMIZE_FOR_NATIVE_ARCH=OFF"
1437 "-Dtensorflow_ENABLE_SSL_SUPPORT=OFF"
1438 "-Dtensorflow_BUILD_CONTRIB_KERNELS=OFF"))
1439 #:make-flags
1440 (list "CC=gcc")
1441 #:modules ((ice-9 ftw)
1442 (guix build utils)
0b967058
EF
1443 (guix build cmake-build-system)
1444 ((guix build python-build-system)
1445 #:select (python-version)))
1446 #:imported-modules (,@%cmake-build-system-modules
1447 (guix build python-build-system))
4fa16c9a
RW
1448 #:phases
1449 (modify-phases %standard-phases
1450 (add-after 'unpack 'set-source-file-times-to-1980
1451 ;; At the end of the tf_python_build_pip_package target, a ZIP
1452 ;; archive should be generated via bdist_wheel, but it fails with
1453 ;; "ZIP does not support timestamps before 1980". Luckily,
1454 ;; SOURCE_DATE_EPOCH is respected, which we set to some time in
1455 ;; 1980.
1456 (lambda _ (setenv "SOURCE_DATE_EPOCH" "315532800") #t))
1457 ;; See https://github.com/tensorflow/tensorflow/issues/20517#issuecomment-406373913
1458 (add-after 'unpack 'python3.7-compatibility
1459 (lambda _
1460 (substitute* '("tensorflow/python/eager/pywrap_tfe_src.cc"
1461 "tensorflow/python/lib/core/ndarray_tensor.cc"
1462 "tensorflow/python/lib/core/py_func.cc")
1463 (("PyUnicode_AsUTF8") "(char *)PyUnicode_AsUTF8"))
1464 (substitute* "tensorflow/c/eager/c_api.h"
1465 (("unsigned char async")
1466 "unsigned char is_async"))
1467
1468 ;; Remove dependency on tensorboard, a complicated but probably
1469 ;; optional package.
1470 (substitute* "tensorflow/tools/pip_package/setup.py"
1471 ((".*'tensorboard >.*") ""))
0b967058
EF
1472
1473 ;; Fix the build with python-3.8, taken from rejected upstream patch:
1474 ;; https://github.com/tensorflow/tensorflow/issues/34197
1475 (substitute* (find-files "tensorflow/python" ".*\\.cc$")
1476 (("(nullptr,)(\\ +/. tp_print)" _ _ tp_print)
1477 (string-append "NULL, " tp_print)))
4fa16c9a
RW
1478 #t))
1479 (add-after 'python3.7-compatibility 'chdir
1480 (lambda _ (chdir "tensorflow/contrib/cmake") #t))
1481 (add-after 'chdir 'disable-downloads
1482 (lambda* (#:key inputs #:allow-other-keys)
1483 (substitute* (find-files "external" "\\.cmake$")
1484 (("GIT_REPOSITORY.*") "")
1485 (("GIT_TAG.*") "")
1486 (("PREFIX ")
1487 "DOWNLOAD_COMMAND \"\"\nPREFIX "))
1488
1489 ;; Use packages from Guix
1490 (let ((grpc (assoc-ref inputs "grpc")))
1491 (substitute* "CMakeLists.txt"
1492 ;; Sqlite
1493 (("include\\(sqlite\\)") "")
1494 (("\\$\\{sqlite_STATIC_LIBRARIES\\}")
1495 (string-append (assoc-ref inputs "sqlite")
1496 "/lib/libsqlite3.so"))
1497 (("sqlite_copy_headers_to_destination") "")
1498
1499 ;; PNG
1500 (("include\\(png\\)") "")
1501 (("\\$\\{png_STATIC_LIBRARIES\\}")
1502 (string-append (assoc-ref inputs "libpng")
1503 "/lib/libpng16.so"))
1504 (("png_copy_headers_to_destination") "")
1505
1506 ;; JPEG
1507 (("include\\(jpeg\\)") "")
1508 (("\\$\\{jpeg_STATIC_LIBRARIES\\}")
1509 (string-append (assoc-ref inputs "libjpeg")
1510 "/lib/libjpeg.so"))
1511 (("jpeg_copy_headers_to_destination") "")
1512
1513 ;; GIF
1514 (("include\\(gif\\)") "")
1515 (("\\$\\{gif_STATIC_LIBRARIES\\}")
1516 (string-append (assoc-ref inputs "giflib")
1517 "/lib/libgif.so"))
1518 (("gif_copy_headers_to_destination") "")
1519
1520 ;; lmdb
1521 (("include\\(lmdb\\)") "")
1522 (("\\$\\{lmdb_STATIC_LIBRARIES\\}")
1523 (string-append (assoc-ref inputs "lmdb")
1524 "/lib/liblmdb.so"))
1525 (("lmdb_copy_headers_to_destination") "")
1526
1527 ;; Protobuf
1528 (("include\\(protobuf\\)") "")
1529 (("protobuf_copy_headers_to_destination") "")
1530 (("^ +protobuf") "")
1531
1532 ;; gRPC
1533 (("include\\(grpc\\)")
1534 "find_package(grpc REQUIRED NAMES gRPC)")
1535 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES grpc\\)") "")
1536
1537 ;; Eigen
1538 (("include\\(eigen\\)")
1539 (string-append "find_package(eigen REQUIRED NAMES Eigen3)
1540set(eigen_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/external/eigen_archive "
1541 (assoc-ref inputs "eigen") "/include/eigen3)"))
1542 (("^ +eigen") "")
1543
1544 ;; snappy
1545 (("include\\(snappy\\)")
1546 "add_definitions(-DTF_USE_SNAPPY)")
1547 (("list\\(APPEND tensorflow_EXTERNAL_DEPENDENCIES snappy\\)") "")
1548
1549 ;; jsoncpp
1550 (("include\\(jsoncpp\\)") "")
1551 (("^ +jsoncpp") ""))
1552
1553 (substitute* "tf_core_framework.cmake"
1554 ((" grpc") "")
1555 (("\\$\\{GRPC_BUILD\\}/grpc_cpp_plugin")
1556 (which "grpc_cpp_plugin"))
1557 ;; Link with gRPC libraries
1558 (("add_library\\(tf_protos_cc.*" m)
1559 (string-append m
1560 (format #f "\ntarget_link_libraries(tf_protos_cc PRIVATE \
1561~a/lib/libgrpc++_unsecure.a \
1562~a/lib/libgrpc_unsecure.a \
1563~a/lib/libaddress_sorting.a \
1564~a/lib/libgpr.a \
1565~a//lib/libcares.so
1566)\n"
1567 grpc grpc grpc grpc
1568 (assoc-ref inputs "c-ares"))))))
1569 (substitute* "tf_tools.cmake"
1570 (("add_dependencies\\(\\$\\{proto_text.*") ""))
1571 ;; Remove dependency on bundled grpc
1572 (substitute* "tf_core_distributed_runtime.cmake"
1573 (("tf_core_cpu grpc") "tf_core_cpu"))
1574
1575 ;; This directory is a dependency of many targets.
1576 (mkdir-p "protobuf")
1577 #t))
1578 (add-after 'configure 'unpack-third-party-sources
1579 (lambda* (#:key inputs #:allow-other-keys)
1580 ;; This is needed to configure bundled packages properly.
1581 (setenv "CONFIG_SHELL" (which "bash"))
1582 (for-each
1583 (lambda (name)
1584 (let* ((what (assoc-ref inputs (string-append name "-src")))
1585 (name* (string-map (lambda (c)
1586 (if (char=? c #\-)
1587 #\_ c)) name))
1588 (where (string-append "../build/" name* "/src/" name*)))
1589 (cond
1590 ((string-suffix? ".zip" what)
1591 (mkdir-p where)
1592 (with-directory-excursion where
1593 (invoke "unzip" what)))
1594 ((string-suffix? ".tar.gz" what)
1595 (mkdir-p where)
1596 (invoke "tar" "xf" what
1597 "-C" where "--strip-components=1"))
1598 (else
1599 (let ((parent (dirname where)))
1600 (mkdir-p parent)
1601 (with-directory-excursion parent
1602 (when (file-exists? name*)
1603 (delete-file-recursively name*))
1604 (copy-recursively what name*)
1605 (map make-file-writable
1606 (find-files name* ".*"))))))))
1607 (list "boringssl"
1608 "cub"
1609 "double-conversion"
1610 "farmhash"
1611 "fft2d"
1612 "highwayhash"
1613 "nsync"
1614 "re2"))
1615
1616 (rename-file "../build/cub/src/cub/cub-1.8.0/"
1617 "../build/cub/src/cub/cub/")
1618 #t))
1619 (add-after 'unpack 'fix-python-build
1620 (lambda* (#:key inputs outputs #:allow-other-keys)
1621 (mkdir-p "protobuf-src")
1622 (invoke "tar" "xf" (assoc-ref inputs "protobuf:src")
1623 "-C" "protobuf-src" "--strip-components=1")
1624 (mkdir-p "eigen-src")
1625 (invoke "tar" "xf" (assoc-ref inputs "eigen:src")
1626 "-C" "eigen-src" "--strip-components=1")
1627
1628 (substitute* "tensorflow/contrib/cmake/tf_python.cmake"
1629 ;; Ensure that all Python dependencies can be found at build time.
1630 (("PYTHONPATH=\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/tf_python" m)
1631 (string-append m ":" (getenv "PYTHONPATH")))
1632 ;; Take protobuf source files from our source package.
1633 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/protobuf/src/protobuf/src/google")
1634 (string-append (getcwd) "/protobuf-src/src/google")))
1635
1636 (substitute* '("tensorflow/contrib/cmake/tf_shared_lib.cmake"
1637 "tensorflow/contrib/cmake/tf_python.cmake")
1638 ;; Take Eigen source files from our source package.
1639 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/eigen/src/eigen/")
1640 (string-append (getcwd) "/eigen-src/"))
1641 ;; Take Eigen headers from our own package.
1642 (("\\$\\{CMAKE_CURRENT_BINARY_DIR\\}/external/eigen_archive")
1643 (string-append (assoc-ref inputs "eigen") "/include/eigen3")))
1644
1645 ;; Correct the RUNPATH of ops libraries generated for Python.
1646 ;; TODO: this doesn't work :(
1647 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1648 ;; warning: RUNPATH contains bogus entries: ("/tmp/guix-build-tensorflow-1.9.0.drv-0/source/tensorflow/contrib/build")
1649 ;; /gnu/store/...-tensorflow-1.9.0/lib/python3.7/site-packages/tensorflow/contrib/seq2seq/python/ops/lib_beam_search_ops.so:
1650 ;; error: depends on 'libpywrap_tensorflow_internal.so', which
1651 ;; cannot be found in RUNPATH ...
1652 (substitute* "tensorflow/contrib/cmake/tf_cc_ops.cmake"
1653 (("set_target_properties.*")
1654 (string-append "set_target_properties(${_AT_TARGET} PROPERTIES \
1655COMPILE_FLAGS ${target_compile_flags} \
1656INSTALL_RPATH_USE_LINK_PATH TRUE \
1657INSTALL_RPATH " (assoc-ref outputs "out") "/lib)\n")))
1658 #t))
1659 (add-after 'build 'build-pip-package
1660 (lambda* (#:key outputs #:allow-other-keys)
1661 (setenv "LDFLAGS"
1662 (string-append "-Wl,-rpath="
1663 (assoc-ref outputs "out") "/lib"))
1664 (invoke "make" "tf_python_build_pip_package")
1665 #t))
1666 (add-after 'build-pip-package 'install-python
0b967058 1667 (lambda* (#:key inputs outputs #:allow-other-keys)
4fa16c9a 1668 (let ((out (assoc-ref outputs "out"))
0b967058
EF
1669 (wheel (car (find-files "../build/tf_python/dist/" "\\.whl$")))
1670 (python-version (python-version
1671 (assoc-ref inputs "python"))))
4fa16c9a
RW
1672 (invoke "python" "-m" "pip" "install" wheel
1673 (string-append "--prefix=" out))
1674
1675 ;; XXX: broken RUNPATH, see fix-python-build phase.
1676 (delete-file
1677 (string-append
0b967058
EF
1678 out "/lib/python" python-version
1679 "/site-packages/tensorflow/contrib/"
4fa16c9a
RW
1680 "seq2seq/python/ops/lib_beam_search_ops.so"))
1681 #t))))))
1682 (native-inputs
1683 `(("pkg-config" ,pkg-config)
7373eb83
MB
1684 ("protobuf:native" ,protobuf-3.6) ; protoc
1685 ("protobuf:src" ,(package-source protobuf-3.6))
4fa16c9a 1686 ("eigen:src" ,(package-source eigen-for-tensorflow))
0fdec2a3
MB
1687 ;; install_pip_packages.sh wants setuptools 39.1.0 specifically.
1688 ("python-setuptools" ,python-setuptools-for-tensorflow)
1689
4fa16c9a
RW
1690 ;; The commit hashes and URLs for third-party source code are taken
1691 ;; from "tensorflow/workspace.bzl".
1692 ("boringssl-src"
1693 ,(let ((commit "ee7aa02")
1694 (revision "1"))
1695 (origin
1696 (method git-fetch)
1697 (uri (git-reference
1698 (url "https://boringssl.googlesource.com/boringssl")
1699 (commit commit)))
1700 (file-name (string-append "boringssl-0-" revision
1701 (string-take commit 7)
1702 "-checkout"))
1703 (sha256
1704 (base32
1705 "1jf693q0nw0adsic6cgmbdx6g7wr4rj4vxa8j1hpn792fqhd8wgw")))))
1706 ("cub-src"
1707 ,(let ((version "1.8.0"))
1708 (origin
1709 (method url-fetch)
1710 (uri (string-append "https://mirror.bazel.build/github.com/NVlabs/"
1711 "cub/archive/" version ".zip"))
1712 (file-name (string-append "cub-" version ".zip"))
1713 (sha256
1714 (base32
1715 "1hsqikqridb90dkxkjr2918dcry6pfh46ccnwrzawl56aamhdykb")))))
1716 ("double-conversion-src"
1717 ,(let ((commit "5664746")
1718 (revision "1"))
1719 (origin
1720 (method git-fetch)
1721 (uri (git-reference
b0e7b699 1722 (url "https://github.com/google/double-conversion")
4fa16c9a
RW
1723 (commit commit)))
1724 (file-name
1725 (git-file-name "double-conversion"
1726 (string-append "0-" revision "."
1727 (string-take commit 7))))
1728 (sha256
1729 (base32
1730 "1h5lppqqxcvdg5jq42i5msgwx20ryij3apvmndflngrgdpc04gn1")))))
1731 ("farmhash-src"
1732 ,(let ((commit "816a4ae622e964763ca0862d9dbd19324a1eaf45"))
1733 (origin
1734 (method url-fetch)
1735 (uri (string-append
1736 "https://mirror.bazel.build/github.com/google/farmhash/archive/"
1737 commit ".tar.gz"))
1738 (file-name (string-append "farmhash-0-" (string-take commit 7)
1739 ".tar.gz"))
1740 (sha256
1741 (base32
1742 "185b2xdxl4d4cnsnv6abg8s22gxvx8673jq2yaq85bz4cdy58q35")))))
1743 ;; The license notice on the home page at
1744 ;; http://www.kurims.kyoto-u.ac.jp/~ooura/fft.html says:
1745 ;; Copyright Takuya OOURA, 1996-2001
1746 ;;
1747 ;; You may use, copy, modify and distribute this code for any purpose
1748 ;; (include commercial use) and without fee. Please refer to this
1749 ;; package when you modify this code.
1750 ;;
1751 ;; We take the identical tarball from the Bazel mirror, because the URL
1752 ;; at the home page is not versioned and might change.
1753 ("fft2d-src"
1754 ,(origin
1755 (method url-fetch)
1756 (uri "https://mirror.bazel.build/www.kurims.kyoto-u.ac.jp/~ooura/fft.tgz")
1757 (file-name "fft2d.tar.gz")
1758 (sha256
1759 (base32
1760 "15jjkfvhqvl2c0753d2di8hz0pyzn598g74wqy79awdrf1y67fsj"))))
1761 ("highwayhash-src"
1762 ,(let ((commit "be5edafc2e1a455768e260ccd68ae7317b6690ee")
1763 (revision "1"))
1764 (origin
1765 (method git-fetch)
1766 (uri (git-reference
b0e7b699 1767 (url "https://github.com/google/highwayhash")
4fa16c9a
RW
1768 (commit commit)))
1769 (file-name (string-append "highwayhash-0-" revision
1770 (string-take commit 7)
1771 "-checkout"))
1772 (sha256
1773 (base32
1774 "154jwf98cyy54hldr94pgjn85zynly3abpnc1avmb8a18lzwjyb6")))))
1775 ("nsync-src"
1776 ,(let ((version "0559ce013feac8db639ee1bf776aca0325d28777")
1777 (revision "1"))
1778 (origin
1779 (method url-fetch)
1780 (uri (string-append "https://mirror.bazel.build/"
1781 "github.com/google/nsync/archive/"
1782 version ".tar.gz"))
1783 (file-name (string-append "nsync-0." revision
1784 "-" (string-take version 7)
1785 ".tar.gz"))
1786 (sha256
1787 (base32
1788 "0qdkyqym34x739mmzv97ah5r7ph462v5xkxqxvidmcfqbi64b132")))))
1789 ("re2-src"
1790 ,(let ((commit "e7efc48")
1791 (revision "1"))
1792 (origin
1793 (method git-fetch)
1794 (uri (git-reference
1795 (url "https://github.com/google/re2")
1796 (commit commit)))
1797 (file-name (string-append "re2-0-" revision
1798 (string-take commit 7)
1799 "-checkout"))
1800 (sha256
1801 (base32
1802 "161g9841rjfsy5pn52fcis0s9hdr7rxvb06pad38j5rppfihvign")))))
1803 ("googletest" ,googletest)
1804 ("swig" ,swig)
1805 ("unzip" ,unzip)))
1806 (propagated-inputs
1807 `(("python-absl-py" ,python-absl-py)
1808 ("python-astor" ,python-astor)
1809 ("python-gast" ,python-gast)
1810 ("python-grpcio" ,python-grpcio)
1811 ("python-numpy" ,python-numpy)
7373eb83 1812 ("python-protobuf" ,python-protobuf-3.6)
4fa16c9a
RW
1813 ("python-six" ,python-six)
1814 ("python-termcolo" ,python-termcolor)
1815 ("python-wheel" ,python-wheel)))
1816 (inputs
3b458d54 1817 `(("c-ares" ,c-ares)
4fa16c9a
RW
1818 ("eigen" ,eigen-for-tensorflow)
1819 ("gemmlowp" ,gemmlowp-for-tensorflow)
1820 ("lmdb" ,lmdb)
4bd428a7 1821 ("libjpeg" ,libjpeg-turbo)
4fa16c9a
RW
1822 ("libpng" ,libpng)
1823 ("giflib" ,giflib)
80a8583a 1824 ("grpc" ,grpc-1.16.1 "static")
447fafe3 1825 ("grpc:bin" ,grpc-1.16.1)
4fa16c9a
RW
1826 ("jsoncpp" ,jsoncpp-for-tensorflow)
1827 ("snappy" ,snappy)
1828 ("sqlite" ,sqlite)
7373eb83 1829 ("protobuf" ,protobuf-3.6)
4fa16c9a
RW
1830 ("python" ,python-wrapper)
1831 ("zlib" ,zlib)))
1832 (home-page "https://tensorflow.org")
1833 (synopsis "Machine learning framework")
1834 (description
1835 "TensorFlow is a flexible platform for building and training machine
1836learning models. It provides a library for high performance numerical
1837computation and includes high level Python APIs, including both a sequential
1838API for beginners that allows users to build models quickly by plugging
1839together building blocks and a subclassing API with an imperative style for
1840advanced research.")
1841 (license license:asl2.0)))
d60b064d
NG
1842
1843(define-public python-iml
1844 (package
1845 (name "python-iml")
1846 (version "0.6.2")
1847 (source
1848 (origin
1849 (method url-fetch)
1850 (uri (pypi-uri "iml" version))
1851 (sha256
1852 (base32
1853 "1k8szlpm19rcwcxdny9qdm3gmaqq8akb4xlvrzyz8c2d679aak6l"))))
1854 (build-system python-build-system)
1855 (propagated-inputs
7146c8c7 1856 `(("ipython" ,python-ipython)
d60b064d
NG
1857 ("numpy" ,python-numpy)
1858 ("pandas" ,python-pandas)
1859 ("scipy" ,python-scipy)))
bcbd6340
EK
1860 (native-inputs
1861 `(("nose" ,python-nose)))
dd003125 1862 (home-page "https://github.com/interpretable-ml/iml")
d60b064d
NG
1863 (synopsis "Interpretable Machine Learning (iML) package")
1864 (description "Interpretable ML (iML) is a set of data type objects,
1865visualizations, and interfaces that can be used by any method designed to
1866explain the predictions of machine learning models (or really the output of
1867any function). It currently contains the interface and IO code from the Shap
1868project, and it will potentially also do the same for the Lime project.")
1869 (license license:expat)))
d93ad191
RW
1870
1871(define-public python-keras-applications
1872 (package
1873 (name "python-keras-applications")
1874 (version "1.0.8")
1875 (source
1876 (origin
1877 (method url-fetch)
1878 (uri (pypi-uri "Keras_Applications" version))
1879 (sha256
1880 (base32
1881 "1rcz31ca4axa6kzhjx4lwqxbg4wvlljkj8qj9a7p9sfd5fhzjyam"))))
1882 (build-system python-build-system)
1883 ;; The tests require Keras, but this package is needed to build Keras.
1884 (arguments '(#:tests? #f))
1885 (propagated-inputs
1886 `(("python-h5py" ,python-h5py)
1887 ("python-numpy" ,python-numpy)))
1888 (native-inputs
1889 `(("python-pytest" ,python-pytest)
1890 ("python-pytest-cov" ,python-pytest-cov)
1891 ("python-pytest-pep8" ,python-pytest-pep8)
1892 ("python-pytest-xdist" ,python-pytest-xdist)))
1893 (home-page "https://github.com/keras-team/keras-applications")
1894 (synopsis "Reference implementations of popular deep learning models")
1895 (description
1896 "This package provides reference implementations of popular deep learning
1897models for use with the Keras deep learning framework.")
1898 (license license:expat)))
4abc5066
RW
1899
1900(define-public python-keras-preprocessing
1901 (package
1902 (name "python-keras-preprocessing")
1903 (version "1.1.0")
1904 (source
1905 (origin
1906 (method url-fetch)
1907 (uri (pypi-uri "Keras_Preprocessing" version))
1908 (sha256
1909 (base32
1910 "1r98nm4k1svsqjyaqkfk23i31bl1kcfcyp7094yyj3c43phfp3as"))))
1911 (build-system python-build-system)
1912 (propagated-inputs
1913 `(("python-numpy" ,python-numpy)
1914 ("python-six" ,python-six)))
1915 (native-inputs
1916 `(("python-pandas" ,python-pandas)
1917 ("python-pillow" ,python-pillow)
1918 ("python-pytest" ,python-pytest)
1919 ("python-pytest-cov" ,python-pytest-cov)
1920 ("python-pytest-xdist" ,python-pytest-xdist)
1921 ("tensorflow" ,tensorflow)))
1922 (home-page "https://github.com/keras-team/keras-preprocessing/")
1923 (synopsis "Data preprocessing and augmentation for deep learning models")
1924 (description
1925 "Keras Preprocessing is the data preprocessing and data augmentation
1926module of the Keras deep learning library. It provides utilities for working
1927with image data, text data, and sequence data.")
1928 (license license:expat)))
f1765b57
RW
1929
1930(define-public python-keras
1931 (package
1932 (name "python-keras")
1933 (version "2.2.4")
1934 (source
1935 (origin
1936 (method url-fetch)
1937 (uri (pypi-uri "Keras" version))
b16e0827 1938 (patches (search-patches "python-keras-integration-test.patch"))
f1765b57
RW
1939 (sha256
1940 (base32
1941 "1j8bsqzh49vjdxy6l1k4iwax5vpjzniynyd041xjavdzvfii1dlh"))))
1942 (build-system python-build-system)
1943 (arguments
1944 `(#:phases
1945 (modify-phases %standard-phases
1946 (add-after 'unpack 'remove-tests-for-unavailable-features
1947 (lambda _
1948 (delete-file "keras/backend/theano_backend.py")
1949 (delete-file "keras/backend/cntk_backend.py")
1950 (delete-file "tests/keras/backend/backend_test.py")
1951
1952 ;; FIXME: This doesn't work because Tensorflow is missing the
1953 ;; coder ops library.
1954 (delete-file "tests/keras/test_callbacks.py")
1955 #t))
1956 (replace 'check
1957 (lambda _
1958 ;; These tests attempt to download data files from the internet.
1959 (delete-file "tests/integration_tests/test_datasets.py")
1960 (delete-file "tests/integration_tests/imagenet_utils_test.py")
5f37d7e3
MC
1961 ;; Backport https://github.com/keras-team/keras/pull/12479.
1962 (substitute* "tests/keras/engine/test_topology.py"
1963 (("np.ones\\(\\(3, 2\\)\\)")
1964 "1."))
1965 (invoke "python" "-m" "pytest"
1966 ;; The following test fail only in the build container;
1967 ;; skip it.
1968 "-k" "not test_selu"))))))
f1765b57
RW
1969 (propagated-inputs
1970 `(("python-h5py" ,python-h5py)
1971 ("python-keras-applications" ,python-keras-applications)
1972 ("python-keras-preprocessing" ,python-keras-preprocessing)
1973 ("python-numpy" ,python-numpy)
1974 ("python-pydot" ,python-pydot)
1975 ("python-pyyaml" ,python-pyyaml)
1976 ("python-scipy" ,python-scipy)
1977 ("python-six" ,python-six)
1978 ("tensorflow" ,tensorflow)
1979 ("graphviz" ,graphviz)))
1980 (native-inputs
1981 `(("python-pandas" ,python-pandas)
1982 ("python-pytest" ,python-pytest)
1983 ("python-pytest-cov" ,python-pytest-cov)
1984 ("python-pytest-pep8" ,python-pytest-pep8)
1985 ("python-pytest-timeout" ,python-pytest-timeout)
1986 ("python-pytest-xdist" ,python-pytest-xdist)
1987 ("python-sphinx" ,python-sphinx)
1988 ("python-requests" ,python-requests)))
1989 (home-page "https://github.com/keras-team/keras")
1990 (synopsis "High-level deep learning framework")
1991 (description "Keras is a high-level neural networks API, written in Python
1992and capable of running on top of TensorFlow. It was developed with a focus on
1993enabling fast experimentation. Use Keras if you need a deep learning library
1994that:
1995
1996@itemize
1997@item Allows for easy and fast prototyping (through user friendliness,
1998 modularity, and extensibility).
1999@item Supports both convolutional networks and recurrent networks, as well as
2000 combinations of the two.
2001@item Runs seamlessly on CPU and GPU.
2002@end itemize\n")
2003 (license license:expat)))
6e760872 2004
58b13287
GL
2005(define-public gloo
2006 (let ((version "0.0.0") ; no proper version tag
2007 (commit "ca528e32fea9ca8f2b16053cff17160290fc84ce")
2008 (revision "0"))
2009 (package
2010 (name "gloo")
2011 (version (git-version version revision commit))
2012 (source
2013 (origin
2014 (method git-fetch)
2015 (uri (git-reference
b0e7b699 2016 (url "https://github.com/facebookincubator/gloo")
58b13287
GL
2017 (commit commit)))
2018 (file-name (git-file-name name version))
2019 (sha256
2020 (base32
2021 "1q9f80zy75f6njrzrqkmhc0g3qxs4gskr7ns2jdqanxa2ww7a99w"))))
2022 (build-system cmake-build-system)
2023 (native-inputs
2024 `(("googletest" ,googletest)))
2025 (arguments
2026 `(#:configure-flags '("-DBUILD_TEST=1")
2027 #:phases
2028 (modify-phases %standard-phases
2029 (replace 'check
2030 (lambda _
2031 (invoke "make" "gloo_test")
2032 #t)))))
2033 (synopsis "Collective communications library")
2034 (description
2035 "Gloo is a collective communications library. It comes with a
2036number of collective algorithms useful for machine learning applications.
2037These include a barrier, broadcast, and allreduce.")
2038 (home-page "https://github.com/facebookincubator/gloo")
2039 (license license:bsd-3))))
5e42d197
BG
2040
2041(define-public python-umap-learn
2042 (package
2043 (name "python-umap-learn")
2044 (version "0.3.10")
2045 (source
2046 (origin
2047 (method url-fetch)
2048 (uri (pypi-uri "umap-learn" version))
2049 (sha256
2050 (base32
2051 "02ada2yy6km6zgk2836kg1c97yrcpalvan34p8c57446finnpki1"))))
2052 (build-system python-build-system)
2053 (native-inputs
e2ca10a4
RJ
2054 `(("python-joblib" ,python-joblib)
2055 ("python-nose" ,python-nose)))
5e42d197
BG
2056 (propagated-inputs
2057 `(("python-numba" ,python-numba)
2058 ("python-numpy" ,python-numpy)
2059 ("python-scikit-learn" ,python-scikit-learn)
2060 ("python-scipy" ,python-scipy)))
2061 (home-page "https://github.com/lmcinnes/umap")
2062 (synopsis
2063 "Uniform Manifold Approximation and Projection")
2064 (description
2065 "Uniform Manifold Approximation and Projection is a dimension reduction
2066technique that can be used for visualisation similarly to t-SNE, but also for
2067general non-linear dimension reduction.")
2068 (license license:bsd-3)))