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