gnu: Add kaldi.
[jackhill/guix/guix.git] / gnu / packages / machine-learning.scm
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2015, 2016, 2017, 2018, 2019 Ricardo Wurmus <rekado@elephly.net>
3 ;;; Copyright © 2016 Efraim Flashner <efraim@flashner.co.il>
4 ;;; Copyright © 2016, 2017 Marius Bakke <mbakke@fastmail.com>
5 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
6 ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
7 ;;; Copyright © 2018 Kei Kebreau <kkebreau@posteo.net>
8 ;;; Copyright © 2018 Mark Meyer <mark@ofosos.org>
9 ;;; Copyright © 2018 Ben Woodcroft <donttrustben@gmail.com>
10 ;;; Copyright © 2018 Fis Trivial <ybbs.daans@hotmail.com>
11 ;;; Copyright © 2018 Julien Lepiller <julien@lepiller.eu>
12 ;;; Copyright © 2018 Björn Höfling <bjoern.hoefling@bjoernhoefling.de>
13 ;;;
14 ;;; This file is part of GNU Guix.
15 ;;;
16 ;;; GNU Guix is free software; you can redistribute it and/or modify it
17 ;;; under the terms of the GNU General Public License as published by
18 ;;; the Free Software Foundation; either version 3 of the License, or (at
19 ;;; your option) any later version.
20 ;;;
21 ;;; GNU Guix is distributed in the hope that it will be useful, but
22 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;;; GNU General Public License for more details.
25 ;;;
26 ;;; You should have received a copy of the GNU General Public License
27 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
28
29 (define-module (gnu packages machine-learning)
30 #:use-module ((guix licenses) #:prefix license:)
31 #:use-module (guix packages)
32 #:use-module (guix utils)
33 #:use-module (guix download)
34 #:use-module (guix svn-download)
35 #:use-module (guix build-system cmake)
36 #:use-module (guix build-system gnu)
37 #:use-module (guix build-system ocaml)
38 #:use-module (guix build-system python)
39 #:use-module (guix build-system r)
40 #:use-module (guix git-download)
41 #:use-module (gnu packages)
42 #:use-module (gnu packages algebra)
43 #:use-module (gnu packages audio)
44 #:use-module (gnu packages autotools)
45 #:use-module (gnu packages base)
46 #:use-module (gnu packages boost)
47 #:use-module (gnu packages check)
48 #:use-module (gnu packages compression)
49 #:use-module (gnu packages cran)
50 #:use-module (gnu packages dejagnu)
51 #:use-module (gnu packages gcc)
52 #:use-module (gnu packages glib)
53 #:use-module (gnu packages gstreamer)
54 #:use-module (gnu packages image)
55 #:use-module (gnu packages linux)
56 #:use-module (gnu packages maths)
57 #:use-module (gnu packages mpi)
58 #:use-module (gnu packages ocaml)
59 #:use-module (gnu packages onc-rpc)
60 #:use-module (gnu packages perl)
61 #:use-module (gnu packages pkg-config)
62 #:use-module (gnu packages python)
63 #:use-module (gnu packages python-xyz)
64 #:use-module (gnu packages statistics)
65 #:use-module (gnu packages swig)
66 #:use-module (gnu packages xml)
67 #:use-module (gnu packages xorg))
68
69 (define-public fann
70 ;; The last release is >100 commits behind, so we package from git.
71 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
72 (package
73 (name "fann")
74 (version (string-append "2.2.0-1." (string-take commit 8)))
75 (source (origin
76 (method git-fetch)
77 (uri (git-reference
78 (url "https://github.com/libfann/fann.git")
79 (commit commit)))
80 (file-name (string-append name "-" version "-checkout"))
81 (sha256
82 (base32
83 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
84 (build-system cmake-build-system)
85 (arguments
86 `(#:phases
87 (modify-phases %standard-phases
88 (replace 'check
89 (lambda* (#:key outputs #:allow-other-keys)
90 (let* ((out (assoc-ref outputs "out")))
91 (with-directory-excursion (string-append (getcwd) "/tests")
92 (invoke "./fann_tests"))))))))
93 (home-page "http://leenissen.dk/fann/wp/")
94 (synopsis "Fast Artificial Neural Network")
95 (description
96 "FANN is a free open source neural network library, which implements
97 multilayer artificial neural networks in C with support for both fully
98 connected and sparsely connected networks.")
99 (license license:lgpl2.1))))
100
101 (define-public libsvm
102 (package
103 (name "libsvm")
104 (version "3.22")
105 (source
106 (origin
107 (method url-fetch)
108 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
109 name "-" version ".tar.gz"))
110 (sha256
111 (base32
112 "0zd7s19y5vb7agczl6456bn45cj1y64739sslaskw1qk7dywd0bd"))))
113 (build-system gnu-build-system)
114 (arguments
115 `(#:tests? #f ;no "check" target
116 #:phases (modify-phases %standard-phases
117 (delete 'configure)
118 (replace
119 'install ; no ‘install’ target
120 (lambda* (#:key outputs #:allow-other-keys)
121 (let* ((out (assoc-ref outputs "out"))
122 (bin (string-append out "/bin/")))
123 (mkdir-p bin)
124 (for-each (lambda (file)
125 (copy-file file (string-append bin file)))
126 '("svm-train"
127 "svm-predict"
128 "svm-scale")))
129 #t)))))
130 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
131 (synopsis "Library for Support Vector Machines")
132 (description
133 "LIBSVM is a machine learning library for support vector
134 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
135 distribution estimation (one-class SVM). It supports multi-class
136 classification.")
137 (license license:bsd-3)))
138
139 (define-public python-libsvm
140 (package (inherit libsvm)
141 (name "python-libsvm")
142 (build-system gnu-build-system)
143 (arguments
144 `(#:tests? #f ;no "check" target
145 #:make-flags '("-C" "python")
146 #:phases
147 (modify-phases %standard-phases
148 (delete 'configure)
149 (replace
150 'install ; no ‘install’ target
151 (lambda* (#:key inputs outputs #:allow-other-keys)
152 (let ((site (string-append (assoc-ref outputs "out")
153 "/lib/python"
154 (string-take
155 (string-take-right
156 (assoc-ref inputs "python") 5) 3)
157 "/site-packages/")))
158 (substitute* "python/svm.py"
159 (("../libsvm.so.2") "libsvm.so.2"))
160 (mkdir-p site)
161 (for-each (lambda (file)
162 (copy-file file (string-append site (basename file))))
163 (find-files "python" "\\.py"))
164 (copy-file "libsvm.so.2"
165 (string-append site "libsvm.so.2")))
166 #t)))))
167 (inputs
168 `(("python" ,python)))
169 (synopsis "Python bindings of libSVM")))
170
171 (define-public ghmm
172 ;; The latest release candidate is several years and a couple of fixes have
173 ;; been published since. This is why we download the sources from the SVN
174 ;; repository.
175 (let ((svn-revision 2341))
176 (package
177 (name "ghmm")
178 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
179 (source (origin
180 (method svn-fetch)
181 (uri (svn-reference
182 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
183 (revision svn-revision)))
184 (file-name (string-append name "-" version))
185 (sha256
186 (base32
187 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
188 (build-system gnu-build-system)
189 (arguments
190 `(#:imported-modules (,@%gnu-build-system-modules
191 (guix build python-build-system))
192 #:phases
193 (modify-phases %standard-phases
194 (add-after 'unpack 'enter-dir
195 (lambda _ (chdir "ghmm") #t))
196 (delete 'check)
197 (add-after 'install 'check
198 (assoc-ref %standard-phases 'check))
199 (add-before 'check 'fix-PYTHONPATH
200 (lambda* (#:key inputs outputs #:allow-other-keys)
201 (let ((python-version ((@@ (guix build python-build-system)
202 get-python-version)
203 (assoc-ref inputs "python"))))
204 (setenv "PYTHONPATH"
205 (string-append (getenv "PYTHONPATH")
206 ":" (assoc-ref outputs "out")
207 "/lib/python" python-version
208 "/site-packages")))
209 #t))
210 (add-after 'enter-dir 'fix-runpath
211 (lambda* (#:key outputs #:allow-other-keys)
212 (substitute* "ghmmwrapper/setup.py"
213 (("^(.*)extra_compile_args = \\[" line indent)
214 (string-append indent
215 "extra_link_args = [\"-Wl,-rpath="
216 (assoc-ref outputs "out") "/lib\"],\n"
217 line
218 "\"-Wl,-rpath="
219 (assoc-ref outputs "out")
220 "/lib\", ")))
221 #t))
222 (add-after 'enter-dir 'disable-broken-tests
223 (lambda _
224 (substitute* "tests/Makefile.am"
225 ;; GHMM_SILENT_TESTS is assumed to be a command.
226 (("TESTS_ENVIRONMENT.*") "")
227 ;; Do not build broken tests.
228 (("chmm .*") "")
229 (("read_fa .*") "")
230 (("mcmc .*") "")
231 (("label_higher_order_test.*$")
232 "label_higher_order_test\n"))
233
234 ;; These Python unittests are broken as there is no gato.
235 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
236 (substitute* "ghmmwrapper/ghmmunittests.py"
237 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
238 line indent)
239 (string-append indent
240 "@unittest.skip(\"Disabled by Guix\")\n"
241 line)))
242 #t))
243 (add-after 'disable-broken-tests 'autogen
244 (lambda _
245 (invoke "bash" "autogen.sh"))))))
246 (inputs
247 `(("python" ,python-2) ; only Python 2 is supported
248 ("libxml2" ,libxml2)))
249 (native-inputs
250 `(("pkg-config" ,pkg-config)
251 ("dejagnu" ,dejagnu)
252 ("swig" ,swig)
253 ("autoconf" ,autoconf)
254 ("automake" ,automake)
255 ("libtool" ,libtool)))
256 (home-page "http://ghmm.org")
257 (synopsis "Hidden Markov Model library")
258 (description
259 "The General Hidden Markov Model library (GHMM) is a C library with
260 additional Python bindings implementing a wide range of types of @dfn{Hidden
261 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
262 training, HMM clustering, HMM mixtures.")
263 (license license:lgpl2.0+))))
264
265 (define-public mcl
266 (package
267 (name "mcl")
268 (version "14.137")
269 (source (origin
270 (method url-fetch)
271 (uri (string-append
272 "http://micans.org/mcl/src/mcl-"
273 (string-replace-substring version "." "-")
274 ".tar.gz"))
275 (sha256
276 (base32
277 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
278 (build-system gnu-build-system)
279 (arguments
280 `(#:configure-flags (list "--enable-blast")))
281 (inputs
282 `(("perl" ,perl)))
283 (home-page "http://micans.org/mcl/")
284 (synopsis "Clustering algorithm for graphs")
285 (description
286 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
287 fast and scalable unsupervised cluster algorithm for graphs (also known as
288 networks) based on simulation of (stochastic) flow in graphs.")
289 ;; In the LICENCE file and web page it says "The software is licensed
290 ;; under the GNU General Public License, version 3.", but in several of
291 ;; the source code files it suggests GPL3 or later.
292 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
293 (license license:gpl3)))
294
295 (define-public ocaml-mcl
296 (package
297 (name "ocaml-mcl")
298 (version "12-068oasis4")
299 (source
300 (origin
301 (method url-fetch)
302 (uri (string-append
303 "https://github.com/fhcrc/mcl/archive/"
304 version ".tar.gz"))
305 (file-name (string-append name "-" version ".tar.gz"))
306 (sha256
307 (base32
308 "1l5jbhwjpsj38x8b9698hfpkv75h8hn3kj0gihjhn8ym2cwwv110"))))
309 (build-system ocaml-build-system)
310 (arguments
311 `(#:ocaml ,ocaml-4.02
312 #:findlib ,ocaml4.02-findlib
313 #:phases
314 (modify-phases %standard-phases
315 (add-before 'configure 'patch-paths
316 (lambda _
317 (substitute* "configure"
318 (("SHELL = /bin/sh") (string-append "SHELL = "(which "sh"))))
319 (substitute* "setup.ml"
320 (("LDFLAGS=-fPIC")
321 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh"))))
322 #t)))))
323 (home-page "https://github.com/fhcrc/mcl")
324 (synopsis "OCaml wrappers around MCL")
325 (description
326 "This package provides OCaml bindings for the MCL graph clustering
327 algorithm.")
328 (license license:gpl3)))
329
330 (define-public randomjungle
331 (package
332 (name "randomjungle")
333 (version "2.1.0")
334 (source
335 (origin
336 (method url-fetch)
337 (uri (string-append
338 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
339 "/randomjungle/randomjungle-" version ".tar_.gz"))
340 (patches (search-patches "randomjungle-disable-static-build.patch"))
341 (sha256
342 (base32
343 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
344 (build-system gnu-build-system)
345 (arguments
346 `(#:configure-flags
347 (list "--disable-static"
348 (string-append "--with-boost="
349 (assoc-ref %build-inputs "boost")))
350 #:phases
351 (modify-phases %standard-phases
352 (add-before
353 'configure 'set-CXXFLAGS
354 (lambda _
355 (setenv "CXXFLAGS" "-fpermissive ")
356 #t)))))
357 (inputs
358 `(("boost" ,boost)
359 ("gsl" ,gsl)
360 ("libxml2" ,libxml2)
361 ("zlib" ,zlib)))
362 (native-inputs
363 `(("gfortran" ,gfortran)
364 ("gfortran:lib" ,gfortran "lib")))
365 ;; Non-portable assembly instructions are used so building fails on
366 ;; platforms other than x86_64 or i686.
367 (supported-systems '("x86_64-linux" "i686-linux"))
368 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
369 (synopsis "Implementation of the Random Forests machine learning method")
370 (description
371 "Random Jungle is an implementation of Random Forests. It is supposed to
372 analyse high dimensional data. In genetics, it can be used for analysing big
373 Genome Wide Association (GWA) data. Random Forests is a powerful machine
374 learning method. Most interesting features are variable selection, missing
375 value imputation, classifier creation, generalization error estimation and
376 sample proximities between pairs of cases.")
377 (license license:gpl3+)))
378
379 (define-public openfst
380 (package
381 (name "openfst")
382 (version "1.7.1")
383 (source (origin
384 (method url-fetch)
385 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
386 "FstDownload/openfst-" version ".tar.gz"))
387 (sha256
388 (base32
389 "0x9wfcqd8hq4h349s7j77sr60h8xjdfshqw1m3a2n6z5bdr9qkm1"))))
390 (build-system gnu-build-system)
391 (home-page "http://www.openfst.org")
392 (synopsis "Library for weighted finite-state transducers")
393 (description "OpenFst is a library for constructing, combining,
394 optimizing, and searching weighted finite-state transducers (FSTs).")
395 (license license:asl2.0)))
396
397 (define-public shogun
398 (package
399 (name "shogun")
400 (version "6.1.3")
401 (source
402 (origin
403 (method url-fetch)
404 (uri (string-append
405 "ftp://shogun-toolbox.org/shogun/releases/"
406 (version-major+minor version)
407 "/sources/shogun-" version ".tar.bz2"))
408 (sha256
409 (base32
410 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
411 (modules '((guix build utils)
412 (ice-9 rdelim)))
413 (snippet
414 '(begin
415 ;; Remove non-free sources and files referencing them
416 (for-each delete-file
417 (find-files "src/shogun/classifier/svm/"
418 "SVMLight\\.(cpp|h)"))
419 (for-each delete-file
420 (find-files "examples/undocumented/libshogun/"
421 (string-append
422 "(classifier_.*svmlight.*|"
423 "evaluation_cross_validation_locked_comparison).cpp")))
424 ;; Remove non-free functions.
425 (define (delete-ifdefs file)
426 (with-atomic-file-replacement file
427 (lambda (in out)
428 (let loop ((line (read-line in 'concat))
429 (skipping? #f))
430 (if (eof-object? line)
431 #t
432 (let ((skip-next?
433 (or (and skipping?
434 (not (string-prefix?
435 "#endif //USE_SVMLIGHT" line)))
436 (string-prefix?
437 "#ifdef USE_SVMLIGHT" line))))
438 (when (or (not skipping?)
439 (and skipping? (not skip-next?)))
440 (display line out))
441 (loop (read-line in 'concat) skip-next?)))))))
442 (for-each delete-ifdefs
443 (append
444 (find-files "src/shogun/classifier/mkl"
445 "^MKLClassification\\.cpp")
446 (find-files "src/shogun/classifier/svm"
447 "^SVMLightOneClass\\.(cpp|h)")
448 (find-files "src/shogun/multiclass"
449 "^ScatterSVM\\.(cpp|h)")
450 (find-files "src/shogun/kernel/"
451 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
452 (find-files "src/shogun/regression/svr"
453 "^(MKLRegression|SVRLight)\\.(cpp|h)")
454 (find-files "src/shogun/transfer/domain_adaptation"
455 "^DomainAdaptationSVM\\.(cpp|h)")))
456 #t))))
457 (build-system cmake-build-system)
458 (arguments
459 '(#:tests? #f ;no check target
460 #:phases
461 (modify-phases %standard-phases
462 (add-after 'unpack 'delete-broken-symlinks
463 (lambda _
464 (for-each delete-file '("applications/arts/data"
465 "applications/asp/data"
466 "applications/easysvm/data"
467 "applications/msplicer/data"
468 "applications/ocr/data"
469 "examples/meta/data"
470 "examples/undocumented/data"))
471 #t))
472 (add-after 'unpack 'change-R-target-path
473 (lambda* (#:key outputs #:allow-other-keys)
474 (substitute* '("src/interfaces/r/CMakeLists.txt"
475 "examples/meta/r/CMakeLists.txt")
476 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
477 (string-append (assoc-ref outputs "out")
478 "/lib/R/library/")))
479 #t))
480 (add-after 'unpack 'fix-octave-modules
481 (lambda* (#:key outputs #:allow-other-keys)
482 (substitute* "src/interfaces/octave/CMakeLists.txt"
483 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
484 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
485 ;; change target directory
486 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
487 (string-append (assoc-ref outputs "out")
488 "/share/octave/packages")))
489 (substitute* '("src/interfaces/octave/swig_typemaps.i"
490 "src/interfaces/octave/sg_print_functions.cpp")
491 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
492 (("octave/config\\.h") "octave/octave-config.h")
493 (("octave/oct-obj.h") "octave/ovl.h"))
494 #t))
495 (add-after 'unpack 'move-rxcpp
496 (lambda* (#:key inputs #:allow-other-keys)
497 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
498 (mkdir-p rxcpp-dir)
499 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
500 #t)))
501 (add-before 'build 'set-HOME
502 ;; $HOME needs to be set at some point during the build phase
503 (lambda _ (setenv "HOME" "/tmp") #t)))
504 #:configure-flags
505 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
506 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
507 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
508 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
509 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
510 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
511 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
512 "-DINTERFACE_OCTAVE=ON"
513 "-DINTERFACE_PYTHON=ON"
514 "-DINTERFACE_R=ON")))
515 (inputs
516 `(("python" ,python)
517 ("numpy" ,python-numpy)
518 ("r-minimal" ,r-minimal)
519 ("octave" ,octave-cli)
520 ("swig" ,swig)
521 ("eigen" ,eigen)
522 ("hdf5" ,hdf5)
523 ("atlas" ,atlas)
524 ("arpack" ,arpack-ng)
525 ("lapack" ,lapack)
526 ("glpk" ,glpk)
527 ("libxml2" ,libxml2)
528 ("lzo" ,lzo)
529 ("zlib" ,zlib)))
530 (native-inputs
531 `(("pkg-config" ,pkg-config)
532 ("rxcpp" ,rxcpp)))
533 ;; Non-portable SSE instructions are used so building fails on platforms
534 ;; other than x86_64.
535 (supported-systems '("x86_64-linux"))
536 (home-page "http://shogun-toolbox.org/")
537 (synopsis "Machine learning toolbox")
538 (description
539 "The Shogun Machine learning toolbox provides a wide range of unified and
540 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
541 combine multiple data representations, algorithm classes, and general purpose
542 tools. This enables both rapid prototyping of data pipelines and extensibility
543 in terms of new algorithms.")
544 (license license:gpl3+)))
545
546 (define-public rxcpp
547 (package
548 (name "rxcpp")
549 (version "4.0.0")
550 (source
551 (origin
552 (method url-fetch)
553 (uri (string-append "https://github.com/ReactiveX/RxCpp/archive/v"
554 version ".tar.gz"))
555 (sha256
556 (base32
557 "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"))
558 (file-name (string-append name "-" version ".tar.gz"))))
559 (build-system cmake-build-system)
560 (arguments
561 `(#:phases
562 (modify-phases %standard-phases
563 (add-after 'unpack 'remove-werror
564 (lambda _
565 (substitute* (find-files ".")
566 (("-Werror") ""))
567 #t))
568 (replace 'check
569 (lambda _
570 (invoke "ctest"))))))
571 (native-inputs
572 `(("catch" ,catch-framework)))
573 (home-page "http://reactivex.io/")
574 (synopsis "Reactive Extensions for C++")
575 (description
576 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
577 values-distributed-in-time. ReactiveX is a library for composing asynchronous
578 and event-based programs by using observable sequences.
579
580 It extends the observer pattern to support sequences of data and/or events and
581 adds operators that allow you to compose sequences together declaratively while
582 abstracting away concerns about things like low-level threading,
583 synchronization, thread-safety, concurrent data structures, and non-blocking
584 I/O.")
585 (license license:asl2.0)))
586
587 (define-public r-adaptivesparsity
588 (package
589 (name "r-adaptivesparsity")
590 (version "1.6")
591 (source (origin
592 (method url-fetch)
593 (uri (cran-uri "AdaptiveSparsity" version))
594 (sha256
595 (base32
596 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
597 (properties
598 `((upstream-name . "AdaptiveSparsity")))
599 (build-system r-build-system)
600 (arguments
601 `(#:phases
602 (modify-phases %standard-phases
603 (add-after 'unpack 'link-against-armadillo
604 (lambda _
605 (substitute* "src/Makevars"
606 (("PKG_LIBS=" prefix)
607 (string-append prefix "-larmadillo"))))))))
608 (propagated-inputs
609 `(("r-mass" ,r-mass)
610 ("r-matrix" ,r-matrix)
611 ("r-rcpp" ,r-rcpp)
612 ("r-rcpparmadillo" ,r-rcpparmadillo)))
613 (inputs
614 `(("armadillo" ,armadillo)))
615 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
616 (synopsis "Adaptive sparsity models")
617 (description
618 "This package implements the Figueiredo machine learning algorithm for
619 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
620 geometric models.")
621 (license license:lgpl3+)))
622
623 (define-public r-kernlab
624 (package
625 (name "r-kernlab")
626 (version "0.9-27")
627 (source
628 (origin
629 (method url-fetch)
630 (uri (cran-uri "kernlab" version))
631 (sha256
632 (base32
633 "1m0xqf6gyvwayz7w3c83y32ayvnlz0jicj8ijk808zq9sh7dbbgn"))))
634 (build-system r-build-system)
635 (home-page "https://cran.r-project.org/web/packages/kernlab")
636 (synopsis "Kernel-based machine learning tools")
637 (description
638 "This package provides kernel-based machine learning methods for
639 classification, regression, clustering, novelty detection, quantile regression
640 and dimensionality reduction. Among other methods @code{kernlab} includes
641 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
642 and a QP solver.")
643 (license license:gpl2)))
644
645 (define-public dlib
646 (package
647 (name "dlib")
648 (version "19.7")
649 (source (origin
650 (method url-fetch)
651 (uri (string-append
652 "http://dlib.net/files/dlib-" version ".tar.bz2"))
653 (sha256
654 (base32
655 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
656 (modules '((guix build utils)))
657 (snippet
658 '(begin
659 ;; Delete ~13MB of bundled dependencies.
660 (delete-file-recursively "dlib/external")
661 (delete-file-recursively "docs/dlib/external")
662 #t))))
663 (build-system cmake-build-system)
664 (arguments
665 `(#:phases
666 (modify-phases %standard-phases
667 (add-after 'unpack 'disable-asserts
668 (lambda _
669 ;; config.h recommends explicitly enabling or disabling asserts
670 ;; when building as a shared library. By default neither is set.
671 (substitute* "dlib/config.h"
672 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
673 #t))
674 (add-after 'disable-asserts 'disable-failing-tests
675 (lambda _
676 ;; One test times out on MIPS, so we need to disable it.
677 ;; Others are flaky on some platforms.
678 (let* ((system ,(or (%current-target-system)
679 (%current-system)))
680 (disabled-tests (cond
681 ((string-prefix? "mips64" system)
682 '("object_detector" ; timeout
683 "data_io"))
684 ((string-prefix? "armhf" system)
685 '("learning_to_track"))
686 ((string-prefix? "i686" system)
687 '("optimization"))
688 (else '()))))
689 (for-each
690 (lambda (test)
691 (substitute* "dlib/test/makefile"
692 (((string-append "SRC \\+= " test "\\.cpp")) "")))
693 disabled-tests)
694 #t)))
695 (replace 'check
696 (lambda _
697 ;; No test target, so we build and run the unit tests here.
698 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
699 (with-directory-excursion test-dir
700 (invoke "make" "-j" (number->string (parallel-job-count)))
701 (invoke "./dtest" "--runall"))
702 #t)))
703 (add-after 'install 'delete-static-library
704 (lambda* (#:key outputs #:allow-other-keys)
705 (delete-file (string-append (assoc-ref outputs "out")
706 "/lib/libdlib.a"))
707 #t)))))
708 (native-inputs
709 `(("pkg-config" ,pkg-config)
710 ;; For tests.
711 ("libnsl" ,libnsl)))
712 (inputs
713 `(("giflib" ,giflib)
714 ("lapack" ,lapack)
715 ("libjpeg" ,libjpeg)
716 ("libpng" ,libpng)
717 ("libx11" ,libx11)
718 ("openblas" ,openblas)
719 ("zlib" ,zlib)))
720 (synopsis
721 "Toolkit for making machine learning and data analysis applications in C++")
722 (description
723 "Dlib is a modern C++ toolkit containing machine learning algorithms and
724 tools. It is used in both industry and academia in a wide range of domains
725 including robotics, embedded devices, mobile phones, and large high performance
726 computing environments.")
727 (home-page "http://dlib.net")
728 (license license:boost1.0)))
729
730 (define-public python-scikit-learn
731 (package
732 (name "python-scikit-learn")
733 (version "0.20.1")
734 (source
735 (origin
736 (method git-fetch)
737 (uri (git-reference
738 (url "https://github.com/scikit-learn/scikit-learn.git")
739 (commit version)))
740 (file-name (git-file-name name version))
741 (sha256
742 (base32
743 "0fkhwg3xn1s7ln9q1szq6kwc4jhwvjh8w4kmv9wcrqy7cq3lbv0d"))))
744 (build-system python-build-system)
745 (arguments
746 `(#:phases
747 (modify-phases %standard-phases
748 (add-after 'build 'build-ext
749 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
750 (replace 'check
751 (lambda _
752 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
753 (setenv "OPENBLAS_NUM_THREADS" "1")
754
755 ;; Some tests require write access to $HOME.
756 (setenv "HOME" "/tmp")
757
758 (invoke "pytest" "sklearn" "-m" "not network")))
759 ;; FIXME: This fails with permission denied
760 (delete 'reset-gzip-timestamps))))
761 (inputs
762 `(("openblas" ,openblas)))
763 (native-inputs
764 `(("python-pytest" ,python-pytest)
765 ("python-pandas" ,python-pandas) ;for tests
766 ("python-cython" ,python-cython)))
767 (propagated-inputs
768 `(("python-numpy" ,python-numpy)
769 ("python-scipy" ,python-scipy)))
770 (home-page "http://scikit-learn.org/")
771 (synopsis "Machine Learning in Python")
772 (description
773 "Scikit-learn provides simple and efficient tools for data mining and
774 data analysis.")
775 (license license:bsd-3)))
776
777 (define-public python2-scikit-learn
778 (package-with-python2 python-scikit-learn))
779
780 (define-public python-autograd
781 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
782 (revision "0")
783 (version (git-version "0.0.0" revision commit)))
784 (package
785 (name "python-autograd")
786 (home-page "https://github.com/HIPS/autograd")
787 (source (origin
788 (method git-fetch)
789 (uri (git-reference
790 (url home-page)
791 (commit commit)))
792 (sha256
793 (base32
794 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
795 (file-name (git-file-name name version))))
796 (version version)
797 (build-system python-build-system)
798 (native-inputs
799 `(("python-nose" ,python-nose)
800 ("python-pytest" ,python-pytest)))
801 (propagated-inputs
802 `(("python-future" ,python-future)
803 ("python-numpy" ,python-numpy)))
804 (arguments
805 `(#:phases (modify-phases %standard-phases
806 (replace 'check
807 (lambda _
808 (invoke "py.test" "-v"))))))
809 (synopsis "Efficiently computes derivatives of NumPy code")
810 (description "Autograd can automatically differentiate native Python and
811 NumPy code. It can handle a large subset of Python's features, including loops,
812 ifs, recursion and closures, and it can even take derivatives of derivatives
813 of derivatives. It supports reverse-mode differentiation
814 (a.k.a. backpropagation), which means it can efficiently take gradients of
815 scalar-valued functions with respect to array-valued arguments, as well as
816 forward-mode differentiation, and the two can be composed arbitrarily. The
817 main intended application of Autograd is gradient-based optimization.")
818 (license license:expat))))
819
820 (define-public python2-autograd
821 (package-with-python2 python-autograd))
822
823 (define-public lightgbm
824 (package
825 (name "lightgbm")
826 (version "2.0.12")
827 (source (origin
828 (method url-fetch)
829 (uri (string-append
830 "https://github.com/Microsoft/LightGBM/archive/v"
831 version ".tar.gz"))
832 (sha256
833 (base32
834 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
835 (file-name (string-append name "-" version ".tar.gz"))))
836 (native-inputs
837 `(("python-pytest" ,python-pytest)
838 ("python-nose" ,python-nose)))
839 (inputs
840 `(("openmpi" ,openmpi)))
841 (propagated-inputs
842 `(("python-numpy" ,python-numpy)
843 ("python-scipy" ,python-scipy)))
844 (arguments
845 `(#:configure-flags
846 '("-DUSE_MPI=ON")
847 #:phases
848 (modify-phases %standard-phases
849 (replace 'check
850 (lambda* (#:key outputs #:allow-other-keys)
851 (with-directory-excursion ,(string-append "../LightGBM-" version)
852 (invoke "pytest" "tests/c_api_test/test_.py")))))))
853 (build-system cmake-build-system)
854 (home-page "https://github.com/Microsoft/LightGBM")
855 (synopsis "Gradient boosting framework based on decision tree algorithms")
856 (description "LightGBM is a gradient boosting framework that uses tree
857 based learning algorithms. It is designed to be distributed and efficient with
858 the following advantages:
859
860 @itemize
861 @item Faster training speed and higher efficiency
862 @item Lower memory usage
863 @item Better accuracy
864 @item Parallel and GPU learning supported (not enabled in this package)
865 @item Capable of handling large-scale data
866 @end itemize\n")
867 (license license:expat)))
868
869 (define-public vowpal-wabbit
870 ;; Language bindings not included.
871 (package
872 (name "vowpal-wabbit")
873 (version "8.5.0")
874 (source (origin
875 (method url-fetch)
876 (uri (string-append
877 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
878 version ".tar.gz"))
879 (sha256
880 (base32
881 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
882 (file-name (string-append name "-" version ".tar.gz"))))
883 (inputs
884 `(("boost" ,boost)
885 ("zlib" ,zlib)))
886 (arguments
887 `(#:configure-flags
888 (list (string-append "--with-boost="
889 (assoc-ref %build-inputs "boost")))))
890 (build-system gnu-build-system)
891 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
892 (synopsis "Fast machine learning library for online learning")
893 (description "Vowpal Wabbit is a machine learning system with techniques
894 such as online, hashing, allreduce, reductions, learning2search, active, and
895 interactive learning.")
896 (license license:bsd-3)))
897
898 (define-public python2-fastlmm
899 (package
900 (name "python2-fastlmm")
901 (version "0.2.21")
902 (source
903 (origin
904 (method url-fetch)
905 (uri (pypi-uri "fastlmm" version ".zip"))
906 (sha256
907 (base32
908 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
909 (build-system python-build-system)
910 (arguments
911 `(#:tests? #f ; some test files are missing
912 #:python ,python-2)) ; only Python 2.7 is supported
913 (propagated-inputs
914 `(("python2-numpy" ,python2-numpy)
915 ("python2-scipy" ,python2-scipy)
916 ("python2-matplotlib" ,python2-matplotlib)
917 ("python2-pandas" ,python2-pandas)
918 ("python2-scikit-learn" ,python2-scikit-learn)
919 ("python2-pysnptools" ,python2-pysnptools)))
920 (native-inputs
921 `(("unzip" ,unzip)
922 ("python2-cython" ,python2-cython)
923 ("python2-mock" ,python2-mock)
924 ("python2-nose" ,python2-nose)))
925 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
926 (synopsis "Perform genome-wide association studies on large data sets")
927 (description
928 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
929 Models, is a program for performing both single-SNP and SNP-set genome-wide
930 association studies (GWAS) on extremely large data sets.")
931 (license license:asl2.0)))
932
933 ;; There have been no proper releases yet.
934 (define-public kaldi
935 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
936 (revision "1"))
937 (package
938 (name "kaldi")
939 (version (git-version "0" revision commit))
940 (source (origin
941 (method git-fetch)
942 (uri (git-reference
943 (url "https://github.com/kaldi-asr/kaldi.git")
944 (commit commit)))
945 (file-name (git-file-name name version))
946 (sha256
947 (base32
948 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
949 (build-system gnu-build-system)
950 (arguments
951 `(#:test-target "test"
952 #:phases
953 (modify-phases %standard-phases
954 (add-after 'unpack 'chdir
955 (lambda _ (chdir "src") #t))
956 (replace 'configure
957 (lambda* (#:key build system inputs outputs #:allow-other-keys)
958 (when (not (or (string-prefix? "x86_64" system)
959 (string-prefix? "i686" system)))
960 (substitute* "makefiles/linux_openblas.mk"
961 (("-msse -msse2") "")))
962 (substitute* "makefiles/default_rules.mk"
963 (("/bin/bash") (which "bash")))
964 (substitute* "Makefile"
965 (("ext_depend: check_portaudio")
966 "ext_depend:"))
967 (substitute* '("online/Makefile"
968 "onlinebin/Makefile"
969 "gst-plugin/Makefile")
970 (("../../tools/portaudio/install")
971 (assoc-ref inputs "portaudio")))
972
973 ;; This `configure' script doesn't support variables passed as
974 ;; arguments, nor does it support "prefix".
975 (let ((out (assoc-ref outputs "out"))
976 (openblas (assoc-ref inputs "openblas"))
977 (openfst (assoc-ref inputs "openfst")))
978 (substitute* "configure"
979 (("check_for_slow_expf;") "")
980 ;; This affects the RPATH and also serves as the installation
981 ;; directory.
982 (("KALDILIBDIR=`pwd`/lib")
983 (string-append "KALDILIBDIR=" out "/lib")))
984 (mkdir-p out) ; must exist
985 (setenv "CONFIG_SHELL" (which "bash"))
986 (setenv "OPENFST_VER" ,(package-version openfst))
987 (invoke "./configure"
988 "--use-cuda=no"
989 "--shared"
990 (string-append "--openblas-root=" openblas)
991 (string-append "--fst-root=" openfst)))))
992 (add-after 'build 'build-ext-and-gstreamer-plugin
993 (lambda _
994 (invoke "make" "-C" "online" "depend")
995 (invoke "make" "-C" "online")
996 (invoke "make" "-C" "onlinebin" "depend")
997 (invoke "make" "-C" "onlinebin")
998 (invoke "make" "-C" "gst-plugin" "depend")
999 (invoke "make" "-C" "gst-plugin")
1000 #t))
1001 ;; TODO: also install the executables.
1002 (replace 'install
1003 (lambda* (#:key outputs #:allow-other-keys)
1004 (let* ((out (assoc-ref outputs "out"))
1005 (lib (string-append out "/lib")))
1006 (mkdir-p lib)
1007 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so" lib)
1008 #t))))))
1009 (inputs
1010 `(("alsa-lib" ,alsa-lib)
1011 ("gfortran" ,gfortran "lib")
1012 ("glib" ,glib)
1013 ("gstreamer" ,gstreamer)
1014 ("jack" ,jack-1)
1015 ("openblas" ,openblas)
1016 ("openfst" ,openfst)
1017 ("portaudio" ,portaudio)
1018 ("python" ,python)))
1019 (native-inputs
1020 `(("glib" ,glib "bin") ; glib-genmarshal
1021 ("grep" ,grep)
1022 ("sed" ,sed)
1023 ("pkg-config" ,pkg-config)
1024 ("which" ,which)))
1025 (home-page "https://kaldi-asr.org/")
1026 (synopsis "Speech recognition toolkit")
1027 (description "Kaldi is an extensible toolkit for speech recognition
1028 written in C++.")
1029 (license license:asl2.0))))