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>
14 ;;; This file is part of GNU Guix.
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.
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.
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/>.
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 bash)
47 #:use-module (gnu packages boost)
48 #:use-module (gnu packages check)
49 #:use-module (gnu packages compression)
50 #:use-module (gnu packages cran)
51 #:use-module (gnu packages dejagnu)
52 #:use-module (gnu packages gcc)
53 #:use-module (gnu packages glib)
54 #:use-module (gnu packages gstreamer)
55 #:use-module (gnu packages image)
56 #:use-module (gnu packages linux)
57 #:use-module (gnu packages maths)
58 #:use-module (gnu packages mpi)
59 #:use-module (gnu packages ocaml)
60 #:use-module (gnu packages onc-rpc)
61 #:use-module (gnu packages perl)
62 #:use-module (gnu packages pkg-config)
63 #:use-module (gnu packages python)
64 #:use-module (gnu packages python-web)
65 #:use-module (gnu packages python-xyz)
66 #:use-module (gnu packages statistics)
67 #:use-module (gnu packages swig)
68 #:use-module (gnu packages web)
69 #:use-module (gnu packages xml)
70 #:use-module (gnu packages xorg))
73 ;; The last release is >100 commits behind, so we package from git.
74 (let ((commit "d71d54788bee56ba4cf7522801270152da5209d7"))
77 (version (string-append "2.2.0-1." (string-take commit 8)))
81 (url "https://github.com/libfann/fann.git")
83 (file-name (string-append name "-" version "-checkout"))
86 "0ibwpfrjs6q2lijs8slxjgzb2llcl6rk3v2ski4r6215g5jjhg3x"))))
87 (build-system cmake-build-system)
90 (modify-phases %standard-phases
92 (lambda* (#:key outputs #:allow-other-keys)
93 (let* ((out (assoc-ref outputs "out")))
94 (with-directory-excursion (string-append (getcwd) "/tests")
95 (invoke "./fann_tests"))))))))
96 (home-page "http://leenissen.dk/fann/wp/")
97 (synopsis "Fast Artificial Neural Network")
99 "FANN is a free open source neural network library, which implements
100 multilayer artificial neural networks in C with support for both fully
101 connected and sparsely connected networks.")
102 (license license:lgpl2.1))))
104 (define-public libsvm
111 (uri (string-append "https://www.csie.ntu.edu.tw/~cjlin/libsvm/"
112 name "-" version ".tar.gz"))
115 "0zd7s19y5vb7agczl6456bn45cj1y64739sslaskw1qk7dywd0bd"))))
116 (build-system gnu-build-system)
118 `(#:tests? #f ;no "check" target
119 #:phases (modify-phases %standard-phases
122 'install ; no ‘install’ target
123 (lambda* (#:key outputs #:allow-other-keys)
124 (let* ((out (assoc-ref outputs "out"))
125 (bin (string-append out "/bin/")))
127 (for-each (lambda (file)
128 (copy-file file (string-append bin file)))
133 (home-page "http://www.csie.ntu.edu.tw/~cjlin/libsvm/")
134 (synopsis "Library for Support Vector Machines")
136 "LIBSVM is a machine learning library for support vector
137 classification, (C-SVC, nu-SVC), regression (epsilon-SVR, nu-SVR) and
138 distribution estimation (one-class SVM). It supports multi-class
140 (license license:bsd-3)))
142 (define-public python-libsvm
143 (package (inherit libsvm)
144 (name "python-libsvm")
145 (build-system gnu-build-system)
147 `(#:tests? #f ;no "check" target
148 #:make-flags '("-C" "python")
150 (modify-phases %standard-phases
153 'install ; no ‘install’ target
154 (lambda* (#:key inputs outputs #:allow-other-keys)
155 (let ((site (string-append (assoc-ref outputs "out")
159 (assoc-ref inputs "python") 5) 3)
161 (substitute* "python/svm.py"
162 (("../libsvm.so.2") "libsvm.so.2"))
164 (for-each (lambda (file)
165 (copy-file file (string-append site (basename file))))
166 (find-files "python" "\\.py"))
167 (copy-file "libsvm.so.2"
168 (string-append site "libsvm.so.2")))
171 `(("python" ,python)))
172 (synopsis "Python bindings of libSVM")))
175 ;; The latest release candidate is several years and a couple of fixes have
176 ;; been published since. This is why we download the sources from the SVN
178 (let ((svn-revision 2341))
181 (version (string-append "0.9-rc3-0." (number->string svn-revision)))
185 (url "http://svn.code.sf.net/p/ghmm/code/trunk")
186 (revision svn-revision)))
187 (file-name (string-append name "-" version))
190 "0qbq1rqp94l530f043qzp8aw5lj7dng9wq0miffd7spd1ff638wq"))))
191 (build-system gnu-build-system)
193 `(#:imported-modules (,@%gnu-build-system-modules
194 (guix build python-build-system))
196 (modify-phases %standard-phases
197 (add-after 'unpack 'enter-dir
198 (lambda _ (chdir "ghmm") #t))
200 (add-after 'install 'check
201 (assoc-ref %standard-phases 'check))
202 (add-before 'check 'fix-PYTHONPATH
203 (lambda* (#:key inputs outputs #:allow-other-keys)
204 (let ((python-version ((@@ (guix build python-build-system)
206 (assoc-ref inputs "python"))))
208 (string-append (getenv "PYTHONPATH")
209 ":" (assoc-ref outputs "out")
210 "/lib/python" python-version
213 (add-after 'enter-dir 'fix-runpath
214 (lambda* (#:key outputs #:allow-other-keys)
215 (substitute* "ghmmwrapper/setup.py"
216 (("^(.*)extra_compile_args = \\[" line indent)
217 (string-append indent
218 "extra_link_args = [\"-Wl,-rpath="
219 (assoc-ref outputs "out") "/lib\"],\n"
222 (assoc-ref outputs "out")
225 (add-after 'enter-dir 'disable-broken-tests
227 (substitute* "tests/Makefile.am"
228 ;; GHMM_SILENT_TESTS is assumed to be a command.
229 (("TESTS_ENVIRONMENT.*") "")
230 ;; Do not build broken tests.
234 (("label_higher_order_test.*$")
235 "label_higher_order_test\n"))
237 ;; These Python unittests are broken as there is no gato.
238 ;; See https://sourceforge.net/p/ghmm/support-requests/3/
239 (substitute* "ghmmwrapper/ghmmunittests.py"
240 (("^(.*)def (testNewXML|testMultipleTransitionClasses|testNewXML)"
242 (string-append indent
243 "@unittest.skip(\"Disabled by Guix\")\n"
246 (add-after 'disable-broken-tests 'autogen
248 (invoke "bash" "autogen.sh"))))))
250 `(("python" ,python-2) ; only Python 2 is supported
251 ("libxml2" ,libxml2)))
253 `(("pkg-config" ,pkg-config)
256 ("autoconf" ,autoconf)
257 ("automake" ,automake)
258 ("libtool" ,libtool)))
259 (home-page "http://ghmm.org")
260 (synopsis "Hidden Markov Model library")
262 "The General Hidden Markov Model library (GHMM) is a C library with
263 additional Python bindings implementing a wide range of types of @dfn{Hidden
264 Markov Models} (HMM) and algorithms: discrete, continuous emissions, basic
265 training, HMM clustering, HMM mixtures.")
266 (license license:lgpl2.0+))))
275 "http://micans.org/mcl/src/mcl-"
276 (string-replace-substring version "." "-")
280 "15xlax3z31lsn62vlg94hkm75nm40q4679amnfg13jm8m2bnhy5m"))))
281 (build-system gnu-build-system)
283 `(#:configure-flags (list "--enable-blast")))
286 (home-page "http://micans.org/mcl/")
287 (synopsis "Clustering algorithm for graphs")
289 "The MCL algorithm is short for the @dfn{Markov Cluster Algorithm}, a
290 fast and scalable unsupervised cluster algorithm for graphs (also known as
291 networks) based on simulation of (stochastic) flow in graphs.")
292 ;; In the LICENCE file and web page it says "The software is licensed
293 ;; under the GNU General Public License, version 3.", but in several of
294 ;; the source code files it suggests GPL3 or later.
295 ;; http://listserver.ebi.ac.uk/pipermail/mcl-users/2016/000376.html
296 (license license:gpl3)))
298 (define-public ocaml-mcl
301 (version "12-068oasis4")
306 "https://github.com/fhcrc/mcl/archive/"
308 (file-name (string-append name "-" version ".tar.gz"))
311 "1l5jbhwjpsj38x8b9698hfpkv75h8hn3kj0gihjhn8ym2cwwv110"))))
312 (build-system ocaml-build-system)
314 `(#:ocaml ,ocaml-4.02
315 #:findlib ,ocaml4.02-findlib
317 (modify-phases %standard-phases
318 (add-before 'configure 'patch-paths
320 (substitute* "configure"
321 (("SHELL = /bin/sh") (string-append "SHELL = "(which "sh"))))
322 (substitute* "setup.ml"
324 (string-append "LDFLAGS=-fPIC\"; \"SHELL=" (which "sh"))))
326 (home-page "https://github.com/fhcrc/mcl")
327 (synopsis "OCaml wrappers around MCL")
329 "This package provides OCaml bindings for the MCL graph clustering
331 (license license:gpl3)))
333 (define-public randomjungle
335 (name "randomjungle")
341 "https://www.imbs.uni-luebeck.de/fileadmin/files/Software"
342 "/randomjungle/randomjungle-" version ".tar_.gz"))
343 (patches (search-patches "randomjungle-disable-static-build.patch"))
346 "12c8rf30cla71swx2mf4ww9mfd8jbdw5lnxd7dxhyw1ygrvg6y4w"))))
347 (build-system gnu-build-system)
350 (list "--disable-static"
351 (string-append "--with-boost="
352 (assoc-ref %build-inputs "boost")))
354 (modify-phases %standard-phases
356 'configure 'set-CXXFLAGS
358 (setenv "CXXFLAGS" "-fpermissive ")
366 `(("gfortran" ,gfortran)
367 ("gfortran:lib" ,gfortran "lib")))
368 ;; Non-portable assembly instructions are used so building fails on
369 ;; platforms other than x86_64 or i686.
370 (supported-systems '("x86_64-linux" "i686-linux"))
371 (home-page "https://www.imbs.uni-luebeck.de/forschung/software/details.html#c224")
372 (synopsis "Implementation of the Random Forests machine learning method")
374 "Random Jungle is an implementation of Random Forests. It is supposed to
375 analyse high dimensional data. In genetics, it can be used for analysing big
376 Genome Wide Association (GWA) data. Random Forests is a powerful machine
377 learning method. Most interesting features are variable selection, missing
378 value imputation, classifier creation, generalization error estimation and
379 sample proximities between pairs of cases.")
380 (license license:gpl3+)))
382 (define-public openfst
388 (uri (string-append "http://www.openfst.org/twiki/pub/FST/"
389 "FstDownload/openfst-" version ".tar.gz"))
392 "0x9wfcqd8hq4h349s7j77sr60h8xjdfshqw1m3a2n6z5bdr9qkm1"))))
393 (build-system gnu-build-system)
394 (home-page "http://www.openfst.org")
395 (synopsis "Library for weighted finite-state transducers")
396 (description "OpenFst is a library for constructing, combining,
397 optimizing, and searching weighted finite-state transducers (FSTs).")
398 (license license:asl2.0)))
400 (define-public shogun
408 "ftp://shogun-toolbox.org/shogun/releases/"
409 (version-major+minor version)
410 "/sources/shogun-" version ".tar.bz2"))
413 "1rn9skm3nw6hr7mr3lgp2gfqhi7ii0lyxck7qmqnf8avq349s5jp"))
414 (modules '((guix build utils)
418 ;; Remove non-free sources and files referencing them
419 (for-each delete-file
420 (find-files "src/shogun/classifier/svm/"
421 "SVMLight\\.(cpp|h)"))
422 (for-each delete-file
423 (find-files "examples/undocumented/libshogun/"
425 "(classifier_.*svmlight.*|"
426 "evaluation_cross_validation_locked_comparison).cpp")))
427 ;; Remove non-free functions.
428 (define (delete-ifdefs file)
429 (with-atomic-file-replacement file
431 (let loop ((line (read-line in 'concat))
433 (if (eof-object? line)
438 "#endif //USE_SVMLIGHT" line)))
440 "#ifdef USE_SVMLIGHT" line))))
441 (when (or (not skipping?)
442 (and skipping? (not skip-next?)))
444 (loop (read-line in 'concat) skip-next?)))))))
445 (for-each delete-ifdefs
447 (find-files "src/shogun/classifier/mkl"
448 "^MKLClassification\\.cpp")
449 (find-files "src/shogun/classifier/svm"
450 "^SVMLightOneClass\\.(cpp|h)")
451 (find-files "src/shogun/multiclass"
452 "^ScatterSVM\\.(cpp|h)")
453 (find-files "src/shogun/kernel/"
454 "^(Kernel|CombinedKernel|ProductKernel)\\.(cpp|h)")
455 (find-files "src/shogun/regression/svr"
456 "^(MKLRegression|SVRLight)\\.(cpp|h)")
457 (find-files "src/shogun/transfer/domain_adaptation"
458 "^DomainAdaptationSVM\\.(cpp|h)")))
460 (build-system cmake-build-system)
462 '(#:tests? #f ;no check target
464 (modify-phases %standard-phases
465 (add-after 'unpack 'delete-broken-symlinks
467 (for-each delete-file '("applications/arts/data"
468 "applications/asp/data"
469 "applications/easysvm/data"
470 "applications/msplicer/data"
471 "applications/ocr/data"
473 "examples/undocumented/data"))
475 (add-after 'unpack 'change-R-target-path
476 (lambda* (#:key outputs #:allow-other-keys)
477 (substitute* '("src/interfaces/r/CMakeLists.txt"
478 "examples/meta/r/CMakeLists.txt")
479 (("\\$\\{R_COMPONENT_LIB_PATH\\}")
480 (string-append (assoc-ref outputs "out")
483 (add-after 'unpack 'fix-octave-modules
484 (lambda* (#:key outputs #:allow-other-keys)
485 (substitute* "src/interfaces/octave/CMakeLists.txt"
486 (("^include_directories\\(\\$\\{OCTAVE_INCLUDE_DIRS\\}")
487 "include_directories(${OCTAVE_INCLUDE_DIRS} ${OCTAVE_INCLUDE_DIRS}/octave")
488 ;; change target directory
489 (("\\$\\{OCTAVE_OCT_LOCAL_API_FILE_DIR\\}")
490 (string-append (assoc-ref outputs "out")
491 "/share/octave/packages")))
492 (substitute* '("src/interfaces/octave/swig_typemaps.i"
493 "src/interfaces/octave/sg_print_functions.cpp")
494 ;; "octave/config.h" and "octave/oct-obj.h" deprecated in Octave.
495 (("octave/config\\.h") "octave/octave-config.h")
496 (("octave/oct-obj.h") "octave/ovl.h"))
498 (add-after 'unpack 'move-rxcpp
499 (lambda* (#:key inputs #:allow-other-keys)
500 (let ((rxcpp-dir "shogun/third-party/rxcpp"))
502 (install-file (assoc-ref inputs "rxcpp") rxcpp-dir)
504 (add-before 'build 'set-HOME
505 ;; $HOME needs to be set at some point during the build phase
506 (lambda _ (setenv "HOME" "/tmp") #t)))
508 (list "-DCMAKE_BUILD_WITH_INSTALL_RPATH=TRUE"
509 "-DUSE_SVMLIGHT=OFF" ;disable proprietary SVMLIGHT
510 "-DBUILD_META_EXAMPLES=OFF" ;requires unpackaged ctags
511 ;;"-DINTERFACE_JAVA=ON" ;requires unpackaged jblas
512 ;;"-DINTERFACE_RUBY=ON" ;requires unpackaged ruby-narray
513 ;;"-DINTERFACE_PERL=ON" ;"FindPerlLibs" does not exist
514 ;;"-DINTERFACE_LUA=ON" ;fails because lua doesn't build pkgconfig file
515 "-DINTERFACE_OCTAVE=ON"
516 "-DINTERFACE_PYTHON=ON"
517 "-DINTERFACE_R=ON")))
520 ("numpy" ,python-numpy)
521 ("r-minimal" ,r-minimal)
522 ("octave" ,octave-cli)
527 ("arpack" ,arpack-ng)
534 `(("pkg-config" ,pkg-config)
536 ;; Non-portable SSE instructions are used so building fails on platforms
537 ;; other than x86_64.
538 (supported-systems '("x86_64-linux"))
539 (home-page "http://shogun-toolbox.org/")
540 (synopsis "Machine learning toolbox")
542 "The Shogun Machine learning toolbox provides a wide range of unified and
543 efficient Machine Learning (ML) methods. The toolbox seamlessly allows to
544 combine multiple data representations, algorithm classes, and general purpose
545 tools. This enables both rapid prototyping of data pipelines and extensibility
546 in terms of new algorithms.")
547 (license license:gpl3+)))
556 (uri (string-append "https://github.com/ReactiveX/RxCpp/archive/v"
560 "0y2isr8dy2n1yjr9c5570kpc9lvdlch6jv0jvw000amwn5d3krsh"))
561 (file-name (string-append name "-" version ".tar.gz"))))
562 (build-system cmake-build-system)
565 (modify-phases %standard-phases
566 (add-after 'unpack 'remove-werror
568 (substitute* (find-files ".")
573 (invoke "ctest"))))))
575 `(("catch" ,catch-framework)))
576 (home-page "http://reactivex.io/")
577 (synopsis "Reactive Extensions for C++")
579 "The Reactive Extensions for C++ (RxCpp) is a library of algorithms for
580 values-distributed-in-time. ReactiveX is a library for composing asynchronous
581 and event-based programs by using observable sequences.
583 It extends the observer pattern to support sequences of data and/or events and
584 adds operators that allow you to compose sequences together declaratively while
585 abstracting away concerns about things like low-level threading,
586 synchronization, thread-safety, concurrent data structures, and non-blocking
588 (license license:asl2.0)))
590 (define-public r-adaptivesparsity
592 (name "r-adaptivesparsity")
596 (uri (cran-uri "AdaptiveSparsity" version))
599 "0imr5m8mll9j6n4icsv6z9rl5kbnwsp9wvzrg7n90nnmcxq2cz91"))))
601 `((upstream-name . "AdaptiveSparsity")))
602 (build-system r-build-system)
605 (modify-phases %standard-phases
606 (add-after 'unpack 'link-against-armadillo
608 (substitute* "src/Makevars"
609 (("PKG_LIBS=" prefix)
610 (string-append prefix "-larmadillo"))))))))
613 ("r-matrix" ,r-matrix)
615 ("r-rcpparmadillo" ,r-rcpparmadillo)))
617 `(("armadillo" ,armadillo)))
618 (home-page "https://cran.r-project.org/web/packages/AdaptiveSparsity")
619 (synopsis "Adaptive sparsity models")
621 "This package implements the Figueiredo machine learning algorithm for
622 adaptive sparsity and the Wong algorithm for adaptively sparse gaussian
624 (license license:lgpl3+)))
626 (define-public r-kernlab
633 (uri (cran-uri "kernlab" version))
636 "1m0xqf6gyvwayz7w3c83y32ayvnlz0jicj8ijk808zq9sh7dbbgn"))))
637 (build-system r-build-system)
638 (home-page "https://cran.r-project.org/web/packages/kernlab")
639 (synopsis "Kernel-based machine learning tools")
641 "This package provides kernel-based machine learning methods for
642 classification, regression, clustering, novelty detection, quantile regression
643 and dimensionality reduction. Among other methods @code{kernlab} includes
644 Support Vector Machines, Spectral Clustering, Kernel PCA, Gaussian Processes
646 (license license:gpl2)))
655 "http://dlib.net/files/dlib-" version ".tar.bz2"))
658 "1mljz02kwkrbggyncxv5fpnyjdybw2qihaacb3js8yfkw12vwpc2"))
659 (modules '((guix build utils)))
662 ;; Delete ~13MB of bundled dependencies.
663 (delete-file-recursively "dlib/external")
664 (delete-file-recursively "docs/dlib/external")
666 (build-system cmake-build-system)
669 (modify-phases %standard-phases
670 (add-after 'unpack 'disable-asserts
672 ;; config.h recommends explicitly enabling or disabling asserts
673 ;; when building as a shared library. By default neither is set.
674 (substitute* "dlib/config.h"
675 (("^//#define DLIB_DISABLE_ASSERTS") "#define DLIB_DISABLE_ASSERTS"))
677 (add-after 'disable-asserts 'disable-failing-tests
679 ;; One test times out on MIPS, so we need to disable it.
680 ;; Others are flaky on some platforms.
681 (let* ((system ,(or (%current-target-system)
683 (disabled-tests (cond
684 ((string-prefix? "mips64" system)
685 '("object_detector" ; timeout
687 ((string-prefix? "armhf" system)
688 '("learning_to_track"))
689 ((string-prefix? "i686" system)
694 (substitute* "dlib/test/makefile"
695 (((string-append "SRC \\+= " test "\\.cpp")) "")))
700 ;; No test target, so we build and run the unit tests here.
701 (let ((test-dir (string-append "../dlib-" ,version "/dlib/test")))
702 (with-directory-excursion test-dir
703 (invoke "make" "-j" (number->string (parallel-job-count)))
704 (invoke "./dtest" "--runall"))
706 (add-after 'install 'delete-static-library
707 (lambda* (#:key outputs #:allow-other-keys)
708 (delete-file (string-append (assoc-ref outputs "out")
712 `(("pkg-config" ,pkg-config)
721 ("openblas" ,openblas)
724 "Toolkit for making machine learning and data analysis applications in C++")
726 "Dlib is a modern C++ toolkit containing machine learning algorithms and
727 tools. It is used in both industry and academia in a wide range of domains
728 including robotics, embedded devices, mobile phones, and large high performance
729 computing environments.")
730 (home-page "http://dlib.net")
731 (license license:boost1.0)))
733 (define-public python-scikit-learn
735 (name "python-scikit-learn")
741 (url "https://github.com/scikit-learn/scikit-learn.git")
743 (file-name (git-file-name name version))
746 "0fkhwg3xn1s7ln9q1szq6kwc4jhwvjh8w4kmv9wcrqy7cq3lbv0d"))))
747 (build-system python-build-system)
750 (modify-phases %standard-phases
751 (add-after 'build 'build-ext
752 (lambda _ (invoke "python" "setup.py" "build_ext" "--inplace") #t))
755 ;; Restrict OpenBLAS threads to prevent segfaults while testing!
756 (setenv "OPENBLAS_NUM_THREADS" "1")
758 ;; Some tests require write access to $HOME.
759 (setenv "HOME" "/tmp")
761 (invoke "pytest" "sklearn" "-m" "not network")))
762 ;; FIXME: This fails with permission denied
763 (delete 'reset-gzip-timestamps))))
765 `(("openblas" ,openblas)))
767 `(("python-pytest" ,python-pytest)
768 ("python-pandas" ,python-pandas) ;for tests
769 ("python-cython" ,python-cython)))
771 `(("python-numpy" ,python-numpy)
772 ("python-scipy" ,python-scipy)))
773 (home-page "http://scikit-learn.org/")
774 (synopsis "Machine Learning in Python")
776 "Scikit-learn provides simple and efficient tools for data mining and
778 (license license:bsd-3)))
780 (define-public python2-scikit-learn
781 (package-with-python2 python-scikit-learn))
783 (define-public python-autograd
784 (let* ((commit "442205dfefe407beffb33550846434baa90c4de7")
786 (version (git-version "0.0.0" revision commit)))
788 (name "python-autograd")
789 (home-page "https://github.com/HIPS/autograd")
797 "189sv2xb0mwnjawa9z7mrgdglc1miaq93pnck26r28fi1jdwg0z4"))
798 (file-name (git-file-name name version))))
800 (build-system python-build-system)
802 `(("python-nose" ,python-nose)
803 ("python-pytest" ,python-pytest)))
805 `(("python-future" ,python-future)
806 ("python-numpy" ,python-numpy)))
808 `(#:phases (modify-phases %standard-phases
811 (invoke "py.test" "-v"))))))
812 (synopsis "Efficiently computes derivatives of NumPy code")
813 (description "Autograd can automatically differentiate native Python and
814 NumPy code. It can handle a large subset of Python's features, including loops,
815 ifs, recursion and closures, and it can even take derivatives of derivatives
816 of derivatives. It supports reverse-mode differentiation
817 (a.k.a. backpropagation), which means it can efficiently take gradients of
818 scalar-valued functions with respect to array-valued arguments, as well as
819 forward-mode differentiation, and the two can be composed arbitrarily. The
820 main intended application of Autograd is gradient-based optimization.")
821 (license license:expat))))
823 (define-public python2-autograd
824 (package-with-python2 python-autograd))
826 (define-public lightgbm
833 "https://github.com/Microsoft/LightGBM/archive/v"
837 "132zf0yk0545mg72hyzxm102g3hpb6ixx9hnf8zd2k55gas6cjj1"))
838 (file-name (string-append name "-" version ".tar.gz"))))
840 `(("python-pytest" ,python-pytest)
841 ("python-nose" ,python-nose)))
843 `(("openmpi" ,openmpi)))
845 `(("python-numpy" ,python-numpy)
846 ("python-scipy" ,python-scipy)))
851 (modify-phases %standard-phases
853 (lambda* (#:key outputs #:allow-other-keys)
854 (with-directory-excursion ,(string-append "../LightGBM-" version)
855 (invoke "pytest" "tests/c_api_test/test_.py")))))))
856 (build-system cmake-build-system)
857 (home-page "https://github.com/Microsoft/LightGBM")
858 (synopsis "Gradient boosting framework based on decision tree algorithms")
859 (description "LightGBM is a gradient boosting framework that uses tree
860 based learning algorithms. It is designed to be distributed and efficient with
861 the following advantages:
864 @item Faster training speed and higher efficiency
865 @item Lower memory usage
866 @item Better accuracy
867 @item Parallel and GPU learning supported (not enabled in this package)
868 @item Capable of handling large-scale data
870 (license license:expat)))
872 (define-public vowpal-wabbit
873 ;; Language bindings not included.
875 (name "vowpal-wabbit")
880 "https://github.com/JohnLangford/vowpal_wabbit/archive/"
884 "0clp2kb7rk5sckhllxjr5a651awf4s8dgzg4659yh4hf5cqnf0gr"))
885 (file-name (string-append name "-" version ".tar.gz"))))
891 (list (string-append "--with-boost="
892 (assoc-ref %build-inputs "boost")))))
893 (build-system gnu-build-system)
894 (home-page "https://github.com/JohnLangford/vowpal_wabbit")
895 (synopsis "Fast machine learning library for online learning")
896 (description "Vowpal Wabbit is a machine learning system with techniques
897 such as online, hashing, allreduce, reductions, learning2search, active, and
898 interactive learning.")
899 (license license:bsd-3)))
901 (define-public python2-fastlmm
903 (name "python2-fastlmm")
908 (uri (pypi-uri "fastlmm" version ".zip"))
911 "1q8c34rpmwkfy3r4d5172pzdkpfryj561897z9r3x22gq7813x1m"))))
912 (build-system python-build-system)
914 `(#:tests? #f ; some test files are missing
915 #:python ,python-2)) ; only Python 2.7 is supported
917 `(("python2-numpy" ,python2-numpy)
918 ("python2-scipy" ,python2-scipy)
919 ("python2-matplotlib" ,python2-matplotlib)
920 ("python2-pandas" ,python2-pandas)
921 ("python2-scikit-learn" ,python2-scikit-learn)
922 ("python2-pysnptools" ,python2-pysnptools)))
925 ("python2-cython" ,python2-cython)
926 ("python2-mock" ,python2-mock)
927 ("python2-nose" ,python2-nose)))
928 (home-page "http://research.microsoft.com/en-us/um/redmond/projects/mscompbio/fastlmm/")
929 (synopsis "Perform genome-wide association studies on large data sets")
931 "FaST-LMM, which stands for Factored Spectrally Transformed Linear Mixed
932 Models, is a program for performing both single-SNP and SNP-set genome-wide
933 association studies (GWAS) on extremely large data sets.")
934 (license license:asl2.0)))
936 ;; There have been no proper releases yet.
938 (let ((commit "2f95609f0bb085bd3a1dc5eb0a39f3edea59e606")
942 (version (git-version "0" revision commit))
946 (url "https://github.com/kaldi-asr/kaldi.git")
948 (file-name (git-file-name name version))
951 "082qh3pfi7hvncylp4xsmkfahbd7gb0whdfa4rwrx7fxk9rdh3kz"))))
952 (build-system gnu-build-system)
954 `(#:test-target "test"
956 (modify-phases %standard-phases
957 (add-after 'unpack 'chdir
958 (lambda _ (chdir "src") #t))
960 (lambda* (#:key build system inputs outputs #:allow-other-keys)
961 (when (not (or (string-prefix? "x86_64" system)
962 (string-prefix? "i686" system)))
963 (substitute* "makefiles/linux_openblas.mk"
964 (("-msse -msse2") "")))
965 (substitute* "makefiles/default_rules.mk"
966 (("/bin/bash") (which "bash")))
967 (substitute* "Makefile"
968 (("ext_depend: check_portaudio")
970 (substitute* '("online/Makefile"
972 "gst-plugin/Makefile")
973 (("../../tools/portaudio/install")
974 (assoc-ref inputs "portaudio")))
976 ;; This `configure' script doesn't support variables passed as
977 ;; arguments, nor does it support "prefix".
978 (let ((out (assoc-ref outputs "out"))
979 (openblas (assoc-ref inputs "openblas"))
980 (openfst (assoc-ref inputs "openfst")))
981 (substitute* "configure"
982 (("check_for_slow_expf;") "")
983 ;; This affects the RPATH and also serves as the installation
985 (("KALDILIBDIR=`pwd`/lib")
986 (string-append "KALDILIBDIR=" out "/lib")))
987 (mkdir-p out) ; must exist
988 (setenv "CONFIG_SHELL" (which "bash"))
989 (setenv "OPENFST_VER" ,(package-version openfst))
990 (invoke "./configure"
993 (string-append "--openblas-root=" openblas)
994 (string-append "--fst-root=" openfst)))))
995 (add-after 'build 'build-ext-and-gstreamer-plugin
997 (invoke "make" "-C" "online" "depend")
998 (invoke "make" "-C" "online")
999 (invoke "make" "-C" "onlinebin" "depend")
1000 (invoke "make" "-C" "onlinebin")
1001 (invoke "make" "-C" "gst-plugin" "depend")
1002 (invoke "make" "-C" "gst-plugin")
1004 ;; TODO: also install the executables.
1006 (lambda* (#:key outputs #:allow-other-keys)
1007 (let* ((out (assoc-ref outputs "out"))
1008 (inc (string-append out "/include"))
1009 (lib (string-append out "/lib")))
1011 ;; The build phase installed symlinks to the actual
1012 ;; libraries. Install the actual targets.
1013 (for-each (lambda (file)
1014 (let ((target (readlink file)))
1016 (install-file target lib)))
1017 (find-files lib "\\.so"))
1019 (for-each (lambda (file)
1020 (let ((target-dir (string-append inc "/" (dirname file))))
1021 (install-file file target-dir)))
1022 (find-files "." "\\.h"))
1023 (install-file "gst-plugin/libgstonlinegmmdecodefaster.so"
1024 (string-append lib "/gstreamer-1.0"))
1027 `(("alsa-lib" ,alsa-lib)
1028 ("gfortran" ,gfortran "lib")
1030 ("gstreamer" ,gstreamer)
1032 ("openblas" ,openblas)
1033 ("openfst" ,openfst)
1034 ("portaudio" ,portaudio)
1035 ("python" ,python)))
1037 `(("glib" ,glib "bin") ; glib-genmarshal
1040 ("pkg-config" ,pkg-config)
1042 (home-page "https://kaldi-asr.org/")
1043 (synopsis "Speech recognition toolkit")
1044 (description "Kaldi is an extensible toolkit for speech recognition
1046 (license license:asl2.0))))
1048 (define-public gst-kaldi-nnet2-online
1049 (let ((commit "617e43e73c7cc45eb9119028c02bd4178f738c4a")
1052 (name "gst-kaldi-nnet2-online")
1053 (version (git-version "0" revision commit))
1057 (url "https://github.com/alumae/gst-kaldi-nnet2-online.git")
1059 (file-name (git-file-name name version))
1062 "0xh3w67b69818s6ib02ara4lw7wamjdmh4jznvkpzrs4skbs9jx9"))))
1063 (build-system gnu-build-system)
1065 `(#:tests? #f ; there are none
1067 (list (string-append "SHELL="
1068 (assoc-ref %build-inputs "bash") "/bin/bash")
1069 (string-append "KALDI_ROOT="
1070 (assoc-ref %build-inputs "kaldi-src"))
1071 (string-append "KALDILIBDIR="
1072 (assoc-ref %build-inputs "kaldi") "/lib")
1073 "KALDI_FLAVOR=dynamic")
1075 (modify-phases %standard-phases
1076 (add-after 'unpack 'chdir
1077 (lambda _ (chdir "src") #t))
1079 (lambda* (#:key inputs #:allow-other-keys)
1080 (let ((glib (assoc-ref inputs "glib")))
1081 (setenv "CXXFLAGS" "-std=c++11 -fPIC")
1082 (setenv "CPLUS_INCLUDE_PATH"
1083 (string-append glib "/include/glib-2.0:"
1084 glib "/lib/glib-2.0/include:"
1085 (assoc-ref inputs "gstreamer")
1086 "/include/gstreamer-1.0:"
1087 (getenv "CPLUS_INCLUDE_PATH"))))
1088 (substitute* "Makefile"
1089 (("include \\$\\(KALDI_ROOT\\)/src/kaldi.mk") "")
1090 (("\\$\\(error Cannot find") "#"))))
1091 (add-before 'build 'build-depend
1092 (lambda* (#:key make-flags #:allow-other-keys)
1093 (apply invoke "make" "depend" make-flags)))
1095 (lambda* (#:key outputs #:allow-other-keys)
1096 (let* ((out (assoc-ref outputs "out"))
1097 (lib (string-append out "/lib/gstreamer-1.0")))
1098 (install-file "libgstkaldinnet2onlinedecoder.so" lib)
1102 ("gstreamer" ,gstreamer)
1103 ("jansson" ,jansson)
1104 ("openfst" ,openfst)
1108 ("glib:bin" ,glib "bin") ; glib-genmarshal
1109 ("kaldi-src" ,(package-source kaldi))
1110 ("pkg-config" ,pkg-config)))
1111 (home-page "https://kaldi-asr.org/")
1112 (synopsis "Gstreamer plugin for decoding speech")
1113 (description "This package provides a GStreamer plugin that wraps
1114 Kaldi's @code{SingleUtteranceNnet2Decoder}. It requires iVector-adapted DNN
1115 acoustic models. The iVectors are adapted to the current audio stream
1117 (license license:asl2.0))))
1119 (define-public kaldi-gstreamer-server
1120 (let ((commit "1735ba49c5dc0ebfc184e45105fc600cd9f1f508")
1123 (name "kaldi-gstreamer-server")
1124 (version (git-version "0" revision commit))
1128 (url "https://github.com/alumae/kaldi-gstreamer-server.git")
1130 (file-name (git-file-name name version))
1133 "0j701m7lbwmzqxsfanj882v7881hrbmpqybbczbxqpcbg8q34w0k"))))
1134 (build-system gnu-build-system)
1136 `(#:tests? #f ; there are no tests that can be run automatically
1137 #:modules ((guix build utils)
1138 (guix build gnu-build-system)
1141 (modify-phases %standard-phases
1144 (lambda* (#:key outputs #:allow-other-keys)
1145 ;; Disable hash randomization to ensure the generated .pycs
1146 ;; are reproducible.
1147 (setenv "PYTHONHASHSEED" "0")
1148 (with-directory-excursion "kaldigstserver"
1149 (for-each (lambda (file)
1153 "-f" ; force rebuild
1155 (find-files "." "\\.py$")))
1158 (lambda* (#:key inputs outputs #:allow-other-keys)
1159 (let* ((out (assoc-ref outputs "out"))
1160 (bin (string-append out "/bin"))
1161 (share (string-append out "/share/kaldi-gstreamer-server/")))
1162 ;; Install Python files
1163 (with-directory-excursion "kaldigstserver"
1164 (for-each (cut install-file <> share)
1165 (find-files "." ".*")))
1167 ;; Install sample configuration files
1168 (for-each (cut install-file <> share)
1169 (find-files "." "\\.yaml"))
1171 ;; Install executables
1173 (let* ((server (string-append bin "/kaldi-gst-server"))
1174 (client (string-append bin "/kaldi-gst-client"))
1175 (worker (string-append bin "/kaldi-gst-worker"))
1176 (PYTHONPATH (getenv "PYTHONPATH"))
1177 (GST_PLUGIN_PATH (string-append
1178 (assoc-ref inputs "gst-kaldi-nnet2-online")
1179 "/lib/gstreamer-1.0:${GST_PLUGIN_PATH}"))
1180 (wrap (lambda (wrapper what)
1181 (with-output-to-file wrapper
1185 export PYTHONPATH=~a
1186 export GST_PLUGIN_PATH=~a
1187 exec ~a ~a/~a \"$@\"~%"
1188 (which "bash") PYTHONPATH GST_PLUGIN_PATH
1189 (which "python") share what)))
1190 (chmod wrapper #o555))))
1192 (list server client worker)
1193 (list "master_server.py"
1198 `(("gst-kaldi-nnet2-online" ,gst-kaldi-nnet2-online)
1199 ("python2" ,python-2)
1200 ("python2-futures" ,python2-futures)
1201 ("python2-pygobject" ,python2-pygobject)
1202 ("python2-pyyaml" ,python2-pyyaml)
1203 ("python2-tornado" ,python2-tornado)
1204 ("python2-ws4py" ,python2-ws4py-for-kaldi-gstreamer-server)))
1205 (home-page "https://github.com/alumae/kaldi-gstreamer-server")
1206 (synopsis "Real-time full-duplex speech recognition server")
1207 (description "This is a real-time full-duplex speech recognition server,
1208 based on the Kaldi toolkit and the GStreamer framework and implemented in
1210 (license license:bsd-2))))