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