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